forked from MyOutDeskLLC/node-browser-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowsers.js
79 lines (65 loc) · 1.85 KB
/
browsers.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
75
76
77
78
79
const Path = require("path");
const fs = require("fs");
const { setupDefaultPaths: setupPaths } = require("./history_paths");
const CHROME = "Google Chrome";
const browserDbLocations = {
chrome: "",
};
const defaultPaths = {
chrome: "",
};
setupPaths(defaultPaths);
/**
* Find all files recursively in specific folder with specific extension, e.g:
* findFilesInDir('./project/src', '.html') ==> ['./project/src/a.html','./project/src/build/index.html']
* @param {String} startPath Path relative to this file or other file which requires this files
* @param {String} filter Extension name, e.g: '.html'
* @param targetFile
* @param depth
* @return {Array} Result files with path string in an array
*/
function findFilesInDir(startPath, filter, targetFile, depth = 0) {
if (depth === 4) {
return [];
}
let results = [];
if (!fs.existsSync(startPath)) {
return results;
}
const files = fs.readdirSync(startPath);
for (let i = 0; i < files.length; i++) {
const filename = Path.join(startPath, files[i]);
if (!fs.existsSync(filename)) {
// eslint-disable-next-line no-continue
continue;
}
const stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
results = results.concat(findFilesInDir(filename, filter, targetFile, depth + 1));
} else if (filename.endsWith(targetFile) === true) {
results.push(filename);
}
}
return results;
}
/**
* Finds the path to the browsers DB file.
* Returns an array of strings, paths, or an empty array
* @param path
* @param browserName
* @returns {Array}
*/
function findPaths(path, browserName) {
switch (browserName) {
case CHROME:
return findFilesInDir(path, "History", `${Path.sep}History`);
default:
return [];
}
}
module.exports = {
findPaths,
browserDbLocations,
defaultPaths,
CHROME,
};