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; repository: Repository;
}> = { }> = {
'core': { '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) repository: ('core' as Repository)
}, },
'extra': { '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) 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[]> { async function fetchFromMirror(url: string, repository: Repository): Promise<Package[]> {
const response = await fetch(url); const response = await fetch(url);
const text = await response.text(); const data = await response.json();
// 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(' ');
// Parse the json file content and return a list of packages
return data.map((item: any) => {
return { return {
name, name: item.name,
version, version: item.version,
description: description.join(' '), description: item.description,
repository repository
}; };
}); });