@fudrouter/fsrouter 0.6.101 → 0.6.103

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.
@@ -13,7 +13,7 @@ function killMitmByPidFile() {
13
13
  const mitmPidFile = path.join(
14
14
  process.platform === "win32"
15
15
  ? path.join(process.env.APPDATA || "", "9router")
16
- : path.join(os.homedir(), ".amrouter"),
16
+ : path.join(os.homedir(), ".fsrouter"),
17
17
  "mitm",
18
18
  ".mitm.pid"
19
19
  );
@@ -108,7 +108,7 @@ function getDataDir() {
108
108
  if (process.platform === "win32") {
109
109
  return path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), "9router");
110
110
  }
111
- return path.join(os.homedir(), ".amrouter");
111
+ return path.join(os.homedir(), ".fsrouter");
112
112
  }
113
113
 
114
114
  function resolveBundledUpdaterPath() {
@@ -2,7 +2,8 @@ import fs from "node:fs";
2
2
  import path from "path";
3
3
  import os from "os";
4
4
 
5
- const APP_NAME = "amrouter";
5
+ const APP_NAME = "fsrouter";
6
+ const LEGACY_APP_NAME = "amrouter";
6
7
 
7
8
  function defaultDir() {
8
9
  if (process.platform === "win32") {
@@ -11,19 +12,43 @@ function defaultDir() {
11
12
  return path.join(os.homedir(), `.${APP_NAME}`);
12
13
  }
13
14
 
15
+ function legacyDir() {
16
+ if (process.platform === "win32") {
17
+ return path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), LEGACY_APP_NAME);
18
+ }
19
+ return path.join(os.homedir(), `.${LEGACY_APP_NAME}`);
20
+ }
21
+
14
22
  export function getDataDir() {
15
23
  const configured = process.env.DATA_DIR;
16
- if (!configured) return defaultDir();
17
- try {
18
- fs.mkdirSync(configured, { recursive: true });
19
- return configured;
20
- } catch (e) {
21
- if (e?.code === "EACCES" || e?.code === "EPERM") {
22
- console.warn(`[DATA_DIR] '${configured}' not writable → fallback ~/.${APP_NAME}`);
23
- return defaultDir();
24
+ if (configured) {
25
+ try {
26
+ fs.mkdirSync(configured, { recursive: true });
27
+ return configured;
28
+ } catch (e) {
29
+ if (e?.code === "EACCES" || e?.code === "EPERM") {
30
+ console.warn(`[DATA_DIR] '${configured}' not writable → fallback ~/.${APP_NAME}`);
31
+ return defaultDir();
32
+ }
33
+ throw e;
34
+ }
35
+ }
36
+ const dir = defaultDir();
37
+ // Backward-compat: if the new dir doesn't exist yet but the legacy `amrouter`
38
+ // dir does, migrate it (rename) so existing data isn't lost on first launch.
39
+ if (!fs.existsSync(dir)) {
40
+ const old = legacyDir();
41
+ if (fs.existsSync(old)) {
42
+ try {
43
+ fs.renameSync(old, dir);
44
+ console.log(`[DATA_DIR] Migrated legacy data folder ${old} → ${dir}`);
45
+ } catch (e) {
46
+ console.warn(`[DATA_DIR] Could not migrate ${old} → ${dir}: ${e.message}`);
47
+ }
24
48
  }
25
- throw e;
26
49
  }
50
+ try { fs.mkdirSync(dir, { recursive: true }); } catch { /* ignore */ }
51
+ return dir;
27
52
  }
28
53
 
29
54
  export const DATA_DIR = getDataDir();
@@ -8,7 +8,7 @@ import os from "os";
8
8
  const DATA_DIR = process.env.DATA_DIR
9
9
  || (process.platform === "win32"
10
10
  ? path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), "9router")
11
- : path.join(os.homedir(), ".amrouter"));
11
+ : path.join(os.homedir(), ".fsrouter"));
12
12
 
13
13
  const CACHE_FILE = path.join(DATA_DIR, "mitm", "aliases.json");
14
14
 
