Replace timestamp-based IDs with UUIDs for guaranteed uniqueness and race condition safety
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[
|
||||
{
|
||||
"id": "m1",
|
||||
"id": "550e8400-e29b-41d4-a716-446655440001",
|
||||
"firstName": "Max",
|
||||
"lastName": "Mustermann",
|
||||
"email": "max@example.com",
|
||||
@@ -9,7 +9,7 @@
|
||||
"notes": "Herren 1"
|
||||
},
|
||||
{
|
||||
"id": "m2",
|
||||
"id": "550e8400-e29b-41d4-a716-446655440002",
|
||||
"firstName": "Anna",
|
||||
"lastName": "Schmidt",
|
||||
"email": "",
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
[
|
||||
{
|
||||
"id": "n1729515536050",
|
||||
"title": "aaa",
|
||||
"content": "bbb",
|
||||
"author": "Admin",
|
||||
"created": "2025-10-21T13:08:56.050Z",
|
||||
"updated": "2025-10-21T13:08:56.050Z"
|
||||
},
|
||||
{
|
||||
"id": "n1729514969710",
|
||||
"id": "660e8400-e29b-41d4-a716-446655440001",
|
||||
"title": "Alles neu",
|
||||
"content": "Die seite ist brandneu",
|
||||
"author": "Admin",
|
||||
@@ -16,11 +8,11 @@
|
||||
"updated": "2025-10-21T12:49:29.710Z"
|
||||
},
|
||||
{
|
||||
"id": "n1",
|
||||
"id": "660e8400-e29b-41d4-a716-446655440002",
|
||||
"title": "Willkommen im Mitgliederbereich",
|
||||
"content": "Hier finden Sie ab sofort alle internen Neuigkeiten und Ankündigungen des Harheimer TC.",
|
||||
"author": "Vorstand",
|
||||
"created": "2025-01-15T10:00:00.000Z",
|
||||
"updated": "2025-01-15T10:00:00.000Z"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
@@ -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) => {
|
||||
@@ -75,10 +76,10 @@ export async function saveMember(memberData) {
|
||||
throw new Error('Mitglied nicht gefunden')
|
||||
}
|
||||
} else {
|
||||
// Add new
|
||||
// Add new - use UUID for guaranteed uniqueness
|
||||
const newMember = {
|
||||
id: `m${Date.now()}`,
|
||||
...memberData
|
||||
...memberData,
|
||||
id: randomUUID() // Cryptographically secure unique ID
|
||||
}
|
||||
members.push(newMember)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user