feat(migrate): Karakeep bookmarks importer

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-04 22:21:03 +10:00
parent af2dacbc00
commit b0d87fe5bf
2 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import * as refs from '../../lib/db/repos/refs.js';
const SYS = { kind: 'system', id: null };
// Karakeep REST: GET /api/v1/bookmarks?cursor=... → { bookmarks:[{id,content:{url,title}}], nextCursor }.
export async function importKarakeep({ apiUrl = process.env.KARAKEEP_URL, token = process.env.KARAKEEP_TOKEN, spaceId, dryRun = false, fetchImpl = fetch }) {
let cursor = null, created = 0;
do {
const u = `${apiUrl}/api/v1/bookmarks?limit=100${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''}`;
const res = await fetchImpl(u, { headers: { Authorization: `Bearer ${token}` } });
if (!res.ok) throw new Error(`karakeep ${res.status}`);
const body = await res.json();
for (const b of (body.bookmarks || [])) {
const url = b.content?.url; if (!url) continue;
created++;
if (dryRun) continue;
await refs.upsertByExternal({ space_id: spaceId, kind: 'url', source_url: url, title: b.content?.title || url, source_kind: 'karakeep', external_id: String(b.id) }, SYS);
}
cursor = body.nextCursor || null;
} while (cursor);
return { created };
}