| 12 | const modrinthAPIBase = "https://api.modrinth.com/v2" |
| 13 | |
| 14 | func getSHA1Hash(filePath string) (string, error) { |
| 15 | f, err := os.Open(filePath) |
| 16 | if err != nil { |
| 17 | return "", fmt.Errorf("error opening file %s: %w", filePath, err) |
| 18 | } |
| 19 | defer f.Close() |
| 20 | |
| 21 | h := sha1.New() |
| 22 | if _, err := io.CopyBuffer(h, f, make([]byte, 65536)); err != nil { |
| 23 | return "", fmt.Errorf("error reading file %s: %w", filePath, err) |
| 24 | } |
| 25 | return fmt.Sprintf("%x", h.Sum(nil)), nil |
| 26 | } |
| 27 | |
| 28 | func getModInfo(sha1Hash string) (*ModrinthVersion, error) { |
| 29 | url := fmt.Sprintf("%s/version_file/%s", modrinthAPIBase, sha1Hash) |