tangled
alpha
login
or
join now
flo-bit.dev
/
blento
21
fork
atom
your personal website on atproto - mirror
blento.app
21
fork
atom
overview
issues
pulls
pipelines
remove api routes
Florian
4 weeks ago
573b3c21
99b8faa4
-62
2 changed files
expand all
collapse all
unified
split
src
routes
api
reloadRecent
+server.ts
update
+server.ts
-30
src/routes/api/reloadRecent/+server.ts
···
1
1
-
import { getDetailedProfile } from '$lib/atproto';
2
2
-
import { createCache } from '$lib/cache';
3
3
-
import { json } from '@sveltejs/kit';
4
4
-
import type { AppBskyActorDefs } from '@atcute/bluesky';
5
5
-
6
6
-
export async function GET({ platform }) {
7
7
-
const cache = createCache(platform);
8
8
-
if (!cache) return json('no cache');
9
9
-
10
10
-
const existingUsers = await cache.get('meta', 'updatedBlentos');
11
11
-
12
12
-
const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers
13
13
-
? JSON.parse(existingUsers)
14
14
-
: [];
15
15
-
16
16
-
const existingUsersSet = new Set(existingUsersArray.map((v) => v.did));
17
17
-
18
18
-
const newProfilesPromises: Promise<AppBskyActorDefs.ProfileViewDetailed | undefined>[] = [];
19
19
-
for (const did of Array.from(existingUsersSet)) {
20
20
-
const profile = getDetailedProfile({ did });
21
21
-
newProfilesPromises.push(profile);
22
22
-
if (newProfilesPromises.length > 20) break;
23
23
-
}
24
24
-
25
25
-
const newProfiles = await Promise.all(newProfilesPromises);
26
26
-
27
27
-
await cache.put('meta', 'updatedBlentos', JSON.stringify(newProfiles));
28
28
-
29
29
-
return json('ok');
30
30
-
}
-32
src/routes/api/update/+server.ts
···
1
1
-
import { createCache } from '$lib/cache';
2
2
-
import { getCache, loadData } from '$lib/website/load';
3
3
-
import { env } from '$env/dynamic/private';
4
4
-
import { json } from '@sveltejs/kit';
5
5
-
import type { AppBskyActorDefs } from '@atcute/bluesky';
6
6
-
7
7
-
export async function GET({ platform }) {
8
8
-
const cache = createCache(platform);
9
9
-
if (!cache) return json('no cache');
10
10
-
11
11
-
const existingUsers = await cache.get('meta', 'updatedBlentos');
12
12
-
13
13
-
const existingUsersArray: AppBskyActorDefs.ProfileViewDetailed[] = existingUsers
14
14
-
? JSON.parse(existingUsers)
15
15
-
: [];
16
16
-
17
17
-
const existingUsersHandle = existingUsersArray.map((v) => v.handle);
18
18
-
19
19
-
for (const handle of existingUsersHandle) {
20
20
-
if (!handle) continue;
21
21
-
22
22
-
try {
23
23
-
const cached = await getCache(handle, 'self', cache);
24
24
-
if (!cached) await loadData(handle, cache, true, 'self', env);
25
25
-
} catch (error) {
26
26
-
console.error(error);
27
27
-
return json('error');
28
28
-
}
29
29
-
}
30
30
-
31
31
-
return json('ok');
32
32
-
}