your personal website on atproto - mirror blento.app
at statusphere-fix 33 lines 1.0 kB view raw
1import type { UserCache } from '$lib/types'; 2import { getCache, loadData } from '$lib/website/load'; 3import type { AppBskyActorDefs } from '@atcute/bluesky'; 4import { json } from '@sveltejs/kit'; 5 6export async function GET({ platform }) { 7 if (!platform?.env?.USER_DATA_CACHE) return json('no cache'); 8 const existingUsers = await platform?.env?.USER_DATA_CACHE?.get('updatedBlentos'); 9 10 const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers 11 ? JSON.parse(existingUsers) 12 : []; 13 14 const existingUsersHandle = existingUsersArray.map((v) => v.handle); 15 16 const cache = platform?.env?.USER_DATA_CACHE as unknown; 17 18 for (const handle of existingUsersHandle) { 19 if (!handle) continue; 20 21 console.log('updating', handle); 22 try { 23 const cached = await getCache(handle, 'self', cache as UserCache); 24 if (!cached) await loadData(handle, cache as UserCache, true); 25 } catch (error) { 26 console.error(error); 27 return json('error'); 28 } 29 console.log('updated', handle); 30 } 31 32 return json('ok'); 33}