Skip to content

Commit 91ed3c1

Browse files
mja00ci010
authored andcommitted
feat: add get project version by hash method
1 parent e8e2887 commit 91ed3c1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/modrinth/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,28 @@ export class ModrinthV2Client {
320320
return versions
321321
}
322322

323+
/**
324+
* @see https://docs.modrinth.com/api/operations/versionfromhash/
325+
*/
326+
async getProjectVersionByHash(hash: string, { algorithm = 'sha1', multiple = false }: { algorithm?: string; multiple?: boolean } = {}, signal?: AbortSignal) {
327+
const url = new URL(this.baseUrl + '/v2/version_file/' + hash)
328+
url.searchParams.append('algorithm', algorithm)
329+
url.searchParams.append('multiple', multiple ? 'true' : 'false')
330+
const response = await this.fetch(url, {
331+
method: 'GET',
332+
headers: {
333+
...this.headers,
334+
'content-type': 'application/json',
335+
},
336+
signal,
337+
})
338+
if (response.status !== 200) {
339+
throw new ModerinthApiError(url.toString(), response.status, await response.text())
340+
}
341+
const versions = await response.json() as ProjectVersion
342+
return versions
343+
}
344+
323345
/**
324346
* @see https://docs.modrinth.com/api-spec#tag/version-files/operation/getLatestVersionsFromHashes
325347
*/

0 commit comments

Comments
 (0)