From 751a77ac42ef8b38e59298c2a01a55e50e235eaa Mon Sep 17 00:00:00 2001 From: CELESTIFYX Team <96723939+XlebyllleK@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:14:26 +0200 Subject: [PATCH] feat: Refactor package parsing from text format to JSON --- src/services/api.ts | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/services/api.ts b/src/services/api.ts index 26dea7a..52314b0 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -9,33 +9,27 @@ export const MIRRORS: Record = { '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 { 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 }; });