From 1055e3b5bdb2e497c049ac7f9e31c998b6935989 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Tue, 31 Dec 2024 11:17:37 +0100 Subject: [PATCH 1/8] split audit log into a separate database and compress payload --- .gitignore | 2 + package.json | 3 +- pages/admin/audit-log/[username]/[id].vue | 2 +- pnpm-lock.yaml | 22 +++--- server/audit.ts | 78 ++++++++++++++++++-- server/auditMigration.ts | 87 +++++++++++++++++++++++ server/express/admin.ts | 8 +-- server/express/census.ts | 2 +- server/express/images.ts | 2 +- server/express/inclusive.ts | 2 +- server/express/mfa.ts | 2 +- server/express/names.ts | 2 +- server/express/nouns.ts | 2 +- server/express/profile.ts | 2 +- server/express/sources.ts | 2 +- server/express/subscription.ts | 2 +- server/express/terms.ts | 2 +- server/express/translations.ts | 2 +- server/express/user.ts | 2 +- server/index.ts | 3 + 20 files changed, 195 insertions(+), 34 deletions(-) create mode 100644 server/auditMigration.ts diff --git a/.gitignore b/.gitignore index 63d95f429..3d923fbce 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ /db.sqlite-wal /db.sqlite-* +/audit.sqlite + /*.sqlite /daemonise.json diff --git a/package.json b/package.json index 0017cb2a4..0118dccca 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,8 @@ "uuid": "^8.3.2", "vue3-lazy-hydration": "^1.2.1", "vuedraggable": "^4.1.0", - "zh_cn_zh_tw": "^1.0.7" + "zh_cn_zh_tw": "^1.0.7", + "zlib": "^1.0.5" }, "devDependencies": { "@babel/eslint-parser": "^7.24.5", diff --git a/pages/admin/audit-log/[username]/[id].vue b/pages/admin/audit-log/[username]/[id].vue index 58e79d526..7f6f4a733 100644 --- a/pages/admin/audit-log/[username]/[id].vue +++ b/pages/admin/audit-log/[username]/[id].vue @@ -65,7 +65,7 @@ {{ logEntry.event.split('/')[0] }}/{{ logEntry.event.split('/')[1] }} -
{{ JSON.stringify(JSON.parse(logEntry.payload), null, 4) }}
+
{{ JSON.stringify(logEntry.payload, null, 4) }}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9c7ac5797..cab338531 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -215,13 +215,16 @@ importers: zh_cn_zh_tw: specifier: ^1.0.7 version: 1.0.7 + zlib: + specifier: ^1.0.5 + version: 1.0.5 devDependencies: '@babel/eslint-parser': specifier: ^7.24.5 - version: 7.25.1(@babel/core@7.25.2)(eslint@9.13.0(jiti@2.4.0)) + version: 7.25.1(@babel/core@7.26.0)(eslint@9.13.0(jiti@2.4.0)) '@babel/plugin-syntax-import-assertions': specifier: ^7.24.1 - version: 7.25.6(@babel/core@7.25.2) + version: 7.25.6(@babel/core@7.26.0) '@fortawesome/fontawesome-pro': specifier: git+ssh://git@gitlab.com:Avris/FontAwesomePro.git version: git+https://git@gitlab.com:Avris/FontAwesomePro.git#f00db606f659dca78b143b7bcab5671b2cb459a8 @@ -8580,6 +8583,10 @@ packages: resolution: {integrity: sha512-zK7YHHz4ZXpW89AHXUPbQVGKI7uvkd3hzusTdotCg1UxyaVtg0zFJSTfW/Dq5f7OBBVnq6cZIaC8Ti4hb6dtCA==} engines: {node: '>= 14'} + zlib@1.0.5: + resolution: {integrity: sha512-40fpE2II+Cd3k8HWTWONfeKE2jL+P42iWJ1zzps5W51qcTsOUKM5Q5m2PFb0CLxlmFAaUuUdJGc3OfZy947v0w==} + engines: {node: '>=0.2.0'} + zod@3.23.8: resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} @@ -9234,9 +9241,9 @@ snapshots: transitivePeerDependencies: - supports-color - '@babel/eslint-parser@7.25.1(@babel/core@7.25.2)(eslint@9.13.0(jiti@2.4.0))': + '@babel/eslint-parser@7.25.1(@babel/core@7.26.0)(eslint@9.13.0(jiti@2.4.0))': dependencies: - '@babel/core': 7.25.2 + '@babel/core': 7.26.0 '@nicolo-ribaudo/eslint-scope-5-internals': 5.1.1-v1 eslint: 9.13.0(jiti@2.4.0) eslint-visitor-keys: 2.1.0 @@ -9538,11 +9545,6 @@ snapshots: '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.24.8 - '@babel/plugin-syntax-import-assertions@7.25.6(@babel/core@7.25.2)': - dependencies: - '@babel/core': 7.25.2 - '@babel/helper-plugin-utils': 7.24.8 - '@babel/plugin-syntax-import-assertions@7.25.6(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 @@ -18703,4 +18705,6 @@ snapshots: compress-commons: 6.0.2 readable-stream: 4.5.2 + zlib@1.0.5: {} + zod@3.23.8: {} diff --git a/server/audit.ts b/server/audit.ts index 4b51b254b..5c29d8fb1 100644 --- a/server/audit.ts +++ b/server/audit.ts @@ -1,26 +1,94 @@ +import { promisify } from 'util'; +import zlib from 'zlib'; + import * as Sentry from '@sentry/node'; import SQL from 'sql-template-strings'; +import * as sqlite from 'sqlite'; +import sqlite3 from 'sqlite3'; import { ulid } from 'ulid'; -import type { Database } from './db.ts'; import type { UserRow } from './express/user.ts'; +import { rootDir } from '~/server/paths.ts'; + interface Payload { userId?: string; [key: string]: unknown; } -export default async ( - req: { db: Database; user?: Pick | null; rawUser?: Pick | undefined }, +let connection: sqlite.Database | null = null; +const connect = async (): Promise => { + if (!connection) { + connection = await sqlite.open({ + filename: `${rootDir}/audit.sqlite`, + driver: sqlite3.Database, + }); + + // we don't want to replicate the migration setup just for this, so a little workaround here. + // it's already executed on live db, so only creating the table on dev + if (process.env.NODE_ENV === 'development') { + await connection.exec(` + CREATE TABLE IF NOT EXISTS audit_log + ( + id TEXT NOT NULL PRIMARY KEY, + userId TEXT, + username TEXT, + aboutUserId TEXT NULL, + event TEXT NOT NULL, + payload BLOB NULL + ); + CREATE INDEX IF NOT EXISTS "audit_log_userId" ON "audit_log" ("userId"); + CREATE INDEX IF NOT EXISTS "audit_log_username" ON "audit_log" ("username"); + CREATE INDEX IF NOT EXISTS "audit_log_aboutUserId" ON "audit_log" ("aboutUserId"); + `); + } + } + + return connection; +}; + +export const closeAuditLogConnection = async () => { + if (connection) { + await connection.close(); + connection = null; + } +}; + +const gzip = promisify(zlib.gzip); +const gunzip = promisify(zlib.gunzip); + +export const auditLog = async ( + req: { user?: Pick | null; rawUser?: Pick | undefined }, event: string, payload: Payload | null = null, ): Promise => { + const db = await connect(); + try { + const compressedPayload = payload + ? await gzip(Buffer.from(JSON.stringify(payload))) + : null; + const user = req.user || req.rawUser || { id: null, username: null }; - await req.db.get(SQL`INSERT INTO audit_log (id, userId, aboutUserId, username, event, payload) VALUES ( - ${ulid()}, ${user.id}, ${payload?.userId || null}, ${user.username}, ${event}, ${payload ? JSON.stringify(payload) : null} + await db.get(SQL`INSERT INTO audit_log (id, userId, aboutUserId, username, event, payload) VALUES ( + ${ulid()}, ${user.id}, ${payload?.userId || null}, ${user.username}, ${event}, ${compressedPayload} )`); } catch (error) { Sentry.captureException(error); } }; + +export const fetchAuditLog = async (username: string, userId: string, aboutUserId: string) => { + const db = await connect(); + + const entries = await db.all(SQL` + SELECT * FROM audit_log + WHERE username = ${username} OR userId = ${userId} OR aboutUserId = ${aboutUserId} + ORDER BY id DESC + `); + + return await Promise.all(entries.map(async (entry) => { + const payload = entry.payload ? JSON.parse((await gunzip(entry.payload)).toString()) : null; + return { ...entry, payload }; + })); +}; diff --git a/server/auditMigration.ts b/server/auditMigration.ts new file mode 100644 index 000000000..12ff08963 --- /dev/null +++ b/server/auditMigration.ts @@ -0,0 +1,87 @@ +// pnpm run-file server/auditMigration.ts + +import { promisify } from 'util'; +import zlib from 'zlib'; + +import SQL from 'sql-template-strings'; +import * as sqlite from 'sqlite'; +import sqlite3 from 'sqlite3'; + +import dbConnection from './db.ts'; + +import { rootDir } from '~/server/paths.ts'; + +const gzip = promisify(zlib.gzip); + +const connectAudit = async (): Promise => { + const connection = await sqlite.open({ + filename: `${rootDir}/audit.sqlite`, + driver: sqlite3.Database, + }); + + await connection.exec(` + CREATE TABLE IF NOT EXISTS audit_log + ( + id TEXT NOT NULL PRIMARY KEY, + userId TEXT, + username TEXT, + aboutUserId TEXT NULL, + event TEXT NOT NULL, + payload BLOB NULL + ); + CREATE INDEX IF NOT EXISTS "audit_log_userId" ON "audit_log" ("userId"); + CREATE INDEX IF NOT EXISTS "audit_log_username" ON "audit_log" ("username"); + CREATE INDEX IF NOT EXISTS "audit_log_aboutUserId" ON "audit_log" ("aboutUserId"); + `); + + return connection; +}; + +async function migrate(): Promise { + const oldDb = await dbConnection(); + const auditDb = await connectAudit(); + + const { count } = await oldDb.get(SQL`SELECT COUNT(*) as count FROM audit_log`); + let processed = 0; + + while (true) { + const entries = await oldDb.all(SQL` + SELECT * + FROM audit_log + ORDER BY id DESC + LIMIT 10000 + `); + + console.log(`[${processed}/${count} (${100 * Math.round(processed / count * 1000) / 1000}%)] Processing ${entries.length} entries…`); + + if (entries.length === 0) { + break; + } + + for (const entry of entries) { + const compressedPayload = entry.payload + ? await gzip(Buffer.from(entry.payload)) + : null; + + try { + await auditDb.get(SQL`INSERT INTO audit_log (id, userId, aboutUserId, username, event, payload) VALUES ( + ${entry.id}, ${entry.userId}, ${entry.aboutUserId}, ${entry.username}, ${entry.event}, ${compressedPayload} + )`); + } catch (error) { + // likely unique constraint issue, because we can't be atomic across databases. report and ignore. + console.error(error); + } + + await oldDb.get(SQL`DELETE FROM audit_log WHERE id = ${entry.id}`); + } + + processed += entries.length; + } + + await oldDb.get(SQL`VACUUM`); + + await oldDb.close(); + await auditDb.close(); +} + +await migrate(); diff --git a/server/express/admin.ts b/server/express/admin.ts index 8bde25e50..c67a4bf40 100644 --- a/server/express/admin.ts +++ b/server/express/admin.ts @@ -12,7 +12,7 @@ import allLocales from '../../locale/locales.ts'; import type { LocaleDescription } from '../../locale/locales.ts'; import buildLocaleList from '../../src/buildLocaleList.ts'; import { buildDict, now, shuffle, handleErrorAsync, filterObjectKeys } from '../../src/helpers.ts'; -import auditLog from '../audit.ts'; +import { auditLog, fetchAuditLog } from '../audit.ts'; import avatar from '../avatar.ts'; import { archiveBan, liftBan } from '../ban.ts'; import type { Database } from '../db.ts'; @@ -714,11 +714,7 @@ router.get('/admin/audit-log/:username/:id', handleErrorAsync(async (req, res) = return res.status(401).json({ error: 'Unauthorised' }); } - return res.json(await req.db.all(SQL` - SELECT * FROM audit_log - WHERE username = ${req.params.username} OR userId = ${req.params.id} OR aboutUserId = ${req.params.id} - ORDER BY id DESC - `)); + return res.json(await fetchAuditLog(req.params.username, req.params.id, req.params.id)); })); router.get('/admin/authenticators/:id', handleErrorAsync(async (req, res) => { diff --git a/server/express/census.ts b/server/express/census.ts index 6c06ebea5..93575e0f8 100644 --- a/server/express/census.ts +++ b/server/express/census.ts @@ -9,7 +9,7 @@ import type { Aggregate } from '../../locale/config.ts'; import { groupBy, handleErrorAsync } from '../../src/helpers.ts'; import { intersection, difference } from '../../src/sets.ts'; import { buildChart } from '../../src/stats.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; interface CensusRow { id: string; diff --git a/server/express/images.ts b/server/express/images.ts index 809aa602b..d72b50443 100644 --- a/server/express/images.ts +++ b/server/express/images.ts @@ -11,7 +11,7 @@ import SQL from 'sql-template-strings'; import { ulid } from 'ulid'; import { handleErrorAsync } from '../../src/helpers.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import { awsConfig, awsParams } from '../aws.ts'; import { rootDir } from '../paths.ts'; diff --git a/server/express/inclusive.ts b/server/express/inclusive.ts index c7f34dd31..c8307ac59 100644 --- a/server/express/inclusive.ts +++ b/server/express/inclusive.ts @@ -5,7 +5,7 @@ import { ulid } from 'ulid'; import { handleErrorAsync, sortClearedLinkedText } from '../../src/helpers.ts'; import type { User } from '../../src/user.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import type { Database } from '../db.ts'; interface InclusiveRow { diff --git a/server/express/mfa.ts b/server/express/mfa.ts index 3e2652d40..e82e0fb07 100644 --- a/server/express/mfa.ts +++ b/server/express/mfa.ts @@ -3,7 +3,7 @@ import speakeasy from 'speakeasy'; import { longtimeCookieSetting } from '../../src/cookieSettings.ts'; import { handleErrorAsync } from '../../src/helpers.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import type { Database } from '../db.ts'; import { diff --git a/server/express/names.ts b/server/express/names.ts index 3e25eef56..bf15f9a60 100644 --- a/server/express/names.ts +++ b/server/express/names.ts @@ -4,7 +4,7 @@ import SQL from 'sql-template-strings'; import { ulid } from 'ulid'; import { handleErrorAsync } from '../../src/helpers.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import type { Database } from '../db.ts'; interface NameRow { diff --git a/server/express/nouns.ts b/server/express/nouns.ts index 3647305e4..e13f38c50 100644 --- a/server/express/nouns.ts +++ b/server/express/nouns.ts @@ -7,7 +7,7 @@ import { ulid } from 'ulid'; import type { Translations } from '../../locale/translations.ts'; import { clearKey, handleErrorAsync } from '../../src/helpers.ts'; import type { User } from '../../src/user.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import type { Database } from '../db.ts'; import { loadSuml } from '../loader.ts'; import { registerLocaleFont } from '../localeFont.ts'; diff --git a/server/express/profile.ts b/server/express/profile.ts index f68ce058a..5dffe03f8 100644 --- a/server/express/profile.ts +++ b/server/express/profile.ts @@ -29,7 +29,7 @@ import type { } from '../../src/profile.ts'; import { socialProviders } from '../../src/socialProviders.ts'; import { colours, styles } from '../../src/styling.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import avatar from '../avatar.ts'; import { awsConfig, awsParams } from '../aws.ts'; import crypto from '../crypto.ts'; diff --git a/server/express/sources.ts b/server/express/sources.ts index 59a50bebd..ff21452e5 100644 --- a/server/express/sources.ts +++ b/server/express/sources.ts @@ -4,7 +4,7 @@ import SQL from 'sql-template-strings'; import { ulid } from 'ulid'; import { clearKey, handleErrorAsync } from '../../src/helpers.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import type { Database } from '../db.ts'; export interface SourceRow { diff --git a/server/express/subscription.ts b/server/express/subscription.ts index 63fb5037b..cdebb912d 100644 --- a/server/express/subscription.ts +++ b/server/express/subscription.ts @@ -3,7 +3,7 @@ import SQL from 'sql-template-strings'; import { ulid } from 'ulid'; import { handleErrorAsync } from '../../src/helpers.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import { validateEmail } from './user.ts'; diff --git a/server/express/terms.ts b/server/express/terms.ts index da623deba..6c7fce1ad 100644 --- a/server/express/terms.ts +++ b/server/express/terms.ts @@ -5,7 +5,7 @@ import { ulid } from 'ulid'; import { handleErrorAsync, sortClearedLinkedText, clearKey } from '../../src/helpers.ts'; import type { User } from '../../src/user.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import type { Database } from '../db.ts'; interface TermDb { diff --git a/server/express/translations.ts b/server/express/translations.ts index 63101d43e..63b1b136f 100644 --- a/server/express/translations.ts +++ b/server/express/translations.ts @@ -3,7 +3,7 @@ import SQL from 'sql-template-strings'; import { ulid } from 'ulid'; import { findAdmins, handleErrorAsync } from '../../src/helpers.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import { deduplicateEmailPreset } from './user.ts'; diff --git a/server/express/user.ts b/server/express/user.ts index 0fad0b031..388b3a7ed 100644 --- a/server/express/user.ts +++ b/server/express/user.ts @@ -12,7 +12,7 @@ import { longtimeCookieSetting } from '../../src/cookieSettings.ts'; import { buildDict, makeId, now, handleErrorAsync, obfuscateEmail } from '../../src/helpers.ts'; import type { User } from '../../src/user.ts'; import { usernameRegex, usernameUnsafeRegex } from '../../src/username.ts'; -import auditLog from '../audit.ts'; +import { auditLog } from '../audit.ts'; import avatar from '../avatar.ts'; import { lookupBanArchive } from '../ban.ts'; import { validateCaptcha } from '../captcha.ts'; diff --git a/server/index.ts b/server/index.ts index 16c28e85d..54e8c0fee 100644 --- a/server/index.ts +++ b/server/index.ts @@ -41,6 +41,7 @@ import translationsRoute from './express/translations.ts'; import userRoute from './express/user.ts'; import { config } from './social.ts'; +import { closeAuditLogConnection } from '~/server/audit.ts'; import useAuthentication from '~/server/utils/useAuthentication.ts'; const MemoryStore = memorystore(session); @@ -132,6 +133,7 @@ router.use(async function (req, res, next) { }; res.on('finish', async () => { await req.db.close(); + await closeAuditLogConnection(); }); res.set('Access-Control-Allow-Origin', '*'); res.set('Access-Control-Allow-Headers', 'authorization,content-type'); @@ -171,6 +173,7 @@ router.use((err: Error, req: Request, res: Response, _next: NextFunction) => { console.error(formatError(err, req)); res.status(500).send('Unexpected server error'); req.db.close(); + closeAuditLogConnection(); }); export default useBase('/api', defineExpressHandler(router)); From 6d8dbbb617724910ccbffab10f4f2b7a84d70836 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Tue, 31 Dec 2024 11:35:12 +0100 Subject: [PATCH 2/8] fix types --- server/express/user.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/express/user.ts b/server/express/user.ts index 388b3a7ed..e61047af3 100644 --- a/server/express/user.ts +++ b/server/express/user.ts @@ -106,7 +106,7 @@ export const saveAuthenticator = async ( payload, }); } - await auditLog({ db, user }, 'auth/saved_authenticator', { + await auditLog({ user }, 'auth/saved_authenticator', { type, payloadId: payload.id || undefined, name: payload.name || undefined, @@ -478,7 +478,7 @@ router.post('/user/init', handleErrorAsync(async (req, res) => { if (user) { const { block } = await fetchLoginAttempts(req.db, user.id); if (block) { - await auditLog({ db: req.db, user }, 'auth/login_too_many_attempts'); + await auditLog({ user }, 'auth/login_too_many_attempts'); return res.json({ error: 'user.tooManyAttempts' }); } } @@ -490,12 +490,12 @@ router.post('/user/init', handleErrorAsync(async (req, res) => { }; if (!await validateEmail(payload.email)) { - await auditLog({ db: req.db, user }, 'auth/email_invalid', { email: payload.email }); + await auditLog({ user }, 'auth/email_invalid', { email: payload.email }); return res.json({ error: 'user.account.changeEmail.invalid' }); } if (!user && await lookupBanArchive(req.db, 'email', payload)) { - await auditLog({ db: req.db, user }, 'auth/blocked_archive_ban'); + await auditLog({ user }, 'auth/blocked_archive_ban'); return res.status(401).json({ error: 'Unauthorised' }); } @@ -511,12 +511,12 @@ router.post('/user/init', handleErrorAsync(async (req, res) => { mailer(payload.email, 'confirmCode', { code: payload.code }); - await auditLog({ db: req.db, user }, 'auth/requested_email_code', { email: payload.email }); + await auditLog({ user }, 'auth/requested_email_code', { email: payload.email }); }, async () => { const auth = await findLatestEmailAuthenticator(req.db, payload.email, 'email'); codeKey = auth ? auth.id : null; - await auditLog({ db: req.db, user }, 'auth/requested_email_code_duplicate', { email: payload.email }); + await auditLog({ user }, 'auth/requested_email_code_duplicate', { email: payload.email }); }, ); } From 02faf1b4ecc3809297fd62095881e1a809b24b53 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Tue, 31 Dec 2024 17:20:17 +0100 Subject: [PATCH 3/8] =?UTF-8?q?audit=20log=20migration=20=E2=80=93=20extra?= =?UTF-8?q?=20debug=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/auditMigration.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/auditMigration.ts b/server/auditMigration.ts index 12ff08963..aaed51850 100644 --- a/server/auditMigration.ts +++ b/server/auditMigration.ts @@ -44,6 +44,8 @@ async function migrate(): Promise { const { count } = await oldDb.get(SQL`SELECT COUNT(*) as count FROM audit_log`); let processed = 0; + const startedAt = new Date(); + while (true) { const entries = await oldDb.all(SQL` SELECT * @@ -52,7 +54,9 @@ async function migrate(): Promise { LIMIT 10000 `); - console.log(`[${processed}/${count} (${100 * Math.round(processed / count * 1000) / 1000}%)] Processing ${entries.length} entries…`); + const progress = Math.round(processed / count * 1000) / 1000; + const elapsedMinutes = Math.round((new Date().getTime() - startedAt.getTime()) / 1000 / 60 * 100) / 100; + console.log(`[Done: ${processed}/${count} (${100 * progress}%)] [Elapsed: ${elapsedMinutes} min] Processing ${entries.length} entries…`); if (entries.length === 0) { break; From 8c8c971e20a461235f34e477a96d6bdf69e61be8 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Tue, 31 Dec 2024 19:46:02 +0100 Subject: [PATCH 4/8] fix merge conflict --- pnpm-lock.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75b1df287..49979601b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -215,6 +215,9 @@ importers: zh_cn_zh_tw: specifier: ^1.0.7 version: 1.0.7 + zlib: + specifier: ^1.0.5 + version: 1.0.5 devDependencies: '@babel/eslint-parser': specifier: ^7.24.5 @@ -8687,6 +8690,10 @@ packages: resolution: {integrity: sha512-zK7YHHz4ZXpW89AHXUPbQVGKI7uvkd3hzusTdotCg1UxyaVtg0zFJSTfW/Dq5f7OBBVnq6cZIaC8Ti4hb6dtCA==} engines: {node: '>= 14'} + zlib@1.0.5: + resolution: {integrity: sha512-40fpE2II+Cd3k8HWTWONfeKE2jL+P42iWJ1zzps5W51qcTsOUKM5Q5m2PFb0CLxlmFAaUuUdJGc3OfZy947v0w==} + engines: {node: '>=0.2.0'} + zod@3.23.8: resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} @@ -18916,4 +18923,6 @@ snapshots: compress-commons: 6.0.2 readable-stream: 4.6.0 + zlib@1.0.5: {} + zod@3.23.8: {} From 9bc8230d82201b57b80092c7c4b6531c31a13ba7 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Tue, 31 Dec 2024 19:53:58 +0100 Subject: [PATCH 5/8] typechecks --- server/audit.ts | 2 +- server/auditMigration.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/audit.ts b/server/audit.ts index 5c29d8fb1..1b4fc824c 100644 --- a/server/audit.ts +++ b/server/audit.ts @@ -66,7 +66,7 @@ export const auditLog = async ( try { const compressedPayload = payload - ? await gzip(Buffer.from(JSON.stringify(payload))) + ? await gzip(Buffer.from(JSON.stringify(payload))as Uint8Array) : null; const user = req.user || req.rawUser || { id: null, username: null }; diff --git a/server/auditMigration.ts b/server/auditMigration.ts index aaed51850..306b2bfe1 100644 --- a/server/auditMigration.ts +++ b/server/auditMigration.ts @@ -64,7 +64,7 @@ async function migrate(): Promise { for (const entry of entries) { const compressedPayload = entry.payload - ? await gzip(Buffer.from(entry.payload)) + ? await gzip(Buffer.from(entry.payload) as Uint8Array) : null; try { From c44b7fed3ed4fe138dde1439d8ef9702223f1c68 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Tue, 31 Dec 2024 19:59:56 +0100 Subject: [PATCH 6/8] typechecks --- server/audit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/audit.ts b/server/audit.ts index 1b4fc824c..8ef6babca 100644 --- a/server/audit.ts +++ b/server/audit.ts @@ -66,7 +66,7 @@ export const auditLog = async ( try { const compressedPayload = payload - ? await gzip(Buffer.from(JSON.stringify(payload))as Uint8Array) + ? await gzip(Buffer.from(JSON.stringify(payload)) as Uint8Array) : null; const user = req.user || req.rawUser || { id: null, username: null }; From 23fc8e3bd9a89156fff7b5b2594117ead24b0f81 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Thu, 2 Jan 2025 12:59:19 +0100 Subject: [PATCH 7/8] CR improvements --- package.json | 3 +-- pnpm-lock.yaml | 9 --------- server/audit.ts | 2 +- server/auditMigration.ts | 2 +- server/express/profile.ts | 2 +- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 5bb8dc5d3..6ce16a86f 100644 --- a/package.json +++ b/package.json @@ -83,8 +83,7 @@ "uuid": "^8.3.2", "vue3-lazy-hydration": "^1.2.1", "vuedraggable": "^4.1.0", - "zh_cn_zh_tw": "^1.0.7", - "zlib": "^1.0.5" + "zh_cn_zh_tw": "^1.0.7" }, "devDependencies": { "@babel/eslint-parser": "^7.24.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49979601b..75b1df287 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -215,9 +215,6 @@ importers: zh_cn_zh_tw: specifier: ^1.0.7 version: 1.0.7 - zlib: - specifier: ^1.0.5 - version: 1.0.5 devDependencies: '@babel/eslint-parser': specifier: ^7.24.5 @@ -8690,10 +8687,6 @@ packages: resolution: {integrity: sha512-zK7YHHz4ZXpW89AHXUPbQVGKI7uvkd3hzusTdotCg1UxyaVtg0zFJSTfW/Dq5f7OBBVnq6cZIaC8Ti4hb6dtCA==} engines: {node: '>= 14'} - zlib@1.0.5: - resolution: {integrity: sha512-40fpE2II+Cd3k8HWTWONfeKE2jL+P42iWJ1zzps5W51qcTsOUKM5Q5m2PFb0CLxlmFAaUuUdJGc3OfZy947v0w==} - engines: {node: '>=0.2.0'} - zod@3.23.8: resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} @@ -18923,6 +18916,4 @@ snapshots: compress-commons: 6.0.2 readable-stream: 4.6.0 - zlib@1.0.5: {} - zod@3.23.8: {} diff --git a/server/audit.ts b/server/audit.ts index 8ef6babca..ea6df666c 100644 --- a/server/audit.ts +++ b/server/audit.ts @@ -1,5 +1,5 @@ import { promisify } from 'util'; -import zlib from 'zlib'; +import zlib from 'node:zlib'; import * as Sentry from '@sentry/node'; import SQL from 'sql-template-strings'; diff --git a/server/auditMigration.ts b/server/auditMigration.ts index 306b2bfe1..57f63a53c 100644 --- a/server/auditMigration.ts +++ b/server/auditMigration.ts @@ -1,7 +1,7 @@ // pnpm run-file server/auditMigration.ts import { promisify } from 'util'; -import zlib from 'zlib'; +import zlib from 'node:zlib'; import SQL from 'sql-template-strings'; import * as sqlite from 'sqlite'; diff --git a/server/express/profile.ts b/server/express/profile.ts index ad92d0c4b..9bc009046 100644 --- a/server/express/profile.ts +++ b/server/express/profile.ts @@ -1,5 +1,5 @@ import fs from 'fs'; -import zlib from 'zlib'; +import zlib from 'node:zlib'; import { S3, NoSuchKey } from '@aws-sdk/client-s3'; import * as Sentry from '@sentry/node'; From a3c2dbb0a7e33f2a5e41ed98d1de621c1b765658 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Thu, 2 Jan 2025 13:06:08 +0100 Subject: [PATCH 8/8] =?UTF-8?q?oh=20linter=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/audit.ts | 2 +- server/auditMigration.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/audit.ts b/server/audit.ts index ea6df666c..6b7f85b94 100644 --- a/server/audit.ts +++ b/server/audit.ts @@ -1,5 +1,5 @@ -import { promisify } from 'util'; import zlib from 'node:zlib'; +import { promisify } from 'util'; import * as Sentry from '@sentry/node'; import SQL from 'sql-template-strings'; diff --git a/server/auditMigration.ts b/server/auditMigration.ts index 57f63a53c..de019b7be 100644 --- a/server/auditMigration.ts +++ b/server/auditMigration.ts @@ -1,7 +1,7 @@ // pnpm run-file server/auditMigration.ts -import { promisify } from 'util'; import zlib from 'node:zlib'; +import { promisify } from 'util'; import SQL from 'sql-template-strings'; import * as sqlite from 'sqlite';