mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 23:48:15 -07:00
Use async fileExists
This commit is contained in:
parent
99160eadb3
commit
28192d7723
5 changed files with 21 additions and 15 deletions
|
|
@ -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<IpluginOutputArgs> => {
|
||||
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,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<IpluginOutputArgs> => {
|
|||
|
||||
// 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}`);
|
||||
|
|
|
|||
|
|
@ -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<IpluginOutputArgs> => {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<void> => {
|
||||
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,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { promises as fsp } from 'fs';
|
||||
import { IpluginInputArgs } from './interfaces/interfaces';
|
||||
|
||||
export const fileExists = async (path:string): Promise<boolean> => !!(await fsp.stat(path).catch(() => false));
|
||||
|
||||
export const getContainer = (filePath: string): string => {
|
||||
const parts = filePath.split('.');
|
||||
return parts[parts.length - 1];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue