forked from longmenwaideyu/ueditor-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
40 lines (40 loc) · 1.07 KB
/
util.js
File metadata and controls
40 lines (40 loc) · 1.07 KB
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
var util = {};
var guid = 1000;
var config = null;
util.setConfig = function(c) {
config = c;
}
util.getFileName = function(extname) {
var d = new Date();
var name = [ d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(),
d.getMinutes(), d.getSeconds(), d.getMilliseconds(), guid++ ]
.join('_') + extname;
return name;
}
util.getUrlRoot = function (dPath) {
if (config.mode == 'local')
return dPath;
else return config.hostName + '/' + config.staticPath;
}
util.getRealDynamicPath = function (req) {
var dPath = config.dynamicPath;
if (typeof dPath == 'function')
dPath = dPath(req);
return dPath;
}
util.stringify = function (obj) {
var str = obj;
try {
str = JSON.stringify(obj);
}catch (e) {
}
return str;
}
util.readdir = function(path, callback) {
if (config.mode == 'bcs') {
util.bcsListObject(dPath, callback);
} else {
fs.readdir(path.join(config.staticPath, dPath), callback);
}
}
module.exports = util;