Skip to content

Commit 33da7a7

Browse files
authored
chore: skip file access checks on unmapped node (#877)
* chore: skip file access checks on unmapped node * chore: update configVars * refactor: add getConfigVars * refactor: move configVars
1 parent e499375 commit 33da7a7

File tree

21 files changed

+146
-91
lines changed

21 files changed

+146
-91
lines changed

FlowPlugins/CommunityFlowPlugins/input/inputFile/1.0.0/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ var details = function () { return ({
8484
exports.details = details;
8585
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8686
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
87-
var lib, orignalFolder, _a, fileAccessChecks, pauseNodeIfAccessChecksFail, nodeID, _b, serverIP, serverPort, apiKey, url, pauseNode, checkReadWrite;
88-
return __generator(this, function (_c) {
89-
switch (_c.label) {
87+
var lib, orignalFolder, _a, fileAccessChecks, pauseNodeIfAccessChecksFail, nodeID, _b, serverIP, serverPort, apiKey, url, pauseNode, checkReadWrite, isNotUnmappedNode;
88+
var _c, _d;
89+
return __generator(this, function (_e) {
90+
switch (_e.label) {
9091
case 0:
9192
lib = require('../../../../../methods/lib')();
9293
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
@@ -131,9 +132,11 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
131132
switch (_a.label) {
132133
case 0:
133134
_a.trys.push([0, 2, , 5]);
135+
args.jobLog("Checking read access for: \"".concat(location, "\""));
134136
return [4 /*yield*/, fs_1.promises.access(location, fs_1.promises.constants.R_OK)];
135137
case 1:
136138
_a.sent();
139+
args.jobLog('Read access OK');
137140
return [3 /*break*/, 5];
138141
case 2:
139142
err_1 = _a.sent();
@@ -163,18 +166,19 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
163166
}
164167
});
165168
}); };
166-
if (!fileAccessChecks) return [3 /*break*/, 3];
169+
isNotUnmappedNode = ((_d = (_c = args === null || args === void 0 ? void 0 : args.configVars) === null || _c === void 0 ? void 0 : _c.config) === null || _d === void 0 ? void 0 : _d.nodeType) !== 'unmapped';
170+
if (!(fileAccessChecks && isNotUnmappedNode)) return [3 /*break*/, 3];
167171
args.jobLog('Checking file access');
168172
return [4 /*yield*/, checkReadWrite(orignalFolder)];
169173
case 1:
170-
_c.sent();
174+
_e.sent();
171175
return [4 /*yield*/, checkReadWrite(args.librarySettings.cache)];
172176
case 2:
173-
_c.sent();
177+
_e.sent();
174178
return [3 /*break*/, 4];
175179
case 3:
176180
args.jobLog('Skipping file access checks');
177-
_c.label = 4;
181+
_e.label = 4;
178182
case 4: return [2 /*return*/, {
179183
outputFileObj: args.inputFileObj,
180184
outputNumber: 1,

FlowPluginsTs/CommunityFlowPlugins/input/inputFile/1.0.0/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
8888

8989
const checkReadWrite = async (location: string) => {
9090
try {
91+
args.jobLog(`Checking read access for: "${location}"`);
9192
await fsp.access(location, fsp.constants.R_OK);
93+
args.jobLog('Read access OK');
9294
} catch (err) {
9395
args.jobLog(JSON.stringify(err));
9496
if (pauseNodeIfAccessChecksFail) {
@@ -109,7 +111,9 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
109111
}
110112
};
111113

112-
if (fileAccessChecks) {
114+
const isNotUnmappedNode = args?.configVars?.config?.nodeType !== 'unmapped';
115+
116+
if (fileAccessChecks && isNotUnmappedNode) {
113117
args.jobLog('Checking file access');
114118
await checkReadWrite(orignalFolder);
115119
await checkReadWrite(args.librarySettings.cache);

FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,37 @@ export interface IpluginOutputArgs {
123123
variables: Ivariables,
124124
}
125125

126+
export interface IconfigVars {
127+
config: {
128+
nodeID: string,
129+
nodeName: string,
130+
serverURL: string,
131+
serverIP: string,
132+
serverPort: string,
133+
handbrakePath: string,
134+
ffmpegPath: string,
135+
mkvpropeditPath: string,
136+
pathTranslators: {
137+
server: string,
138+
node: string,
139+
}[],
140+
platform_arch_isdocker: string,
141+
logLevel: string,
142+
processPid: number,
143+
priority: number,
144+
cronPluginUpdate: string,
145+
apiKey: string,
146+
seededWorkerLimits?:{
147+
[index: string]: number,
148+
},
149+
maxLogSizeMB: number,
150+
pollInterval: number,
151+
nodeType: 'mapped' | 'unmapped',
152+
unmappedNodeCache: string,
153+
startPaused: boolean,
154+
}
155+
}
156+
126157
export interface IpluginInputArgs {
127158
inputFileObj: IFileObject,
128159
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -157,6 +188,7 @@ export interface IpluginInputArgs {
157188
logOutcome: (outcome: string) => void,
158189
scanIndividualFile?: (filee: IFileObjectMin, scanTypes: IscanTypes) => Promise<IFileObject>,
159190
updateStat: (db: string, key: string, inc: number) => Promise<void>,
191+
configVars: IconfigVars,
160192
deps: {
161193
// eslint-disable-next-line @typescript-eslint/no-explicit-any
162194
fsextra: any,
@@ -179,13 +211,7 @@ export interface IpluginInputArgs {
179211
axios: any,
180212
// eslint-disable-next-line @typescript-eslint/no-explicit-any
181213
crudTransDBN: (collection: string, mode: string, docID: string, obj: any) => any,
182-
configVars: {
183-
config: {
184-
serverIP: string,
185-
serverPort: string,
186-
apiKey: string,
187-
}
188-
}
214+
configVars: IconfigVars,
189215
},
190216
// eslint-disable-next-line @typescript-eslint/no-explicit-any
191217
installClassicPluginDeps: (deps: string[]) => Promise<any>,

tests/FlowPlugins/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { details, plugin } from
1010
'../../../../../../FlowPluginsTs/CommunityFlowPlugins/basic/basicVideoOrAudio/1.0.0/index';
1111
import { IpluginInputArgs } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces';
1212
import { IFileObject } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/synced/IFileObject';
13+
import getConfigVars from '../../../../configVars';
1314

1415
const sampleH264_1 = require('../../../../../sampleData/media/sampleH264_1.json');
1516
const sampleAAC = require('../../../../../sampleData/media/sampleAAC_1.json');
@@ -19,6 +20,8 @@ describe('basicVideoOrAudio Plugin', () => {
1920
let baseArgs: IpluginInputArgs;
2021

2122
beforeEach(() => {
23+
const configVars = getConfigVars();
24+
2225
baseArgs = {
2326
inputs: {
2427
basicSettingsType: 'video',
@@ -74,6 +77,7 @@ describe('basicVideoOrAudio Plugin', () => {
7477
lastSuccessfulRun: null,
7578
updateStat: jest.fn(),
7679
installClassicPluginDeps: jest.fn(),
80+
configVars,
7781
deps: {
7882
fsextra: {
7983
ensureDirSync: jest.fn(),
@@ -96,13 +100,7 @@ describe('basicVideoOrAudio Plugin', () => {
96100
ncp: jest.fn(),
97101
axios: {},
98102
crudTransDBN: jest.fn(),
99-
configVars: {
100-
config: {
101-
serverIP: '127.0.0.1',
102-
serverPort: '8266',
103-
apiKey: '',
104-
},
105-
},
103+
configVars,
106104
},
107105
} as IpluginInputArgs;
108106
});

tests/FlowPlugins/CommunityFlowPlugins/classic/runClassicFilterPlugin/1.0.0/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { plugin } from
22
'../../../../../../FlowPluginsTs/CommunityFlowPlugins/classic/runClassicFilterPlugin/1.0.0/index';
33
import { IpluginInputArgs } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces';
4+
import getConfigVars from '../../../../configVars';
45

56
const sampleH264 = require('../../../../../sampleData/media/sampleH264_1.json');
67

@@ -33,7 +34,7 @@ describe('runClassicFilterPlugin 1.0.0', () => {
3334
requireFromString: jest.fn(),
3435
axios: {},
3536
os: {},
36-
configVars: {},
37+
configVars: getConfigVars(),
3738
},
3839
} as unknown as IpluginInputArgs;
3940
});

tests/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { plugin } from
22
'../../../../../../FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/1.0.0/index';
33
import { IpluginInputArgs } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces';
4+
import getConfigVars from '../../../../configVars';
45

56
const sampleH264 = require('../../../../../sampleData/media/sampleH264_1.json');
67

@@ -47,7 +48,7 @@ describe('runClassicTranscodePlugin 1.0.0', () => {
4748
requireFromString: jest.fn(),
4849
axios: {},
4950
os: {},
50-
configVars: {},
51+
configVars: getConfigVars(),
5152
},
5253
ffmpegPath: '/usr/bin/ffmpeg',
5354
handbrakePath: '/usr/bin/handbrake',

tests/FlowPlugins/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { plugin } from
22
'../../../../../../FlowPluginsTs/CommunityFlowPlugins/classic/runClassicTranscodePlugin/2.0.0/index';
33
import { IpluginInputArgs } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces';
4+
import getConfigVars from '../../../../configVars';
45

56
const sampleH264 = require('../../../../../sampleData/media/sampleH264_1.json');
67

@@ -47,7 +48,7 @@ describe('runClassicTranscodePlugin 2.0.0', () => {
4748
requireFromString: jest.fn(),
4849
axios: {},
4950
os: {},
50-
configVars: {},
51+
configVars: getConfigVars(),
5152
},
5253
ffmpegPath: '/usr/bin/ffmpeg',
5354
handbrakePath: '/usr/bin/handbrake',

tests/FlowPlugins/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { plugin } from
22
'../../../../../../FlowPluginsTs/CommunityFlowPlugins/ffmpegCommand/ffmpegCommandExecute/1.0.0/index';
33
import { IpluginInputArgs } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces';
44
import { IFileObject } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/synced/IFileObject';
5+
import getConfigVars from '../../../../configVars';
56

67
const sampleH264 = require('../../../../../sampleData/media/sampleH264_1.json');
78

@@ -22,6 +23,8 @@ describe('ffmpegCommandExecute Plugin', () => {
2223
runCli: jest.fn().mockResolvedValue({ cliExitCode: 0 }),
2324
}));
2425

26+
const configVars = getConfigVars();
27+
2528
baseArgs = {
2629
inputs: {},
2730
variables: {
@@ -66,6 +69,7 @@ describe('ffmpegCommandExecute Plugin', () => {
6669
logOutcome: jest.fn(),
6770
logFullCliOutput: false,
6871
workDir: '/tmp/work',
72+
configVars,
6973
deps: {
7074
fsextra: {
7175
ensureDirSync: jest.fn(),
@@ -88,13 +92,7 @@ describe('ffmpegCommandExecute Plugin', () => {
8892
ncp: jest.fn(),
8993
axios: {},
9094
crudTransDBN: jest.fn(),
91-
configVars: {
92-
config: {
93-
serverIP: '127.0.0.1',
94-
serverPort: '8266',
95-
apiKey: '',
96-
},
97-
},
95+
configVars,
9896
},
9997
} as Partial<IpluginInputArgs> as IpluginInputArgs;
10098
});

tests/FlowPlugins/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { plugin } from
22
'../../../../../../FlowPluginsTs/CommunityFlowPlugins/file/compareFileSizeRatio/1.0.0/index';
33
import { IpluginInputArgs } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces';
44
import { IFileObject } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/synced/IFileObject';
5+
import getConfigVars from '../../../../configVars';
56

67
const sampleH264 = require('../../../../../sampleData/media/sampleH264_1.json');
78
const sampleMP3 = require('../../../../../sampleData/media/sampleMP3_1.json');
@@ -17,6 +18,8 @@ describe('compareFileSizeRatio Plugin', () => {
1718
file_size: 100.0,
1819
} as IFileObject;
1920

21+
const configVars = getConfigVars();
22+
2023
baseArgs = {
2124
inputs: {
2225
greaterThan: '40',
@@ -26,6 +29,7 @@ describe('compareFileSizeRatio Plugin', () => {
2629
inputFileObj: JSON.parse(JSON.stringify(sampleH264)) as IFileObject,
2730
originalLibraryFile: mockOriginalFile,
2831
jobLog: jest.fn(),
32+
configVars,
2933
} as Partial<IpluginInputArgs> as IpluginInputArgs;
3034

3135
// Set default working file size (50 MB = 50% of original)

tests/FlowPlugins/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { promises as fsp } from 'fs';
22
import { plugin } from
33
'../../../../../../FlowPluginsTs/CommunityFlowPlugins/file/copyToWorkDirectory/1.0.0/index';
44
import { IpluginInputArgs } from '../../../../../../FlowPluginsTs/FlowHelpers/1.0.0/interfaces/interfaces';
5+
import getConfigVars from '../../../../configVars';
56

67
const sampleH264 = require('../../../../../sampleData/media/sampleH264_1.json');
78

@@ -24,6 +25,8 @@ describe('copyToWorkDirectory Plugin', () => {
2425
beforeEach(() => {
2526
jest.clearAllMocks();
2627

28+
const configVars = getConfigVars();
29+
2730
baseArgs = {
2831
inputs: {},
2932
variables: {} as IpluginInputArgs['variables'],
@@ -53,6 +56,7 @@ describe('copyToWorkDirectory Plugin', () => {
5356
logFullCliOutput: false,
5457
logOutcome: jest.fn(),
5558
updateStat: jest.fn(),
59+
configVars,
5660
deps: {
5761
fsextra: {
5862
ensureDirSync: mockEnsureDirSync,
@@ -71,13 +75,7 @@ describe('copyToWorkDirectory Plugin', () => {
7175
ncp: jest.fn(),
7276
axios: jest.fn(),
7377
crudTransDBN: jest.fn(),
74-
configVars: {
75-
config: {
76-
serverIP: 'localhost',
77-
serverPort: '8265',
78-
apiKey: '',
79-
},
80-
},
78+
configVars,
8179
},
8280
installClassicPluginDeps: jest.fn(),
8381
} as IpluginInputArgs;

0 commit comments

Comments
 (0)