@@ -225,11 +225,36 @@ func ModUploadHandler(w http.ResponseWriter, r *http.Request) {
225
225
return
226
226
}
227
227
228
- err = mods .UploadMod (formFile , fileHeader )
229
- if err != nil {
230
- resp = fmt .Sprintf ("error saving file to mods: %s" , err )
228
+ // if the file is a zip file, we handle it as mod
229
+ // if the file is mod-settings.dat or mod-list.json, we just replace the
230
+ if filepath .Ext (fileHeader .Filename ) == ".zip" {
231
+ err = mods .UploadMod (formFile , fileHeader )
232
+ if err != nil {
233
+ resp = fmt .Sprintf ("error saving file to mods: %s" , err )
234
+ log .Println (resp )
235
+ w .WriteHeader (http .StatusInternalServerError )
236
+ return
237
+ }
238
+ } else if fileHeader .Filename == "mod-settings.dat" || fileHeader .Filename == "mod-list.json" {
239
+ modsDir := filepath .Join (bootstrap .GetConfig ().FactorioModsDir , fileHeader .Filename )
240
+ file , err := os .Create (modsDir )
241
+ if err != nil {
242
+ resp = fmt .Sprintf ("error creating %s: %s" , fileHeader .Filename , err )
243
+ log .Println (resp )
244
+ w .WriteHeader (http .StatusBadRequest )
245
+ return
246
+ }
247
+ _ , err = io .Copy (file , formFile )
248
+ if err != nil {
249
+ resp = fmt .Sprintf ("error saving %s: %s" , fileHeader .Filename , err )
250
+ log .Println (resp )
251
+ w .WriteHeader (http .StatusBadRequest )
252
+ return
253
+ }
254
+ } else {
255
+ resp = fmt .Sprintf ("The uploaded file wasn't a zip-file, a mod-settings. dat or a mod-info.json" )
231
256
log .Println (resp )
232
- w .WriteHeader (http .StatusInternalServerError )
257
+ w .WriteHeader (http .StatusBadRequest )
233
258
return
234
259
}
235
260
@@ -296,7 +321,7 @@ func ModDownloadHandler(w http.ResponseWriter, r *http.Request) {
296
321
writerHeader .Set ("Content-Disposition" , fmt .Sprintf ("attachment; filename=\" %s\" " , "all_installed_mods.zip" ))
297
322
}
298
323
299
- //LoadModsFromSaveHandler returns JSON response with the found mods
324
+ // LoadModsFromSaveHandler returns JSON response with the found mods
300
325
func LoadModsFromSaveHandler (w http.ResponseWriter , r * http.Request ) {
301
326
var err error
302
327
var resp interface {}
0 commit comments