-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (45 loc) · 1.3 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
http = require('http');
fs = require('fs');
path = require('path');
root = process.env.CLOUD_DIR;
http.createServer(function (req, res) {
// list
if (req.url == '/') {
res.writeHead(200, {'Content-Type': 'text/html'});
var response = '<pre>FILES IN ' + process.env.CLOUD_DIR + ': \n';
response += '------------------\n\n';
var readDir = function (dpath) {
var filenames = fs.readdirSync(dpath);
filenames.forEach(function (filename) {
var thePath = path.join(dpath, filename);
if (fs.lstatSync(thePath).isDirectory()) {
response += '\n\n' + thePath.toUpperCase() + '\n';
response += '\n';
readDir(thePath);
} else {
response += filename + '\n';
}
});
};
readDir(root);
response += '</pre>\n\n<a href="/clean">Clean it up!</a>';
res.end(response);
//delete
} else if (req.url == '/clean') {
res.writeHead(200, {'Content-Type': 'text/plain'});
var deleteDir = function (dpath) {
var filenames = fs.readdirSync(dpath);
filenames.forEach(function (filename) {
var thePath = path.join(dpath, filename);
if (fs.lstatSync(thePath).isDirectory()) {
deleteDir(thePath);
fs.rmdirSync(thePath);
} else {
fs.unlinkSync(thePath);
}
});
};
deleteDir(root);
res.end('Done.');
}
}).listen(process.env.PORT);