Fix copy progress, remove v2.0.0, fix subtitle default naming, enforce strict no-upcoding on audio
Build / Lint & Test (push) Successful in 3m15s

This commit is contained in:
PickleRick committed 2026-09-30 17:26:19 +02:00
1 parent 7ee5a5bc48
commit 86448988ed
12 files changed
+470 -348

No files matched your search

@@ -1,15 +1,18 @@
'use strict';
const path = require('path');
const fs = require('fs');
const fs = require('fs');
const { copyWithProgress } = require('../../../../FlowHelpers/1.0.0/copyWithProgress');
/* eslint-disable no-param-reassign */
const details = () => ({
name: 'Replace Original File',
description:
'Copies the processed file to the original library path, verifies the copy, '
+ 'and atomically replaces the original with rollback if replacement fails.',
'Copies the processed file to the original library path with streamed progress, '
+ 'size verification, an atomic rename, and rollback if replacement fails.',
style: { borderColor: '#FF9800' },
tags: 'utility,replace',
tags: 'utility,replace,progress',
isStartPlugin: false,
pType: '',
requiresVersion: '2.11.01',
@@ -25,22 +28,13 @@ const details = () => ({
tooltip: 'Delete the processed file after it has replaced the original.',
},
],
outputs: [{ number: 1, tooltip: 'Original file replaced — continue to next plugin' }],
outputs: [
{ number: 1, tooltip: 'Original file replaced — continue to next plugin' },
],
});
const copyAndVerify = (source, destination) => {
fs.copyFileSync(source, destination);
const sourceSize = fs.statSync(source).size;
const destinationSize = fs.statSync(destination).size;
if (sourceSize !== destinationSize) {
throw new Error(
`Copy size mismatch: expected ${sourceSize} bytes, got ${destinationSize}`,
);
}
};
const plugin = async (args) => {
const { inputFileObj, variables, jobLog } = args;
const { inputFileObj, variables, jobLog, updateWorker } = args;
const source = inputFileObj._id;
const configuredDestination = variables.originalLibraryFile || args.originalLibraryFile;
const destination = typeof configuredDestination === 'string'
@@ -69,14 +63,28 @@ const plugin = async (args) => {
let installed = false;
try {
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
copyAndVerify(source, temporary);
if (fs.existsSync(temporary)) {
fs.unlinkSync(temporary);
}
jobLog(`[replaceOriginalFile] Copying processed file to temporary destination: ${temporary}\n`);
await copyWithProgress({
source,
destination: temporary,
jobLog,
updateWorker,
updateProgress: args.updateProgress,
label: 'replaceOriginalFile',
});
if (fs.existsSync(destination)) {
if (fs.existsSync(backup)) fs.unlinkSync(backup);
if (fs.existsSync(backup)) {
fs.unlinkSync(backup);
}
fs.renameSync(destination, backup);
backupCreated = true;
}
fs.renameSync(temporary, destination);
installed = true;
@@ -87,6 +95,7 @@ const plugin = async (args) => {
jobLog(`[replaceOriginalFile] WARNING: Could not remove backup ${backup}: ${error.message}\n`);
}
}
if ((args.inputs.deleteSource || 'true') === 'true') {
try {
fs.unlinkSync(source);
@@ -102,9 +111,11 @@ const plugin = async (args) => {
variables,
};
} catch (error) {
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
if (fs.existsSync(temporary)) {
try { fs.unlinkSync(temporary); } catch (_) { /* ignore */ }
}
if (backupCreated && !installed && !fs.existsSync(destination)) {
fs.renameSync(backup, destination);
try { fs.renameSync(backup, destination); } catch (_) { /* ignore */ }
}
throw new Error(`[replaceOriginalFile] Replacement failed: ${error.message}`);
}