@fdm-monster/server
Version:
FDM Monster is a bulk OctoPrint, Klipper, PrusaLink and BambuLab manager to set up, configure and monitor 3D printers. Our aim is to provide neat overview over your farm.
61 lines (60 loc) • 1.79 kB
JavaScript
import { NotFoundException } from "../../exceptions/runtime.exceptions.js";
import { RequestError } from "octokit";
//#region src/services/core/github.service.ts
var GithubService = class {
constructor(octokitService) {
this.octokitService = octokitService;
}
async wasAuthenticated() {
return (await this.octokitService.auth())?.type === "token";
}
async getRateLimit() {
return this.octokitService.rest.rateLimit.get();
}
async getLatestRelease(owner, repo) {
try {
return await this.octokitService.rest.repos.getLatestRelease({
owner,
repo
});
} catch (e) {
if (e instanceof RequestError && e.status === 404) throw new NotFoundException(`Could not find latest release`);
throw e;
}
}
async getReleases(owner, repo) {
try {
return await this.octokitService.rest.repos.listReleases({
owner,
repo
});
} catch (e) {
if (e instanceof RequestError && e.status === 404) throw new NotFoundException(`Could not find releases`);
throw e;
}
}
async getReleaseByTag(owner, repo, tag) {
return await this.octokitService.rest.repos.getReleaseByTag({
owner,
repo,
tag
}).catch((e) => {
if (e instanceof RequestError && e.status === 404) throw new NotFoundException(`Could not find release with tag ${tag}`);
throw e;
});
}
async requestAsset(owner, repo, assetId) {
return await this.octokitService.request("GET /repos/:owner/:repo/releases/assets/:asset_id", {
headers: { Accept: "application/octet-stream" },
owner,
repo,
asset_id: assetId
}).catch((e) => {
if (e instanceof RequestError && e.status === 404) throw new NotFoundException(`Could not find asset with id ${assetId}`);
throw e;
});
}
};
//#endregion
export { GithubService };
//# sourceMappingURL=github.service.js.map