chore: initiate the website file

This commit is contained in:
RiO
2024-12-27 06:16:26 +05:30
commit 2d9c1ea88f
30 changed files with 7255 additions and 0 deletions

36
src/services/api.ts Normal file
View File

@@ -0,0 +1,36 @@
import { Package } from '../types';
const MIRRORS = [
'https://raw.githubusercontent.com/d3v1l0n/snigdhaos-core/refs/heads/master/packages.txt',
'https://raw.githubusercontent.com/archlinux/svntogit-packages/master/packages.txt'
];
async function fetchFromMirror(url: string): Promise<Package[]> {
const response = await fetch(url);
const text = await response.text();
return text
.split('\n')
.filter(Boolean)
.map((line) => {
const [name, version, ...descParts] = line.split(' ');
return {
name,
version,
description: descParts.join(' '),
repository: 'core' as const,
};
});
}
export async function fetchPackages(): Promise<Package[]> {
for (const mirror of MIRRORS) {
try {
return await fetchFromMirror(mirror);
} catch (error) {
console.warn(`Failed to fetch from mirror ${mirror}:`, error);
continue;
}
}
throw new Error('All mirrors failed to respond');
}