-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (34 loc) · 1.08 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
const fs = require('fs');
require('dotenv').config()
const usbDetect = require('usb-detection');
const drivelist = require('drivelist');
// console.log(process.env.KEY_LOCATION);
const key = fs.readFileSync(String(process.env.KEY_LOCATION), 'utf-8')
let usbList = [];
usbDetect.startMonitoring();
// Detect insert
usbDetect.on('add', () => {
const poll = setInterval(() => {
drivelist.list().then((drives) => {
drives.forEach((drive) => {
if (drive.isUSB) {
const mountPath = drive.mountpoints[0].path;
if (!usbList.includes(mountPath)) {
confirmation(mountPath, key); //op
usbList.push(mountPath);
clearInterval(poll)
}
}
})
})
}, 2000)
});
function confirmation(path) {
const attempt = fs.readFileSync(`${path}/test/text.txt`, 'utf8');
if(parseInt(key) == parseInt(attempt)){
console.log(`I'm in`)
}
else{
console.log('Cancelled');
}
}