Helps with eventually adding other pages Also makes it clear it's the backend that decides what data to send to the frontend
75 linhas
2,5 KiB
TypeScript
75 linhas
2,5 KiB
TypeScript
import { headers, parseJson, type Handler } from "../..";
|
|
|
|
export type Info = {
|
|
username: string
|
|
event: {
|
|
name: string
|
|
division: string
|
|
}
|
|
entry: {
|
|
name: string
|
|
description: string
|
|
url: string
|
|
}
|
|
results: {
|
|
overall: {rating: string | null, ranking: number | null}
|
|
graphics: {rating: string | null, ranking: number | null}
|
|
audio: {rating: string | null, ranking: number | null}
|
|
gameplay: {rating: string | null, ranking: number | null}
|
|
originality: {rating: string | null, ranking: number | null}
|
|
theme: {rating: string | null, ranking: number | null}
|
|
}
|
|
} | undefined;
|
|
|
|
const username = "Taevas";
|
|
|
|
export const alakajam: Handler = async () => {
|
|
/** https://alakajam.com/api */
|
|
const response = await parseJson(await fetch(`https://alakajam.com/api/user/${username}/latestEntry`, {headers})) as {
|
|
name: string
|
|
latest_entry: {
|
|
event_name: string
|
|
division: string
|
|
title: string
|
|
description: string
|
|
url: string
|
|
results: {
|
|
rating_1: string | null
|
|
rating_2: string | null
|
|
rating_3: string | null
|
|
rating_4: string | null
|
|
rating_5: string | null
|
|
rating_6: string | null
|
|
ranking_1: number | null
|
|
ranking_2: number | null
|
|
ranking_3: number | null
|
|
ranking_4: number | null
|
|
ranking_5: number | null
|
|
ranking_6: number | null
|
|
}
|
|
}
|
|
};
|
|
|
|
const activity: Info = {
|
|
username: response.name,
|
|
event: {
|
|
name: response.latest_entry.event_name,
|
|
division: response.latest_entry.division
|
|
},
|
|
entry: {
|
|
name: response.latest_entry.title,
|
|
description: response.latest_entry.description,
|
|
url: response.latest_entry.url
|
|
},
|
|
results: {
|
|
overall: {rating: response.latest_entry.results.rating_1, ranking: response.latest_entry.results.ranking_1},
|
|
graphics: {rating: response.latest_entry.results.rating_2, ranking: response.latest_entry.results.ranking_2},
|
|
audio: {rating: response.latest_entry.results.rating_3, ranking: response.latest_entry.results.ranking_3},
|
|
gameplay: {rating: response.latest_entry.results.rating_4, ranking: response.latest_entry.results.ranking_4},
|
|
originality: {rating: response.latest_entry.results.rating_5, ranking: response.latest_entry.results.ranking_5},
|
|
theme: {rating: response.latest_entry.results.rating_6, ranking: response.latest_entry.results.ranking_6},
|
|
}
|
|
};
|
|
|
|
return Response.json(activity, {status: 200});
|
|
};
|