-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
57 lines (51 loc) · 1.7 KB
/
app.js
File metadata and controls
57 lines (51 loc) · 1.7 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Created by bileskou on 16/8/20.
*/
const Koa = require('koa');
const Router = require('koa-router');
const fs = require("fs");
const serve = require('koa-static');
const app = new Koa();
const router = new Router();
router.get('/version/:system/:arch/', ctx => {
var system = ctx.params.system;
var arch = ctx.params.arch;
var folder_exists = fs.existsSync('./version');
var dir_paths = fs.readdirSync('./version');
var ves = '0.0.0.0';
dir_paths.forEach(filename => {
var vesTemp1 = ves.split('.');
var vesTemp2 = filename.split('.');
if (parseInt(vesTemp1[0]) < parseInt(vesTemp2[0])
|| parseInt(vesTemp1[1]) < parseInt(vesTemp2[1])
|| parseInt(vesTemp1[2]) < parseInt(vesTemp2[2])
|| parseInt(vesTemp1[3]) < parseInt(vesTemp2[3])) {
ves = filename;
}
});
console.log(ves);
var file_paths = fs.readdirSync('./version/' + ves);
console.log(file_paths);
var file_path = "";
file_paths.forEach(filePath => {
if (filePath.match(new RegExp(".*" + system + "_" + arch + ".*"))) {
file_path = filePath;
}
});
console.log(file_path);
if (folder_exists && file_path !== "")
ctx.body = {result: true, msg: "success", data: ves + "/" + file_path};
else
ctx.body = {result: false, msg: "can't find the last", data: null};
});
app.use(async(ctx, next) => {
const start = new Date();
await next();
const ms = new Date() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
})
.use(router.routes())
.use(router.allowedMethods())
.use(serve('./version'));
app.listen(3000);
console.log("application listen port 3000");