🌉 Address code review: extract URL constant, localize fallback, improve variable naming
Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
parent
40c12c75a3
commit
7e633c70ab
|
|
@ -117,9 +117,9 @@ router.post('/syslog-receive', async (req, res) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
const timestampStr = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
||||||
const safeDevId = String(devId).replace(/[^a-zA-Z0-9_-]/g, '');
|
const safeDevId = String(devId).replace(/[^a-zA-Z0-9_-]/g, '');
|
||||||
const filename = `SYSLOG-${safeDevId}-${timestamp}.json`;
|
const filename = `SYSLOG-${safeDevId}-${timestampStr}.json`;
|
||||||
const filePath = `syslog-inbox/${filename}`;
|
const filePath = `syslog-inbox/${filename}`;
|
||||||
const content = Buffer.from(JSON.stringify(syslog, null, 2)).toString('base64');
|
const content = Buffer.from(JSON.stringify(syslog, null, 2)).toString('base64');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ async function getPageTitle(pageId, token) {
|
||||||
return props[key].title.map(t => t.plain_text).join('');
|
return props[key].title.map(t => t.plain_text).join('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'Untitled';
|
return '未命名广播';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ══════════════════════════════════════════════════════════
|
// ══════════════════════════════════════════════════════════
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const OUTPUT_DIR = path.join('data', 'broadcasts', 'pdf');
|
const OUTPUT_DIR = path.join('data', 'broadcasts', 'pdf');
|
||||||
|
const SITE_BASE_URL = 'https://guanghulab.com';
|
||||||
|
|
||||||
// ══════════════════════════════════════════════════════════
|
// ══════════════════════════════════════════════════════════
|
||||||
// 上传模式
|
// 上传模式
|
||||||
|
|
@ -49,10 +50,10 @@ async function uploadToServer(pdfFiles) {
|
||||||
|
|
||||||
const filename = path.basename(pdfPath);
|
const filename = path.basename(pdfPath);
|
||||||
const destPath = path.join(serverDir, filename);
|
const destPath = path.join(serverDir, filename);
|
||||||
|
const downloadUrl = `${SITE_BASE_URL}/broadcasts/${filename}`;
|
||||||
|
|
||||||
if (isCI) {
|
if (isCI) {
|
||||||
// CI 环境:仅记录,由部署脚本负责实际复制
|
// CI 环境:仅记录,由部署脚本负责实际复制
|
||||||
const downloadUrl = `https://guanghulab.com/broadcasts/${filename}`;
|
|
||||||
results.push({ ...item, download_url: downloadUrl });
|
results.push({ ...item, download_url: downloadUrl });
|
||||||
console.log(` 📋 ${filename} → ${downloadUrl} (CI模式·待部署)`);
|
console.log(` 📋 ${filename} → ${downloadUrl} (CI模式·待部署)`);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -61,7 +62,6 @@ async function uploadToServer(pdfFiles) {
|
||||||
fs.mkdirSync(serverDir, { recursive: true });
|
fs.mkdirSync(serverDir, { recursive: true });
|
||||||
}
|
}
|
||||||
fs.copyFileSync(pdfPath, destPath);
|
fs.copyFileSync(pdfPath, destPath);
|
||||||
const downloadUrl = `https://guanghulab.com/broadcasts/${filename}`;
|
|
||||||
results.push({ ...item, download_url: downloadUrl });
|
results.push({ ...item, download_url: downloadUrl });
|
||||||
console.log(` ✅ ${filename} → ${destPath}`);
|
console.log(` ✅ ${filename} → ${destPath}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue