-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (53 loc) · 1.89 KB
/
index.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
module.exports = async($, router) => {
await $.rq('init');
await $.st(await $.pa('asset'), { defer: true, });
await $.io(await $.rq('io'));
router.get('/', async(ctx, next) => {
await next();
if(ctx.req.url == '/kq1/') {
ctx.status = 301;
ctx.redirect('https://'+ctx.accept.headers.host+'/kq1');
return;
}
let query = {};
if(ctx.originalUrl != ctx._matchedRoute)
query = qs.parse(qs.unescape(ctx.originalUrl.replace('/kq1\?', '')));
if(!query.serv) query.serv = 'cn';
ctx.type = 'html';
ctx.body = fs.createReadStream(await $.pa('asset/html/index.html'))
.pipe(replaceStream('${serv}', query.serv))
.pipe(replaceStream('${word}', query.word || ''))
.pipe(replaceStream('${page}', query.page || 1))
.pipe(replaceStream('${mark}', query.mark || ''));
});
router.get('/subs/:sub/:name.:ext', async(ctx) => {
let p = ctx.params;
ctx.type = p.ext;
if(ctx.query.tab)
ctx.body = fs.createReadStream(await $.pa(`asset/subs/${p.sub}/${p.name}.${p.ext}`))
.pipe(replaceStream('__name__', p.sub));
else
ctx.body = fs.createReadStream(await $.pa(`asset/subs/${p.sub}/${p.name}.${p.ext}`))
.pipe(replaceStream('__name__', p.sub)).pipe(replaceStream('\t', ''));
});
// let queryer = await $.rq('libs/queryer');
// router.get('/ex', async(ctx) => {
// let result = await queryer(
// {id:{$gt:99961001}}, {}, 'cn', 1, 1000
// );
// let r = [];
// for(let c of result[0]) {
// r.push([c.name, c.rare, c.skill.suport3[0]?c.skill.suport3[0].content[0].replace('<samp title="技能元素等价于卡面显示的元素">技能</samp>', '技能'):'']);
// }
// let str = '<table border="0">';
// for(let c of r) {
// str += `
// <tr>
// <th>${c[0]}(${c[1]})</th>
// <th>${c[2]}</th>
// </tr>`.trim();
// }
// str += '</table>';
// ctx.body = str;
// });
};