aboutsummaryrefslogtreecommitdiff
path: root/internal/sources/sources.go
blob: d99ff5e95fb5af6c95af01bf387e9966b5725a75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2026 Arslaan Pathan
// This software is licensed under the ARPL. See LICENSE for details.

package sources

import (
	"fmt"
	"encoding/json"
	"net/http"
	"io"
)

type PackageListing struct {
	// no need for a Name field, that's handled by kiirotoml, and the structure for a Kiiro source would be a "listing.json" file inside of a folder with the package name, we all goods
	Repository string `json:"repo"`
	KiirofileOverride *string `json:"kiirofile_override"`
	KiirotomlOverride *string `json:"kiirotoml_override"`
}

func FetchPackageListing(url string) (*PackageListing, error) {
	fmt.Println("Fetching package listing...")

	res, err := http.Get(url)
	if err != nil {
		return nil, err
	}

	body, err := io.ReadAll(res.Body)
	res.Body.Close()

	if res.StatusCode > 299 {
		return nil, err
	}
	if err != nil {
		return nil, err
	}

	packageListing, err := ParsePackageListing(body)
	if err != nil {
		return nil, err
	}
	fmt.Println("Fetched package listing!")
	return packageListing, nil
}

func ParsePackageListing(pkgListingJSON []byte) (*PackageListing, error) {
	var packageListing PackageListing
	err := json.Unmarshal(pkgListingJSON, &packageListing)
	if err != nil {
		return nil, err
	}
	return &packageListing, nil
}