mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-09 07:29:04 -07:00
Only replace if needed
This commit is contained in:
parent
a621a0c459
commit
f410caf1ad
2 changed files with 36 additions and 3 deletions
|
|
@ -74,6 +74,16 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
|||
lib = require('../../../../../methods/lib')();
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
if (args.inputFileObj._id === args.originalLibraryFile._id
|
||||
&& args.inputFileObj.file_size === args.originalLibraryFile.file_size) {
|
||||
args.jobLog('File has not changed, no need to replace file');
|
||||
return [2 /*return*/, {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
}];
|
||||
}
|
||||
args.jobLog('File has changed, replacing original file');
|
||||
currentPath = args.inputFileObj._id;
|
||||
newPath = getNewPath(args.originalLibraryFile._id, currentPath);
|
||||
newPathTmp = "".concat(newPath, ".tmp");
|
||||
|
|
@ -85,10 +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); })];
|
||||
case 1:
|
||||
_a.sent();
|
||||
fs.renameSync(currentPath, newPathTmp);
|
||||
// delete original file
|
||||
if (fs.existsSync(args.originalLibraryFile._id)) {
|
||||
fs.unlinkSync(args.originalLibraryFile._id);
|
||||
}
|
||||
// delete temp file
|
||||
if (fs.existsSync(newPath)) {
|
||||
fs.unlinkSync(newPath);
|
||||
}
|
||||
fs.renameSync(currentPath, newPathTmp);
|
||||
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 2000); })];
|
||||
case 2:
|
||||
_a.sent();
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ const getNewPath = (originalPath:string, tempPath:string) => {
|
|||
const originalPathParts = originalPath.split('.');
|
||||
|
||||
originalPathParts[originalPathParts.length - 1] = container;
|
||||
|
||||
return originalPathParts.join('.');
|
||||
};
|
||||
|
||||
|
|
@ -42,6 +41,20 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
|||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||
|
||||
if (
|
||||
args.inputFileObj._id === args.originalLibraryFile._id
|
||||
&& args.inputFileObj.file_size === args.originalLibraryFile.file_size
|
||||
) {
|
||||
args.jobLog('File has not changed, no need to replace file');
|
||||
return {
|
||||
outputFileObj: args.inputFileObj,
|
||||
outputNumber: 1,
|
||||
variables: args.variables,
|
||||
};
|
||||
}
|
||||
|
||||
args.jobLog('File has changed, replacing original file');
|
||||
|
||||
const currentPath = args.inputFileObj._id;
|
||||
const newPath = getNewPath(args.originalLibraryFile._id, currentPath);
|
||||
const newPathTmp = `${newPath}.tmp`;
|
||||
|
|
@ -54,12 +67,17 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
|||
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
|
||||
fs.renameSync(currentPath, newPathTmp);
|
||||
// delete original file
|
||||
if (fs.existsSync(args.originalLibraryFile._id)) {
|
||||
fs.unlinkSync(args.originalLibraryFile._id);
|
||||
}
|
||||
|
||||
// delete temp file
|
||||
if (fs.existsSync(newPath)) {
|
||||
fs.unlinkSync(newPath);
|
||||
}
|
||||
|
||||
fs.renameSync(currentPath, newPathTmp);
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000));
|
||||
fs.renameSync(newPathTmp, newPath);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue