mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
Check if download URL is null instead of allowModDistribution; fixes issue with null values for latter
This commit is contained in:
parent
bf2f060efc
commit
e71b63ea98
@ -459,7 +459,7 @@ func (c cfDownloader) GetFilesMetadata(mods []*core.Mod) ([]core.MetaDownloaderD
|
|||||||
downloaderData := make([]core.MetaDownloaderData, len(mods))
|
downloaderData := make([]core.MetaDownloaderData, len(mods))
|
||||||
indexMap := make(map[int]int)
|
indexMap := make(map[int]int)
|
||||||
projectMetadata := make([]cfUpdateData, len(mods))
|
projectMetadata := make([]cfUpdateData, len(mods))
|
||||||
modIDs := make([]int, len(mods))
|
fileIDs := make([]int, len(mods))
|
||||||
for i, v := range mods {
|
for i, v := range mods {
|
||||||
updateData, ok := v.GetParsedUpdateData("curseforge")
|
updateData, ok := v.GetParsedUpdateData("curseforge")
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -468,68 +468,47 @@ func (c cfDownloader) GetFilesMetadata(mods []*core.Mod) ([]core.MetaDownloaderD
|
|||||||
project := updateData.(cfUpdateData)
|
project := updateData.(cfUpdateData)
|
||||||
indexMap[project.ProjectID] = i
|
indexMap[project.ProjectID] = i
|
||||||
projectMetadata[i] = project
|
projectMetadata[i] = project
|
||||||
modIDs[i] = project.ProjectID
|
fileIDs[i] = project.FileID
|
||||||
}
|
}
|
||||||
|
|
||||||
modData, err := cfDefaultClient.getModInfoMultiple(modIDs)
|
fileData, err := cfDefaultClient.getFileInfoMultiple(fileIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get CurseForge mod metadata: %w", err)
|
return nil, fmt.Errorf("failed to get CurseForge file metadata: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFileInfo := func(modID int, fileInfo modFileInfo) {
|
modIDsToLookup := make([]int, 0)
|
||||||
// If metadata already exists (i.e. opted-out) update it with more metadata
|
fileNames := make([]string, len(mods))
|
||||||
if meta, ok := downloaderData[indexMap[modID]].(*cfDownloadMetadata); ok {
|
for _, file := range fileData {
|
||||||
if meta.noDistribution {
|
if _, ok := indexMap[file.ModID]; !ok {
|
||||||
meta.websiteUrl = meta.websiteUrl + "/files/" + strconv.Itoa(fileInfo.ID)
|
return nil, fmt.Errorf("unknown project ID in response: %v (file %v, name %v)", file.ModID, file.ID, file.FileName)
|
||||||
meta.fileName = fileInfo.FileName
|
}
|
||||||
}
|
// Opted-out mods don't provide their download URLs
|
||||||
|
if file.DownloadURL == "" {
|
||||||
|
modIDsToLookup = append(modIDsToLookup, file.ModID)
|
||||||
|
fileNames[indexMap[file.ModID]] = file.FileName
|
||||||
} else {
|
} else {
|
||||||
downloaderData[indexMap[modID]] = &cfDownloadMetadata{
|
downloaderData[indexMap[file.ModID]] = &cfDownloadMetadata{
|
||||||
url: fileInfo.DownloadURL,
|
url: file.DownloadURL,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileIDsToLookup := make([]int, 0)
|
if len(modIDsToLookup) > 0 {
|
||||||
for _, mod := range modData {
|
modData, err := cfDefaultClient.getModInfoMultiple(modIDsToLookup)
|
||||||
if _, ok := indexMap[mod.ID]; !ok {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unknown mod ID in response: %v (for %v)", mod.ID, mod.Name)
|
return nil, fmt.Errorf("failed to get CurseForge project metadata: %w", err)
|
||||||
}
|
}
|
||||||
if !mod.AllowModDistribution {
|
for _, mod := range modData {
|
||||||
|
if _, ok := indexMap[mod.ID]; !ok {
|
||||||
|
return nil, fmt.Errorf("unknown project ID in response: %v (for %v)", mod.ID, mod.Name)
|
||||||
|
}
|
||||||
downloaderData[indexMap[mod.ID]] = &cfDownloadMetadata{
|
downloaderData[indexMap[mod.ID]] = &cfDownloadMetadata{
|
||||||
noDistribution: true, // Inverted so the default value is not this (probably doesn't matter)
|
noDistribution: true, // Inverted so the default value is not this (probably doesn't matter)
|
||||||
name: mod.Name,
|
name: mod.Name,
|
||||||
websiteUrl: mod.Links.WebsiteURL,
|
websiteUrl: mod.Links.WebsiteURL + "/files/" + strconv.Itoa(fileIDs[indexMap[mod.ID]]),
|
||||||
|
fileName: fileNames[indexMap[mod.ID]],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileID := projectMetadata[indexMap[mod.ID]].FileID
|
|
||||||
fileInfoFound := false
|
|
||||||
// First look in latest files
|
|
||||||
for _, fileInfo := range mod.LatestFiles {
|
|
||||||
if fileInfo.ID == fileID {
|
|
||||||
fileInfoFound = true
|
|
||||||
handleFileInfo(mod.ID, fileInfo)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !fileInfoFound {
|
|
||||||
fileIDsToLookup = append(fileIDsToLookup, fileID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(fileIDsToLookup) > 0 {
|
|
||||||
fileData, err := cfDefaultClient.getFileInfoMultiple(fileIDsToLookup)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get CurseForge file metadata: %w", err)
|
|
||||||
}
|
|
||||||
for _, fileInfo := range fileData {
|
|
||||||
if _, ok := indexMap[fileInfo.ModID]; !ok {
|
|
||||||
return nil, fmt.Errorf("unknown mod ID in response: %v from file %v (for %v)", fileInfo.ModID, fileInfo.ID, fileInfo.FileName)
|
|
||||||
}
|
|
||||||
handleFileInfo(fileInfo.ModID, fileInfo)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return downloaderData, nil
|
return downloaderData, nil
|
||||||
|
@ -145,9 +145,8 @@ type modInfo struct {
|
|||||||
FileType int `json:"releaseType"`
|
FileType int `json:"releaseType"`
|
||||||
Modloader int `json:"modLoader"`
|
Modloader int `json:"modLoader"`
|
||||||
} `json:"latestFilesIndexes"`
|
} `json:"latestFilesIndexes"`
|
||||||
ModLoaders []string `json:"modLoaders"`
|
ModLoaders []string `json:"modLoaders"`
|
||||||
AllowModDistribution bool `json:"allowModDistribution"`
|
Links struct {
|
||||||
Links struct {
|
|
||||||
WebsiteURL string `json:"websiteUrl"`
|
WebsiteURL string `json:"websiteUrl"`
|
||||||
} `json:"links"`
|
} `json:"links"`
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user