Replace timestamp-based IDs with UUIDs for guaranteed uniqueness and race condition safety

This commit is contained in:
Torsten Schulz (local)
2025-10-21 15:23:48 +02:00
parent 3fe1c8adc0
commit f0b628d746
18 changed files with 149 additions and 154 deletions

View File

@@ -1,5 +1,6 @@
import { promises as fs } from 'fs'
import path from 'path'
import { randomUUID } from 'crypto'
// Handle both dev and production paths
const getDataPath = (filename) => {
@@ -64,10 +65,10 @@ export async function saveNews(newsData) {
throw new Error('News nicht gefunden')
}
} else {
// Add new
// Add new - use UUID for guaranteed uniqueness
const newItem = {
...newsData,
id: `n${Date.now()}`, // ID must come AFTER ...newsData to not be overwritten
id: randomUUID(), // Cryptographically secure unique ID
created: new Date().toISOString(),
updated: new Date().toISOString()
}