Spaces:
Sleeping
Sleeping
RAQIM Deploy commited on
Commit ·
76dbc8b
1
Parent(s): c91b3ca
Deploy RAQIM 2026-05-02 20:35
Browse files
artifacts/api-server/src/routes/convert.ts
CHANGED
|
@@ -1028,9 +1028,11 @@ router.post("/upload", upload.single("file"), async (req: AuthRequest, res) => {
|
|
| 1028 |
});
|
| 1029 |
} catch (err) {
|
| 1030 |
const e = err instanceof Error ? err : new Error(String(err));
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
|
|
|
|
|
|
| 1034 |
}
|
| 1035 |
});
|
| 1036 |
|
|
@@ -1096,9 +1098,11 @@ router.post("/upload-split", upload.single("file"), async (req: AuthRequest, res
|
|
| 1096 |
res.status(202).json({ jobs });
|
| 1097 |
} catch (err) {
|
| 1098 |
const e = err instanceof Error ? err : new Error(String(err));
|
| 1099 |
-
|
| 1100 |
-
|
| 1101 |
-
|
|
|
|
|
|
|
| 1102 |
}
|
| 1103 |
});
|
| 1104 |
|
|
|
|
| 1028 |
});
|
| 1029 |
} catch (err) {
|
| 1030 |
const e = err instanceof Error ? err : new Error(String(err));
|
| 1031 |
+
const cause = (e as NodeJS.ErrnoException & { cause?: Error }).cause;
|
| 1032 |
+
const rootMsg = cause?.message ?? e.message;
|
| 1033 |
+
console.error("[RAQIM] /upload error:", rootMsg, "\n outer:", e.message, "\n stack:", e.stack);
|
| 1034 |
+
req.log?.error({ err, cause: cause?.message }, "upload error");
|
| 1035 |
+
res.status(500).json({ error: "server_error", message: rootMsg || "فشل الرفع" });
|
| 1036 |
}
|
| 1037 |
});
|
| 1038 |
|
|
|
|
| 1098 |
res.status(202).json({ jobs });
|
| 1099 |
} catch (err) {
|
| 1100 |
const e = err instanceof Error ? err : new Error(String(err));
|
| 1101 |
+
const cause = (e as NodeJS.ErrnoException & { cause?: Error }).cause;
|
| 1102 |
+
const rootMsg = cause?.message ?? e.message;
|
| 1103 |
+
console.error("[RAQIM] /upload-split error:", rootMsg, "\n outer:", e.message, "\n stack:", e.stack);
|
| 1104 |
+
req.log?.error({ err, cause: cause?.message }, "upload-split error");
|
| 1105 |
+
res.status(500).json({ error: "server_error", message: rootMsg || "فشل الرفع" });
|
| 1106 |
}
|
| 1107 |
});
|
| 1108 |
|
scripts/db-hf-sync.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { execSync, spawnSync } from "child_process";
|
|
| 10 |
import fs from "fs";
|
| 11 |
import path from "path";
|
| 12 |
import { fileURLToPath } from "url";
|
|
|
|
| 13 |
|
| 14 |
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
| 15 |
|
|
@@ -65,6 +66,15 @@ export async function pullDb() {
|
|
| 65 |
const srcDb = path.join(CLONE_DIR, "raqim.db");
|
| 66 |
if (fs.existsSync(srcDb)) {
|
| 67 |
fs.copyFileSync(srcDb, DB_PATH);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
console.log("[db-sync] ✓ DB restored from HF Dataset.");
|
| 69 |
} else {
|
| 70 |
console.log("[db-sync] No existing DB in dataset — starting fresh.");
|
|
@@ -81,6 +91,16 @@ export async function pushDb() {
|
|
| 81 |
run(`git clone --depth=1 "${gitUrl()}" "${CLONE_DIR}"`);
|
| 82 |
}
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
fs.copyFileSync(DB_PATH, path.join(CLONE_DIR, "raqim.db"));
|
| 85 |
|
| 86 |
run(`git -C "${CLONE_DIR}" config user.email "sync@raqim.app"`);
|
|
|
|
| 10 |
import fs from "fs";
|
| 11 |
import path from "path";
|
| 12 |
import { fileURLToPath } from "url";
|
| 13 |
+
import { DatabaseSync } from "node:sqlite";
|
| 14 |
|
| 15 |
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
| 16 |
|
|
|
|
| 66 |
const srcDb = path.join(CLONE_DIR, "raqim.db");
|
| 67 |
if (fs.existsSync(srcDb)) {
|
| 68 |
fs.copyFileSync(srcDb, DB_PATH);
|
| 69 |
+
// Remove any stale WAL/SHM files that belonged to the old DB —
|
| 70 |
+
// they have different salt values and will confuse SQLite.
|
| 71 |
+
for (const suffix of ["-wal", "-shm"]) {
|
| 72 |
+
const stale = DB_PATH + suffix;
|
| 73 |
+
if (fs.existsSync(stale)) {
|
| 74 |
+
fs.rmSync(stale);
|
| 75 |
+
console.log(`[db-sync] Removed stale ${suffix} file.`);
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
console.log("[db-sync] ✓ DB restored from HF Dataset.");
|
| 79 |
} else {
|
| 80 |
console.log("[db-sync] No existing DB in dataset — starting fresh.");
|
|
|
|
| 91 |
run(`git clone --depth=1 "${gitUrl()}" "${CLONE_DIR}"`);
|
| 92 |
}
|
| 93 |
|
| 94 |
+
// Checkpoint WAL into the main DB file before copying so the backup
|
| 95 |
+
// is a self-contained, consistent snapshot without a dangling WAL.
|
| 96 |
+
try {
|
| 97 |
+
const tmpDb = new DatabaseSync(DB_PATH);
|
| 98 |
+
tmpDb.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
| 99 |
+
tmpDb.close();
|
| 100 |
+
} catch (e) {
|
| 101 |
+
console.warn("[db-sync] WAL checkpoint failed (non-fatal):", e.message);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
fs.copyFileSync(DB_PATH, path.join(CLONE_DIR, "raqim.db"));
|
| 105 |
|
| 106 |
run(`git -C "${CLONE_DIR}" config user.email "sync@raqim.app"`);
|