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 };
|
||||
Reference in new issue
Block a user