-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnuke.ts
More file actions
90 lines (80 loc) · 2.28 KB
/
nuke.ts
File metadata and controls
90 lines (80 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// src/lib/nuke.ts
import { randomBytes } from "node:crypto"
import { db } from "@/lib/db"
import {
appSettings,
clientSnapshots,
clientUptimeBuckets,
dismissedAlerts,
downloadClients,
notificationDeliveryState,
notificationTargets,
tagGroupMembers,
tagGroups,
torrentDailyCheckpoints,
trackerDailyCheckpoints,
trackerRoles,
trackerSnapshots,
trackers,
} from "@/lib/db/schema"
import { stopScheduler } from "@/lib/scheduler"
function randomHex(bytes: number): string {
return randomBytes(bytes).toString("hex")
}
export async function scrubAndDeleteAll(): Promise<void> {
stopScheduler()
await db.transaction(async (tx) => {
await tx.update(trackerSnapshots).set({
username: randomHex(16),
group: randomHex(16),
})
await tx.update(trackers).set({
encryptedApiToken: randomHex(64),
name: randomHex(8),
baseUrl: randomHex(16),
lastError: null,
qbtTag: null,
})
await tx.update(trackerRoles).set({
roleName: randomHex(8),
notes: null,
})
await tx.update(appSettings).set({
passwordHash: randomHex(32),
encryptionSalt: randomHex(32),
encryptedSchedulerKey: null,
username: null,
totpSecret: null,
totpBackupCodes: null,
encryptedProxyPassword: null,
encryptedBackupPassword: null,
})
await tx.update(downloadClients).set({
encryptedUsername: randomHex(64),
encryptedPassword: randomHex(64),
name: randomHex(8),
host: randomHex(16),
lastError: null,
})
await tx.update(notificationTargets).set({
encryptedConfig: randomHex(64),
name: randomHex(8),
lastDeliveryError: null,
})
await tx.delete(dismissedAlerts)
await tx.delete(clientUptimeBuckets)
await tx.delete(torrentDailyCheckpoints)
await tx.delete(trackerDailyCheckpoints)
await tx.delete(clientSnapshots)
await tx.delete(trackerSnapshots)
await tx.delete(trackerRoles)
await tx.delete(tagGroupMembers)
await tx.delete(tagGroups)
await tx.delete(notificationDeliveryState)
await tx.delete(notificationTargets)
await tx.delete(downloadClients)
await tx.delete(trackers)
await tx.delete(appSettings)
})
;(globalThis as unknown as Record<string, unknown>).__backfillDone = false
}