Skip to content

Commit

Permalink
Merge pull request #645 from HaveAGitGat/node_scan
Browse files Browse the repository at this point in the history
Use Node scan function if available
  • Loading branch information
HaveAGitGat authored May 21, 2024
2 parents 7bb090d + ff3c73f commit e142db1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 36 deletions.
47 changes: 31 additions & 16 deletions FlowPlugins/FlowHelpers/1.0.0/classicPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.runClassicPlugin = void 0;
var fs_1 = require("fs");
var fileUtils_1 = require("./fileUtils");
var runClassicPlugin = function (args, type) { return __awaiter(void 0, void 0, void 0, function () {
var path, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, pluginSrcStr, res, container, cacheFilePath, scanTypes, pluginInputFileObj, originalLibraryFile, otherArguments, result;
var path, pluginSourceId, parts, pluginSource, pluginId, relativePluginPath, absolutePath, classicPlugin, pluginSrcStr, res, container, cacheFilePath, scanTypes, pluginInputFileObj, originalLibraryFile, inputFileScanArgs, originalLibraryFileScanArgs, otherArguments, result;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
Expand Down Expand Up @@ -99,28 +99,43 @@ var runClassicPlugin = function (args, type) { return __awaiter(void 0, void 0,
container = (0, fileUtils_1.getContainer)(args.inputFileObj._id);
cacheFilePath = "".concat((0, fileUtils_1.getPluginWorkDir)(args), "/").concat((0, fileUtils_1.getFileName)(args.inputFileObj._id), ".").concat(container);
scanTypes = (0, fileUtils_1.getScanTypes)([pluginSrcStr]);
inputFileScanArgs = {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
};
originalLibraryFileScanArgs = {
_id: args.originalLibraryFile._id,
file: args.originalLibraryFile.file,
DB: args.originalLibraryFile.DB,
footprintId: args.originalLibraryFile.footprintId,
};
if (!(typeof args.scanIndividualFile !== 'undefined')) return [3 /*break*/, 12];
args.jobLog('Scanning files using Node');
return [4 /*yield*/, args.scanIndividualFile(inputFileScanArgs, scanTypes)];
case 10:
pluginInputFileObj = _b.sent();
return [4 /*yield*/, args.scanIndividualFile(originalLibraryFileScanArgs, scanTypes)];
case 11:
originalLibraryFile = _b.sent();
return [3 /*break*/, 15];
case 12:
args.jobLog('Scanning files using Server API');
return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
},
file: inputFileScanArgs,
scanTypes: scanTypes,
})];
case 10:
case 13:
pluginInputFileObj = _b.sent();
return [4 /*yield*/, args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.originalLibraryFile._id,
file: args.originalLibraryFile.file,
DB: args.originalLibraryFile.DB,
footprintId: args.originalLibraryFile.footprintId,
},
file: originalLibraryFileScanArgs,
scanTypes: scanTypes,
})];
case 11:
case 14:
originalLibraryFile = _b.sent();
_b.label = 15;
case 15:
otherArguments = {
handbrakePath: args.handbrakePath,
ffmpegPath: args.ffmpegPath,
Expand All @@ -135,7 +150,7 @@ var runClassicPlugin = function (args, type) { return __awaiter(void 0, void 0,
job: args.job,
};
return [4 /*yield*/, classicPlugin.plugin(pluginInputFileObj, args.librarySettings, args.inputs, otherArguments)];
case 12:
case 16:
result = _b.sent();
if (((_a = result === null || result === void 0 ? void 0 : result.file) === null || _a === void 0 ? void 0 : _a._id) && args.inputFileObj._id !== result.file._id) {
// eslint-disable-next-line no-param-reassign
Expand Down
55 changes: 36 additions & 19 deletions FlowPluginsTs/FlowHelpers/1.0.0/classicPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getContainer, getFileName, getPluginWorkDir, getScanTypes,
} from './fileUtils';
import { IpluginInputArgs } from './interfaces/interfaces';
import { IFileObject } from './interfaces/synced/IFileObject';

export interface IrunClassicPlugin {
result:{
Expand Down Expand Up @@ -90,25 +91,41 @@ export const runClassicPlugin = async (args:IpluginInputArgs, type:'filter'|'tra

const scanTypes = getScanTypes([pluginSrcStr]);

const pluginInputFileObj = await args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
},
scanTypes,
});

const originalLibraryFile = await args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: {
_id: args.originalLibraryFile._id,
file: args.originalLibraryFile.file,
DB: args.originalLibraryFile.DB,
footprintId: args.originalLibraryFile.footprintId,
},
scanTypes,
});
let pluginInputFileObj:IFileObject;
let originalLibraryFile:IFileObject;

const inputFileScanArgs = {
_id: args.inputFileObj._id,
file: args.inputFileObj.file,
DB: args.inputFileObj.DB,
footprintId: args.inputFileObj.footprintId,
};

const originalLibraryFileScanArgs = {
_id: args.originalLibraryFile._id,
file: args.originalLibraryFile.file,
DB: args.originalLibraryFile.DB,
footprintId: args.originalLibraryFile.footprintId,
};

// added in 2.19.01
if (typeof args.scanIndividualFile !== 'undefined') {
args.jobLog('Scanning files using Node');
pluginInputFileObj = await args.scanIndividualFile(inputFileScanArgs, scanTypes);
originalLibraryFile = await args.scanIndividualFile(originalLibraryFileScanArgs, scanTypes);
} else {
args.jobLog('Scanning files using Server API');

pluginInputFileObj = await args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: inputFileScanArgs,
scanTypes,
});

originalLibraryFile = await args.deps.axiosMiddleware('api/v2/scan-individual-file', {
file: originalLibraryFileScanArgs,
scanTypes,
});
}

const otherArguments = {
handbrakePath: args.handbrakePath,
Expand Down
4 changes: 3 additions & 1 deletion FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IFileObject, Istreams } from './synced/IFileObject';
import { IscanTypes } from '../fileUtils';
import { IFileObject, IFileObjectMin, Istreams } from './synced/IFileObject';
import Ijob from './synced/jobInterface';

export interface IpluginInputUi {
Expand Down Expand Up @@ -136,6 +137,7 @@ export interface IpluginInputArgs {
updateWorker: IupdateWorker,
logFullCliOutput: boolean,
logOutcome: (outcome: string) => void,
scanIndividualFile?: (filee: IFileObjectMin, scanTypes: IscanTypes) => IFileObject,
deps: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fsextra: any,
Expand Down

0 comments on commit e142db1

Please sign in to comment.