ssr_degrade.js
1.75 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
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
const Router = require('koa-router');
const SsrDegradeModel = require('../models/ssrDegradeModel');
let r = new Router();
const ssrDegrade = {
async index(ctx, next) {
const ssrDegradeModel = new SsrDegradeModel();
const apps = await ssrDegradeModel.getApps();
return ctx.render('action/ssr_degrade', {
list: apps || []
});
},
async editPage(ctx, next) {
const ssrDegradeModel = new SsrDegradeModel();
const app = ctx.request.query.app;
if (!app) {
return ctx.render('action/ssr_degrade_edit', {
data: {}
});
}
const appData = await ssrDegradeModel.getApp(app);
return ctx.render('action/ssr_degrade_edit', {
data: appData
});
},
async edit(ctx, next) {
const ssrDegradeModel = new SsrDegradeModel();
const data = ctx.request.body;
if (!data.app || !Array.isArray(data.degrades)) {
return ctx.body = {
code: 400,
message: '参数错误'
};
}
const result = ssrDegradeModel.editApp(data);
if (result) {
return ctx.body = {
code: 200,
};
}
return ctx.body = {
code: 500,
message: '失败'
};
},
async delete(ctx, next) {
const ssrDegradeModel = new SsrDegradeModel();
const app = ctx.request.query.app;
if (!app) {
return ctx.body = {
code: 400,
message: '参数错误'
};
}
const result = ssrDegradeModel.deleteApp({app});
if (result) {
return ctx.body = {
code: 200,
};
}
return ctx.body = {
code: 500,
message: '失败'
};
}
};
r.get('/index', ssrDegrade.index);
r.get('/edit', ssrDegrade.editPage);
r.post('/edit', ssrDegrade.edit);
r.get('/delete', ssrDegrade.delete);
module.exports = r;