From e08aa2356df939b2dba56cc7142254fe28b887c3 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sat, 1 Jun 2024 08:06:44 +0100 Subject: [PATCH 1/6] Use fsp for promises --- .../file/copyMoveFolderContent/1.0.0/index.ts | 4 ++-- .../file/copyToDirectory/1.0.0/index.ts | 4 ++-- .../file/copyToWorkDirectory/1.0.0/index.ts | 4 ++-- .../file/deleteFile/1.0.0/index.ts | 11 ++++++----- .../handbrake/handbrakeCustomArguments/1.0.0/index.ts | 4 ++-- .../handbrake/handbrakeCustomArguments/2.0.0/index.ts | 4 ++-- .../input/inputFile/1.0.0/index.ts | 6 +++--- FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts | 4 ++-- FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts | 8 ++++---- FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts | 4 ++-- 10 files changed, 27 insertions(+), 26 deletions(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/copyMoveFolderContent/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/copyMoveFolderContent/1.0.0/index.ts index 3d2ed097e..ca4615f25 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/copyMoveFolderContent/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/copyMoveFolderContent/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getContainer, getFileAbosluteDir, getSubStem, } from '../../../../FlowHelpers/1.0.0/fileUtils'; @@ -188,7 +188,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { sourceDir = getFileAbosluteDir(args.inputFileObj._id); } - let filesInDir = (await fs.readdir(sourceDir)) + let filesInDir = (await fsp.readdir(sourceDir)) .map((row) => ({ source: `${sourceDir}/${row}`, destination: normJoinPath({ diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/copyToDirectory/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/copyToDirectory/1.0.0/index.ts index 6d198602b..a5bf4fd2d 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/copyToDirectory/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/copyToDirectory/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getContainer, getFileName, getSubStem } from '../../../../FlowHelpers/1.0.0/fileUtils'; import { IpluginDetails, @@ -126,7 +126,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { args.deps.fsextra.ensureDirSync(outputPath); - await fs.copyFile(args.inputFileObj._id, ouputFilePath); + await fsp.copyFile(args.inputFileObj._id, ouputFilePath); return { outputFileObj: { diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index.ts index 04458d1f8..00f8b2270 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils'; import { IpluginDetails, @@ -67,7 +67,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { args.deps.fsextra.ensureDirSync(outputPath); - await fs.copyFile(args.inputFileObj._id, ouputFilePath); + await fsp.copyFile(args.inputFileObj._id, ouputFilePath); return { outputFileObj: { diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts index 1969c22f0..e403d9ca9 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/deleteFile/1.0.0/index.ts @@ -1,4 +1,5 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; + import { IpluginDetails, IpluginInputArgs, @@ -64,21 +65,21 @@ const plugin = async (args: IpluginInputArgs): Promise => { if (fileToDelete === 'workingFile') { args.jobLog(`Deleting working file ${args.inputFileObj._id}`); - await fs.unlink(args.inputFileObj._id); + await fsp.unlink(args.inputFileObj._id); } else if (fileToDelete === 'originalFile') { args.jobLog(`Deleting original file ${args.originalLibraryFile._id}`); - await fs.unlink(args.originalLibraryFile._id); + await fsp.unlink(args.originalLibraryFile._id); } const fileDir = getFileAbosluteDir(args.originalLibraryFile._id); if (deleteParentFolderIfEmpty) { args.jobLog(`Checking if folder ${fileDir} is empty`); - const files = await fs.readdir(fileDir); + const files = await fsp.readdir(fileDir); if (files.length === 0) { args.jobLog(`Deleting empty folder ${fileDir}`); - await fs.rmdir(fileDir); + await fsp.rmdir(fileDir); } else { args.jobLog(`Folder ${fileDir} is not empty, skipping delete`); } diff --git a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts index 1b97c8721..e44dd1b15 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils'; import { IpluginDetails, @@ -99,7 +99,7 @@ const plugin = async (args:IpluginInputArgs):Promise => { if (presetString.trim() !== '') { const preset = JSON.parse(presetString); - await fs.writeFile(presetPath, JSON.stringify(preset, null, 2)); + await fsp.writeFile(presetPath, JSON.stringify(preset, null, 2)); cliArgs.push('--preset-import-file'); cliArgs.push(presetPath); cliArgs.push('-Z'); diff --git a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts index 6ac4355c4..546517bf9 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/handbrake/handbrakeCustomArguments/2.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils'; import { IpluginDetails, @@ -142,7 +142,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { if (useJsonPreset) { const preset = JSON.parse(presetString); - await fs.writeFile(presetPath, JSON.stringify(preset, null, 2)); + await fsp.writeFile(presetPath, JSON.stringify(preset, null, 2)); cliArgs.push('--preset-import-file'); cliArgs.push(presetPath); cliArgs.push('-Z'); diff --git a/FlowPluginsTs/CommunityFlowPlugins/input/inputFile/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/input/inputFile/1.0.0/index.ts index 0dc18a081..b6b220e2e 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/input/inputFile/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/input/inputFile/1.0.0/index.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { IpluginDetails, @@ -86,7 +86,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { const checkReadWrite = async (location: string) => { try { - await fs.access(location, fs.constants.R_OK); + await fsp.access(location, fsp.constants.R_OK); } catch (err) { args.jobLog(JSON.stringify(err)); if (pauseNodeIfAccessChecksFail) { @@ -97,7 +97,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { } try { - await fs.access(location, fs.constants.W_OK); + await fsp.access(location, fsp.constants.W_OK); } catch (err) { args.jobLog(JSON.stringify(err)); if (pauseNodeIfAccessChecksFail) { diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts b/FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts index 5ccf331b7..22ee25caf 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getContainer, getFileName, getPluginWorkDir, getScanTypes, } from './fileUtils'; @@ -43,7 +43,7 @@ export const runClassicPlugin = async (args:IpluginInputArgs, type:'filter'|'tra let pluginSrcStr = ''; if (pluginSource === 'Community') { classicPlugin = args.deps.importFresh(relativePluginPath); - pluginSrcStr = await fs.readFile(absolutePath, 'utf8'); + pluginSrcStr = await fsp.readFile(absolutePath, 'utf8'); } else { // eslint-disable-next-line no-await-in-loop const res = await args.deps.axiosMiddleware('api/v2/read-plugin', { diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts b/FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts index d3a487153..809d55889 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/fileMoveOrCopy.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { getFileSize } from './fileUtils'; import { IpluginInputArgs } from './interfaces/interfaces'; @@ -48,7 +48,7 @@ const tryMove = async ({ let error = false; try { - await fs.rename(sourcePath, destinationPath); + await fsp.rename(sourcePath, destinationPath); } catch (err) { error = true; args.jobLog(`File move error: ${JSON.stringify(err)}`); @@ -157,7 +157,7 @@ const tryNormalCopy = async ({ let error = false; try { - await fs.copyFile(sourcePath, destinationPath); + await fsp.copyFile(sourcePath, destinationPath); } catch (err) { error = true; args.jobLog(`File copy error: ${JSON.stringify(err)}`); @@ -186,7 +186,7 @@ const cleanSourceFile = async ({ }) => { try { args.jobLog(`Deleting source file ${sourcePath}`); - await fs.unlink(sourcePath); + await fsp.unlink(sourcePath); } catch (err) { args.jobLog(`Failed to delete source file ${sourcePath}: ${JSON.stringify(err)}`); } diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts b/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts index a7f4cfeba..9879e7ad0 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'fs'; +import { promises as fsp } from 'fs'; import { IpluginInputArgs } from './interfaces/interfaces'; export const getContainer = (filePath: string): string => { @@ -37,7 +37,7 @@ export const getSubStem = ({ }; export const getFileSize = async (file:string):Promise => { - const stats = await fs.stat(file); + const stats = await fsp.stat(file); const { size } = stats; return size; }; From 99160eadb3d74bbe01705ba14c0b14196b38d168 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sat, 1 Jun 2024 08:10:05 +0100 Subject: [PATCH 2/6] Ensure es6 import --- .../file/replaceOriginalFile/1.0.0/index.ts | 2 +- .../CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts | 3 +-- FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts | 5 +++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts index bd66ba3cb..41030685e 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts @@ -1,3 +1,4 @@ +import fs from 'fs'; import fileMoveOrCopy from '../../../../FlowHelpers/1.0.0/fileMoveOrCopy'; import { getContainer, getFileAbosluteDir, getFileName, @@ -32,7 +33,6 @@ const details = (): IpluginDetails => ({ // eslint-disable-next-line @typescript-eslint/no-unused-vars const plugin = async (args: IpluginInputArgs): Promise => { - const fs = require('fs'); const lib = require('../../../../../methods/lib')(); // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts index 14b7d1e8b..04806c481 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts @@ -1,3 +1,4 @@ +import fs from 'fs'; import { IpluginDetails, IpluginInputArgs, @@ -51,8 +52,6 @@ const plugin = (args:IpluginInputArgs):IpluginOutputArgs => { // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); - const fs = require('fs'); - const oldFile = args.inputFileObj._id; const newFile = `${args.inputFileObj._id}.tmp`; diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts index 4bb36cbf7..56355e0c5 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts @@ -1,11 +1,10 @@ +import fs from 'fs'; import { editreadyParser, ffmpegParser, getHandBrakeFps, handbrakeParser, } from './cliParsers'; import { Ilog, IupdateWorker } from './interfaces/interfaces'; import { IFileObject, Istreams } from './interfaces/synced/IFileObject'; -const fs = require('fs'); - const fancyTimeFormat = (time: number) => { // Hours, minutes and seconds @@ -127,7 +126,9 @@ class CLI { try { if (fs.existsSync(this.config.outputFilePath)) { let singleFileSize = fs.statSync(this.config.outputFilePath); + // @ts-expect-error type singleFileSize = singleFileSize.size; + // @ts-expect-error type outputFileSizeInGbytes = singleFileSize / (1024 * 1024 * 1024); if (outputFileSizeInGbytes !== this.oldOutSize) { From 28192d77231460c53bcd6a2444c8bc7ba855f20b Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sat, 1 Jun 2024 08:27:41 +0100 Subject: [PATCH 3/6] Use async fileExists --- .../file/checkFileExists/1.0.0/index.ts | 15 ++++++++------- .../file/replaceOriginalFile/1.0.0/index.ts | 3 ++- .../video/transcodeVideo/1.0.0/index.ts | 5 +++-- FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts | 11 ++++++----- FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts | 2 ++ 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileExists/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileExists/1.0.0/index.ts index a16c39c4b..de26096f0 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/checkFileExists/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/checkFileExists/1.0.0/index.ts @@ -1,5 +1,6 @@ -import fs from 'fs'; -import { getContainer, getFileAbosluteDir, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils'; +import { + fileExists, getContainer, getFileAbosluteDir, getFileName, +} from '../../../../FlowHelpers/1.0.0/fileUtils'; import { IpluginDetails, IpluginInputArgs, @@ -57,7 +58,7 @@ const details = (): IpluginDetails => ({ }); // eslint-disable-next-line @typescript-eslint/no-unused-vars -const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { +const plugin = async (args: IpluginInputArgs): Promise => { const lib = require('../../../../../methods/lib')(); // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); @@ -71,9 +72,9 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { fileToCheck = fileToCheck.replace(/\${container}/g, getContainer(args.inputFileObj._id)); fileToCheck = `${directory}/${fileToCheck}`; - let fileExists = false; - if (fs.existsSync(fileToCheck)) { - fileExists = true; + let fileDoesExist = false; + if (await fileExists(fileToCheck)) { + fileDoesExist = true; args.jobLog(`File exists: ${fileToCheck}`); } else { args.jobLog(`File does not exist: ${fileToCheck}`); @@ -81,7 +82,7 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => { return { outputFileObj: args.inputFileObj, - outputNumber: fileExists ? 1 : 2, + outputNumber: fileDoesExist ? 1 : 2, variables: args.variables, }; }; diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts index 41030685e..d84bacd82 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts @@ -1,6 +1,7 @@ import fs from 'fs'; import fileMoveOrCopy from '../../../../FlowHelpers/1.0.0/fileMoveOrCopy'; import { + fileExists, getContainer, getFileAbosluteDir, getFileName, } from '../../../../FlowHelpers/1.0.0/fileUtils'; import { @@ -76,7 +77,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { // delete original file if ( - fs.existsSync(args.originalLibraryFile._id) + await fileExists(args.originalLibraryFile._id) && args.originalLibraryFile._id !== currentPath ) { args.jobLog(`Deleting original file:${args.originalLibraryFile._id}`); diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts index 04806c481..b74345daa 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts @@ -4,6 +4,7 @@ import { IpluginInputArgs, IpluginOutputArgs, } from '../../../../FlowHelpers/1.0.0/interfaces/interfaces'; +import { fileExists } from '../../../../FlowHelpers/1.0.0/fileUtils'; /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ const details = ():IpluginDetails => ({ @@ -47,7 +48,7 @@ const details = ():IpluginDetails => ({ }); // eslint-disable-next-line @typescript-eslint/no-unused-vars -const plugin = (args:IpluginInputArgs):IpluginOutputArgs => { +const plugin = async (args:IpluginInputArgs):Promise => { const lib = require('../../../../../methods/lib')(); // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); @@ -55,7 +56,7 @@ const plugin = (args:IpluginInputArgs):IpluginOutputArgs => { const oldFile = args.inputFileObj._id; const newFile = `${args.inputFileObj._id}.tmp`; - if (fs.existsSync(newFile)) { + if (await fileExists(newFile)) { fs.unlinkSync(newFile); } diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts index 56355e0c5..84018e815 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/cliUtils.ts @@ -4,6 +4,7 @@ import { } from './cliParsers'; import { Ilog, IupdateWorker } from './interfaces/interfaces'; import { IFileObject, Istreams } from './interfaces/synced/IFileObject'; +import { fileExists } from './fileUtils'; const fancyTimeFormat = (time: number) => { // Hours, minutes and seconds @@ -92,7 +93,7 @@ class CLI { this.config = config; } - updateETA = (perc: number): void => { + updateETA = async (perc: number): Promise => { if (perc > 0) { if (this.lastProgCheck === 0) { this.lastProgCheck = new Date().getTime(); @@ -124,7 +125,7 @@ class CLI { let outputFileSizeInGbytes; try { - if (fs.existsSync(this.config.outputFilePath)) { + if (await fileExists(this.config.outputFilePath)) { let singleFileSize = fs.statSync(this.config.outputFilePath); // @ts-expect-error type singleFileSize = singleFileSize.size; @@ -180,7 +181,7 @@ class CLI { }); if (percentage > 0) { - this.updateETA(percentage); + void this.updateETA(percentage); this.config.updateWorker({ percentage, }); @@ -236,7 +237,7 @@ class CLI { } if (percentage > 0) { - this.updateETA(percentage); + void this.updateETA(percentage); this.config.updateWorker({ percentage, }); @@ -246,7 +247,7 @@ class CLI { str, }); if (percentage > 0) { - this.updateETA(percentage); + void this.updateETA(percentage); this.config.updateWorker({ percentage, }); diff --git a/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts b/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts index 9879e7ad0..d06e5b25b 100644 --- a/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts +++ b/FlowPluginsTs/FlowHelpers/1.0.0/fileUtils.ts @@ -1,6 +1,8 @@ import { promises as fsp } from 'fs'; import { IpluginInputArgs } from './interfaces/interfaces'; +export const fileExists = async (path:string): Promise => !!(await fsp.stat(path).catch(() => false)); + export const getContainer = (filePath: string): string => { const parts = filePath.split('.'); return parts[parts.length - 1]; From 20a7e85ed74125ede115936ca03c65898297e8f7 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sat, 1 Jun 2024 08:33:12 +0100 Subject: [PATCH 4/6] Promisify fs.unlinkSync --- .../file/replaceOriginalFile/1.0.0/index.ts | 4 ++-- .../CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts index d84bacd82..3f48f2344 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.ts @@ -1,4 +1,4 @@ -import fs from 'fs'; +import { promises as fsp } from 'fs'; import fileMoveOrCopy from '../../../../FlowHelpers/1.0.0/fileMoveOrCopy'; import { fileExists, @@ -81,7 +81,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { && args.originalLibraryFile._id !== currentPath ) { args.jobLog(`Deleting original file:${args.originalLibraryFile._id}`); - fs.unlinkSync(args.originalLibraryFile._id); + await fsp.unlink(args.originalLibraryFile._id); } await new Promise((resolve) => setTimeout(resolve, 2000)); diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts index b74345daa..cc9f730cc 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts @@ -1,4 +1,4 @@ -import fs from 'fs'; +import fs, { promises as fsp } from 'fs'; import { IpluginDetails, IpluginInputArgs, @@ -57,7 +57,7 @@ const plugin = async (args:IpluginInputArgs):Promise => { const newFile = `${args.inputFileObj._id}.tmp`; if (await fileExists(newFile)) { - fs.unlinkSync(newFile); + await fsp.unlink(newFile); } fs.copyFileSync(oldFile, newFile); From d77265fb6a23f3f48b7718bb79f9ab47a2e9f6ba Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Sat, 1 Jun 2024 08:35:07 +0100 Subject: [PATCH 5/6] Promisify copyFileSync --- .../CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts index cc9f730cc..643f88176 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.ts @@ -1,4 +1,4 @@ -import fs, { promises as fsp } from 'fs'; +import { promises as fsp } from 'fs'; import { IpluginDetails, IpluginInputArgs, @@ -60,7 +60,7 @@ const plugin = async (args:IpluginInputArgs):Promise => { await fsp.unlink(newFile); } - fs.copyFileSync(oldFile, newFile); + await fsp.copyFile(oldFile, newFile); return { outputFileObj: { _id: newFile }, From c3b29ecb7796403fefdbf48f6539e9bd8222a8a2 Mon Sep 17 00:00:00 2001 From: HaveAGitGat Date: Sat, 1 Jun 2024 07:41:57 +0000 Subject: [PATCH 6/6] Apply auto-build changes --- .../file/checkFileExists/1.0.0/index.js | 94 ++++++++++----- .../file/replaceOriginalFile/1.0.0/index.js | 23 ++-- .../video/transcodeVideo/1.0.0/index.js | 83 ++++++++++--- FlowPlugins/FlowHelpers/1.0.0/cliUtils.js | 109 ++++++++++-------- FlowPlugins/FlowHelpers/1.0.0/fileUtils.js | 9 +- 5 files changed, 216 insertions(+), 102 deletions(-) diff --git a/FlowPlugins/CommunityFlowPlugins/file/checkFileExists/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/checkFileExists/1.0.0/index.js index b0da3c3cb..d4e0643fc 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/checkFileExists/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/checkFileExists/1.0.0/index.js @@ -1,10 +1,42 @@ "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.plugin = exports.details = void 0; -var fs_1 = __importDefault(require("fs")); var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils"); /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ var details = function () { return ({ @@ -57,28 +89,36 @@ var details = function () { return ({ }); }; exports.details = details; // eslint-disable-next-line @typescript-eslint/no-unused-vars -var plugin = function (args) { - var lib = require('../../../../../methods/lib')(); - // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign - args.inputs = lib.loadDefaultValues(args.inputs, details); - var directory = String(args.inputs.directory).trim() || (0, fileUtils_1.getFileAbosluteDir)(args.inputFileObj._id); - var fileName = (0, fileUtils_1.getFileName)(args.inputFileObj._id); - var fileToCheck = String(args.inputs.fileToCheck).trim(); - fileToCheck = fileToCheck.replace(/\${fileName}/g, fileName); - fileToCheck = fileToCheck.replace(/\${container}/g, (0, fileUtils_1.getContainer)(args.inputFileObj._id)); - fileToCheck = "".concat(directory, "/").concat(fileToCheck); - var fileExists = false; - if (fs_1.default.existsSync(fileToCheck)) { - fileExists = true; - args.jobLog("File exists: ".concat(fileToCheck)); - } - else { - args.jobLog("File does not exist: ".concat(fileToCheck)); - } - return { - outputFileObj: args.inputFileObj, - outputNumber: fileExists ? 1 : 2, - variables: args.variables, - }; -}; +var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () { + var lib, directory, fileName, fileToCheck, fileDoesExist; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + lib = require('../../../../../methods/lib')(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign + args.inputs = lib.loadDefaultValues(args.inputs, details); + directory = String(args.inputs.directory).trim() || (0, fileUtils_1.getFileAbosluteDir)(args.inputFileObj._id); + fileName = (0, fileUtils_1.getFileName)(args.inputFileObj._id); + fileToCheck = String(args.inputs.fileToCheck).trim(); + fileToCheck = fileToCheck.replace(/\${fileName}/g, fileName); + fileToCheck = fileToCheck.replace(/\${container}/g, (0, fileUtils_1.getContainer)(args.inputFileObj._id)); + fileToCheck = "".concat(directory, "/").concat(fileToCheck); + fileDoesExist = false; + return [4 /*yield*/, (0, fileUtils_1.fileExists)(fileToCheck)]; + case 1: + if (_a.sent()) { + fileDoesExist = true; + args.jobLog("File exists: ".concat(fileToCheck)); + } + else { + args.jobLog("File does not exist: ".concat(fileToCheck)); + } + return [2 /*return*/, { + outputFileObj: args.inputFileObj, + outputNumber: fileDoesExist ? 1 : 2, + variables: args.variables, + }]; + } + }); +}); }; exports.plugin = plugin; diff --git a/FlowPlugins/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.js index f27c9dbaa..fc27cc3e8 100644 --- a/FlowPlugins/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/file/replaceOriginalFile/1.0.0/index.js @@ -40,6 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.plugin = exports.details = void 0; +var fs_1 = require("fs"); var fileMoveOrCopy_1 = __importDefault(require("../../../../FlowHelpers/1.0.0/fileMoveOrCopy")); var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils"); /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ @@ -66,11 +67,10 @@ var details = function () { return ({ exports.details = details; // eslint-disable-next-line @typescript-eslint/no-unused-vars var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () { - var fs, lib, currentPath, orignalFolder, fileName, container, newPath, newPathTmp; + var lib, currentPath, orignalFolder, fileName, container, newPath, newPathTmp; return __generator(this, function (_a) { switch (_a.label) { case 0: - fs = require('fs'); lib = require('../../../../../methods/lib')(); // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign args.inputs = lib.loadDefaultValues(args.inputs, details); @@ -106,14 +106,17 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function })]; case 2: _a.sent(); - // delete original file - if (fs.existsSync(args.originalLibraryFile._id) - && args.originalLibraryFile._id !== currentPath) { - args.jobLog("Deleting original file:".concat(args.originalLibraryFile._id)); - fs.unlinkSync(args.originalLibraryFile._id); - } - return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })]; + return [4 /*yield*/, (0, fileUtils_1.fileExists)(args.originalLibraryFile._id)]; case 3: + if (!((_a.sent()) + && args.originalLibraryFile._id !== currentPath)) return [3 /*break*/, 5]; + args.jobLog("Deleting original file:".concat(args.originalLibraryFile._id)); + return [4 /*yield*/, fs_1.promises.unlink(args.originalLibraryFile._id)]; + case 4: + _a.sent(); + _a.label = 5; + case 5: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })]; + case 6: _a.sent(); return [4 /*yield*/, (0, fileMoveOrCopy_1.default)({ operation: 'move', @@ -121,7 +124,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function destinationPath: newPath, args: args, })]; - case 4: + case 7: _a.sent(); return [2 /*return*/, { outputFileObj: { diff --git a/FlowPlugins/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.js b/FlowPlugins/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.js index 3f05e5fa2..aa543a011 100644 --- a/FlowPlugins/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.js +++ b/FlowPlugins/CommunityFlowPlugins/video/transcodeVideo/1.0.0/index.js @@ -1,6 +1,44 @@ "use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.plugin = exports.details = void 0; +var fs_1 = require("fs"); +var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils"); /* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */ var details = function () { return ({ name: 'Transcode Video File', @@ -42,21 +80,32 @@ var details = function () { return ({ }); }; exports.details = details; // eslint-disable-next-line @typescript-eslint/no-unused-vars -var plugin = function (args) { - var lib = require('../../../../../methods/lib')(); - // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign - args.inputs = lib.loadDefaultValues(args.inputs, details); - var fs = require('fs'); - var oldFile = args.inputFileObj._id; - var newFile = "".concat(args.inputFileObj._id, ".tmp"); - if (fs.existsSync(newFile)) { - fs.unlinkSync(newFile); - } - fs.copyFileSync(oldFile, newFile); - return { - outputFileObj: { _id: newFile }, - outputNumber: 1, - variables: args.variables, - }; -}; +var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () { + var lib, oldFile, newFile; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + lib = require('../../../../../methods/lib')(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign + args.inputs = lib.loadDefaultValues(args.inputs, details); + oldFile = args.inputFileObj._id; + newFile = "".concat(args.inputFileObj._id, ".tmp"); + return [4 /*yield*/, (0, fileUtils_1.fileExists)(newFile)]; + case 1: + if (!_a.sent()) return [3 /*break*/, 3]; + return [4 /*yield*/, fs_1.promises.unlink(newFile)]; + case 2: + _a.sent(); + _a.label = 3; + case 3: return [4 /*yield*/, fs_1.promises.copyFile(oldFile, newFile)]; + case 4: + _a.sent(); + return [2 /*return*/, { + outputFileObj: { _id: newFile }, + outputNumber: 1, + variables: args.variables, + }]; + } + }); +}); }; exports.plugin = plugin; diff --git a/FlowPlugins/FlowHelpers/1.0.0/cliUtils.js b/FlowPlugins/FlowHelpers/1.0.0/cliUtils.js index 210bb5fb4..0205188d2 100644 --- a/FlowPlugins/FlowHelpers/1.0.0/cliUtils.js +++ b/FlowPlugins/FlowHelpers/1.0.0/cliUtils.js @@ -35,10 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) { if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.CLI = exports.getFFmpegVar = void 0; +var fs_1 = __importDefault(require("fs")); var cliParsers_1 = require("./cliParsers"); -var fs = require('fs'); +var fileUtils_1 = require("./fileUtils"); var fancyTimeFormat = function (time) { // Hours, minutes and seconds // eslint-disable-next-line no-bitwise @@ -93,60 +97,71 @@ var CLI = /** @class */ (function () { this.oldProgress = 0; this.lastProgCheck = 0; this.hbPass = 0; - this.updateETA = function (perc) { - if (perc > 0) { - if (_this.lastProgCheck === 0) { - _this.lastProgCheck = new Date().getTime(); - _this.oldProgress = perc; - } - else if (perc !== _this.oldProgress) { - var n = new Date().getTime(); - var secsSinceLastCheck = (n - _this.lastProgCheck) / 1000; - if (secsSinceLastCheck > 1) { - // eta total - var eta = Math.round((100 / (perc - _this.oldProgress)) * secsSinceLastCheck); + this.updateETA = function (perc) { return __awaiter(_this, void 0, void 0, function () { + var n, secsSinceLastCheck, eta, sum, avg, estSize, outputFileSizeInGbytes, singleFileSize, err_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(perc > 0)) return [3 /*break*/, 6]; + if (!(this.lastProgCheck === 0)) return [3 /*break*/, 1]; + this.lastProgCheck = new Date().getTime(); + this.oldProgress = perc; + return [3 /*break*/, 6]; + case 1: + if (!(perc !== this.oldProgress)) return [3 /*break*/, 6]; + n = new Date().getTime(); + secsSinceLastCheck = (n - this.lastProgCheck) / 1000; + if (!(secsSinceLastCheck > 1)) return [3 /*break*/, 6]; + eta = Math.round((100 / (perc - this.oldProgress)) * secsSinceLastCheck); // eta remaining eta *= ((100 - perc) / 100); - _this.progAVG.push(eta); - // let values = [2, 56, 3, 41, 0, 4, 100, 23]; - var sum = _this.progAVG.reduce( + this.progAVG.push(eta); + sum = this.progAVG.reduce( // eslint-disable-next-line function (previous, current) { return (current += previous); }); - var avg = sum / _this.progAVG.length; - // est size - var estSize = 0; - var outputFileSizeInGbytes = void 0; - try { - if (fs.existsSync(_this.config.outputFilePath)) { - var singleFileSize = fs.statSync(_this.config.outputFilePath); - singleFileSize = singleFileSize.size; - outputFileSizeInGbytes = singleFileSize / (1024 * 1024 * 1024); - if (outputFileSizeInGbytes !== _this.oldOutSize) { - _this.oldOutSize = outputFileSizeInGbytes; - estSize = outputFileSizeInGbytes - + ((100 - perc) / perc) * outputFileSizeInGbytes; - _this.oldEstSize = estSize; - } + avg = sum / this.progAVG.length; + estSize = 0; + outputFileSizeInGbytes = void 0; + _a.label = 2; + case 2: + _a.trys.push([2, 4, , 5]); + return [4 /*yield*/, (0, fileUtils_1.fileExists)(this.config.outputFilePath)]; + case 3: + if (_a.sent()) { + singleFileSize = fs_1.default.statSync(this.config.outputFilePath); + // @ts-expect-error type + singleFileSize = singleFileSize.size; + // @ts-expect-error type + outputFileSizeInGbytes = singleFileSize / (1024 * 1024 * 1024); + if (outputFileSizeInGbytes !== this.oldOutSize) { + this.oldOutSize = outputFileSizeInGbytes; + estSize = outputFileSizeInGbytes + + ((100 - perc) / perc) * outputFileSizeInGbytes; + this.oldEstSize = estSize; } } - catch (err) { - // eslint-disable-next-line no-console - console.log(err); - } - _this.config.updateWorker({ + return [3 /*break*/, 5]; + case 4: + err_1 = _a.sent(); + // eslint-disable-next-line no-console + console.log(err_1); + return [3 /*break*/, 5]; + case 5: + this.config.updateWorker({ ETA: fancyTimeFormat(avg), outputFileSizeInGbytes: outputFileSizeInGbytes === undefined ? 0 : outputFileSizeInGbytes, - estSize: _this.oldEstSize === undefined ? 0 : _this.oldEstSize, + estSize: this.oldEstSize === undefined ? 0 : this.oldEstSize, }); - if (_this.progAVG.length > 30) { - _this.progAVG.splice(0, 1); + if (this.progAVG.length > 30) { + this.progAVG.splice(0, 1); } - _this.lastProgCheck = n; - _this.oldProgress = perc; - } + this.lastProgCheck = n; + this.oldProgress = perc; + _a.label = 6; + case 6: return [2 /*return*/]; } - } - }; + }); + }); }; this.parseOutput = function (data) { var _a, _b, _c, _d, _e, _f, _g; var str = "".concat(data); @@ -166,7 +181,7 @@ var CLI = /** @class */ (function () { hbPass: _this.hbPass, }); if (percentage > 0) { - _this.updateETA(percentage); + void _this.updateETA(percentage); _this.config.updateWorker({ percentage: percentage, }); @@ -214,7 +229,7 @@ var CLI = /** @class */ (function () { }); } if (percentage > 0) { - _this.updateETA(percentage); + void _this.updateETA(percentage); _this.config.updateWorker({ percentage: percentage, }); @@ -225,7 +240,7 @@ var CLI = /** @class */ (function () { str: str, }); if (percentage > 0) { - _this.updateETA(percentage); + void _this.updateETA(percentage); _this.config.updateWorker({ percentage: percentage, }); diff --git a/FlowPlugins/FlowHelpers/1.0.0/fileUtils.js b/FlowPlugins/FlowHelpers/1.0.0/fileUtils.js index 1e3604571..49e8d2b62 100644 --- a/FlowPlugins/FlowHelpers/1.0.0/fileUtils.js +++ b/FlowPlugins/FlowHelpers/1.0.0/fileUtils.js @@ -36,8 +36,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getScanTypes = exports.getPluginWorkDir = exports.moveFileAndValidate = exports.getFileSize = exports.getSubStem = exports.getFfType = exports.getFileAbosluteDir = exports.getFileName = exports.getContainer = void 0; +exports.getScanTypes = exports.getPluginWorkDir = exports.moveFileAndValidate = exports.getFileSize = exports.getSubStem = exports.getFfType = exports.getFileAbosluteDir = exports.getFileName = exports.getContainer = exports.fileExists = void 0; var fs_1 = require("fs"); +var fileExists = function (path) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, fs_1.promises.stat(path).catch(function () { return false; })]; + case 1: return [2 /*return*/, !!(_a.sent())]; + } +}); }); }; +exports.fileExists = fileExists; var getContainer = function (filePath) { var parts = filePath.split('.'); return parts[parts.length - 1];