| 26 | } |
| 27 | |
| 28 | func getModInfo(sha1Hash string) (*ModrinthVersion, error) { |
| 29 | url := fmt.Sprintf("%s/version_file/%s", modrinthAPIBase, sha1Hash) |
| 30 | resp, err := http.Get(url) |
| 31 | if err != nil { |
| 32 | return nil, fmt.Errorf("error fetching mod info for hash %s: %w", sha1Hash, err) |
| 33 | } |
| 34 | defer resp.Body.Close() |
| 35 | |
| 36 | if resp.StatusCode != http.StatusOK { |
| 37 | return nil, fmt.Errorf("API returned status %d for hash %s", resp.StatusCode, sha1Hash) |
| 38 | } |
| 39 | |
| 40 | var info ModrinthVersion |
| 41 | if err := json.NewDecoder(resp.Body).Decode(&info); err != nil { |
| 42 | return nil, fmt.Errorf("error decoding response for hash %s: %w", sha1Hash, err) |
| 43 | } |
| 44 | return &info, nil |
| 45 | } |
| 46 | |
| 47 | func getProjectVersions(projectID string) ([]ModrinthVersion, error) { |
| 48 | url := fmt.Sprintf("%s/project/%s/version", modrinthAPIBase, projectID) |