refactor!: setup file proxy for projects

This commit is contained in:
2026-01-20 19:10:01 -08:00
parent 5eccfe32da
commit a2afc3fa05
17 changed files with 279 additions and 103 deletions

View File

@@ -0,0 +1,28 @@
import type { Project, RepoDefinition } from "$lib/types/project";
export async function resolveProjectData(repo: RepoDefinition): Promise<Project> {
const { id, full_name: fullName } = repo;
let full_name_p = fullName.split("/")
const name = full_name_p[1] ?? fullName;
let description;
const repoResponse = await fetch(`https://api.github.com/repos/${fullName}`);
if (repoResponse.ok) {
const repoData = await repoResponse.json();
description = repoData.description ?? `by ${full_name_p[0]}`;
}
let thumbnail = `https://raw.githubusercontent.com/${fullName}/HEAD/thumbnail.webp`
const thumbResponse = await fetch(thumbnail, { method: 'HEAD' });
if (!thumbResponse.ok) {
thumbnail = `https://picsum.photos/seed/${encodeURIComponent(fullName.replaceAll("/", "-"))}/400/225`;
}
return {
id,
full_name: fullName,
name,
thumbnail,
description
}
}