chatgpt-plugin/server/modules/web_route.js
HalcyonAlcedo 0f9c8a7abe
适配Trss (#575)
* fix: 修复星火api上下文

* 将无星火ck的情况降低为warn

* feat: 添加星火设定自定义代码功能

* 修复星火api模式的一些问题

* 修复导出配置问题

* feat:添加工具箱快捷登录接口

* 添加工具箱快捷登录指令

* 阻止群聊使用快捷登录

* 添加Azure配置支持,修复重复的配置项冲突

* 移除旧版本渲染和新版本帮助

* 添加工具箱

* 更新工具箱替换原有后台

* 更新工具箱适配代码

* 后台适配Trss

* 修复trss不支持sendPrivateMsg的问题

* 优化路由

* 修复路由

* 适配其他uin
2023-10-08 21:37:43 +08:00

63 lines
No EOL
2.4 KiB
JavaScript

import { UserInfo } from './user_data.js'
import fs from 'fs'
async function routes(fastify, options) {
fastify.get('/page/*', async (request, reply) => {
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
fastify.get('/version', async (request, reply) => {
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
fastify.get('/auth/*', async (request, reply) => {
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
fastify.get('/admin*', async (request, reply) => {
const token = request.cookies.token || request.body?.token || 'unknown'
const user = UserInfo(token)
if (!user) {
reply.redirect(301, '/auth/login')
}
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
fastify.get('/admin/dashboard', async (request, reply) => {
const token = request.cookies.token || request.body?.token || 'unknown'
const user = UserInfo(token)
if (!user) {
reply.redirect(301, '/auth/login')
}
if (user.autho === 'admin') {
reply.redirect(301, '/admin/settings')
}
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
fastify.get('/admin/settings', async (request, reply) => {
const token = request.cookies.token || request.body?.token || 'unknown'
const user = UserInfo(token)
if (!user || user.autho != 'admin') {
reply.redirect(301, '/admin/')
}
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
fastify.setNotFoundHandler((request, reply) => {
if (request.method == 'GET') {
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/index.html')
reply.type('text/html').send(stream)
} else {
reply.code(404).send(new Error('Not Found'))
}
})
}
export default routes