Fix out of date dependencies being downloaded (fixes #1)

This commit is contained in:
Kallum Jones 2022-08-14 13:58:25 +01:00
parent 066a63f913
commit 90b5ac79bc
No known key found for this signature in database
GPG Key ID: D7F4589C4D7F81A9
1 changed files with 4 additions and 24 deletions

View File

@ -144,7 +144,8 @@ export default class ModrinthSource implements ModSource {
if (projectId != undefined) {
return this.getLatestVersion(projectId, mcVersion)
} else if (versionId != undefined) {
return this.getVersionFromVersionId(versionId, projectId, mcVersion)
const projectId = await this.getProjectFromVersionId(versionId);
return this.getLatestVersion(projectId, mcVersion);
} else {
throw new Error("Dependency found with no project or version id")
}
@ -186,32 +187,11 @@ export default class ModrinthSource implements ModSource {
* ]
* }
* @param versionId the version id to transform into an object
* @param projectId the project id of this version
* @param mcVersion the Minecraft version we are downloading for
* @return the Version object
*/
async getVersionFromVersionId(versionId: string, projectId: string | undefined, mcVersion: string): Promise<Version> {
async getProjectFromVersionId(versionId: string): Promise<string> {
const response = await axios.get(format(ModrinthSource.SINGLE_VERSION_URL, versionId));
const latestVersion = await response.data;
const latestFile = latestVersion.files[0];
const dependencies = [];
if (!Util.isArrayEmpty(latestVersion.dependencies)) {
for (let dependency of latestVersion.dependencies) {
dependencies.push(await this.getDependency(projectId, dependency.version_id, mcVersion))
}
}
const checksum = latestFile.hashes.sha1;
return {
modId: latestVersion.project_id,
versionNumber: latestVersion.version_number,
fileName: latestFile.filename,
url: latestFile.url,
dependencies: dependencies,
checksum: checksum
};
return latestVersion.project_id;
}
}