mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-28 00:56:31 +02:00
Fix crash creating Modrinth packs with multiple files from the same CF project (fixes #197)
This commit is contained in:
parent
aeae76a569
commit
abf701560d
@ -490,7 +490,8 @@ func (c cfDownloader) GetFilesMetadata(mods []*core.Mod) ([]core.MetaDownloaderD
|
|||||||
}
|
}
|
||||||
|
|
||||||
downloaderData := make([]core.MetaDownloaderData, len(mods))
|
downloaderData := make([]core.MetaDownloaderData, len(mods))
|
||||||
indexMap := make(map[uint32]int)
|
// Need array mapping project ID -> mod index, since there may be multiple files with the same project ID
|
||||||
|
indexMap := make(map[uint32][]int)
|
||||||
projectMetadata := make([]cfUpdateData, len(mods))
|
projectMetadata := make([]cfUpdateData, len(mods))
|
||||||
fileIDs := make([]uint32, len(mods))
|
fileIDs := make([]uint32, len(mods))
|
||||||
for i, v := range mods {
|
for i, v := range mods {
|
||||||
@ -499,7 +500,7 @@ func (c cfDownloader) GetFilesMetadata(mods []*core.Mod) ([]core.MetaDownloaderD
|
|||||||
return nil, fmt.Errorf("failed to read CurseForge update metadata from %s", v.Name)
|
return nil, fmt.Errorf("failed to read CurseForge update metadata from %s", v.Name)
|
||||||
}
|
}
|
||||||
project := updateData.(cfUpdateData)
|
project := updateData.(cfUpdateData)
|
||||||
indexMap[project.ProjectID] = i
|
indexMap[project.ProjectID] = append(indexMap[project.ProjectID], i)
|
||||||
projectMetadata[i] = project
|
projectMetadata[i] = project
|
||||||
fileIDs[i] = project.FileID
|
fileIDs[i] = project.FileID
|
||||||
}
|
}
|
||||||
@ -510,7 +511,7 @@ func (c cfDownloader) GetFilesMetadata(mods []*core.Mod) ([]core.MetaDownloaderD
|
|||||||
}
|
}
|
||||||
|
|
||||||
modIDsToLookup := make([]uint32, 0)
|
modIDsToLookup := make([]uint32, 0)
|
||||||
fileNames := make([]string, len(mods))
|
fileNames := make(map[uint32]string)
|
||||||
for _, file := range fileData {
|
for _, file := range fileData {
|
||||||
if _, ok := indexMap[file.ModID]; !ok {
|
if _, ok := indexMap[file.ModID]; !ok {
|
||||||
return nil, fmt.Errorf("unknown project ID in response: %v (file %v, name %v)", file.ModID, file.ID, file.FileName)
|
return nil, fmt.Errorf("unknown project ID in response: %v (file %v, name %v)", file.ModID, file.ID, file.FileName)
|
||||||
@ -518,10 +519,12 @@ func (c cfDownloader) GetFilesMetadata(mods []*core.Mod) ([]core.MetaDownloaderD
|
|||||||
// Opted-out mods don't provide their download URLs
|
// Opted-out mods don't provide their download URLs
|
||||||
if file.DownloadURL == "" {
|
if file.DownloadURL == "" {
|
||||||
modIDsToLookup = append(modIDsToLookup, file.ModID)
|
modIDsToLookup = append(modIDsToLookup, file.ModID)
|
||||||
fileNames[indexMap[file.ModID]] = file.FileName
|
fileNames[file.ModID] = file.FileName
|
||||||
} else {
|
} else {
|
||||||
downloaderData[indexMap[file.ModID]] = &cfDownloadMetadata{
|
for _, v := range indexMap[file.ModID] {
|
||||||
url: file.DownloadURL,
|
downloaderData[v] = &cfDownloadMetadata{
|
||||||
|
url: file.DownloadURL,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -535,15 +538,24 @@ func (c cfDownloader) GetFilesMetadata(mods []*core.Mod) ([]core.MetaDownloaderD
|
|||||||
if _, ok := indexMap[mod.ID]; !ok {
|
if _, ok := indexMap[mod.ID]; !ok {
|
||||||
return nil, fmt.Errorf("unknown project ID in response: %v (for %v)", mod.ID, mod.Name)
|
return nil, fmt.Errorf("unknown project ID in response: %v (for %v)", mod.ID, mod.Name)
|
||||||
}
|
}
|
||||||
downloaderData[indexMap[mod.ID]] = &cfDownloadMetadata{
|
for _, v := range indexMap[mod.ID] {
|
||||||
noDistribution: true, // Inverted so the default value is not this (probably doesn't matter)
|
downloaderData[v] = &cfDownloadMetadata{
|
||||||
name: mod.Name,
|
noDistribution: true, // Inverted so the default value is not this (probably doesn't matter)
|
||||||
websiteUrl: mod.Links.WebsiteURL + "/files/" + strconv.FormatUint(uint64(fileIDs[indexMap[mod.ID]]), 10),
|
name: mod.Name,
|
||||||
fileName: fileNames[indexMap[mod.ID]],
|
websiteUrl: mod.Links.WebsiteURL + "/files/" + strconv.FormatUint(uint64(fileIDs[v]), 10),
|
||||||
|
fileName: fileNames[mod.ID],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure all files got data
|
||||||
|
for i, v := range downloaderData {
|
||||||
|
if v == nil {
|
||||||
|
return nil, fmt.Errorf("did not get CurseForge metadata for %s", mods[i].Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return downloaderData, nil
|
return downloaderData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user