fix: backend and discord-gateway improvements

- Update shared database schema
- Add shared utils
- Refactor backend middleware, auth routes, and dashboard repository
- Improve media analysis client with better error handling
- Fix searxng search URL construction
- Update URL fetcher for robustness

Co-authored-by: workflow agents
This commit is contained in:
asepharyana
2026-07-02 06:02:07 +07:00
co-authored by workflow agents
parent 81a004d250
commit ade5d6a7c3
9 changed files with 174 additions and 53 deletions
+6
View File
@@ -83,6 +83,12 @@ export const pgMessagesTable = pgTable(
table.created_at,
table.id,
),
guildAiStatusAnalyzedIdx: pgIndex("idx_messages_guild_ai_status_analyzed").on(
table.guild_id,
table.ai_status,
table.ai_analyzed_at,
table.id,
),
guildCreatedDeletedIdx: pgIndex("idx_messages_guild_created_deleted").on(
table.guild_id,
table.created_at,
+34
View File
@@ -6,6 +6,40 @@ export function delay(ms: number): Promise<void> {
export * from "./pagination.js";
// ---------------------------------------------------------------------------
// Centralized AbortController with guaranteed cleanup
// ---------------------------------------------------------------------------
/**
* Creates an AbortController with a timeout that is ALWAYS cleaned up,
* even if the caller throws or returns early without calling clear().
*
* Returns both the controller and a cleanup handle.
*
* Usage:
* const { controller, clear } = createAbortControllerWithTimeout(8000);
* try {
* const res = await fetch(url, { signal: controller.signal });
* // ... work ...
* } finally {
* clear(); // guaranteed to clear the timeout
* }
*/
export function createAbortControllerWithTimeout(
timeoutMs: number,
): { controller: AbortController; clear: () => void } {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
// Unref so the timeout doesn't keep the process alive
timeoutId?.unref?.();
return {
controller,
clear: () => {
clearTimeout(timeoutId);
},
};
}
// ---------------------------------------------------------------------------
// Retry with exponential backoff
// ---------------------------------------------------------------------------