Cleanup: remove unused exports/functions, dead feature stub, fix shutdown
This commit is contained in:
parent
9ba687d0d0
commit
d903aae255
4 changed files with 12 additions and 60 deletions
|
|
@ -20,14 +20,6 @@ function int(name, fallback, { min = 0, max = Number.MAX_SAFE_INTEGER } = {}) {
|
|||
return n;
|
||||
}
|
||||
|
||||
function bool(name, fallback) {
|
||||
const raw = process.env[name];
|
||||
if (raw == null || raw === '') return fallback;
|
||||
if (['1', 'true', 'yes', 'on'].includes(raw.toLowerCase())) return true;
|
||||
if (['0', 'false', 'no', 'off'].includes(raw.toLowerCase())) return false;
|
||||
throw new Error(`${name} must be boolean, got: ${raw}`);
|
||||
}
|
||||
|
||||
const host = (name, fallback) => process.env[name] || fallback;
|
||||
const required = (name) => {
|
||||
const value = process.env[name];
|
||||
|
|
@ -40,7 +32,6 @@ export const WEBAPI_BASE =
|
|||
export const MANAGEMENT_BASE =
|
||||
`http://${host('MANAGEMENT_HOST', '127.0.0.1')}:${port('MANAGEMENT_PORT', 8080)}`;
|
||||
export const PORT = port('PORT', 3000);
|
||||
export const DEV_ID = () => required('DEV_ID');
|
||||
export const SESSION_SECRET = () => required('SESSION_SECRET');
|
||||
|
||||
// Bind address for this app. Default localhost; set 0.0.0.0 only behind nginx.
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
// src/features/broadcasts.js - turns broadcast events into a UI message.
|
||||
// TODO(M0): determine how broadcasts arrive. If they are IMs from a system
|
||||
// screen name, recognize that sender here. If a dedicated event type, subscribe
|
||||
// to it.
|
||||
|
||||
const BROADCAST_SENDERS = new Set(['system', 'admin', 'aolsystemmsg']);
|
||||
|
||||
export function register(ctx) {
|
||||
const { bus, broadcast } = ctx;
|
||||
|
||||
// Heuristic: treat IM-like events from known system senders as broadcasts.
|
||||
bus.on('*', ({ rec, event }) => {
|
||||
const raw = event.raw || {};
|
||||
const from = String(raw.from || raw.sender || raw.screenName || '').toLowerCase();
|
||||
if (!from) return;
|
||||
if (BROADCAST_SENDERS.has(from) || raw.broadcast === true || event.type === 'broadcast') {
|
||||
broadcast(rec, {
|
||||
type: 'broadcast',
|
||||
time: Date.now(),
|
||||
from: raw.from || raw.sender || raw.screenName || 'system',
|
||||
text: raw.text || raw.message || raw.msg || '',
|
||||
raw,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
21
src/oscar.js
21
src/oscar.js
|
|
@ -5,7 +5,7 @@
|
|||
// running Web API. The plan guesses classic Web AIM names: k, a, aimsid, t,
|
||||
// message, f=json. Verify with curl before relying on this in production.
|
||||
|
||||
import { WEBAPI_BASE, MANAGEMENT_BASE, DEV_ID } from './config.js';
|
||||
import { WEBAPI_BASE, MANAGEMENT_BASE } from './config.js';
|
||||
|
||||
export class OscarApiError extends Error {
|
||||
constructor(message, { statusCode, statusText, path, body } = {}) {
|
||||
|
|
@ -111,11 +111,6 @@ export async function sendIM(aimsid, to, message, { base } = {}) {
|
|||
return call('/im/sendIM', { aimsid, t: to, message }, base ? { base } : {});
|
||||
}
|
||||
|
||||
export async function setTyping(aimsid, to, typingStatus = 'typing', { base } = {}) {
|
||||
// TODO(M0): confirm typingStatus values.
|
||||
return call('/im/setTyping', { aimsid, t: to, typingStatus }, base ? { base } : {});
|
||||
}
|
||||
|
||||
// --- Chat ---
|
||||
|
||||
export async function createAndJoinChat(aimsid, room, { base } = {}) {
|
||||
|
|
@ -132,10 +127,6 @@ export async function leaveChat(aimsid, chatId, { base } = {}) {
|
|||
return call('/chat/leaveChat', { aimsid, c: chatId }, base ? { base } : {});
|
||||
}
|
||||
|
||||
export async function setChatTyping(aimsid, chatId, typingStatus = 'typing', { base } = {}) {
|
||||
return call('/chat/setTyping', { aimsid, c: chatId, typingStatus }, base ? { base } : {});
|
||||
}
|
||||
|
||||
// --- Presence / buddy list ---
|
||||
|
||||
export async function getPresence(aimsid, { base } = {}) {
|
||||
|
|
@ -159,15 +150,7 @@ export async function listUsers() {
|
|||
return res.json();
|
||||
}
|
||||
|
||||
export async function listPublicRooms() {
|
||||
// TODO(M0): confirm Management API path/shape for public rooms.
|
||||
const url = new URL('/chat/room/public', MANAGEMENT_BASE);
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) {
|
||||
throw new Error(`Management API /chat/room/public failed: ${res.status}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
|
||||
// Startup health check - makes a cheap request so a wrong port fails clearly.
|
||||
// We intentionally do not log secrets.
|
||||
|
|
|
|||
|
|
@ -7,13 +7,14 @@ import { readdir } from 'node:fs/promises';
|
|||
import path from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
|
||||
import { PORT, LISTEN_HOST, SESSION_SECRET, TRUST_PROXY, COOKIE_SECURE, SESSION_MAX_AGE_MS, NODE_ENV, logStartupConfig } from './config.js';
|
||||
import { getDb, closeDb } from './db.js';
|
||||
import { PORT, LISTEN_HOST, SESSION_SECRET, TRUST_PROXY, COOKIE_SECURE, SESSION_MAX_AGE_MS, logStartupConfig } from './config.js';
|
||||
import { getDb } from './db.js';
|
||||
import { SqliteSessionStore } from './sqlite-session-store.js';
|
||||
import * as oscar from './oscar.js';
|
||||
import { bus } from './bus.js';
|
||||
import { broadcast } from './poller.js';
|
||||
import { authRouter, requireLogin, cleanupSessionById } from './routes/auth.js';
|
||||
import { stopTOCSession } from './toc-session.js';
|
||||
import { streamRouter } from './routes/stream.js';
|
||||
import { messagesRouter } from './routes/messages.js';
|
||||
import { buddiesRouter } from './routes/buddies.js';
|
||||
|
|
@ -155,14 +156,17 @@ async function shutdown(signal) {
|
|||
const tasks = [];
|
||||
for (const rec of sessionsStore.allSessions()) {
|
||||
rec.polling = false;
|
||||
stopTOCSession(rec);
|
||||
for (const client of rec.sseClients) {
|
||||
try { client.end(); } catch { /* ignore */ }
|
||||
}
|
||||
rec.sseClients.clear();
|
||||
tasks.push(
|
||||
oscar.endSession(rec.aimsid)
|
||||
.catch((err) => console.warn(`[shutdown] endSession failed for ${rec.screenName}:`, err.message))
|
||||
);
|
||||
if (rec.aimsid) {
|
||||
tasks.push(
|
||||
oscar.endSession(rec.aimsid, { base: rec.webapiBase })
|
||||
.catch((err) => console.warn(`[shutdown] endSession failed for ${rec.screenName}:`, err.message))
|
||||
);
|
||||
}
|
||||
}
|
||||
await Promise.allSettled(tasks);
|
||||
console.log('[shutdown] done');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue