Update server.js
Browse files
server.js
CHANGED
|
@@ -1,49 +1,30 @@
|
|
| 1 |
const { spawn } = require('child_process');
|
| 2 |
-
const fs = require('fs');
|
| 3 |
const path = require('path');
|
|
|
|
|
|
|
| 4 |
|
| 5 |
const PORT = process.env.PORT || 7860;
|
| 6 |
const HOST = '0.0.0.0';
|
| 7 |
const opencodeBin = path.join(__dirname, 'node_modules', '.bin', 'opencode');
|
| 8 |
|
| 9 |
-
//
|
| 10 |
-
const
|
| 11 |
-
const
|
| 12 |
-
const
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
// 创建持久化目录
|
| 26 |
-
if (!fs.existsSync(dataLocal)) fs.mkdirSync(dataLocal, { recursive: true });
|
| 27 |
-
if (!fs.existsSync(dataConfig)) fs.mkdirSync(dataConfig, { recursive: true });
|
| 28 |
-
|
| 29 |
-
// 删除原有目录(如果存在且不是软链接)
|
| 30 |
-
if (fs.existsSync(LOCAL_SHARE) && !fs.lstatSync(LOCAL_SHARE).isSymbolicLink()) {
|
| 31 |
-
fs.rmSync(LOCAL_SHARE, { recursive: true, force: true });
|
| 32 |
-
}
|
| 33 |
-
if (fs.existsSync(CONFIG_DIR) && !fs.lstatSync(CONFIG_DIR).isSymbolicLink()) {
|
| 34 |
-
fs.rmSync(CONFIG_DIR, { recursive: true, force: true });
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
// 创建软链接
|
| 38 |
-
fs.symlinkSync(dataLocal, LOCAL_SHARE, 'dir');
|
| 39 |
-
fs.symlinkSync(dataConfig, CONFIG_DIR, 'dir');
|
| 40 |
-
console.log('Persistent storage linked to /data');
|
| 41 |
-
} catch (err) {
|
| 42 |
-
console.error('Failed to set up persistent directories:', err.message);
|
| 43 |
-
}
|
| 44 |
}
|
| 45 |
-
|
| 46 |
-
setupPersistentDirs();
|
| 47 |
|
| 48 |
const env = {
|
| 49 |
...process.env,
|
|
|
|
| 1 |
const { spawn } = require('child_process');
|
|
|
|
| 2 |
const path = require('path');
|
| 3 |
+
const fs = require('fs');
|
| 4 |
+
const os = require('os');
|
| 5 |
|
| 6 |
const PORT = process.env.PORT || 7860;
|
| 7 |
const HOST = '0.0.0.0';
|
| 8 |
const opencodeBin = path.join(__dirname, 'node_modules', '.bin', 'opencode');
|
| 9 |
|
| 10 |
+
// 设置持久化目录:如果 /data/opencode_local 存在,则创建软链接
|
| 11 |
+
const homeDir = os.homedir();
|
| 12 |
+
const dataLocal = '/data/opencode_local';
|
| 13 |
+
const dataConfig = '/data/opencode_config';
|
| 14 |
+
const targetLocal = path.join(homeDir, '.local', 'share', 'opencode');
|
| 15 |
+
const targetConfig = path.join(homeDir, '.config', 'opencode');
|
| 16 |
|
| 17 |
+
if (fs.existsSync(dataLocal)) {
|
| 18 |
+
// 移除原有的目录或链接
|
| 19 |
+
if (fs.existsSync(targetLocal)) fs.rmSync(targetLocal, { recursive: true, force: true });
|
| 20 |
+
fs.symlinkSync(dataLocal, targetLocal, 'dir');
|
| 21 |
+
console.log(`Linked ${targetLocal} -> ${dataLocal}`);
|
| 22 |
+
}
|
| 23 |
+
if (fs.existsSync(dataConfig)) {
|
| 24 |
+
if (fs.existsSync(targetConfig)) fs.rmSync(targetConfig, { recursive: true, force: true });
|
| 25 |
+
fs.symlinkSync(dataConfig, targetConfig, 'dir');
|
| 26 |
+
console.log(`Linked ${targetConfig} -> ${dataConfig}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
|
|
|
|
|
|
| 28 |
|
| 29 |
const env = {
|
| 30 |
...process.env,
|