Skip to content

Commit a98e27c

Browse files
fix(audit): preserve URL text when URL row is deleted
1 parent f177424 commit a98e27c

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

apps/backend/routes/auth/getAuditTable.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export const getAuditTable = async () => {
178178
created_at
179179
content
180180
url_id
181+
url_text
181182
url {
182183
url
183184
type
@@ -287,7 +288,9 @@ export const getAuditTable = async () => {
287288
short_id: blocker.short_id,
288289
content_hash_id: blocker.content_hash_id,
289290
created_at: blocker.created_at,
290-
url: blocker.url?.url || "Unknown URL",
291+
// Fallback chain: live join → snapshotted url_text (preserved at scan time) → Unknown URL.
292+
// This keeps the URL visible even if the urls row was later deleted (CSV change, manual removal).
293+
url: blocker.url?.url || blocker.url_text || "Unknown URL",
291294
type: blocker.url?.type || "unknown",
292295
url_id: blocker.url_id,
293296
content: blocker.content,

apps/backend/routes/public/scanWebhook.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,15 @@ export const scanWebhook = async () => {
204204
const params = [];
205205
let p = 1;
206206
for (const bd of prepared) {
207-
vals.push(`($${p}, $${p+1}, $${p+2}, $${p+3}, $${p+4}, $${p+5}, $${p+6}, $${p+7})`);
208-
params.push(auditId, JSON.stringify([]), bd.node, bd.contentNormalized, bd.contentHashId, bd.shortId, urlId, effectiveScanId);
209-
p += 8;
207+
vals.push(`($${p}, $${p+1}, $${p+2}, $${p+3}, $${p+4}, $${p+5}, $${p+6}, $${p+7}, $${p+8})`);
208+
// Snapshot the URL string as `url_text` so it survives URL row deletion
209+
// (e.g., CSV format change removing/replacing URLs). Falls back to NULL
210+
// if the webhook payload didn't include the url.
211+
params.push(auditId, JSON.stringify([]), bd.node, bd.contentNormalized, bd.contentHashId, bd.shortId, urlId, effectiveScanId, url ?? null);
212+
p += 9;
210213
}
211214
const result = await db.query({
212-
text: `INSERT INTO "blockers" ("audit_id", "targets", "content", "content_normalized", "content_hash_id", "short_id", "url_id", "scan_id") VALUES ${vals.join(', ')} RETURNING "id"`,
215+
text: `INSERT INTO "blockers" ("audit_id", "targets", "content", "content_normalized", "content_hash_id", "short_id", "url_id", "scan_id", "url_text") VALUES ${vals.join(', ')} RETURNING "id"`,
213216
values: params,
214217
});
215218
blockerIds = result.rows.map((r: any) => r.id);

0 commit comments

Comments
 (0)