mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00

* 重构shell (#17) * 更新正则 * 更新update命令 * 移除测试代码 * 重构删除日志命令 * 更新entrypoint * 更新dockerfile * 完善shell调用 * 修复share shell引用 * 修复entrypoint * 修复share shell * 修复share.sh * 修改依赖重装逻辑 * 更新docker entrypoint * curl 使用静默模式 * 更新ql raw * 修复添加单个任务 * 修复shell语法 * 添加定时任务进程 * 更新默认定时任务 * 更新定时任务重启schedule * 更新青龙重启逻辑 * 修复定时任务列表创建 * 修复schedule进程 * 修复entrypoint * 更新task命令 * pm2 restart替换成reload * 修复task命令参数引入 * 完善ql repo命令 * 修复update.sh * 更新ql repo命令 * ql repo添加登录验证,修复package.json示例 * 修复定时任务命令补全 * 修改默认cron端口 * 修复cron日志弹框异常 * 修改cron新建label * 修复ql repo命令 * 修复cron格式验证 * 修改日志目录格式 * 修改青龙remote url * 修复添加定时cron匹配 * 添加定时任务超时时间设置 * 暂时移除timeout命令 * 恢复定时任务timeout * 修复cookie.sh引用 * 修复shell变量自加 * 修复ck更新状态同步 * 增加tg bot测试,修改增删任务通知 * 修复shell函数返回值 * 修改添加任务日志打印 * 修改entrypoint日志 * 修复api日志打印 * 修改api日志打印 * 定时任务支持批量启用禁用删除运行 * 修改cron管理操作按钮响应样式 * 更新bot启动脚本 * 更新bot启动脚本 * 增加timeout默认值,修改session管理逻辑 * 更新config示例和通知日志 * 更新bot.sh * 更新启动bot命令 * 更新启动bot命令 * 修复task运行参数合并 * 增加停止定时任务功能 * 修复停止定时任务api * 更新停止定时任务日志 * 更新停止任务日志 * 修复删除cron api * 更新删除cron通知文本 * 更新命令提示 * 更新bot启动脚本
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import { Request, Response, NextFunction, Application } from 'express';
|
|
import bodyParser from 'body-parser';
|
|
import cors from 'cors';
|
|
import routes from '../api';
|
|
import config from '../config';
|
|
import jwt from 'express-jwt';
|
|
import fs from 'fs';
|
|
|
|
export default ({ app }: { app: Application }) => {
|
|
app.enable('trust proxy');
|
|
app.use(cors());
|
|
|
|
app.use(bodyParser.json({ limit: '50mb' }));
|
|
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
app.use(
|
|
jwt({ secret: config.secret as string, algorithms: ['HS384'] }).unless({
|
|
path: ['/api/login'],
|
|
}),
|
|
);
|
|
app.use((req, res, next) => {
|
|
if (req.url && req.url.includes('/api/login')) {
|
|
return next();
|
|
}
|
|
const data = fs.readFileSync(config.authConfigFile, 'utf8');
|
|
const authHeader = req.headers.authorization;
|
|
if (data) {
|
|
const { token } = JSON.parse(data);
|
|
if (token && authHeader.includes(token)) {
|
|
return next();
|
|
}
|
|
}
|
|
const err: any = new Error('UnauthorizedError');
|
|
err['status'] = 401;
|
|
next(err);
|
|
});
|
|
app.use(config.api.prefix, routes());
|
|
|
|
app.use((req, res, next) => {
|
|
const err: any = new Error('Not Found');
|
|
err['status'] = 404;
|
|
next(err);
|
|
});
|
|
|
|
app.use(
|
|
(
|
|
err: Error & { status: number },
|
|
req: Request,
|
|
res: Response,
|
|
next: NextFunction,
|
|
) => {
|
|
if (err.name === 'UnauthorizedError') {
|
|
return res
|
|
.status(err.status)
|
|
.send({ code: 401, message: err.message })
|
|
.end();
|
|
}
|
|
return next(err);
|
|
},
|
|
);
|
|
|
|
app.use(
|
|
(
|
|
err: Error & { status: number },
|
|
req: Request,
|
|
res: Response,
|
|
next: NextFunction,
|
|
) => {
|
|
res.status(err.status || 500);
|
|
res.json({
|
|
code: err.status || 500,
|
|
message: err.message,
|
|
});
|
|
},
|
|
);
|
|
};
|