forked from MyOutDeskLLC/node-browser-history
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrowsers.js
130 lines (119 loc) · 3.26 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const Path = require('path')
const fs = require("fs");
const { setupDefaultPaths: setupPaths } = require('./history_paths');
const CHROME = "Google Chrome",
FIREFOX = "Mozilla Firefox",
TORCH = "Torch",
OPERA = "Opera",
ARC = "Arc",
SEAMONKEY = "SeaMonkey",
VIVALDI = "Vivaldi",
SAFARI = "Safari",
MAXTHON = "Maxthon",
EDGE = "Microsoft Edge",
BRAVE = "Brave",
AVAST = "AVAST Browser";
let browserDbLocations = {
chrome: "",
firefox: "",
opera: "",
arc : "",
edge: "",
torch: "",
seamonkey: "",
vivaldi: "",
maxthon: "",
safari: "",
brave: "",
avast: ""
};
let defaultPaths = setupPaths();
/**
* 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) {
try {
if(depth === 4){
return [];
}
let results = [];
if (!fs.existsSync(startPath)) {
return results;
}
let files = fs.readdirSync(startPath);
for (let i = 0; i < files.length; i++) {
let filename = Path.join(startPath, files[i]);
if (!fs.existsSync(filename)) {
continue;
}
let stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
results = results.concat(findFilesInDir(filename, filter, targetFile, depth + 1)); //recurse
} else if(filename.endsWith(targetFile) === true) {
results.push(filename);
}
/*
} else if (filename.indexOf(filter) >= 0 && regExp.test(filename)) {
results.push(filename);
} else if (filename.endsWith('\\History') === true) {
// console.log('-- found: ', filename);
results.push(filename);
}*/
}
return results;
} catch (error) {
console.log('Error in findFilesInDir: ', error);
}
}
/**
* 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 FIREFOX:
case SEAMONKEY:
return findFilesInDir(path, ".sqlite", Path.sep + 'places.sqlite');
case CHROME:
case TORCH:
case OPERA:
case ARC:
case BRAVE:
case VIVALDI:
case EDGE:
case AVAST:
return findFilesInDir(path, "History", Path.sep + 'History');
case SAFARI:
return findFilesInDir(path, ".db", Path.sep + 'History.db');
case MAXTHON:
return findFilesInDir(path, ".dat", Path.sep + 'History.dat');
default:
return [];
}
}
module.exports = {
findPaths,
browserDbLocations,
defaultPaths,
CHROME,
FIREFOX,
TORCH,
OPERA,
ARC,
SEAMONKEY,
VIVALDI,
SAFARI,
MAXTHON,
BRAVE,
EDGE,
AVAST
};