#5 Started on creating page to handle API requests to https://git.luke-else.co.uk

This commit is contained in:
2025-02-06 10:55:26 +00:00
parent 8ab101727e
commit 712d7857db
7 changed files with 78 additions and 7 deletions

26
src/lib/api/git.ts Normal file
View File

@@ -0,0 +1,26 @@
import type { GitRepo } from "../types";
const API_BASE_URL = "https://git.luke-else.co.uk/api/v1";
// const ACCESS_TOKEN = import.meta.env.VITE_GITEA_TOKEN;
export async function fetchRepos(): Promise<GitRepo[]> {
try {
console.log("Fetching repos...");
const response = await fetch(`${API_BASE_URL}/repos/search`, {
headers: {
// "Authorization": `token ${ACCESS_TOKEN}`,
"Content-Type": "application/json"
}
});
if (!response.ok) {
throw new Error(`Error: ${response.statusText}`);
}
const data: { data: GitRepo[] } = await response.json();
return data.data; // Extract the list of repositories
} catch (error) {
console.error("Failed to fetch repos:", error);
return [];
}
}