-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
89 lines (66 loc) · 2.57 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';
const createRouter = require('@arangodb/foxx/router');
const router = createRouter();
const fs = require('fs');
module.context.use(router);
// continued
router.get('/', function (req, res) {
let path = `${module.context.basePath}/index.html`;
let l = fs.read(path);
res.set('content-type', "text/html")
res.send(l);
});
// continued
router.get('/tree', function (req, res) {
let sep=fs.pathSeparator;
let base = module.context.basePath.split(sep).slice(0, -3).join(sep);
let db = req.queryParams.db || module.context.basePath.split(sep).slice(-3)[0];
let app = req.queryParams.app || module.context.basePath.split(sep).slice(-2)[0];
let file = req.queryParams.file || 'manifest.json';
let fullPath = [base,db,app,"APP"].join(sep);//`${base}/${db}/${app}/APP/`;
let tree = fs.listTree(fullPath).filter(f=>fs.isFile(`${fullPath}${sep}${f}`));
res.send({
sep:sep,base:base,db:db,app:app,fullPath:fullPath,tree:tree
});return;
res.send(l);
})
.queryParam('db')
.queryParam('app')
// continued
router.get('/apps', function (req, res) {
let sep=fs.pathSeparator;
let base = module.context.basePath.split(sep).slice(0, -3).join(sep);
let db = req.queryParams.db || "_system";
let list = fs.list(`${base}/${db}`).filter(f=>f!="_appbundles");
res.send({ base: base, apps: list });
})
.queryParam('db')
// continued
router.get('/file', function (req, res) {
let sep=fs.pathSeparator;
let base = module.context.basePath.split(sep).slice(0, -3).join(sep);
let db = req.queryParams.db || module.context.basePath.split(sep).slice(-3)[0];
let app = req.queryParams.app || module.context.basePath.split(sep).slice(-2)[0];
let file = req.queryParams.file || 'manifest.json';
let fullPath = `${base}/${db}/${app}/APP/${file}`;
let l = fs.read(fullPath);
//res.send(`{file:"${path}", content:"${l}"}`);
res.send({ path: file, fullPath: fullPath, content: l });
})
.queryParam('db')
.queryParam('app')
.queryParam('file')
// continued
router.put('/file', function (req, res) {
let sep=fs.pathSeparator;
let base = module.context.basePath.split(sep).slice(0, -3).join(sep);
let db = req.queryParams.db || module.context.basePath.split(sep).slice(-3)[0];
let app = req.queryParams.app || module.context.basePath.split(sep).slice(-2)[0];
let file = req.queryParams.file || 'manifest.json';
let fullPath = `${base}/${db}/${app}/APP/${file}`;
let l = fs.write(fullPath, req.body);
res.send(req);
})
.queryParam('db')
.queryParam('app')
.queryParam('file')