-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparityCheck.js
74 lines (64 loc) · 2.1 KB
/
parityCheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import fs from 'fs';
import { walkSync } from './walkSync.js';
export const parityCheck = () => {
const targetFilePaths = [];
for (const filePath of walkSync(process.env.TARGET_DIR)) {
targetFilePaths.push(filePath);
}
const cloudFilePaths = [];
for (const filePath of walkSync(process.env.CLOUD_DIR)) {
cloudFilePaths.push(filePath);
}
let targetInventory = targetFilePaths.map((i) =>
i.replace(process.env.TARGET_DIR, '')
);
let cloudInventory = cloudFilePaths.map((i) =>
i.replace(process.env.CLOUD_DIR, '')
);
// filter out residual files (e.g., DS_STORE et al.)
// specifically we only look for mp4/MTS extensions!
targetInventory = targetInventory.filter(
(i) =>
i.includes('.mp4') ||
i.includes('.MP4') ||
i.includes('.MTS') ||
i.includes('.mts')
);
cloudInventory = cloudInventory.filter(
(i) =>
i.includes('.mp4') ||
i.includes('.MP4') ||
i.includes('.MTS') ||
i.includes('.mts')
);
const targetInventoryLower = targetInventory.map((i) => i.toLowerCase());
const cloudInventoryLower = cloudInventory.map((i) => i.toLowerCase());
// https://stackoverflow.com/a/33034768/2258480
let missingEntries = [];
let missingCloudFiles = targetInventoryLower.filter((i) => {
missingEntries.push(!cloudInventoryLower.includes(i));
return !cloudInventoryLower.includes(i);
});
missingEntries = [...missingEntries.keys()].filter((i) => missingEntries[i]);
missingCloudFiles = [];
missingEntries.map((i) => missingCloudFiles.push(targetFilePaths[i]));
try {
fs.writeFileSync(
'inventory.json',
JSON.stringify({ target: targetInventory, cloud: cloudInventory })
);
console.log('inventory.json written');
} catch (err) {
console.log(err, 'An error occured while writing JSON Object to File.');
}
try {
fs.writeFileSync(
'missingcloudfiles.json',
JSON.stringify({ missingCloudFiles })
);
console.log('missingcloudfiles.json written');
} catch (err) {
console.log(err, 'An error occured while writing JSON Object to File.');
}
return missingCloudFiles;
};