Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
|
||||
function attachAccountTransaction(db, { actor, target, users } = {}) {
|
||||
if (db.pool) return db;
|
||||
const reads = [];
|
||||
const lookup = (id) => users ? users.get(Number(id)) : Number(target?.id) === Number(id) ? target : null;
|
||||
return {
|
||||
...db,
|
||||
reads,
|
||||
pool: { getConnection: async () => ({
|
||||
beginTransaction: async () => {}, commit: async () => {}, rollback: async () => {}, release() {},
|
||||
execute: async (sql, params = []) => {
|
||||
if (sql.startsWith("SELECT id, admin, suspended, session_epoch")) {
|
||||
reads.push({ sql, params });
|
||||
const liveActor = users?.has(Number(actor?.id)) ? users.get(Number(actor.id)) : actor;
|
||||
return [[liveActor].filter((row) => row && Number(row.admin) === 1)];
|
||||
}
|
||||
if (sql.startsWith("SELECT id, email, admin, session_epoch")) {
|
||||
reads.push({ sql, params });
|
||||
const live = lookup(params[0]);
|
||||
return [live ? [{ ...live }] : []];
|
||||
}
|
||||
return [await db.query(sql, params)];
|
||||
}
|
||||
}) }
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { attachAccountTransaction };
|
||||
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
function assistantHistoryDb(query) {
|
||||
const chat = { id: 7, title: "chat", created_at: 0, updated_at: 0 };
|
||||
const db = {
|
||||
query: async (sql, params) => {
|
||||
if (sql.includes("FROM dashboard_assistant_chats c JOIN users")) return [{ ...chat }];
|
||||
return query(sql, params);
|
||||
}
|
||||
};
|
||||
db.pool = { getConnection: async () => ({
|
||||
beginTransaction: async () => {}, commit: async () => {}, rollback: async () => {}, release() {},
|
||||
execute: async (sql, params) => {
|
||||
if (sql.startsWith("SELECT id, email, suspended FROM users")) return [[{ id: params[0], email: params[1], suspended: 0 }]];
|
||||
if (sql.startsWith("SELECT id FROM dashboard_assistant_chats")) return [[{ id: params[0] }]];
|
||||
if (sql.startsWith("SELECT id, title")) return [[{ ...chat }]];
|
||||
if (sql.startsWith("SELECT title")) return [[{ title: chat.title }]];
|
||||
if (sql.startsWith("INSERT INTO dashboard_assistant_chats")) return [{ insertId: chat.id }];
|
||||
return [await query(sql, params)];
|
||||
}
|
||||
}) };
|
||||
return db;
|
||||
}
|
||||
|
||||
module.exports = { assistantHistoryDb };
|
||||
Reference in new issue
Block a user