mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
Re-encode URLs from CF and when exporting to MR for RFC3986 compliance
This commit is contained in:
parent
fa5de4b4bc
commit
36b6d806c8
14
core/urlutil.go
Normal file
14
core/urlutil.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ReencodeURL(u string) (string, error) {
|
||||||
|
parsed, err := url.Parse(u)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to parse url: %s, %v", u, err)
|
||||||
|
}
|
||||||
|
return parsed.String(), nil
|
||||||
|
}
|
@ -174,12 +174,17 @@ func createModFile(modInfo modInfo, fileInfo modFileInfo, index *core.Index) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u, err := core.ReencodeURL(fileInfo.DownloadURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
modMeta := core.Mod{
|
modMeta := core.Mod{
|
||||||
Name: modInfo.Name,
|
Name: modInfo.Name,
|
||||||
FileName: fileInfo.FileName,
|
FileName: fileInfo.FileName,
|
||||||
Side: core.UniversalSide,
|
Side: core.UniversalSide,
|
||||||
Download: core.ModDownload{
|
Download: core.ModDownload{
|
||||||
URL: fileInfo.DownloadURL,
|
URL: u,
|
||||||
// TODO: murmur2 hashing may be unstable in curse api, calculate the hash manually?
|
// TODO: murmur2 hashing may be unstable in curse api, calculate the hash manually?
|
||||||
// TODO: check if the hash is invalid (e.g. 0)
|
// TODO: check if the hash is invalid (e.g. 0)
|
||||||
HashFormat: "murmur2",
|
HashFormat: "murmur2",
|
||||||
@ -409,10 +414,15 @@ func (u cfUpdater) DoUpdate(mods []*core.Mod, cachedState []interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u, err := core.ReencodeURL(fileInfoData.DownloadURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
v.FileName = fileInfoData.FileName
|
v.FileName = fileInfoData.FileName
|
||||||
v.Name = modState.Name
|
v.Name = modState.Name
|
||||||
v.Download = core.ModDownload{
|
v.Download = core.ModDownload{
|
||||||
URL: fileInfoData.DownloadURL,
|
URL: u,
|
||||||
// TODO: murmur2 hashing may be unstable in curse api, calculate the hash manually?
|
// TODO: murmur2 hashing may be unstable in curse api, calculate the hash manually?
|
||||||
// TODO: check if the hash is invalid (e.g. 0)
|
// TODO: check if the hash is invalid (e.g. 0)
|
||||||
HashFormat: "murmur2",
|
HashFormat: "murmur2",
|
||||||
|
@ -135,6 +135,13 @@ var exportCmd = &cobra.Command{
|
|||||||
serverEnv = envInstalled
|
serverEnv = envInstalled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modrinth URLs must be RFC3986
|
||||||
|
u, err := core.ReencodeURL(mod.Download.URL)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error re-encoding mod URL: %s\n", err.Error())
|
||||||
|
u = mod.Download.URL
|
||||||
|
}
|
||||||
|
|
||||||
manifestFiles[i] = PackFile{
|
manifestFiles[i] = PackFile{
|
||||||
Path: path,
|
Path: path,
|
||||||
Hashes: hashes,
|
Hashes: hashes,
|
||||||
@ -142,7 +149,7 @@ var exportCmd = &cobra.Command{
|
|||||||
Client string `json:"client"`
|
Client string `json:"client"`
|
||||||
Server string `json:"server"`
|
Server string `json:"server"`
|
||||||
}{Client: clientEnv, Server: serverEnv},
|
}{Client: clientEnv, Server: serverEnv},
|
||||||
Downloads: []string{mod.Download.URL},
|
Downloads: []string{u},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user