InstantAdPay data documents in MySQL (Marty 2026-11-13: 'everything database-driven'): docstore.js (same file as LinkSpin) keeps every .json/.jsonl data document in table docs of the InstantAdPay database (DOCSTORE_URL), one writer at a time, first boot imports and sets the files aside. Accounts and the other DB-mode tables are unchanged. Rehearsed on a copy with a copy of the database: 64/64 documents byte-identical, pages and APIs answer after a restart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-13 09:33:16 -06:00
parent 9efdfc8ee9
commit f29f6d1407
2 changed files with 189 additions and 1 deletions
+5 -1
View File
@@ -132,6 +132,7 @@ const ROOT = __dirname;
const PUBLIC_DIR = path.join(ROOT, 'public');
const DATA_DIR = process.env.DATA_DIR || path.join(ROOT, 'data');
require('./safefs').install(DATA_DIR); // every .json data file is written atomically (2026-11-13 rotator.json loss)
const docstore = require('./docstore'); docstore.install(DATA_DIR); // data documents live in MySQL when DOCSTORE_URL is set (2026-11-13, database is the standard)
const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD || 'changeme';
const ADMIN_EMAIL = String(process.env.ADMIN_EMAIL || '').trim().toLowerCase();
// Admin portal sessions: email-code sign-in allowlisted to ADMIN_EMAIL, kept
@@ -140,7 +141,7 @@ const ADMIN_EMAIL = String(process.env.ADMIN_EMAIL || '').trim().toLowerCase();
const ADMIN_SESS_FILE = path.join(DATA_DIR, 'admin-sessions.json');
const ADMIN_TTL = 12 * 60 * 60 * 1000;
let adminSessions = {};
try { adminSessions = JSON.parse(fs.readFileSync(ADMIN_SESS_FILE, 'utf8')) || {}; } catch (e) { adminSessions = {}; }
if (!process.env.DOCSTORE_URL) { try { adminSessions = JSON.parse(fs.readFileSync(ADMIN_SESS_FILE, 'utf8')) || {}; } catch (e) { adminSessions = {}; } } // with MySQL: loaded right after docstore.init
function saveAdminSessions() {
const now = Date.now();
for (const k of Object.keys(adminSessions)) if (!adminSessions[k] || adminSessions[k].expires < now) delete adminSessions[k];
@@ -565,6 +566,9 @@ async function frameCheck(url, inGame) {
}
async function boot() {
await db.init({ dataDir: DATA_DIR }); // no-op without DATABASE_URL (JSON mode)
await docstore.init({}); // before any module reads its data
process.on('SIGTERM', () => { docstore.drain(8000).finally(() => process.exit(0)); });
if (process.env.DOCSTORE_URL) { try { adminSessions = JSON.parse(fs.readFileSync(ADMIN_SESS_FILE, 'utf8')) || {}; } catch (e) { adminSessions = {}; } }
marks.init({ db });
marks.ensureTable().catch(e => console.error('marks table', e.message));
lsconv.init({ db, dataDir: DATA_DIR });