@@ -460,7 +460,7 @@ function isDaemonTunMode() {
460
460
  * Start tailscaled.
461
461
  * - With sudoPassword: TUN mode (root) → Funnel TLS works
462
462
  * - Without: userspace-networking fallback (no sudo, but Funnel TLS unstable)
463
- * State always lives in ~/.amrouter/tailscale/ via --statedir.
463
+ * State always lives in ~/.fsrouter/tailscale/ via --statedir.
464
464
  */
465
465
  export async function startDaemonWithPassword(sudoPassword) {
466
466
  if (IS_WINDOWS) {
@@ -28,7 +28,7 @@ function getDataDir() {
28
28
  if (process.platform === "win32") {
29
29
  return path.join(process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"), "9router");
30
30
  }
31
- return path.join(os.homedir(), ".amrouter");
31
+ return path.join(os.homedir(), ".fsrouter");
32
32
  }
33
33
  const updateDir = path.join(getDataDir(), "update");
34
34
  try { fs.mkdirSync(updateDir, { recursive: true }); } catch { /* best effort */ }
@@ -255,7 +255,7 @@ function executeCodeBuddySignupSingle(accountId, jobId, settings) {
255
255
  }
256
256
  }
257
257
  try {
258
- const logDir = path.join(process.env.DATA_DIR || path.join(process.env.HOME || process.env.USERPROFILE || "/tmp", ".amrouter"), "logs");
258
+ const logDir = path.join(process.env.DATA_DIR || path.join(process.env.HOME || process.env.USERPROFILE || "/tmp", ".fsrouter"), "logs");
259
259
  fs.mkdirSync(logDir, { recursive: true });
260
260
  fs.appendFileSync(`${logDir}/automation_spawn.log`, `[${new Date().toISOString()}] [id]/route.js spawning python: ${venvPython} ${args.join(" ")}\n`);
261
261
  }
@@ -898,7 +898,7 @@ function executeCodeBuddySignup(accountId, jobId, idx, settings, jobStartTimes =
898
898
  }
899
899
  }
900
900
  try {
901
- const logDir = path.join(process.env.DATA_DIR || path.join(process.env.HOME || process.env.USERPROFILE || "/tmp", ".amrouter"), "logs");
901
+ const logDir = path.join(process.env.DATA_DIR || path.join(process.env.HOME || process.env.USERPROFILE || "/tmp", ".fsrouter"), "logs");
902
902
  fs.mkdirSync(logDir, { recursive: true });
903
903
  fs.appendFileSync(`${logDir}/automation_spawn.log`, `[${new Date().toISOString()}] route.js spawning python: ${venvPython} ${args.join(" ")}\n`);
904
904
  }
@@ -241,7 +241,7 @@ export async function POST_handler(req, res) {
241
241
  // ── Background runner ─────────────────────────────────────────────────────────
242
242
  async function runOpenVectaSignup(jobId, email, venvPython, args) {
243
243
  try {
244
- const logDir = path.join(process.env.DATA_DIR || path.join(process.env.HOME || "/tmp", ".amrouter"), "logs");
244
+ const logDir = path.join(process.env.DATA_DIR || path.join(process.env.HOME || "/tmp", ".fsrouter"), "logs");
245
245
  fs.mkdirSync(logDir, { recursive: true });
246
246
  fs.appendFileSync(`${logDir}/automation_spawn.log`, `[${new Date().toISOString()}] openvecta spawning python: ${venvPython} ${args.join(" ")}\n`);
247
247
  }
@@ -91,9 +91,7 @@ export async function POST_handler(req, res) {
91
91
  const hasLogical = !!body.database;
92
92
  if (hasLogical) {
93
93
  progress(15, "Mengimpor data logical (provider, connections, proxy, api keys, combos)...");
94
- // Import on the live connection — do NOT close it first, or getAdapter()
95
- // would keep returning the stale closed instance and every query throws
96
- // "The database connection is not open".
94
+ // Import on the live connection.
97
95
  await importDb(body.database);
98
96
  progress(40, "Flush WAL ke file database utama (checkpoint)...");
99
97
  const db = await getAdapter();
@@ -111,6 +109,26 @@ export async function POST_handler(req, res) {
111
109
  }
112
110
  catch { /* ignore */ }
113
111
  }
112
+ progress(50, "Menutup koneksi DB agar file WAL/SHM tidak terkunci...");
113
+ // Switch journal mode to DELETE so SQLite folds the WAL back into the
114
+ // main db file and deletes -wal/-shm itself — avoids leaving a locked
115
+ // WAL that Windows can't unlink (which previously dropped restored rows).
116
+ if (db && typeof db.exec === "function") {
117
+ try {
118
+ db.exec("PRAGMA journal_mode=DELETE");
119
+ }
120
+ catch { /* ignore */ }
121
+ }
122
+ // Close the connection so Windows releases the -wal/-shm file locks.
123
+ // Logical data is already flushed to the main DB via the checkpoint above.
124
+ if (db && typeof db.close === "function") {
125
+ try {
126
+ db.close();
127
+ }
128
+ catch { /* ignore */ }
129
+ }
130
+ // Clear the cached instance so getAdapter() re-opens fresh on next boot.
131
+ resetAdapter();
114
132
  }
115
133
  else {
116
134
  progress(15, "Menutup koneksi database aktif (raw restore)...");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fudrouter/fsrouter",
3
- "version": "0.6.101",
3
+ "version": "0.6.103",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "9Router v2 — Express Backend (API, SSE, DB, Auth, MITM)",