mirror of
https://github.com/whyour/qinglong.git
synced 2026-06-01 11:20:14 +08:00
* 修改获取示例文件 api path * 增加 debian-slim 基础镜像 * 修复 debian apt 命令,支持 qinglong 命令 * 更新 npm 版本 0.7.7 * 更新 npm v0.8.4 * 修复linux依赖检测 (#2082) * 修复拉取私有仓库 * 修复 shell check_server * 修复 qinglong 命令 * 更新 npm 版本 v0.13.2 * 增加 debian 开发版本 * 修改切换 linux 镜像源 * 修复 qinglong 命令 * 移除 qinglong 命令 npm 默认镜像源 * 修复 workflow * 更新 npm 版本 v0.14.5 * 增加 npx 命令 * 更新 workflow action 版本 * 更新 npm 版本 v0.16.0 * 修复 linux 镜像源 * 更新 npm 版本 v0.17.0 * 更新 npm 版本 v0.18.0 * 修改 npm 安装启动命令 * 更新 npm 版本 v0.19.9 * 修复 debian netcat 包名 * 更新 npm 版本 v0.20.4 * 安装 linux 依赖自动识别 alpine 和 debian * 修改 apt 命令 * 更新 npm 版本 v0.21.2 * 修改 ts 文件执行依赖 * npm 启动增加 reload 逻辑 * 更新 npm 版本 v2.17.8 * 修复 qinglong 命令 * 更新 npm 版本 v2.17.9 * 更新 npm 版本 v2.17.10 * 更新 npm 版本 v2.17.11 * 修改 debian 版本为 12 bookworm * 更新 npm 版本 v2.17.12 * 修改本地服务启动提示 * 更新 npm 版本 v2.17.13 * 写入文件增加文件锁 * 修复系统安装依赖提示 * 更新 npm 版本 v2.18.2-6 * 更新 nodejs 版本 * 更新 npm 版本 v2.18.3-3 * 修复 command 变量 * 移除自动清除 deb * 修复 npm 启动脚本 * 修复发布 npm包依赖文件 * 修改 linux 启动文件逻辑 * 更新 npm 版本 v2.19.0-10 * 修复 apt 命令 * 更新 npm 版本 v2.19.1-0 * 更新 npm 版本 v2.19.2-2 * 增加 packageManager * 增加用户 qinglong * 更新 pipeline * 移除 init_nginx * 更新 npm 版本 v2.20.0 * 更新 npm 版本 2.20.1 * 更新 npm 版本 2.20.2 * fix: 修复非 root 用户启动 * chore: 合并 debian 和 alpine 逻辑 --------- Co-authored-by: dream10201 <xiuxiu10201@gmail.com>
101 lines
2.6 KiB
TypeScript
101 lines
2.6 KiB
TypeScript
import { Router, Request, Response, NextFunction } from 'express';
|
|
import { Container } from 'typedi';
|
|
import { Logger } from 'winston';
|
|
import config from '../config';
|
|
import * as fs from 'fs/promises';
|
|
import { celebrate, Joi } from 'celebrate';
|
|
import { join } from 'path';
|
|
import { SAMPLE_FILES } from '../config/const';
|
|
import ConfigService from '../services/config';
|
|
import { writeFileWithLock } from '../shared/utils';
|
|
const route = Router();
|
|
|
|
export default (app: Router) => {
|
|
app.use('/configs', route);
|
|
|
|
route.get(
|
|
'/samples',
|
|
async (req: Request, res: Response, next: NextFunction) => {
|
|
try {
|
|
res.send({
|
|
code: 200,
|
|
data: SAMPLE_FILES,
|
|
});
|
|
} catch (e) {
|
|
return next(e);
|
|
}
|
|
},
|
|
);
|
|
|
|
route.get(
|
|
'/files',
|
|
async (req: Request, res: Response, next: NextFunction) => {
|
|
const logger: Logger = Container.get('logger');
|
|
try {
|
|
const fileList = await fs.readdir(config.configPath, 'utf-8');
|
|
res.send({
|
|
code: 200,
|
|
data: fileList
|
|
.filter((x) => !config.blackFileList.includes(x))
|
|
.map((x) => {
|
|
return { title: x, value: x };
|
|
}),
|
|
});
|
|
} catch (e) {
|
|
return next(e);
|
|
}
|
|
},
|
|
);
|
|
|
|
route.get(
|
|
'/detail',
|
|
async (req: Request, res: Response, next: NextFunction) => {
|
|
try {
|
|
const configService = Container.get(ConfigService);
|
|
await configService.getFile(req.query.path as string, res);
|
|
} catch (e) {
|
|
return next(e);
|
|
}
|
|
},
|
|
);
|
|
|
|
route.post(
|
|
'/save',
|
|
celebrate({
|
|
body: Joi.object({
|
|
name: Joi.string().required(),
|
|
content: Joi.string().allow('').optional(),
|
|
}),
|
|
}),
|
|
async (req: Request, res: Response, next: NextFunction) => {
|
|
const logger: Logger = Container.get('logger');
|
|
try {
|
|
const { name, content } = req.body;
|
|
if (config.blackFileList.includes(name)) {
|
|
res.send({ code: 403, message: '文件无法访问' });
|
|
}
|
|
let path = join(config.configPath, name);
|
|
if (name.startsWith('data/scripts/')) {
|
|
path = join(config.rootPath, name);
|
|
}
|
|
await writeFileWithLock(path, content);
|
|
res.send({ code: 200, message: '保存成功' });
|
|
} catch (e) {
|
|
return next(e);
|
|
}
|
|
},
|
|
);
|
|
|
|
route.get(
|
|
'/:file',
|
|
async (req: Request, res: Response, next: NextFunction) => {
|
|
try {
|
|
const configService = Container.get(ConfigService);
|
|
await configService.getFile(req.params.file, res);
|
|
} catch (e) {
|
|
return next(e);
|
|
}
|
|
},
|
|
);
|
|
};
|