Skip to content

Commit e9dc110

Browse files
committed
Fixed version parsing and comparison on ModPortalInstallMultipleHandler
The string parsing was incorrect with the updated Version schema. Updated to use the new Version type and comparisons.
1 parent a46f69f commit e9dc110

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/mods_handler.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type ModPortalStruct struct {
2828
} `json:"info_json"`
2929
ReleasedAt time.Time `json:"released_at"`
3030
Sha1 string `json:"sha1"`
31-
Version string `json:"version"`
31+
Version Version `json:"version"`
3232
} `json:"releases"`
3333
Summary string `json:"summary"`
3434
Title string `json:"title"`
@@ -256,8 +256,8 @@ func ModPortalInstallMultipleHandler(w http.ResponseWriter, r *http.Request) {
256256
w.Header().Set("Content-Type", "application/json;charset=UTF-8")
257257
r.ParseForm()
258258

259-
modsList := make([]string, 0)
260-
versionsList := make([]string, 0)
259+
var modsList []string
260+
var versionsList []Version
261261

262262
//Parse incoming data
263263
for key, values := range r.PostForm {
@@ -266,7 +266,15 @@ func ModPortalInstallMultipleHandler(w http.ResponseWriter, r *http.Request) {
266266
modsList = append(modsList, v)
267267
}
268268
} else if key == "mod_version" {
269-
for _, v := range values {
269+
for _, value := range values {
270+
var v Version
271+
if err := v.UnmarshalText([]byte(value)); err != nil {
272+
w.WriteHeader(http.StatusInternalServerError)
273+
resp.Data = fmt.Sprintf("Error in searchModPortal: %s", err)
274+
if err := json.NewEncoder(w).Encode(resp); err != nil {
275+
log.Printf("Error in searchModPortal: %s", err)
276+
}
277+
}
270278
versionsList = append(versionsList, v)
271279
}
272280
}
@@ -316,7 +324,7 @@ func ModPortalInstallMultipleHandler(w http.ResponseWriter, r *http.Request) {
316324

317325
//find correct mod-version
318326
for _, release := range modDetailsStruct.Releases {
319-
if release.Version == versionsList[modIndex] {
327+
if release.Version.Equals(versionsList[modIndex]) {
320328
mods.downloadMod(release.DownloadURL, release.FileName, modDetailsStruct.Name)
321329
break
322330
}

0 commit comments

Comments
 (0)