Add new copy/move options

make-only-subtitle-default
HaveAGitGat 2 years ago
parent f410caf1ad
commit ca8ec26b81

@ -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 };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.plugin = exports.details = void 0;
var fs_1 = require("fs");
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 }] */
var details = function () { return ({
name: 'Copy to Directory',
@ -56,12 +60,12 @@ var details = function () { return ({
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
type: 'directory',
},
tooltip: 'Specify ouput directory',
},
{
name: 'makeWorkingFile',
name: 'keepRelativePath',
type: 'boolean',
defaultValue: 'false',
inputUI: {
@ -71,6 +75,32 @@ var details = function () { return ({
'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',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'dropdown',
options: [
'false',
'true',
],
},
tooltip: 'Make the copied file the working file',
},
],
@ -84,23 +114,54 @@ var details = function () { return ({
exports.details = details;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
var lib, originalFileName, newContainer, outputPath, workingFile;
return __generator(this, function (_a) {
switch (_a.label) {
var lib, _a, copyToWorkDir, keepRelativePath, makeWorkingFile, outputDirectory, originalFileName, newContainer, outputPath, subStem, ouputFilePath, workingFile;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
lib = require('../../../../../methods/lib')();
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
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);
newContainer = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
outputPath = "".concat(args.inputs.outputDirectory, "/").concat(originalFileName, ".").concat(newContainer);
return [4 /*yield*/, fs_1.promises.copyFile(args.inputFileObj._id, outputPath)];
case 1:
_a.sent();
outputPath = '';
if (copyToWorkDir) {
outputPath = args.workDir;
}
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 (args.inputs.makeWorkingFile) {
workingFile = outputPath;
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*/, {
outputFileObj: {
_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 };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.plugin = exports.details = void 0;
var fs_1 = require("fs");
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 }] */
var details = function () { return ({
name: 'Move To Directory',
@ -56,10 +60,23 @@ var details = function () { return ({
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
type: '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: [
{
@ -71,22 +88,50 @@ var details = function () { return ({
exports.details = details;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
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) {
switch (_a.label) {
case 0:
lib = require('../../../../../methods/lib')();
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
args.inputs = lib.loadDefaultValues(args.inputs, details);
keepRelativePath = args.inputs.keepRelativePath;
outputDirectory = String(args.inputs.outputDirectory);
originalFileName = (0, fileUtils_1.getFileName)(args.originalLibraryFile._id);
newContainer = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
outputPath = "".concat(args.inputs.outputDirectory, "/").concat(originalFileName, ".").concat(newContainer);
return [4 /*yield*/, fs_1.promises.rename(args.inputFileObj._id, outputPath)];
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:
_a.sent();
return [2 /*return*/, {
outputFileObj: {
_id: outputPath,
_id: ouputFilePath,
},
outputNumber: 1,
variables: args.variables,

@ -1,6 +1,6 @@
"use strict";
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 parts = filePath.split('.');
return parts[parts.length - 1];
@ -10,8 +10,17 @@ var getFileName = function (filePath) {
var parts = filePath.split('/');
var fileNameAndContainer = parts[parts.length - 1];
var parts2 = fileNameAndContainer.split('.');
return parts2[0];
parts2.pop();
return parts2.join('.');
};
exports.getFileName = getFileName;
var getFfType = function (codecType) { return (codecType === 'video' ? 'v' : 'a'); };
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;

@ -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 { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
import { getContainer, getFileName, getSubStem } from '../../../../FlowHelpers/1.0.0/fileUtils';
import {
IpluginDetails,
IpluginInputArgs,
IpluginOutputArgs,
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
import normJoinPath from '../../../../FlowHelpers/1.0.0/normJoinPath';
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = (): IpluginDetails => ({
@ -24,12 +25,25 @@ const details = (): IpluginDetails => ({
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
type: 'directory',
},
tooltip: 'Specify ouput directory',
},
{
name: 'makeWorkingFile',
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: {
@ -39,6 +53,19 @@ const details = (): IpluginDetails => ({
'true',
],
},
tooltip: 'Specify whether to copy to the working directory',
},
{
name: 'makeWorkingFile',
type: 'boolean',
defaultValue: 'false',
inputUI: {
type: 'dropdown',
options: [
'false',
'true',
],
},
tooltip: 'Make the copied file the working file',
},
],
@ -56,19 +83,57 @@ 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);
const {
copyToWorkDir, keepRelativePath, makeWorkingFile,
} = args.inputs;
const outputDirectory = String(args.inputs.outputDirectory);
const originalFileName = getFileName(args.originalLibraryFile._id);
const newContainer = getContainer(args.inputFileObj._id);
const outputPath = `${args.inputs.outputDirectory}/${originalFileName}.${newContainer}`;
let 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;
}
await fs.copyFile(args.inputFileObj._id, outputPath);
const ouputFilePath = normJoinPath({
upath: args.deps.upath,
paths: [
outputPath,
`${originalFileName}.${newContainer}`,
],
});
let workingFile = args.inputFileObj._id;
if (args.inputs.makeWorkingFile) {
workingFile = outputPath;
if (makeWorkingFile || copyToWorkDir) {
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 {
outputFileObj: {
_id: workingFile,

@ -1,10 +1,11 @@
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 {
IpluginDetails,
IpluginInputArgs,
IpluginOutputArgs,
} from '../../../../FlowHelpers/1.0.0/interfaces/interfaces';
import normJoinPath from '../../../../FlowHelpers/1.0.0/normJoinPath';
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */
const details = ():IpluginDetails => ({
@ -24,10 +25,23 @@ const details = ():IpluginDetails => ({
type: 'string',
defaultValue: '',
inputUI: {
type: 'text',
type: '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: [
{
@ -43,16 +57,51 @@ 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);
const {
keepRelativePath,
} = args.inputs;
const outputDirectory = String(args.inputs.outputDirectory);
const originalFileName = getFileName(args.originalLibraryFile._id);
const newContainer = getContainer(args.inputFileObj._id);
const outputPath = `${args.inputs.outputDirectory}/${originalFileName}.${newContainer}`;
let 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}`);
await fs.rename(args.inputFileObj._id, outputPath);
args.deps.fsextra.ensureDirSync(outputPath);
await fs.rename(args.inputFileObj._id, ouputFilePath);
return {
outputFileObj: {
_id: outputPath,
_id: ouputFilePath,
},
outputNumber: 1,
variables: args.variables,

@ -7,7 +7,22 @@ export const getFileName = (filePath: string):string => {
const parts = filePath.split('/');
const fileNameAndContainer = parts[parts.length - 1];
const parts2 = fileNameAndContainer.split('.');
return parts2[0];
parts2.pop();
return parts2.join('.');
};
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';
export interface IpluginInputUi {
type: 'dropdown' | 'text' | 'textarea',
type: 'dropdown' | 'text' | 'textarea' | 'directory',
options?: string[],
style?:Record<string, unknown>,
onSelect?: {
@ -115,5 +115,7 @@ export interface IpluginInputArgs {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
axiosMiddleware: (endpoint: string, data: Record<string, unknown>) => Promise<any>,
requireFromString: (pluginText: string, relativePath:string) => Record<string, unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
upath:any,
},
}

@ -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…
Cancel
Save