From 1522bf30e10ca24d4da8deb2d6c11d6eb9d8573f Mon Sep 17 00:00:00 2001 From: Angel Pons <22937129+Th3Fanbus@users.noreply.github.com> Date: Tue, 5 Mar 2024 21:03:49 +0000 Subject: [PATCH 1/2] fix: urlencode filename for separate mod targets When a mod's name contains characters that should be urlencoded, any newly-uploaded versions cannot be download because of some errors regarding the URL being invalid. Make sure the returned key is urlencoded for consistency with the rest of the codebase. Signed-off-by: Angel Pons --- storage/storage.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/storage/storage.go b/storage/storage.go index 55d2c4b6..31aa2323 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -404,7 +404,8 @@ func SeparateModTarget(ctx context.Context, body []byte, modID, name, modVersion zipWriter.Close() - key := fmt.Sprintf("/mods/%s/%s.smod", modID, cleanName+"-"+target+"-"+modVersion) + filename := cleanName + "-" + target + "-" + modVersion + key := fmt.Sprintf("/mods/%s/%s.smod", modID, filename) _, err = storage.Put(ctx, key, bytes.NewReader(buf.Bytes())) if err != nil { @@ -415,7 +416,8 @@ func SeparateModTarget(ctx context.Context, body []byte, modID, name, modVersion hash := sha256.New() hash.Write(buf.Bytes()) - return true, key, hex.EncodeToString(hash.Sum(nil)), int64(buf.Len()) + encodedKey := fmt.Sprintf("/mods/%s/%s.smod", modID, EncodeName(filename)) + return true, encodedKey, hex.EncodeToString(hash.Sum(nil)), int64(buf.Len()) } func copyModFileToArchZip(file *zip.File, zipWriter *zip.Writer, newName string) error { From f323a9ffacb2cda31cd2e682bf920cdbd35d3908 Mon Sep 17 00:00:00 2001 From: Angel Pons <22937129+Th3Fanbus@users.noreply.github.com> Date: Wed, 6 Mar 2024 07:41:08 +0000 Subject: [PATCH 2/2] fix: urlencode version in `RenameFilename` As per Mircea's comment on [#44 (comment)](https://github.com/satisfactorymodding/smr-api/pull/44#issuecomment-1902611988): I've also now noticed that RenameVersion is also not correctly escaping the filename, it's only escaping the mod's name, and not the version, which is what causes mods that use build metadata in the version (+build.1234) to fail, so that one should need a similar fix of encoding the filename. Signed-off-by: Angel Pons --- storage/storage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/storage.go b/storage/storage.go index 31aa2323..9c2ec55c 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -276,7 +276,7 @@ func RenameVersion(ctx context.Context, modID string, name string, versionID str return false, "" } - return true, fmt.Sprintf("/mods/%s/%s.smod", modID, EncodeName(cleanName)+"-"+version) + return true, fmt.Sprintf("/mods/%s/%s.smod", modID, EncodeName(cleanName+"-"+version)) } func DeleteMod(ctx context.Context, modID string, name string, versionID string) bool {