mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 21:16:30 +02:00
Switch to Curse API, as auth is not needed anymore
This commit is contained in:
parent
b43849ccdd
commit
c19a4b1e60
@ -154,7 +154,7 @@ func cmdInstall(flags core.Flags, mod string, modArgsTail []string) error {
|
|||||||
if !done {
|
if !done {
|
||||||
modArgs := append([]string{mod}, modArgsTail...)
|
modArgs := append([]string{mod}, modArgsTail...)
|
||||||
searchTerm := strings.Join(modArgs, " ")
|
searchTerm := strings.Join(modArgs, " ")
|
||||||
// TODO: CurseMeta search
|
// TODO: Curse search
|
||||||
// TODO: how to do interactive choices? automatically assume version? ask mod from list? choose first?
|
// TODO: how to do interactive choices? automatically assume version? ask mod from list? choose first?
|
||||||
fmt.Println(searchTerm)
|
fmt.Println(searchTerm)
|
||||||
}
|
}
|
||||||
|
@ -88,13 +88,6 @@ func modIDFromSlug(slug string) (int, error) {
|
|||||||
return response.Data.Addons[0].ID, nil
|
return response.Data.Addons[0].ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// curseMetaError is an error returned by the Staging CurseMeta API
|
|
||||||
type curseMetaError struct {
|
|
||||||
Description string `json:"description"`
|
|
||||||
Error bool `json:"error"`
|
|
||||||
Status int `json:"status"`
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
fileTypeRelease int = iota + 1
|
fileTypeRelease int = iota + 1
|
||||||
fileTypeBeta
|
fileTypeBeta
|
||||||
@ -106,7 +99,7 @@ const (
|
|||||||
dependencyTypeOptional
|
dependencyTypeOptional
|
||||||
)
|
)
|
||||||
|
|
||||||
// modInfo is a subset of the deserialised JSON response from the Staging CurseMeta API for mods (addons)
|
// modInfo is a subset of the deserialised JSON response from the Curse API for mods (addons)
|
||||||
type modInfo struct {
|
type modInfo struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
@ -123,16 +116,12 @@ type modInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getModInfo(modID int) (modInfo, error) {
|
func getModInfo(modID int) (modInfo, error) {
|
||||||
// Uses the Staging CurseMeta api
|
var infoRes modInfo
|
||||||
var response struct {
|
|
||||||
modInfo
|
|
||||||
curseMetaError
|
|
||||||
}
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
||||||
idStr := strconv.Itoa(modID)
|
idStr := strconv.Itoa(modID)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "https://staging_cursemeta.dries007.net/api/v3/direct/addon/"+idStr, nil)
|
req, err := http.NewRequest("GET", "https://addons-ecs.forgesvc.net/api/v2/addon/"+idStr, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return modInfo{}, err
|
return modInfo{}, err
|
||||||
}
|
}
|
||||||
@ -146,20 +135,16 @@ func getModInfo(modID int) (modInfo, error) {
|
|||||||
return modInfo{}, err
|
return modInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.NewDecoder(resp.Body).Decode(&response)
|
err = json.NewDecoder(resp.Body).Decode(&infoRes)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return modInfo{}, err
|
return modInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.Error {
|
if infoRes.ID != modID {
|
||||||
return modInfo{}, fmt.Errorf("Error requesting mod metadata: %s", response.Description)
|
return modInfo{}, fmt.Errorf("Unexpected addon ID in CurseForge response: %d/%d", modID, infoRes.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.ID != modID {
|
return infoRes, nil
|
||||||
return modInfo{}, fmt.Errorf("Unexpected addon ID in CurseForge response: %d/%d", modID, response.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.modInfo, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const cfDateFormatString = "2006-01-02T15:04:05.999"
|
const cfDateFormatString = "2006-01-02T15:04:05.999"
|
||||||
@ -179,7 +164,7 @@ func (f *cfDateFormat) UnmarshalJSON(input []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// modFileInfo is a subset of the deserialised JSON response from the Staging CurseMeta API for mod files
|
// modFileInfo is a subset of the deserialised JSON response from the Curse API for mod files
|
||||||
type modFileInfo struct {
|
type modFileInfo struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
FileName string `json:"fileNameOnDisk"`
|
FileName string `json:"fileNameOnDisk"`
|
||||||
@ -198,17 +183,13 @@ type modFileInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getFileInfo(modID int, fileID int) (modFileInfo, error) {
|
func getFileInfo(modID int, fileID int) (modFileInfo, error) {
|
||||||
// Uses the Staging CurseMeta api
|
var infoRes modFileInfo
|
||||||
var response struct {
|
|
||||||
modFileInfo
|
|
||||||
curseMetaError
|
|
||||||
}
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
||||||
modIDStr := strconv.Itoa(modID)
|
modIDStr := strconv.Itoa(modID)
|
||||||
fileIDStr := strconv.Itoa(fileID)
|
fileIDStr := strconv.Itoa(fileID)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "https://staging_cursemeta.dries007.net/api/v3/direct/addon/"+modIDStr+"/file/"+fileIDStr, nil)
|
req, err := http.NewRequest("GET", "https://addons-ecs.forgesvc.net/api/v2/addon/"+modIDStr+"/file/"+fileIDStr, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return modFileInfo{}, err
|
return modFileInfo{}, err
|
||||||
}
|
}
|
||||||
@ -222,19 +203,15 @@ func getFileInfo(modID int, fileID int) (modFileInfo, error) {
|
|||||||
return modFileInfo{}, err
|
return modFileInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.NewDecoder(resp.Body).Decode(&response)
|
err = json.NewDecoder(resp.Body).Decode(&infoRes)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return modFileInfo{}, err
|
return modFileInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.Error {
|
if infoRes.ID != fileID {
|
||||||
return modFileInfo{}, fmt.Errorf("Error requesting mod file metadata: %s", response.Description)
|
return modFileInfo{}, fmt.Errorf("Unexpected file ID in CurseForge response: %d/%d", modID, infoRes.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.ID != fileID {
|
return infoRes, nil
|
||||||
return modFileInfo{}, fmt.Errorf("Unexpected file ID in CurseForge response: %d/%d", modID, response.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.modFileInfo, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user