mirror of
https://github.com/Snigdha-OS/package-browser.git
synced 2025-09-06 04:35:17 +02:00
feat: Refactor package parsing from text format to JSON
This commit is contained in:
@@ -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
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user