Initial upload to Gitea

This commit is contained in:
antonn committed 2026-11-30 16:32:37 +00:00
1 parent 78193254ad
commit 8478998cae
1485 files changed
+461025 -42348

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
"use strict";
const ATTACHMENT_RETENTION_DAYS = 30;
const ATTACHMENT_PRUNE_INTERVAL_MS = 60_000;
const readableImageSql = "CASE WHEN image_expires_at IS NULL OR image_expires_at > NOW(3) THEN image_data END";
async function ensureAgentAttachmentSchema(db) {
for (const [addition, duplicate] of [
["ADD COLUMN image_expires_at DATETIME(3) NULL", "ER_DUP_FIELDNAME"],
["ADD INDEX idx_ai_messages_image_expiry (image_expires_at)", "ER_DUP_KEYNAME"],
]) {
try { await db.query(`ALTER TABLE ai_messages ${addition}`); } catch (error) {
if (error.code !== duplicate) throw error;
}
}
}
async function pruneExpiredAgentAttachments(db) {
return db.query(`UPDATE ai_messages SET image_data = NULL, image_expires_at = NULL
WHERE image_expires_at <= NOW(3) ORDER BY image_expires_at LIMIT 64`);
}
module.exports = { ATTACHMENT_RETENTION_DAYS, ATTACHMENT_PRUNE_INTERVAL_MS, readableImageSql, ensureAgentAttachmentSchema, pruneExpiredAgentAttachments };