Compare commits

..

9 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] d04c621e6a Simplify baseUrl implementation using URL rewrite
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
2025-12-22 15:07:12 +00:00
copilot-swe-agent[bot] e56bdc8e81 Apply code review suggestions: improve clarity and simplify logic
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
2025-12-22 14:57:49 +00:00
copilot-swe-agent[bot] 60aab8f95d Add clarifying comments and improve code readability
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
2025-12-22 14:55:32 +00:00
copilot-swe-agent[bot] 8bff4202c7 Fix path construction: use req.path directly for whitelist check
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
2025-12-22 14:53:42 +00:00
copilot-swe-agent[bot] 0bae11def6 Address code review feedback: fix JWT regex and path construction
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
2025-12-22 14:51:49 +00:00
copilot-swe-agent[bot] 10f19a5c1d Update websocket and frontend to support base URL
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
2025-12-22 14:47:34 +00:00
copilot-swe-agent[bot] f5f9d464cb Fix whitelist check to use base-URL-aware paths
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
2025-12-22 14:45:14 +00:00
copilot-swe-agent[bot] a38b876a74 Add QlBaseUrl support to backend routes
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
2025-12-22 14:43:36 +00:00
copilot-swe-agent[bot] 2b875d634f Initial plan 2025-12-22 14:36:15 +00:00
4 changed files with 23 additions and 42 deletions
+14
View File
@@ -64,6 +64,19 @@ if (!process.env.QL_DIR) {
const lastVersionFile = `https://qn.whyour.cn/version.yaml`;
// Get and normalize QlBaseUrl
let baseUrl = process.env.QlBaseUrl || '';
if (baseUrl) {
// Ensure it starts with /
if (!baseUrl.startsWith('/')) {
baseUrl = `/${baseUrl}`;
}
// Remove trailing slash for consistency in route definitions
if (baseUrl.endsWith('/')) {
baseUrl = baseUrl.slice(0, -1);
}
}
const rootPath = process.env.QL_DIR as string;
const envFound = dotenv.config({ path: path.join(rootPath, '.env') });
@@ -116,6 +129,7 @@ if (envFound.error) {
export default {
...config,
jwt: config.jwt,
baseUrl,
rootPath,
tmpPath,
dataPath,
-15
View File
@@ -397,21 +397,6 @@ export function psTree(pid: number): Promise<number[]> {
});
}
export function isPidRunning(pid: number): boolean {
// Validate PID: must be a positive integer
if (pid == null || pid <= 0 || !Number.isInteger(pid)) {
return false;
}
try {
// Signal 0 doesn't kill the process, just checks if it exists
process.kill(pid, 0);
return true;
} catch (error) {
return false;
}
}
export async function killTask(pid: number) {
const pids = await psTree(pid);
+7
View File
@@ -15,6 +15,13 @@ import path from 'path';
export default ({ app }: { app: Application }) => {
app.set('trust proxy', 'loopback');
app.use(cors());
// Rewrite URLs to strip baseUrl prefix if configured
// This allows the rest of the app to work without baseUrl awareness
if (config.baseUrl) {
app.use(rewrite(`${config.baseUrl}/*`, '/$1'));
}
app.get(`${config.api.prefix}/env.js`, serveEnv);
app.use(`${config.api.prefix}/static`, express.static(config.uploadPath));
+2 -27
View File
@@ -13,7 +13,7 @@ import { AuthDataType, SystemModel } from '../data/system';
import SystemService from '../services/system';
import UserService from '../services/user';
import { writeFile, readFile } from 'fs/promises';
import { createRandomString, fileExist, safeJSONParse, isPidRunning } from '../config/util';
import { createRandomString, fileExist, safeJSONParse } from '../config/util';
import OpenService from '../services/open';
import { shareStore } from '../shared/store';
import Logger from './logger';
@@ -132,32 +132,7 @@ export default async () => {
});
// 初始化更新所有任务状态为空闲
// 但保留仍在运行的任务的状态
const allCrons = await CrontabModel.findAll({
attributes: ['id', 'pid'],
raw: true,
});
const idsToReset: number[] = [];
for (const cron of allCrons) {
// 如果任务有 PID 且进程仍在运行,则保持其状态
if (cron.pid != null && isPidRunning(cron.pid)) {
// 保留当前状态(running 或 queued
continue;
}
// 收集需要重置的任务 ID
if (cron.id) {
idsToReset.push(cron.id);
}
}
// 批量更新所有需要重置的任务
if (idsToReset.length > 0) {
await CrontabModel.update(
{ status: CrontabStatus.idle, pid: undefined },
{ where: { id: { [Op.in]: idsToReset } } }
);
}
await CrontabModel.update({ status: CrontabStatus.idle }, { where: {} });
// 初始化时执行一次所有的 ql repo 任务
CrontabModel.findAll({