This repository has been archived by the owner on Feb 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
63 lines (51 loc) · 1.33 KB
/
app.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
var chokidar = require('chokidar');
var copy = require("copy-paste");
var notifier = require('node-notifier');
var fs = require('fs');
var settings = require('./settings.js').settings;
var p = require('path');
var debug = require('debug')('upload-screenshot');
var async = require('async');
var service = settings.services[settings.used];
var watcher = chokidar.watch(settings.dir, {
ignoreInitial: true,
persistent: true,
ignored: /[\/\\]\./ //ignore dotfiles
});
try {
var Serv = require('./services/'+service.name);
var s = new Serv(service);
} catch(e) {
console.error(e);
process.exit(1);
}
var q = async.queue(function(path, callback) {
s.upload(path, function(shortlink){
copyShortLink(shortlink, path);
callback();
});
}, 1);
function copyShortLink(shortlink, path) {
copy.copy(shortlink, function() {
notifier.notify({
'title': 'Uploaded',
'message': shortlink,
'appIcon': __dirname + '/icones/up.png',
'contentImage': path,
'open': shortlink
});
});
}
function isPicture(path) {
return !!~['jpeg','jpg','png','gif','bmp','ico']
.indexOf(p.extname(path).substring(1));
}
watcher.on('add', function(path) {
if(!isPicture(path))
return;
fs.exists(path, function(exist) {
if(!exist)
return;
q.push(path);
});
});