typerinth
Version:
A TypeScript library for interacting with the Modrinth API.
38 lines (37 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Route_1 = require("../Route");
const errors_1 = require("../../errors");
class GetVersionFromFileHashRoute extends Route_1.Route {
fileHash;
options;
constructor(baseUrl, ua, cacheManager, fileHash, options = {}) {
super(baseUrl, ua, cacheManager);
this.fileHash = fileHash;
this.options = options;
}
getCacheKey() {
return `version_from_hash:${this.fileHash}`;
}
getUrl() {
const url = Route_1.Route.addPathSegment(this.baseUrl, `/version_file/${this.fileHash}`);
if (this.options.algorithm)
url.searchParams.append('algorithm', this.options.algorithm);
if (!!this.options.multiple)
url.searchParams.append('multiple', this.options.multiple.toString());
return url;
}
parseData(data) {
if (data === null)
throw new errors_1.VersionNotFoundError('Version not found');
if (!data)
throw new errors_1.UnexpectedApiError('Unexpected empty response');
if (data.error) {
if (data.error === 'not_found')
throw new errors_1.VersionNotFoundError('Version not found');
throw new errors_1.ApiError(data.error, data.description);
}
return data;
}
}
exports.default = GetVersionFromFileHashRoute;