atmo.rsvp
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

add update endpoint

Florian aa251081 b1b46dec

+28 -20
+28 -20
src/routes/p/[actor]/notify-updates/+server.ts
··· 1 1 import { error, json } from '@sveltejs/kit'; 2 2 import { getActor } from '$lib/actor'; 3 3 import { isActorIdentifier, type ResourceUri } from '@atcute/lexicons/syntax'; 4 - import { contrail, listEventRecordsFromContrail } from '$lib/contrail'; 4 + import type { Did } from '@atcute/lexicons'; 5 + import { contrail } from '$lib/contrail'; 6 + import { listRecords } from '$lib/atproto/methods'; 5 7 6 8 export async function GET({ params }) { 7 9 if (!isActorIdentifier(params.actor)) { ··· 14 16 throw error(404, 'Not found'); 15 17 } 16 18 17 - // Paginate through all events 18 - const uris: string[] = []; 19 - let cursor: string | undefined; 20 - 21 - do { 22 - const response = await listEventRecordsFromContrail({ 23 - actor: params.actor, 24 - limit: 100, 25 - cursor 26 - }); 19 + // List records directly from the PDS 20 + const records = await listRecords({ 21 + did: did as Did, 22 + collection: 'community.lexicon.calendar.event', 23 + limit: 0 24 + }); 27 25 28 - if (!response) { 29 - if (uris.length === 0) throw error(500, 'Failed to list events'); 30 - break; 31 - } 26 + const uris = records.map((r) => r.uri); 32 27 33 - uris.push(...response.records.map((r) => r.uri)); 34 - cursor = response.cursor ?? undefined; 35 - } while (cursor); 28 + console.log(`[notify-updates] Found ${uris.length} events on PDS for ${params.actor}`); 29 + for (const uri of uris) { 30 + console.log(`[notify-updates] - ${uri}`); 31 + } 36 32 37 33 let totalIndexed = 0; 38 34 let totalDeleted = 0; ··· 41 37 // Batch in groups of 25 (API limit) 42 38 for (let i = 0; i < uris.length; i += 25) { 43 39 const batch = uris.slice(i, i + 25); 40 + const batchNum = Math.floor(i / 25) + 1; 44 41 try { 45 42 const result = await contrail.post('rsvp.atmo.notifyOfUpdate', { 46 43 input: { uris: batch as ResourceUri[] } 47 44 }); 48 45 if (result.ok) { 46 + console.log( 47 + `[notify-updates] Batch ${batchNum} (${batch.length} uris): indexed=${result.data.indexed}, deleted=${result.data.deleted}${result.data.errors?.length ? `, errors=${JSON.stringify(result.data.errors)}` : ''}` 48 + ); 49 49 totalIndexed += result.data.indexed; 50 50 totalDeleted += result.data.deleted; 51 51 if (result.data.errors) allErrors.push(...result.data.errors); 52 + } else { 53 + console.log(`[notify-updates] Batch ${batchNum}: request failed (not ok)`); 54 + allErrors.push(`Batch ${batchNum} returned non-ok response`); 52 55 } 53 - } catch { 54 - allErrors.push(`Batch starting at index ${i} failed`); 56 + } catch (e) { 57 + console.error(`[notify-updates] Batch ${batchNum} threw:`, e); 58 + allErrors.push(`Batch ${batchNum} (index ${i}) failed`); 55 59 } 56 60 } 61 + 62 + console.log( 63 + `[notify-updates] Done: total=${uris.length}, indexed=${totalIndexed}, deleted=${totalDeleted}, errors=${allErrors.length}` 64 + ); 57 65 58 66 return json({ 59 67 total: uris.length,