mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-10 07:50:29 -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue