feat: Refactor package parsing from text format to JSON

This commit is contained in:
CELESTIFYX Team
2025-01-14 11:14:26 +02:00
committed by GitHub
parent 0e824e3a04
commit 751a77ac42

View File

@@ -9,33 +9,27 @@ export const MIRRORS: Record<string, {
repository: Repository;
}> = {
'core': {
url: 'https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-core/refs/heads/master/packages.txt',
url: 'https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-core/refs/heads/master/packages.json',
repository: ('core' as Repository)
},
'extra': {
url: 'https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-extra/refs/heads/master/packages.txt',
url: 'https://raw.githubusercontent.com/Snigdha-OS/snigdhaos-extra/refs/heads/master/packages.json',
repository: ('extra' as Repository)
}
}
// Fetch data from a single mirror (Core or Extra repository)
// Fetch data from a single mirror
async function fetchFromMirror(url: string, repository: Repository): Promise<Package[]> {
const response = await fetch(url);
const text = await response.text();
// Parse the text file content and return a list of packages
return text.split('\n').filter(Boolean).map((line) => {
const [
name,
version,
...description
] = line.split(' ');
const data = await response.json();
// Parse the json file content and return a list of packages
return data.map((item: any) => {
return {
name,
version,
description: description.join(' '),
name: item.name,
version: item.version,
description: item.description,
repository
};
});