diff --git a/src/lib/dashboard.functions.ts b/src/lib/dashboard.functions.ts index 6ed49cf..aa76c48 100644 --- a/src/lib/dashboard.functions.ts +++ b/src/lib/dashboard.functions.ts @@ -181,6 +181,8 @@ export const getStatuses = createServerFn({ method: "GET" }) .where( and(eq(link.userId, user.id), eq(card.dashboardId, data.dashboardId)) ) + // one request must not make the server call thousands of addresses + .limit(200) const up = await Promise.all(links.map((l) => isReachable(l.url))) return Object.fromEntries(links.map((l, i) => [l.id, up[i]])) }) diff --git a/src/lib/transfer.test.ts b/src/lib/transfer.test.ts index 831841c..93828ac 100644 --- a/src/lib/transfer.test.ts +++ b/src/lib/transfer.test.ts @@ -86,6 +86,16 @@ test("backupSchema refuses what is not a web address", () => { assert.ok(backupSchema.safeParse(withUrl("https://example.com")).success) assert.ok(!backupSchema.safeParse(withUrl("javascript:alert(1)")).success) assert.ok(!backupSchema.safeParse({ dashboards: [] }).success) + // 11 cards with 500 links each are more than one file may hold + const links = Array.from({ length: 500 }, () => ({ + name: "L", + url: "https://example.com", + })) + const cards = (n: number) => + Array.from({ length: n }, () => ({ name: "C", links })) + const file = (n: number) => ({ dashboards: [{ name: "D", cards: cards(n) }] }) + assert.ok(backupSchema.safeParse(file(10)).success) + assert.ok(!backupSchema.safeParse(file(11)).success) }) test("portable: uploads stay with their account", () => { diff --git a/src/lib/transfer.ts b/src/lib/transfer.ts index e470d9b..950bf4c 100644 --- a/src/lib/transfer.ts +++ b/src/lib/transfer.ts @@ -4,6 +4,7 @@ import { z } from "zod" const httpUrl = z.url({ protocol: /^https?$/ }).max(2000) const MAX_CARDS = 100 const MAX_LINKS = 500 // per card +const MAX_TOTAL = 5000 // links in one file /** * What an export holds and an import takes: dashboards with their cards and links. @@ -37,7 +38,13 @@ export const backupSchema = z.object({ }) ) .min(1) - .max(20), + .max(20) + // one import is one transaction: keep it small enough for that + .refine( + (dashboards) => + dashboards.flatMap((d) => d.cards.flatMap((c) => c.links)).length <= + MAX_TOTAL + ), }) export type Backup = z.infer @@ -76,6 +83,7 @@ export function parseBookmarks(html: string) { const folders: string[] = [] // the path to where we are let heading: string | null = null // a folder name that waits for its
let skipped = 0 + let total = 0 const tags = /|]*>([\s\S]*?)<\/H3>|]*)>([\s\S]*?)<\/A>/gi for (const [tag, folder, attributes, title] of html.matchAll(tags)) { @@ -95,6 +103,7 @@ export function parseBookmarks(html: string) { } if ( !url.success || + total >= MAX_TOTAL || card.links.length >= MAX_LINKS || (!cards.has(path) && cards.size >= MAX_CARDS) ) { @@ -102,6 +111,7 @@ export function parseBookmarks(html: string) { continue } cards.set(path, card) + total++ card.links.push({ name: (text(title) || new URL(url.data).hostname).slice(0, 60), url: url.data, diff --git a/src/routes/settings.tsx b/src/routes/settings.tsx index b5d4597..289ede3 100644 --- a/src/routes/settings.tsx +++ b/src/routes/settings.tsx @@ -565,6 +565,8 @@ function Settings() { router.navigate({