-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.js
42 lines (34 loc) · 1.07 KB
/
listener.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
/** Imports */
const fs = require('fs');
const detect = require('./detect.js');
const util = require('util');
/** Detect USB device */
detect('attach', (driveLetter) => {
console.log("Sony A6400 Camera Storage device detected on drive %s", driveLetter);
let sourcePath = util.format('%s\\DCIM', driveLetter);
let t = new Date();
let targetPath = util.format('D:\\Photos\\extract-%s-%s-%s-%s-%s-%s',t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds());
copyFile(sourcePath, targetPath)
.then(() => {
console.log('Files downloaded automatically from camera!');
}, (err) => {
throw err;
})
});
/**
* Copy a file from place to place
* @param {string} src
* @param {string} dest
*/
function copyFile(src = '', dest = '') {
return new Promise((resolve, reject) => {
fs.copyFile(src, dest, (err) => {
if(err)
reject(err);
else {
console.log('Copied "%s" -> "%s"', src, dest);
resolve(true);
}
})
});
}