From db854e73d1d6a9153a1ba8ab6e2d7cb430ab9024 Mon Sep 17 00:00:00 2001 From: adueck Date: Mon, 17 Oct 2022 00:24:18 +0500 Subject: [PATCH] hmm didn't work --- functions/src/publish.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/functions/src/publish.ts b/functions/src/publish.ts index 4f8c1d0..b75041c 100644 --- a/functions/src/publish.ts +++ b/functions/src/publish.ts @@ -95,19 +95,25 @@ async function getRawEntries(): Promise { await doc.loadInfo(); const sheet = doc.sheetsByIndex[0]; const rows = await sheet.getRows(); - return await makeEntries(rows); + async function deleteRow(i: number) { + await rows[i].delete(); + } + return await makeEntries(rows, deleteRow); } -async function makeEntries(rows: GoogleSpreadsheetRow[]): Promise { +async function makeEntries(rows: GoogleSpreadsheetRow[], deleteRow: (i: number) => Promise): Promise { const entries: T.DictionaryEntry[] = []; + let sheetIndex = 0; for (let i = 0; i < rows.length; i++) { + sheetIndex++; const row = rows[i]; const nextRow = rows[i+1] || undefined; if (row.ts === nextRow?.ts) { if (row.p !== nextRow.p) throw new Error(`ts ${row.ts} is a duplicate of a different entry`); // this looks like a duplicate entry made by the sheets api // delete it and keep going - await row.delete(); + await deleteRow(sheetIndex); + sheetIndex--; continue; } const e: T.DictionaryEntry = {