your personal website on atproto - mirror blento.app
at mobile-editing 27 lines 986 B view raw
1import { getDetailedProfile } from '$lib/atproto'; 2import { json } from '@sveltejs/kit'; 3import type { AppBskyActorDefs } from '@atcute/bluesky'; 4 5export async function GET({ platform }) { 6 if (!platform?.env?.USER_DATA_CACHE) return json('no cache'); 7 const existingUsers = await platform?.env?.USER_DATA_CACHE?.get('updatedBlentos'); 8 9 const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers 10 ? JSON.parse(existingUsers) 11 : []; 12 13 const existingUsersSet = new Set(existingUsersArray.map((v) => v.did)); 14 15 const newProfilesPromises: Promise<AppBskyActorDefs.ProfileViewDetailed | undefined>[] = []; 16 for (const did of Array.from(existingUsersSet)) { 17 const profile = getDetailedProfile({ did }); 18 newProfilesPromises.push(profile); 19 if (newProfilesPromises.length > 20) break; 20 } 21 22 const newProfiles = await Promise.all(newProfilesPromises); 23 24 await platform?.env?.USER_DATA_CACHE.put('updatedBlentos', JSON.stringify(newProfiles)); 25 26 return json('ok'); 27}