-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
39 lines (31 loc) · 980 Bytes
/
util.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
var sys = require('sys');
var exec = require('child_process').exec;
var imagePath = __dirname + '/tmp/uploads/';
var tempImagePath = __dirname + '/tmp/temp-images/';
function getUrl (text) {
var url,
regex = /((http|https|ftp|ftps))?\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/;
text = text.replace(/\n/g, ' ');
console.log('text: ' + text);
if (text.match(regex)) {
url = text.match(regex)[0];
url = url.indexOf('"') === -1 ? url : url.substr(0, url.indexOf('"'));
} else {
url = null;
}
return url;
};
function cleanImageFolders() {
exec('rm ' + tempImagePath + '*', function (err, stdout, stderr) {
console.log('Removing temporary images..');
sys.puts(stdout);
});
exec('rm ' + imagePath + '*', function (err, stdout, stderr) {
console.log('Removing uploaded images..');
sys.puts(stdout);
});
}
exports.imagePath = imagePath;
exports.tempPath = tempImagePath;
exports.removeImages = cleanImageFolders;
exports.getUrl = getUrl;