forked from yydfys/CatPawOpen
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrouter.js
93 lines (91 loc) · 3.43 KB
/
router.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
90
91
92
93
import kunyu77 from './spider/video/kunyu77.js';
import kkys from './spider/video/kkys.js';
import push from './spider/video/push.js';
import alist from './spider/pan/alist.js';
import _13bqg from './spider/book/13bqg.js';
import copymanga from './spider/book/copymanga.js';
import ffm3u8 from './spider/video/ffm3u8.js';
const spiders = [kunyu77, kkys, ffm3u8, push, alist, _13bqg, copymanga];
const spiderPrefix = '/spider';
/**
* A function to initialize the router.
*
* @param {Object} fastify - The Fastify instance
* @return {Promise<void>} - A Promise that resolves when the router is initialized
*/
export default async function router(fastify) {
// register all spider router
spiders.forEach((spider) => {
const path = spiderPrefix + '/' + spider.meta.key + '/' + spider.meta.type;
fastify.register(spider.api, { prefix: path });
console.log('Register spider: ' + path);
});
/**
* @api {get} /check 检查
*/
fastify.register(
/**
*
* @param {import('fastify').FastifyInstance} fastify
*/
async (fastify) => {
fastify.get(
'/check',
/**
* check api alive or not
* @param {import('fastify').FastifyRequest} _request
* @param {import('fastify').FastifyReply} reply
*/
async function (_request, reply) {
reply.send({ run: !fastify.stop });
}
);
fastify.get(
'/config',
/**
* get catopen format config
* @param {import('fastify').FastifyRequest} _request
* @param {import('fastify').FastifyReply} reply
*/
async function (_request, reply) {
const config = {
video: {
sites: [],
},
read: {
sites: [],
},
comic: {
sites: [],
},
music: {
sites: [],
},
pan: {
sites: [],
},
color: fastify.config.color || [],
};
spiders.forEach((spider) => {
let meta = Object.assign({}, spider.meta);
meta.api = spiderPrefix + '/' + meta.key + '/' + meta.type;
meta.key = 'nodejs_' + meta.key;
const stype = spider.meta.type;
if (stype < 10) {
config.video.sites.push(meta);
} else if (stype >= 10 && stype < 20) {
config.read.sites.push(meta);
} else if (stype >= 20 && stype < 30) {
config.comic.sites.push(meta);
} else if (stype >= 30 && stype < 40) {
config.music.sites.push(meta);
} else if (stype >= 40 && stype < 50) {
config.pan.sites.push(meta);
}
});
reply.send(config);
}
);
}
);
}