feat: add community publishing and news syndication
This commit is contained in:
+54
-40
@@ -1,51 +1,65 @@
|
||||
import type { Database } from '@tursodatabase/database';
|
||||
import { getDatabase } from '$lib/server/database';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
type AuditValue = Record<string, unknown> | unknown[] | null;
|
||||
|
||||
export async function recordIsacAudit(input: {
|
||||
actorId: string;
|
||||
category: string;
|
||||
action: string;
|
||||
entityId: string;
|
||||
before?: AuditValue;
|
||||
after?: AuditValue;
|
||||
actorId: string;
|
||||
category: string;
|
||||
action: string;
|
||||
entityId: string;
|
||||
before?: AuditValue;
|
||||
after?: AuditValue;
|
||||
database?: Database;
|
||||
createdAt?: string;
|
||||
}) {
|
||||
const database = await getDatabase();
|
||||
await (await database.prepare(`INSERT INTO audit_log
|
||||
const database = input.database ?? (await getDatabase());
|
||||
await (
|
||||
await database.prepare(`INSERT INTO audit_log
|
||||
(id,actor_id,entity_type,entity_id,action,before_json,after_json,created_at)
|
||||
VALUES(?,?,?,?,?,?,?,?)`)).run(
|
||||
randomUUID(),
|
||||
input.actorId,
|
||||
input.category,
|
||||
input.entityId,
|
||||
input.action,
|
||||
input.before === undefined ? null : JSON.stringify(input.before),
|
||||
input.after === undefined ? null : JSON.stringify(input.after),
|
||||
new Date().toISOString()
|
||||
);
|
||||
VALUES(?,?,?,?,?,?,?,?)`)
|
||||
).run(
|
||||
randomUUID(),
|
||||
input.actorId,
|
||||
input.category,
|
||||
input.entityId,
|
||||
input.action,
|
||||
input.before === undefined ? null : JSON.stringify(input.before),
|
||||
input.after === undefined ? null : JSON.stringify(input.after),
|
||||
input.createdAt ?? new Date().toISOString(),
|
||||
);
|
||||
}
|
||||
|
||||
export async function auditRecord(table: string, id: string): Promise<Record<string, unknown> | null> {
|
||||
if (![
|
||||
'stat_attributes',
|
||||
'talents',
|
||||
'brand_sets',
|
||||
'gear',
|
||||
'weapons',
|
||||
'weapon_mods',
|
||||
'gear_mods',
|
||||
'os_protocols',
|
||||
'skill_chip_sets',
|
||||
'specializations',
|
||||
'specialization_focuses',
|
||||
'specialization_abilities',
|
||||
'specialization_combat_effects',
|
||||
'specialization_tree_nodes',
|
||||
'roles'
|
||||
].includes(table)) {
|
||||
throw new Error('Unsupported audit table');
|
||||
}
|
||||
const database = await getDatabase();
|
||||
return await (await database.prepare(`SELECT * FROM ${table} WHERE id=?`)).get(id) ?? null;
|
||||
export async function auditRecord(
|
||||
table: string,
|
||||
id: string,
|
||||
): Promise<Record<string, unknown> | null> {
|
||||
if (
|
||||
![
|
||||
'stat_attributes',
|
||||
'talents',
|
||||
'brand_sets',
|
||||
'gear',
|
||||
'weapons',
|
||||
'weapon_mods',
|
||||
'gear_mods',
|
||||
'os_protocols',
|
||||
'skill_chip_sets',
|
||||
'specializations',
|
||||
'specialization_focuses',
|
||||
'specialization_abilities',
|
||||
'specialization_combat_effects',
|
||||
'specialization_tree_nodes',
|
||||
'roles',
|
||||
].includes(table)
|
||||
) {
|
||||
throw new Error('Unsupported audit table');
|
||||
}
|
||||
const database = await getDatabase();
|
||||
return (
|
||||
(await (
|
||||
await database.prepare(`SELECT * FROM ${table} WHERE id=?`)
|
||||
).get(id)) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user