qq-bot-roost 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/web/server.js +31 -0
package/package.json
CHANGED
package/src/web/server.js
CHANGED
|
@@ -1891,6 +1891,37 @@ export async function startWebServer({
|
|
|
1891
1891
|
server.on('error', (e) => log.error('面板出错:', e.message));
|
|
1892
1892
|
|
|
1893
1893
|
const shownHost = host === '0.0.0.0' ? '127.0.0.1' : host;
|
|
1894
|
+
|
|
1895
|
+
/**
|
|
1896
|
+
* 把实际端口写进「端口租约」,让 dsh-roost 知道面板到底在哪。
|
|
1897
|
+
*
|
|
1898
|
+
* 为什么要这个:面板端口被占会自动顺延(上面 listenWithFallback),
|
|
1899
|
+
* 但 `config/bot.json` 里还是用户写的那个——dsh-roost 按配置去连就连不上。
|
|
1900
|
+
* 配置是**意愿**,这里是**现实**,两个都得留着。
|
|
1901
|
+
*
|
|
1902
|
+
* 写 `<root>/data/ports.json`,dsh-roost 读同一个文件。
|
|
1903
|
+
*/
|
|
1904
|
+
try {
|
|
1905
|
+
const { mkdirSync, writeFileSync, renameSync, readFileSync } = await import('node:fs');
|
|
1906
|
+
const { join } = await import('node:path');
|
|
1907
|
+
const leaseFile = join(ROOT, 'data', 'ports.json');
|
|
1908
|
+
let lease = {};
|
|
1909
|
+
try {
|
|
1910
|
+
lease = JSON.parse(readFileSync(leaseFile, 'utf8')) || {};
|
|
1911
|
+
} catch {}
|
|
1912
|
+
lease.roost = { want: port, actual: actualPort, pid: process.pid, at: new Date().toISOString() };
|
|
1913
|
+
mkdirSync(join(ROOT, 'data'), { recursive: true });
|
|
1914
|
+
// 原子写:先写 .tmp 再 rename,免得 dsh-roost 读到半截 JSON
|
|
1915
|
+
writeFileSync(`${leaseFile}.tmp`, JSON.stringify(lease, null, 2), 'utf8');
|
|
1916
|
+
renameSync(`${leaseFile}.tmp`, leaseFile);
|
|
1917
|
+
if (actualPort !== port) {
|
|
1918
|
+
log.warn(`面板实际在 ${actualPort}(配置写的是 ${port},那个被占了)。已写入 data/ports.json`);
|
|
1919
|
+
}
|
|
1920
|
+
} catch (e) {
|
|
1921
|
+
// 写不进去不影响面板运行
|
|
1922
|
+
log.warn(`端口租约写不进去:${e.message}`);
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1894
1925
|
const url = `http://${shownHost}:${actualPort}/${
|
|
1895
1926
|
accessKey ? '?key=' + encodeURIComponent(accessKey) : ''
|
|
1896
1927
|
}`;
|