mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-15 02:05:54 -07:00
Use fsp for promises
This commit is contained in:
parent
a5714ebf34
commit
e08aa2356d
10 changed files with 27 additions and 26 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fsp } from 'fs';
|
||||||
import {
|
import {
|
||||||
getContainer, getFileAbosluteDir, getSubStem,
|
getContainer, getFileAbosluteDir, getSubStem,
|
||||||
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||||
|
|
@ -188,7 +188,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
sourceDir = getFileAbosluteDir(args.inputFileObj._id);
|
sourceDir = getFileAbosluteDir(args.inputFileObj._id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let filesInDir = (await fs.readdir(sourceDir))
|
let filesInDir = (await fsp.readdir(sourceDir))
|
||||||
.map((row) => ({
|
.map((row) => ({
|
||||||
source: `${sourceDir}/${row}`,
|
source: `${sourceDir}/${row}`,
|
||||||
destination: normJoinPath({
|
destination: normJoinPath({
|
||||||
|
|
|
||||||
|
|
@ -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 { getContainer, getFileName, getSubStem } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
|
|
@ -126,7 +126,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
|
|
||||||
args.deps.fsextra.ensureDirSync(outputPath);
|
args.deps.fsextra.ensureDirSync(outputPath);
|
||||||
|
|
||||||
await fs.copyFile(args.inputFileObj._id, ouputFilePath);
|
await fsp.copyFile(args.inputFileObj._id, ouputFilePath);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
outputFileObj: {
|
outputFileObj: {
|
||||||
|
|
|
||||||
|
|
@ -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 { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
|
|
@ -67,7 +67,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
|
|
||||||
args.deps.fsextra.ensureDirSync(outputPath);
|
args.deps.fsextra.ensureDirSync(outputPath);
|
||||||
|
|
||||||
await fs.copyFile(args.inputFileObj._id, ouputFilePath);
|
await fsp.copyFile(args.inputFileObj._id, ouputFilePath);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
outputFileObj: {
|
outputFileObj: {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fsp } from 'fs';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
IpluginInputArgs,
|
IpluginInputArgs,
|
||||||
|
|
@ -64,21 +65,21 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
|
|
||||||
if (fileToDelete === 'workingFile') {
|
if (fileToDelete === 'workingFile') {
|
||||||
args.jobLog(`Deleting working file ${args.inputFileObj._id}`);
|
args.jobLog(`Deleting working file ${args.inputFileObj._id}`);
|
||||||
await fs.unlink(args.inputFileObj._id);
|
await fsp.unlink(args.inputFileObj._id);
|
||||||
} else if (fileToDelete === 'originalFile') {
|
} else if (fileToDelete === 'originalFile') {
|
||||||
args.jobLog(`Deleting original file ${args.originalLibraryFile._id}`);
|
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);
|
const fileDir = getFileAbosluteDir(args.originalLibraryFile._id);
|
||||||
|
|
||||||
if (deleteParentFolderIfEmpty) {
|
if (deleteParentFolderIfEmpty) {
|
||||||
args.jobLog(`Checking if folder ${fileDir} is empty`);
|
args.jobLog(`Checking if folder ${fileDir} is empty`);
|
||||||
const files = await fs.readdir(fileDir);
|
const files = await fsp.readdir(fileDir);
|
||||||
|
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
args.jobLog(`Deleting empty folder ${fileDir}`);
|
args.jobLog(`Deleting empty folder ${fileDir}`);
|
||||||
await fs.rmdir(fileDir);
|
await fsp.rmdir(fileDir);
|
||||||
} else {
|
} else {
|
||||||
args.jobLog(`Folder ${fileDir} is not empty, skipping delete`);
|
args.jobLog(`Folder ${fileDir} is not empty, skipping delete`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
|
|
@ -99,7 +99,7 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
||||||
|
|
||||||
if (presetString.trim() !== '') {
|
if (presetString.trim() !== '') {
|
||||||
const preset = JSON.parse(presetString);
|
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('--preset-import-file');
|
||||||
cliArgs.push(presetPath);
|
cliArgs.push(presetPath);
|
||||||
cliArgs.push('-Z');
|
cliArgs.push('-Z');
|
||||||
|
|
|
||||||
|
|
@ -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 { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils';
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
|
|
@ -142,7 +142,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
|
|
||||||
if (useJsonPreset) {
|
if (useJsonPreset) {
|
||||||
const preset = JSON.parse(presetString);
|
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('--preset-import-file');
|
||||||
cliArgs.push(presetPath);
|
cliArgs.push(presetPath);
|
||||||
cliArgs.push('-Z');
|
cliArgs.push('-Z');
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fsp } from 'fs';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
|
|
@ -86,7 +86,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
|
|
||||||
const checkReadWrite = async (location: string) => {
|
const checkReadWrite = async (location: string) => {
|
||||||
try {
|
try {
|
||||||
await fs.access(location, fs.constants.R_OK);
|
await fsp.access(location, fsp.constants.R_OK);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
args.jobLog(JSON.stringify(err));
|
args.jobLog(JSON.stringify(err));
|
||||||
if (pauseNodeIfAccessChecksFail) {
|
if (pauseNodeIfAccessChecksFail) {
|
||||||
|
|
@ -97,7 +97,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.access(location, fs.constants.W_OK);
|
await fsp.access(location, fsp.constants.W_OK);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
args.jobLog(JSON.stringify(err));
|
args.jobLog(JSON.stringify(err));
|
||||||
if (pauseNodeIfAccessChecksFail) {
|
if (pauseNodeIfAccessChecksFail) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fsp } from 'fs';
|
||||||
import {
|
import {
|
||||||
getContainer, getFileName, getPluginWorkDir, getScanTypes,
|
getContainer, getFileName, getPluginWorkDir, getScanTypes,
|
||||||
} from './fileUtils';
|
} from './fileUtils';
|
||||||
|
|
@ -43,7 +43,7 @@ export const runClassicPlugin = async (args:IpluginInputArgs, type:'filter'|'tra
|
||||||
let pluginSrcStr = '';
|
let pluginSrcStr = '';
|
||||||
if (pluginSource === 'Community') {
|
if (pluginSource === 'Community') {
|
||||||
classicPlugin = args.deps.importFresh(relativePluginPath);
|
classicPlugin = args.deps.importFresh(relativePluginPath);
|
||||||
pluginSrcStr = await fs.readFile(absolutePath, 'utf8');
|
pluginSrcStr = await fsp.readFile(absolutePath, 'utf8');
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
|
const res = await args.deps.axiosMiddleware('api/v2/read-plugin', {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fsp } from 'fs';
|
||||||
|
|
||||||
import { getFileSize } from './fileUtils';
|
import { getFileSize } from './fileUtils';
|
||||||
import { IpluginInputArgs } from './interfaces/interfaces';
|
import { IpluginInputArgs } from './interfaces/interfaces';
|
||||||
|
|
@ -48,7 +48,7 @@ const tryMove = async ({
|
||||||
|
|
||||||
let error = false;
|
let error = false;
|
||||||
try {
|
try {
|
||||||
await fs.rename(sourcePath, destinationPath);
|
await fsp.rename(sourcePath, destinationPath);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = true;
|
error = true;
|
||||||
args.jobLog(`File move error: ${JSON.stringify(err)}`);
|
args.jobLog(`File move error: ${JSON.stringify(err)}`);
|
||||||
|
|
@ -157,7 +157,7 @@ const tryNormalCopy = async ({
|
||||||
|
|
||||||
let error = false;
|
let error = false;
|
||||||
try {
|
try {
|
||||||
await fs.copyFile(sourcePath, destinationPath);
|
await fsp.copyFile(sourcePath, destinationPath);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error = true;
|
error = true;
|
||||||
args.jobLog(`File copy error: ${JSON.stringify(err)}`);
|
args.jobLog(`File copy error: ${JSON.stringify(err)}`);
|
||||||
|
|
@ -186,7 +186,7 @@ const cleanSourceFile = async ({
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
args.jobLog(`Deleting source file ${sourcePath}`);
|
args.jobLog(`Deleting source file ${sourcePath}`);
|
||||||
await fs.unlink(sourcePath);
|
await fsp.unlink(sourcePath);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
args.jobLog(`Failed to delete source file ${sourcePath}: ${JSON.stringify(err)}`);
|
args.jobLog(`Failed to delete source file ${sourcePath}: ${JSON.stringify(err)}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fsp } from 'fs';
|
||||||
import { IpluginInputArgs } from './interfaces/interfaces';
|
import { IpluginInputArgs } from './interfaces/interfaces';
|
||||||
|
|
||||||
export const getContainer = (filePath: string): string => {
|
export const getContainer = (filePath: string): string => {
|
||||||
|
|
@ -37,7 +37,7 @@ export const getSubStem = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFileSize = async (file:string):Promise<number> => {
|
export const getFileSize = async (file:string):Promise<number> => {
|
||||||
const stats = await fs.stat(file);
|
const stats = await fsp.stat(file);
|
||||||
const { size } = stats;
|
const { size } = stats;
|
||||||
return size;
|
return size;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue