Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/recovery/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
import { randomBytes } from "node:crypto";
import { join } from "node:path";
import { MESSAGE_STORAGE, PART_STORAGE, THINKING_TYPES, META_TYPES } from "./constants.js";
import type { StoredMessageMeta, StoredPart, StoredTextPart } from "./types.js";
Expand All @@ -23,7 +24,7 @@ function validatePathId(id: string, name: string): void {

export function generatePartId(): string {
const timestamp = Date.now().toString(16);
const random = Math.random().toString(36).substring(2, 10);
const random = randomBytes(4).toString("hex");
return `prt_${timestamp}${random}`;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async function writeFileWithTimeout(filePath: string, content: string, timeoutMs
}

async function writePreImportBackupFile(backupPath: string, snapshot: AccountStorageV3): Promise<void> {
const uniqueSuffix = `${Date.now()}.${Math.random().toString(36).slice(2, 8)}`;
const uniqueSuffix = `${Date.now()}.${randomBytes(6).toString("hex")}`;
const tempPath = `${backupPath}.${uniqueSuffix}.tmp`;

try {
Expand Down Expand Up @@ -862,7 +862,7 @@ async function loadAccountsInternal(

async function saveAccountsUnlocked(storage: AccountStorageV3): Promise<void> {
const path = getStoragePath();
const uniqueSuffix = `${Date.now()}.${Math.random().toString(36).slice(2, 8)}`;
const uniqueSuffix = `${Date.now()}.${randomBytes(6).toString("hex")}`;
const tempPath = `${path}.${uniqueSuffix}.tmp`;

try {
Expand Down Expand Up @@ -1098,7 +1098,7 @@ export async function loadFlaggedAccounts(): Promise<FlaggedAccountStorageV1> {
export async function saveFlaggedAccounts(storage: FlaggedAccountStorageV1): Promise<void> {
return withStorageLock(async () => {
const path = getFlaggedAccountsPath();
const uniqueSuffix = `${Date.now()}.${Math.random().toString(36).slice(2, 8)}`;
const uniqueSuffix = `${Date.now()}.${randomBytes(6).toString("hex")}`;
const tempPath = `${path}.${uniqueSuffix}.tmp`;

try {
Expand Down
Loading