mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
chore: auto-fix lint & formatting [skip ci]
This commit is contained in:
1 parent
1a0500b812
commit
1348873847
2 files changed
+14
-11
No files matched your search
@@ -35,24 +35,24 @@ export async function loadFragments(db: D1Database): Promise<NamedFragment[]> {
|
|||||||
|
|
||||||
export async function saveFragments(db: D1Database, fragments: NamedFragment[]): Promise<void> {
|
export async function saveFragments(db: D1Database, fragments: NamedFragment[]): Promise<void> {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
// Load existing fragments to determine what to delete
|
// Load existing fragments to determine what to delete
|
||||||
const existing = await loadFragments(db);
|
const existing = await loadFragments(db);
|
||||||
const existingKeys = new Set(existing.map((f) => `${f.id}:${f.groupId ?? ""}`));
|
const existingKeys = new Set(existing.map((f) => `${f.id}:${f.groupId ?? ""}`));
|
||||||
const newKeys = new Set(fragments.map((f) => `${f.id}:${f.groupId ?? ""}`));
|
const newKeys = new Set(fragments.map((f) => `${f.id}:${f.groupId ?? ""}`));
|
||||||
|
|
||||||
const statements: D1PreparedStatement[] = [];
|
const statements: D1PreparedStatement[] = [];
|
||||||
|
|
||||||
// Delete fragments that are no longer present
|
// Delete fragments that are no longer present
|
||||||
for (const key of existingKeys) {
|
for (const key of existingKeys) {
|
||||||
if (!newKeys.has(key)) {
|
if (!newKeys.has(key)) {
|
||||||
const [id, groupId] = key.split(":");
|
const [id, groupId] = key.split(":");
|
||||||
statements.push(
|
statements.push(
|
||||||
db.prepare("DELETE FROM d1_fragments WHERE id = ? AND group_id = ?").bind(id, groupId)
|
db.prepare("DELETE FROM d1_fragments WHERE id = ? AND group_id = ?").bind(id, groupId),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upsert all fragments
|
// Upsert all fragments
|
||||||
for (const f of fragments) {
|
for (const f of fragments) {
|
||||||
statements.push(
|
statements.push(
|
||||||
@@ -68,6 +68,6 @@ export async function saveFragments(db: D1Database, fragments: NamedFragment[]):
|
|||||||
.bind(f.id, f.groupId ?? "", f.name, JSON.stringify(f.node), now, now),
|
.bind(f.id, f.groupId ?? "", f.name, JSON.stringify(f.node), now, now),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.batch(statements);
|
await db.batch(statements);
|
||||||
}
|
}
|
||||||
@@ -88,10 +88,13 @@ export function d1ConfigStore(db: D1Database, kv: KVNamespace): ConfigStore {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function routeStatements(routes: Route[], existingRouteKeys?: Set<string>): D1PreparedStatement[] {
|
function routeStatements(
|
||||||
|
routes: Route[],
|
||||||
|
existingRouteKeys?: Set<string>,
|
||||||
|
): D1PreparedStatement[] {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const statements: D1PreparedStatement[] = [];
|
const statements: D1PreparedStatement[] = [];
|
||||||
|
|
||||||
// If we have existing routes, delete those not in the new set
|
// If we have existing routes, delete those not in the new set
|
||||||
if (existingRouteKeys) {
|
if (existingRouteKeys) {
|
||||||
const newKeys = new Set(routes.map((r) => `${r.id}:${r.groupId ?? ""}`));
|
const newKeys = new Set(routes.map((r) => `${r.id}:${r.groupId ?? ""}`));
|
||||||
@@ -99,7 +102,7 @@ export function d1ConfigStore(db: D1Database, kv: KVNamespace): ConfigStore {
|
|||||||
if (!newKeys.has(key)) {
|
if (!newKeys.has(key)) {
|
||||||
const [id, groupId] = key.split(":");
|
const [id, groupId] = key.split(":");
|
||||||
statements.push(
|
statements.push(
|
||||||
db.prepare("DELETE FROM d1_routes WHERE id = ? AND group_id = ?").bind(id, groupId)
|
db.prepare("DELETE FROM d1_routes WHERE id = ? AND group_id = ?").bind(id, groupId),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,7 +110,7 @@ export function d1ConfigStore(db: D1Database, kv: KVNamespace): ConfigStore {
|
|||||||
// Backward compatibility: delete all routes if no existing set provided
|
// Backward compatibility: delete all routes if no existing set provided
|
||||||
statements.push(db.prepare("DELETE FROM d1_routes"));
|
statements.push(db.prepare("DELETE FROM d1_routes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upsert all routes
|
// Upsert all routes
|
||||||
for (const r of routes) {
|
for (const r of routes) {
|
||||||
statements.push(
|
statements.push(
|
||||||
@@ -142,7 +145,7 @@ export function d1ConfigStore(db: D1Database, kv: KVNamespace): ConfigStore {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return statements;
|
return statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user