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
3 changed files with 38 additions and 97 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,
+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));
+17 -97
View File
@@ -218,108 +218,28 @@ export default class SystemService {
...oDoc,
info: { ...oDoc.info, ...info },
});
let defaultDomain = 'https://dl-cdn.alpinelinux.org';
let targetDomain = 'https://dl-cdn.alpinelinux.org';
if (os.platform() !== 'linux') {
return;
}
let command = '';
// Check if this is a Debian-based system (including Armbian)
// Check for both sources.list and debian_version for more reliable detection
const hasAptSourcesList = await fs.promises.access('/etc/apt/sources.list')
.then(() => true)
.catch(() => false);
const hasDebianVersion = await fs.promises.access('/etc/debian_version')
.then(() => true)
.catch(() => false);
const isDebianBased = hasAptSourcesList || hasDebianVersion;
if (isDebianBased) {
// Handle Debian/Ubuntu/Armbian systems
let defaultDomain = '';
let targetDomain = info.linuxMirror || '';
try {
// Read the current sources.list
const content = await fs.promises.readFile('/etc/apt/sources.list', {
encoding: 'utf-8',
});
// Match the first deb line to extract the current mirror
// Note: This assumes all mirrors in sources.list use the same base URL
// If multiple different mirrors are configured, only the first one will be replaced
const debMatch = content.match(/^deb\s+(https?:\/\/[^\s]+)/m);
if (debMatch) {
defaultDomain = debMatch[1];
}
if (defaultDomain && targetDomain) {
// Sanitize and escape special characters for sed
// Escape backslashes first, then other special characters
const escapedDefault = defaultDomain
.replace(/\\/g, '\\\\') // Escape backslashes first
.replace(/\//g, '\\/') // Escape forward slashes
.replace(/\./g, '\\.'); // Escape dots
const escapedTarget = targetDomain
.replace(/\\/g, '\\\\') // Escape backslashes first
.replace(/\//g, '\\/'); // Escape forward slashes
// Replace mirror URL in main sources.list
command = `sed -i 's/${escapedDefault}/${escapedTarget}/g' /etc/apt/sources.list`;
// Also update sources.list.d if it exists
command += ` && if [ -d /etc/apt/sources.list.d ]; then find /etc/apt/sources.list.d -type f \\( -name "*.list" -o -name "*.sources" \\) -exec sed -i 's/${escapedDefault}/${escapedTarget}/g' {} \\;; fi`;
// Update package lists
command += ` && apt-get update`;
} else if (!defaultDomain && targetDomain) {
// Cannot detect current mirror, log warning
this.logger.warn('Unable to detect current mirror from /etc/apt/sources.list. Mirror update skipped.');
this.sockService.sendMessage({
type: 'updateLinuxMirror',
message: 'Warning: Unable to detect current mirror. Please manually configure /etc/apt/sources.list',
});
}
} catch (error) {
this.logger.error('Failed to read /etc/apt/sources.list', error);
}
} else {
// Handle Alpine Linux systems
let defaultDomain = 'https://dl-cdn.alpinelinux.org';
let targetDomain = 'https://dl-cdn.alpinelinux.org';
try {
const content = await fs.promises.readFile('/etc/apk/repositories', {
encoding: 'utf-8',
});
const domainMatch = content.match(/(http.*)\/alpine\/.*/);
if (domainMatch) {
defaultDomain = domainMatch[1];
}
if (info.linuxMirror) {
targetDomain = info.linuxMirror;
}
// Sanitize and escape special characters for sed
// Escape backslashes first, then other special characters
command = `sed -i 's/${defaultDomain
.replace(/\\/g, '\\\\') // Escape backslashes first
.replace(/\//g, '\\/') // Escape forward slashes
.replace(/\./g, '\\.')}/${targetDomain
.replace(/\\/g, '\\\\') // Escape backslashes first
.replace(/\//g, '\\/')}/g' /etc/apk/repositories && apk update -f`;
} catch (error) {
this.logger.error('Failed to read /etc/apk/repositories', error);
}
const content = await fs.promises.readFile('/etc/apk/repositories', {
encoding: 'utf-8',
});
const domainMatch = content.match(/(http.*)\/alpine\/.*/);
if (domainMatch) {
defaultDomain = domainMatch[1];
}
if (!command) {
this.sockService.sendMessage({
type: 'updateLinuxMirror',
message: 'No supported package manager found or mirror not configured',
});
return;
if (info.linuxMirror) {
targetDomain = info.linuxMirror;
}
const command = `sed -i 's/${defaultDomain.replace(
/\//g,
'\\/',
)}/${targetDomain.replace(
/\//g,
'\\/',
)}/g' /etc/apk/repositories && apk update -f`;
this.scheduleService.runTask(
command,