feat: improve error logging and enhance settings sync functionality

This commit is contained in:
Linus Rath
2026-03-19 08:54:33 +01:00
parent 9b3a47f9be
commit 234129397d
3 changed files with 34 additions and 19 deletions
+5 -2
View File
@@ -1,5 +1,5 @@
import { createHash, createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
import { readFile, writeFile, unlink, mkdir } from 'node:fs/promises';
import { readFile, writeFile, unlink, mkdir, rename } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import path from 'node:path';
import { logger } from '@/lib/logger';
@@ -45,7 +45,10 @@ export async function saveUserSettings(username: string, serverUrl: string, sett
const tag = cipher.getAuthTag();
const data = Buffer.concat([iv, tag, encrypted]);
await writeFile(getSettingsPath(username, serverUrl), data);
const targetPath = getSettingsPath(username, serverUrl);
const tmpPath = targetPath + '.tmp';
await writeFile(tmpPath, data);
await rename(tmpPath, targetPath);
}
export async function loadUserSettings(username: string, serverUrl: string): Promise<Record<string, unknown> | null> {