mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-16 18:45:53 -07:00
Add new copy/move options
This commit is contained in:
parent
f410caf1ad
commit
ca8ec26b81
9 changed files with 326 additions and 33 deletions
|
|
@ -35,10 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.plugin = exports.details = void 0;
|
exports.plugin = exports.details = void 0;
|
||||||
var fs_1 = require("fs");
|
var fs_1 = require("fs");
|
||||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||||
|
var normJoinPath_1 = __importDefault(require("../../../../FlowHelpers/1.0.0/normJoinPath"));
|
||||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||||
var details = function () { return ({
|
var details = function () { return ({
|
||||||
name: 'Copy to Directory',
|
name: 'Copy to Directory',
|
||||||
|
|
@ -56,16 +60,42 @@ var details = function () { return ({
|
||||||
type: 'string',
|
type: 'string',
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
type: 'directory',
|
||||||
},
|
},
|
||||||
tooltip: 'Specify ouput directory',
|
tooltip: 'Specify ouput directory',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'keepRelativePath',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
options: [
|
||||||
|
'false',
|
||||||
|
'true',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip: 'Specify whether to keep the relative path',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'copyToWorkDir',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
options: [
|
||||||
|
'false',
|
||||||
|
'true',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip: 'Specify whether to copy to the working directory',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'makeWorkingFile',
|
name: 'makeWorkingFile',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
defaultValue: 'false',
|
defaultValue: 'false',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
type: 'dropdown',
|
||||||
options: [
|
options: [
|
||||||
'false',
|
'false',
|
||||||
'true',
|
'true',
|
||||||
|
|
@ -84,23 +114,54 @@ var details = function () { return ({
|
||||||
exports.details = details;
|
exports.details = details;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
var lib, originalFileName, newContainer, outputPath, workingFile;
|
var lib, _a, copyToWorkDir, keepRelativePath, makeWorkingFile, outputDirectory, originalFileName, newContainer, outputPath, subStem, ouputFilePath, workingFile;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_b) {
|
||||||
switch (_a.label) {
|
switch (_b.label) {
|
||||||
case 0:
|
case 0:
|
||||||
lib = require('../../../../../methods/lib')();
|
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
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
_a = args.inputs, copyToWorkDir = _a.copyToWorkDir, keepRelativePath = _a.keepRelativePath, makeWorkingFile = _a.makeWorkingFile;
|
||||||
|
outputDirectory = String(args.inputs.outputDirectory);
|
||||||
originalFileName = (0, fileUtils_1.getFileName)(args.originalLibraryFile._id);
|
originalFileName = (0, fileUtils_1.getFileName)(args.originalLibraryFile._id);
|
||||||
newContainer = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
newContainer = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||||
outputPath = "".concat(args.inputs.outputDirectory, "/").concat(originalFileName, ".").concat(newContainer);
|
outputPath = '';
|
||||||
return [4 /*yield*/, fs_1.promises.copyFile(args.inputFileObj._id, outputPath)];
|
if (copyToWorkDir) {
|
||||||
case 1:
|
outputPath = args.workDir;
|
||||||
_a.sent();
|
|
||||||
workingFile = args.inputFileObj._id;
|
|
||||||
if (args.inputs.makeWorkingFile) {
|
|
||||||
workingFile = outputPath;
|
|
||||||
}
|
}
|
||||||
|
else if (keepRelativePath) {
|
||||||
|
subStem = (0, fileUtils_1.getSubStem)({
|
||||||
|
inputPathStem: args.librarySettings.folder,
|
||||||
|
inputPath: args.originalLibraryFile._id,
|
||||||
|
});
|
||||||
|
outputPath = (0, normJoinPath_1.default)({
|
||||||
|
upath: args.deps.upath,
|
||||||
|
paths: [
|
||||||
|
outputDirectory,
|
||||||
|
subStem,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputPath = outputDirectory;
|
||||||
|
}
|
||||||
|
ouputFilePath = (0, normJoinPath_1.default)({
|
||||||
|
upath: args.deps.upath,
|
||||||
|
paths: [
|
||||||
|
outputPath,
|
||||||
|
"".concat(originalFileName, ".").concat(newContainer),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
workingFile = args.inputFileObj._id;
|
||||||
|
if (makeWorkingFile || copyToWorkDir) {
|
||||||
|
workingFile = ouputFilePath;
|
||||||
|
}
|
||||||
|
args.jobLog("Input path: ".concat(args.inputFileObj._id));
|
||||||
|
args.jobLog("Output path: ".concat(outputPath));
|
||||||
|
args.deps.fsextra.ensureDirSync(outputPath);
|
||||||
|
return [4 /*yield*/, fs_1.promises.copyFile(args.inputFileObj._id, ouputFilePath)];
|
||||||
|
case 1:
|
||||||
|
_b.sent();
|
||||||
return [2 /*return*/, {
|
return [2 /*return*/, {
|
||||||
outputFileObj: {
|
outputFileObj: {
|
||||||
_id: workingFile,
|
_id: workingFile,
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.plugin = exports.details = void 0;
|
exports.plugin = exports.details = void 0;
|
||||||
var fs_1 = require("fs");
|
var fs_1 = require("fs");
|
||||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||||
|
var normJoinPath_1 = __importDefault(require("../../../../FlowHelpers/1.0.0/normJoinPath"));
|
||||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||||
var details = function () { return ({
|
var details = function () { return ({
|
||||||
name: 'Move To Directory',
|
name: 'Move To Directory',
|
||||||
|
|
@ -56,10 +60,23 @@ var details = function () { return ({
|
||||||
type: 'string',
|
type: 'string',
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
type: 'directory',
|
||||||
},
|
},
|
||||||
tooltip: 'Specify ouput directory',
|
tooltip: 'Specify ouput directory',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'keepRelativePath',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
options: [
|
||||||
|
'false',
|
||||||
|
'true',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip: 'Specify whether to keep the relative path',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
|
|
@ -71,22 +88,50 @@ var details = function () { return ({
|
||||||
exports.details = details;
|
exports.details = details;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
var lib, originalFileName, newContainer, outputPath;
|
var lib, keepRelativePath, outputDirectory, originalFileName, newContainer, outputPath, subStem, ouputFilePath;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0:
|
case 0:
|
||||||
lib = require('../../../../../methods/lib')();
|
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
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
keepRelativePath = args.inputs.keepRelativePath;
|
||||||
|
outputDirectory = String(args.inputs.outputDirectory);
|
||||||
originalFileName = (0, fileUtils_1.getFileName)(args.originalLibraryFile._id);
|
originalFileName = (0, fileUtils_1.getFileName)(args.originalLibraryFile._id);
|
||||||
newContainer = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
newContainer = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
|
||||||
outputPath = "".concat(args.inputs.outputDirectory, "/").concat(originalFileName, ".").concat(newContainer);
|
outputPath = '';
|
||||||
return [4 /*yield*/, fs_1.promises.rename(args.inputFileObj._id, outputPath)];
|
if (keepRelativePath) {
|
||||||
|
subStem = (0, fileUtils_1.getSubStem)({
|
||||||
|
inputPathStem: args.librarySettings.folder,
|
||||||
|
inputPath: args.originalLibraryFile._id,
|
||||||
|
});
|
||||||
|
outputPath = (0, normJoinPath_1.default)({
|
||||||
|
upath: args.deps.upath,
|
||||||
|
paths: [
|
||||||
|
outputDirectory,
|
||||||
|
subStem,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
outputPath = outputDirectory;
|
||||||
|
}
|
||||||
|
ouputFilePath = (0, normJoinPath_1.default)({
|
||||||
|
upath: args.deps.upath,
|
||||||
|
paths: [
|
||||||
|
outputPath,
|
||||||
|
"".concat(originalFileName, ".").concat(newContainer),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
args.jobLog("Input path: ".concat(args.inputFileObj._id));
|
||||||
|
args.jobLog("Output path: ".concat(ouputFilePath));
|
||||||
|
args.deps.fsextra.ensureDirSync(outputPath);
|
||||||
|
return [4 /*yield*/, fs_1.promises.rename(args.inputFileObj._id, ouputFilePath)];
|
||||||
case 1:
|
case 1:
|
||||||
_a.sent();
|
_a.sent();
|
||||||
return [2 /*return*/, {
|
return [2 /*return*/, {
|
||||||
outputFileObj: {
|
outputFileObj: {
|
||||||
_id: outputPath,
|
_id: ouputFilePath,
|
||||||
},
|
},
|
||||||
outputNumber: 1,
|
outputNumber: 1,
|
||||||
variables: args.variables,
|
variables: args.variables,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.getFfType = exports.getFileName = exports.getContainer = void 0;
|
exports.getSubStem = exports.getFfType = exports.getFileName = exports.getContainer = void 0;
|
||||||
var getContainer = function (filePath) {
|
var getContainer = function (filePath) {
|
||||||
var parts = filePath.split('.');
|
var parts = filePath.split('.');
|
||||||
return parts[parts.length - 1];
|
return parts[parts.length - 1];
|
||||||
|
|
@ -10,8 +10,17 @@ var getFileName = function (filePath) {
|
||||||
var parts = filePath.split('/');
|
var parts = filePath.split('/');
|
||||||
var fileNameAndContainer = parts[parts.length - 1];
|
var fileNameAndContainer = parts[parts.length - 1];
|
||||||
var parts2 = fileNameAndContainer.split('.');
|
var parts2 = fileNameAndContainer.split('.');
|
||||||
return parts2[0];
|
parts2.pop();
|
||||||
|
return parts2.join('.');
|
||||||
};
|
};
|
||||||
exports.getFileName = getFileName;
|
exports.getFileName = getFileName;
|
||||||
var getFfType = function (codecType) { return (codecType === 'video' ? 'v' : 'a'); };
|
var getFfType = function (codecType) { return (codecType === 'video' ? 'v' : 'a'); };
|
||||||
exports.getFfType = getFfType;
|
exports.getFfType = getFfType;
|
||||||
|
var getSubStem = function (_a) {
|
||||||
|
var inputPathStem = _a.inputPathStem, inputPath = _a.inputPath;
|
||||||
|
var subStem = inputPath.substring(inputPathStem.length);
|
||||||
|
var parts = subStem.split('/');
|
||||||
|
parts.pop();
|
||||||
|
return parts.join('/');
|
||||||
|
};
|
||||||
|
exports.getSubStem = getSubStem;
|
||||||
|
|
|
||||||
19
FlowPlugins/FlowHelpers/1.0.0/normJoinPath.js
Normal file
19
FlowPlugins/FlowHelpers/1.0.0/normJoinPath.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
var formatWindowsRootFolder = function (path) {
|
||||||
|
// Remove '.' from end of Windows root folder mapping e.g. 'E:.'
|
||||||
|
if (path.length === 3
|
||||||
|
&& path.charAt(1) === ':'
|
||||||
|
&& path.charAt(2) === '.') {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
path = path.slice(0, -1);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
var normJoinPath = function (_a) {
|
||||||
|
var upath = _a.upath, paths = _a.paths;
|
||||||
|
var path = upath.joinSafe.apply(upath, paths);
|
||||||
|
path = formatWindowsRootFolder(path);
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
exports.default = normJoinPath;
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
import { getContainer, getFileName, getSubStem } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
IpluginInputArgs,
|
IpluginInputArgs,
|
||||||
IpluginOutputArgs,
|
IpluginOutputArgs,
|
||||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||||
|
import normJoinPath from '../../../../FlowHelpers/1.0.0/normJoinPath';
|
||||||
|
|
||||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||||
const details = (): IpluginDetails => ({
|
const details = (): IpluginDetails => ({
|
||||||
|
|
@ -24,16 +25,42 @@ const details = (): IpluginDetails => ({
|
||||||
type: 'string',
|
type: 'string',
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
type: 'directory',
|
||||||
},
|
},
|
||||||
tooltip: 'Specify ouput directory',
|
tooltip: 'Specify ouput directory',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'keepRelativePath',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
options: [
|
||||||
|
'false',
|
||||||
|
'true',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip: 'Specify whether to keep the relative path',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'copyToWorkDir',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
options: [
|
||||||
|
'false',
|
||||||
|
'true',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip: 'Specify whether to copy to the working directory',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'makeWorkingFile',
|
name: 'makeWorkingFile',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
defaultValue: 'false',
|
defaultValue: 'false',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
type: 'dropdown',
|
||||||
options: [
|
options: [
|
||||||
'false',
|
'false',
|
||||||
'true',
|
'true',
|
||||||
|
|
@ -56,19 +83,57 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
|
||||||
|
const {
|
||||||
|
copyToWorkDir, keepRelativePath, makeWorkingFile,
|
||||||
|
} = args.inputs;
|
||||||
|
|
||||||
|
const outputDirectory = String(args.inputs.outputDirectory);
|
||||||
|
|
||||||
const originalFileName = getFileName(args.originalLibraryFile._id);
|
const originalFileName = getFileName(args.originalLibraryFile._id);
|
||||||
const newContainer = getContainer(args.inputFileObj._id);
|
const newContainer = getContainer(args.inputFileObj._id);
|
||||||
|
|
||||||
const outputPath = `${args.inputs.outputDirectory}/${originalFileName}.${newContainer}`;
|
let outputPath = '';
|
||||||
|
|
||||||
await fs.copyFile(args.inputFileObj._id, outputPath);
|
if (copyToWorkDir) {
|
||||||
|
outputPath = args.workDir;
|
||||||
|
} else if (keepRelativePath) {
|
||||||
|
const subStem = getSubStem({
|
||||||
|
inputPathStem: args.librarySettings.folder,
|
||||||
|
inputPath: args.originalLibraryFile._id,
|
||||||
|
});
|
||||||
|
|
||||||
|
outputPath = normJoinPath({
|
||||||
|
upath: args.deps.upath,
|
||||||
|
paths: [
|
||||||
|
outputDirectory,
|
||||||
|
subStem,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
outputPath = outputDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ouputFilePath = normJoinPath({
|
||||||
|
upath: args.deps.upath,
|
||||||
|
paths: [
|
||||||
|
outputPath,
|
||||||
|
`${originalFileName}.${newContainer}`,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
let workingFile = args.inputFileObj._id;
|
let workingFile = args.inputFileObj._id;
|
||||||
|
|
||||||
if (args.inputs.makeWorkingFile) {
|
if (makeWorkingFile || copyToWorkDir) {
|
||||||
workingFile = outputPath;
|
workingFile = ouputFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args.jobLog(`Input path: ${args.inputFileObj._id}`);
|
||||||
|
args.jobLog(`Output path: ${outputPath}`);
|
||||||
|
|
||||||
|
args.deps.fsextra.ensureDirSync(outputPath);
|
||||||
|
|
||||||
|
await fs.copyFile(args.inputFileObj._id, ouputFilePath);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
outputFileObj: {
|
outputFileObj: {
|
||||||
_id: workingFile,
|
_id: workingFile,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
import { getContainer, getFileName, getSubStem } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
IpluginInputArgs,
|
IpluginInputArgs,
|
||||||
IpluginOutputArgs,
|
IpluginOutputArgs,
|
||||||
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
|
||||||
|
import normJoinPath from '../../../../FlowHelpers/1.0.0/normJoinPath';
|
||||||
|
|
||||||
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
|
||||||
const details = ():IpluginDetails => ({
|
const details = ():IpluginDetails => ({
|
||||||
|
|
@ -24,10 +25,23 @@ const details = ():IpluginDetails => ({
|
||||||
type: 'string',
|
type: 'string',
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
inputUI: {
|
inputUI: {
|
||||||
type: 'text',
|
type: 'directory',
|
||||||
},
|
},
|
||||||
tooltip: 'Specify ouput directory',
|
tooltip: 'Specify ouput directory',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'keepRelativePath',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: 'false',
|
||||||
|
inputUI: {
|
||||||
|
type: 'text',
|
||||||
|
options: [
|
||||||
|
'false',
|
||||||
|
'true',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
tooltip: 'Specify whether to keep the relative path',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
outputs: [
|
outputs: [
|
||||||
{
|
{
|
||||||
|
|
@ -43,16 +57,51 @@ const plugin = async (args:IpluginInputArgs):Promise<IpluginOutputArgs> => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
|
||||||
|
const {
|
||||||
|
keepRelativePath,
|
||||||
|
} = args.inputs;
|
||||||
|
|
||||||
|
const outputDirectory = String(args.inputs.outputDirectory);
|
||||||
|
|
||||||
const originalFileName = getFileName(args.originalLibraryFile._id);
|
const originalFileName = getFileName(args.originalLibraryFile._id);
|
||||||
const newContainer = getContainer(args.inputFileObj._id);
|
const newContainer = getContainer(args.inputFileObj._id);
|
||||||
|
|
||||||
const outputPath = `${args.inputs.outputDirectory}/${originalFileName}.${newContainer}`;
|
let outputPath = '';
|
||||||
|
|
||||||
await fs.rename(args.inputFileObj._id, outputPath);
|
if (keepRelativePath) {
|
||||||
|
const subStem = getSubStem({
|
||||||
|
inputPathStem: args.librarySettings.folder,
|
||||||
|
inputPath: args.originalLibraryFile._id,
|
||||||
|
});
|
||||||
|
|
||||||
|
outputPath = normJoinPath({
|
||||||
|
upath: args.deps.upath,
|
||||||
|
paths: [
|
||||||
|
outputDirectory,
|
||||||
|
subStem,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
outputPath = outputDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ouputFilePath = normJoinPath({
|
||||||
|
upath: args.deps.upath,
|
||||||
|
paths: [
|
||||||
|
outputPath,
|
||||||
|
`${originalFileName}.${newContainer}`,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
args.jobLog(`Input path: ${args.inputFileObj._id}`);
|
||||||
|
args.jobLog(`Output path: ${ouputFilePath}`);
|
||||||
|
|
||||||
|
args.deps.fsextra.ensureDirSync(outputPath);
|
||||||
|
await fs.rename(args.inputFileObj._id, ouputFilePath);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
outputFileObj: {
|
outputFileObj: {
|
||||||
_id: outputPath,
|
_id: ouputFilePath,
|
||||||
},
|
},
|
||||||
outputNumber: 1,
|
outputNumber: 1,
|
||||||
variables: args.variables,
|
variables: args.variables,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,22 @@ export const getFileName = (filePath: string):string => {
|
||||||
const parts = filePath.split('/');
|
const parts = filePath.split('/');
|
||||||
const fileNameAndContainer = parts[parts.length - 1];
|
const fileNameAndContainer = parts[parts.length - 1];
|
||||||
const parts2 = fileNameAndContainer.split('.');
|
const parts2 = fileNameAndContainer.split('.');
|
||||||
return parts2[0];
|
parts2.pop();
|
||||||
|
return parts2.join('.');
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFfType = (codecType:string):string => (codecType === 'video' ? 'v' : 'a');
|
export const getFfType = (codecType:string):string => (codecType === 'video' ? 'v' : 'a');
|
||||||
|
|
||||||
|
export const getSubStem = ({
|
||||||
|
inputPathStem,
|
||||||
|
inputPath,
|
||||||
|
}: {
|
||||||
|
inputPathStem: string,
|
||||||
|
inputPath: string,
|
||||||
|
}):string => {
|
||||||
|
const subStem = inputPath.substring(inputPathStem.length);
|
||||||
|
const parts = subStem.split('/');
|
||||||
|
parts.pop();
|
||||||
|
|
||||||
|
return parts.join('/');
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { IFileObject, Istreams } from './synced/IFileObject';
|
||||||
import Ijob from './synced/jobInterface';
|
import Ijob from './synced/jobInterface';
|
||||||
|
|
||||||
export interface IpluginInputUi {
|
export interface IpluginInputUi {
|
||||||
type: 'dropdown' | 'text' | 'textarea',
|
type: 'dropdown' | 'text' | 'textarea' | 'directory',
|
||||||
options?: string[],
|
options?: string[],
|
||||||
style?:Record<string, unknown>,
|
style?:Record<string, unknown>,
|
||||||
onSelect?: {
|
onSelect?: {
|
||||||
|
|
@ -115,5 +115,7 @@ export interface IpluginInputArgs {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
axiosMiddleware: (endpoint: string, data: Record<string, unknown>) => Promise<any>,
|
axiosMiddleware: (endpoint: string, data: Record<string, unknown>) => Promise<any>,
|
||||||
requireFromString: (pluginText: string, relativePath:string) => Record<string, unknown>,
|
requireFromString: (pluginText: string, relativePath:string) => Record<string, unknown>,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
upath:any,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
FlowPluginsTs/FlowHelpers/1.0.0/normJoinPath.ts
Normal file
28
FlowPluginsTs/FlowHelpers/1.0.0/normJoinPath.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
const formatWindowsRootFolder = (path: string): string => {
|
||||||
|
// Remove '.' from end of Windows root folder mapping e.g. 'E:.'
|
||||||
|
if (
|
||||||
|
path.length === 3
|
||||||
|
&& path.charAt(1) === ':'
|
||||||
|
&& path.charAt(2) === '.'
|
||||||
|
) {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
path = path.slice(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
|
||||||
|
const normJoinPath = ({
|
||||||
|
upath,
|
||||||
|
paths,
|
||||||
|
}:{
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
upath: any,
|
||||||
|
paths: string[]
|
||||||
|
}):string => {
|
||||||
|
let path = upath.joinSafe(...paths);
|
||||||
|
path = formatWindowsRootFolder(path);
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default normJoinPath;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue