|
1 | | -/** |
2 | | - * 控制器路由注册模块 |
3 | | - * 统一管理和注册所有控制器路由 |
4 | | - * 提供应用程序的所有API端点和功能模块 |
5 | | - */ |
6 | 1 | import formBody from '@fastify/formbody'; |
7 | 2 | import websocket from '@fastify/websocket'; |
| 3 | +import websocketController from './websocket.js'; |
| 4 | +import staticController from './static.js'; |
| 5 | +import docsController from './docs.js'; |
| 6 | +import configController from './config.js'; |
| 7 | +import apiController from './api.js'; |
| 8 | +import mediaProxyController from './mediaProxy.js'; |
| 9 | +import rootController from './root.js'; |
| 10 | +import encoderController from './encoder.js'; |
| 11 | +import decoderController from './decoder.js'; |
| 12 | +import authcoderController from './authcoder.js'; |
| 13 | +import webController from './web.js'; |
| 14 | +import httpController from './http.js'; |
| 15 | +import clipboardPusherController from './clipboard-pusher.js'; |
| 16 | +// import taskerController from './tasker.js'; |
| 17 | +import cronTaskerController from './cron-tasker.js'; |
| 18 | +import sourceCheckerController from './source-checker.js'; |
| 19 | +import imageStoreController from './image-store.js'; |
| 20 | +import webdavProxyController from './webdav-proxy.js'; |
| 21 | +import ftpProxyController from './ftp-proxy.js'; |
| 22 | +import fileProxyController from './file-proxy.js'; |
| 23 | +import m3u8ProxyController from './m3u8-proxy.js'; |
| 24 | +import unifiedProxyController from './unified-proxy.js'; |
| 25 | +import githubController from './github.js'; |
| 26 | +import websocketServerController from "./websocketServer.js"; |
8 | 27 |
|
9 | | -// 懒加载辅助函数 |
10 | | -const lazyRegister = (fastify, importFn, options) => { |
11 | | - fastify.register(async (instance, opts) => { |
12 | | - const module = await importFn(); |
13 | | - const plugin = module.default || module; |
14 | | - // 使用传入的 options (全局配置) |
15 | | - await instance.register(plugin, options); |
16 | | - }); |
17 | | -}; |
18 | | - |
19 | | -/** |
20 | | - * 注册所有路由控制器 |
21 | | - * 将各个功能模块的路由注册到Fastify实例中 |
22 | | - * @param {Object} fastify - Fastify应用实例 |
23 | | - * @param {Object} options - 路由配置选项 |
24 | | - */ |
25 | 28 | export const registerRoutes = (fastify, options) => { |
26 | | - // 注册插件以支持 application/x-www-form-urlencoded |
27 | 29 | fastify.register(formBody); |
28 | | - // 注册WebSocket插件 |
29 | 30 | fastify.register(websocket); |
30 | | - |
31 | | - // WebSocket实时日志控制器-最早引入才能全局拦截console日志 |
32 | | - lazyRegister(fastify, () => import('./websocket.js'), options); |
33 | | - // 静态文件服务控制器 |
34 | | - lazyRegister(fastify, () => import('./static.js'), options); |
35 | | - // 文档服务控制器 |
36 | | - lazyRegister(fastify, () => import('./docs.js'), options); |
37 | | - // 配置管理控制器 |
38 | | - lazyRegister(fastify, () => import('./config.js'), options); |
39 | | - // API接口控制器 |
40 | | - lazyRegister(fastify, () => import('./api.js'), options); |
41 | | - // 媒体代理控制器 |
42 | | - lazyRegister(fastify, () => import('./mediaProxy.js'), options); |
43 | | - // 根路径控制器 |
44 | | - lazyRegister(fastify, () => import('./root.js'), options); |
45 | | - // 编码器控制器 |
46 | | - lazyRegister(fastify, () => import('./encoder.js'), options); |
47 | | - // 解码器控制器 |
48 | | - lazyRegister(fastify, () => import('./decoder.js'), options); |
49 | | - // 认证编码控制器 |
50 | | - lazyRegister(fastify, () => import('./authcoder.js'), options); |
51 | | - // Web界面控制器 |
52 | | - lazyRegister(fastify, () => import('./web.js'), options); |
53 | | - // HTTP请求控制器 |
54 | | - lazyRegister(fastify, () => import('./http.js'), options); |
55 | | - // 剪贴板推送控制器 |
56 | | - lazyRegister(fastify, () => import('./clipboard-pusher.js'), options); |
57 | | - // 任务控制器(已注释) |
58 | | - // lazyRegister(fastify, () => import('./tasker.js'), options); |
59 | | - // 定时任务控制器 |
60 | | - lazyRegister(fastify, () => import('./cron-tasker.js'), options); |
61 | | - // 源检查控制器 |
62 | | - lazyRegister(fastify, () => import('./source-checker.js'), options); |
63 | | - // 图片存储控制器 |
64 | | - lazyRegister(fastify, () => import('./image-store.js'), options); |
65 | | - // WebDAV 代理控制器 |
66 | | - lazyRegister(fastify, () => import('./webdav-proxy.js'), options); |
67 | | - // FTP 代理控制器 |
68 | | - lazyRegister(fastify, () => import('./ftp-proxy.js'), options); |
69 | | - // 文件代理控制器 |
70 | | - lazyRegister(fastify, () => import('./file-proxy.js'), options); |
71 | | - lazyRegister(fastify, () => import('./m3u8-proxy.js'), options); |
72 | | - // 注册统一代理路由 |
73 | | - lazyRegister(fastify, () => import('./unified-proxy.js'), options); |
74 | | - // 注册GitHub Release路由 |
75 | | - lazyRegister(fastify, () => import('./github.js'), options); |
| 31 | + |
| 32 | + fastify.register(websocketController, options); |
| 33 | + fastify.register(staticController, options); |
| 34 | + fastify.register(docsController, options); |
| 35 | + fastify.register(configController, options); |
| 36 | + fastify.register(apiController, options); |
| 37 | + fastify.register(mediaProxyController, options); |
| 38 | + fastify.register(rootController, options); |
| 39 | + fastify.register(encoderController, options); |
| 40 | + fastify.register(decoderController, options); |
| 41 | + fastify.register(authcoderController, options); |
| 42 | + fastify.register(webController, options); |
| 43 | + fastify.register(httpController, options); |
| 44 | + fastify.register(clipboardPusherController, options); |
| 45 | + // fastify.register(taskerController, options); |
| 46 | + fastify.register(cronTaskerController, options); |
| 47 | + fastify.register(sourceCheckerController, options); |
| 48 | + fastify.register(imageStoreController, options); |
| 49 | + fastify.register(webdavProxyController, options); |
| 50 | + fastify.register(ftpProxyController, options); |
| 51 | + fastify.register(fileProxyController, options); |
| 52 | + fastify.register(m3u8ProxyController, options); |
| 53 | + fastify.register(unifiedProxyController, options); |
| 54 | + fastify.register(githubController, options); |
76 | 55 | }; |
77 | 56 |
|
78 | | -/** |
79 | | - * 注册弹幕路由控制器 |
80 | | - * 将弹幕功能模块的路由注册到Fastify实例中 |
81 | | - * @param {Object} wsApp - Ws实时弹幕预览应用实例 |
82 | | - * @param {Object} options - 路由配置选项 |
83 | | - */ |
84 | 57 | export const registerWsRoutes = (wsApp, options) => { |
85 | | - lazyRegister(wsApp, () => import("./websocketServer.js"), options); |
86 | | -} |
| 58 | + wsApp.register(websocketServerController, options); |
| 59 | +}; |
0 commit comments