-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
64 lines (53 loc) · 1.73 KB
/
index.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
/**
* tozan
* https://github.com/paazmaya/tozan
* Index filesystem by creating metadata database
*
* Copyright (c) Juga Paazmaya <[email protected]> (https://paazmaya.fi)
* Licensed under the MIT license
*/
import {
execSync
} from 'node:child_process';
import arrayUniq from 'array-uniq';
import constants from './lib/constants.js';
import findFiles from './lib/find-files.js';
import processFiles from './lib/process-files.js';
/**
* What is the version of OpenSSL binary?
* Used for checking its existence.
* Exposed for unit testing only.
*
* @param {string} command Command for checking version
* @returns {string|boolean} Version or false
*/
export const openSSLVersion = (command) => {
try {
return execSync(command, constants.EXEC_OPTIONS);
}
catch {
console.error('Looks like "openssl" is not available, hence cannot continue.');
return false;
}
};
/**
* Checks that OpenSSL is available before getting a list of files and process them.
*
* @param {string} directory Root directory in which images should be
* @param {object} options Options that are all boolean values and false by default
* @param {string} options.database Possible database file to be used with SQLite
* @param {string} options.algorithm Hash algorithm to use
* @param {boolean} options.ignoreDotFiles Ignore files and directories that begin with a dot
*
* @returns {boolean} Processed or not
*/
export default function tozan(directory, options) {
const version = openSSLVersion(constants.OPENSSL_VERSION);
if (!version) {
return false;
}
console.log(`Using "${version.trim()}" for ${options.algorithm} hashing`);
const files = arrayUniq(findFiles(directory, options));
processFiles(files, options);
return true;
}