data endpoint for entity 90008 (aka. a website)
0
fork

Configure Feed

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

add activity endpoint

dawn 755eaebf b015e000

+37 -5
+23 -5
src/lib/activity.ts
··· 1 1 import { get, writable } from 'svelte/store'; 2 2 import { parseFeed } from '@rowanmanning/feed-parser'; 3 3 4 + export const ACTIVITY_PREVIEW_LIMIT = 7; 5 + 4 6 const lastCommits = writable<Activity[]>([]); 5 7 6 8 export const updateCommits = async () => { ··· 8 10 const githubFeed = await parseFeedToActivity('https://github.com/90-008.atom'); 9 11 const codebergFeed = await parseFeedToActivity('https://codeberg.org/90-008.atom'); 10 12 const tangledFeed = await fetchTangledActivity(); 11 - const mergedFeed = sortActivities(githubFeed.concat(codebergFeed).concat(tangledFeed)).slice( 12 - 0, 13 - 7 14 - ); 13 + const mergedFeed = sortActivities(githubFeed.concat(codebergFeed).concat(tangledFeed)); 15 14 lastCommits.set(mergedFeed); 16 15 } catch (why) { 17 16 console.log('could not fetch git activity: ', why); ··· 19 18 }; 20 19 21 20 export const getLastActivity = () => { 21 + return get(lastCommits).slice(0, ACTIVITY_PREVIEW_LIMIT); 22 + }; 23 + 24 + export const getCurrentActivity = () => { 22 25 return get(lastCommits); 23 26 }; 24 27 25 - type Activity = { 28 + export const activityToJson = (activity: Activity): ActivityJson => { 29 + return { 30 + ...activity, 31 + date: activity.date?.toISOString() ?? null 32 + }; 33 + }; 34 + 35 + export const currentActivityToJson = (activities: Activity[]) => { 36 + return activities.map(activityToJson); 37 + }; 38 + 39 + export type Activity = { 26 40 source: string; 27 41 description: string; 28 42 link: string | null; 29 43 date: Date | null; 30 44 id?: string; 45 + }; 46 + 47 + export type ActivityJson = Omit<Activity, 'date'> & { 48 + date: string | null; 31 49 }; 32 50 33 51 const toHex = (bytes: number[]): string => {
+14
src/routes/_api/activity/+server.ts
··· 1 + import { currentActivityToJson, getCurrentActivity } from '$lib/activity'; 2 + import { json } from '@sveltejs/kit'; 3 + 4 + export const GET = async ({ url }) => { 5 + const limitParam = url.searchParams.get('limit'); 6 + const limit = limitParam === null ? null : Number.parseInt(limitParam, 10); 7 + const activity = getCurrentActivity(); 8 + const selectedActivity = 9 + limit === null || Number.isNaN(limit) ? activity : activity.slice(0, Math.max(limit, 0)); 10 + 11 + return json({ 12 + activity: currentActivityToJson(selectedActivity) 13 + }); 14 + };