mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 17:55:55 -07:00
Merge pull request #444 from HaveAGitGat/2.10.01
Only delete if rename succeeds
This commit is contained in:
commit
5872a0ff77
2 changed files with 13 additions and 12 deletions
|
|
@ -95,15 +95,15 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
|
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
|
||||||
case 1:
|
case 1:
|
||||||
_a.sent();
|
_a.sent();
|
||||||
// delete original file
|
|
||||||
if (fs.existsSync(args.originalLibraryFile._id)) {
|
|
||||||
fs.unlinkSync(args.originalLibraryFile._id);
|
|
||||||
}
|
|
||||||
// delete temp file
|
// delete temp file
|
||||||
if (fs.existsSync(newPath)) {
|
if (fs.existsSync(newPath)) {
|
||||||
fs.unlinkSync(newPath);
|
fs.unlinkSync(newPath);
|
||||||
}
|
}
|
||||||
fs.renameSync(currentPath, newPathTmp);
|
fs.renameSync(currentPath, newPathTmp);
|
||||||
|
// delete original file
|
||||||
|
if (fs.existsSync(args.originalLibraryFile._id)) {
|
||||||
|
fs.unlinkSync(args.originalLibraryFile._id);
|
||||||
|
}
|
||||||
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
|
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
|
||||||
case 2:
|
case 2:
|
||||||
_a.sent();
|
_a.sent();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import {
|
||||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||||
|
|
||||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||||
const details = ():IpluginDetails => ({
|
const details = (): IpluginDetails => ({
|
||||||
name: 'Replace Original File',
|
name: 'Replace Original File',
|
||||||
description: 'Replace the original file',
|
description: 'Replace the original file',
|
||||||
style: {
|
style: {
|
||||||
|
|
@ -24,7 +24,7 @@ const details = ():IpluginDetails => ({
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const getNewPath = (originalPath:string, tempPath:string) => {
|
const getNewPath = (originalPath: string, tempPath: string) => {
|
||||||
const tempPathParts = tempPath.split('.');
|
const tempPathParts = tempPath.split('.');
|
||||||
const container = tempPathParts[tempPathParts.length - 1];
|
const container = tempPathParts[tempPathParts.length - 1];
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ const getNewPath = (originalPath:string, tempPath:string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const lib = require('../../../../../methods/lib')();
|
const lib = require('../../../../../methods/lib')();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
|
|
@ -67,17 +67,18 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||||
|
|
||||||
// delete original file
|
|
||||||
if (fs.existsSync(args.originalLibraryFile._id)) {
|
|
||||||
fs.unlinkSync(args.originalLibraryFile._id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete temp file
|
// delete temp file
|
||||||
if (fs.existsSync(newPath)) {
|
if (fs.existsSync(newPath)) {
|
||||||
fs.unlinkSync(newPath);
|
fs.unlinkSync(newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.renameSync(currentPath, newPathTmp);
|
fs.renameSync(currentPath, newPathTmp);
|
||||||
|
|
||||||
|
// delete original file
|
||||||
|
if (fs.existsSync(args.originalLibraryFile._id)) {
|
||||||
|
fs.unlinkSync(args.originalLibraryFile._id);
|
||||||
|
}
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||||
fs.renameSync(newPathTmp, newPath);
|
fs.renameSync(newPathTmp, newPath);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue