move providers into their own module
This commit is contained in:
parent
a356c1c0be
commit
4607520e97
2 changed files with 75 additions and 69 deletions
|
@ -1,7 +1,12 @@
|
||||||
import * as toml from "toml";
|
import * as toml from "toml";
|
||||||
import Resource from "./resource";
|
import Resource from "./resource";
|
||||||
|
import {
|
||||||
// const CURSE_CLIENT = new CurseForgeClient();
|
Provider,
|
||||||
|
ModrinthProvider,
|
||||||
|
CurseForgeProvider,
|
||||||
|
UrlProvider,
|
||||||
|
GitHubProvider,
|
||||||
|
} from "./provider";
|
||||||
|
|
||||||
export interface Metafile {
|
export interface Metafile {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -10,73 +15,6 @@ export interface Metafile {
|
||||||
provider: Provider;
|
provider: Provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class Provider {
|
|
||||||
constructor(
|
|
||||||
public hash: string,
|
|
||||||
public hashFormat: string,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
abstract get downloadUrl(): Resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class UrlProvider extends Provider {
|
|
||||||
constructor(
|
|
||||||
public hash: string,
|
|
||||||
public hashFormat: string,
|
|
||||||
private url: string,
|
|
||||||
) {
|
|
||||||
super(hash, hashFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
get downloadUrl(): Resource {
|
|
||||||
return new Resource(this.url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ModrinthProvider extends UrlProvider {
|
|
||||||
constructor(
|
|
||||||
hash: string,
|
|
||||||
hashFormat: string,
|
|
||||||
url: string,
|
|
||||||
public modId: string,
|
|
||||||
public versionId: string,
|
|
||||||
) {
|
|
||||||
super(hash, hashFormat, url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class GitHubProvider extends UrlProvider {
|
|
||||||
constructor(
|
|
||||||
hash: string,
|
|
||||||
hashFormat: string,
|
|
||||||
url: string,
|
|
||||||
public branch: string,
|
|
||||||
public regex: string,
|
|
||||||
public slug: string,
|
|
||||||
public tag: string,
|
|
||||||
) {
|
|
||||||
super(hash, hashFormat, url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CurseForgeProvider extends Provider {
|
|
||||||
constructor(
|
|
||||||
hash: string,
|
|
||||||
hashFormat: string,
|
|
||||||
public mode: string,
|
|
||||||
public fileId: number,
|
|
||||||
public projectId: number,
|
|
||||||
) {
|
|
||||||
super(hash, hashFormat);
|
|
||||||
}
|
|
||||||
|
|
||||||
get downloadUrl(): Resource {
|
|
||||||
return new Resource(
|
|
||||||
`https://www.curseforge.com/api/v1/mods/${this.projectId}/files/${this.fileId}/download`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a file entry in the Packwiz index.
|
* Represents a file entry in the Packwiz index.
|
||||||
*/
|
*/
|
||||||
|
|
68
src/provider.ts
Normal file
68
src/provider.ts
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
import Resource from "./resource";
|
||||||
|
|
||||||
|
export abstract class Provider {
|
||||||
|
constructor(
|
||||||
|
public hash: string,
|
||||||
|
public hashFormat: string,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
abstract get downloadUrl(): Resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class UrlProvider extends Provider {
|
||||||
|
constructor(
|
||||||
|
public hash: string,
|
||||||
|
public hashFormat: string,
|
||||||
|
private url: string,
|
||||||
|
) {
|
||||||
|
super(hash, hashFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
get downloadUrl(): Resource {
|
||||||
|
return new Resource(this.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ModrinthProvider extends UrlProvider {
|
||||||
|
constructor(
|
||||||
|
hash: string,
|
||||||
|
hashFormat: string,
|
||||||
|
url: string,
|
||||||
|
public modId: string,
|
||||||
|
public versionId: string,
|
||||||
|
) {
|
||||||
|
super(hash, hashFormat, url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GitHubProvider extends UrlProvider {
|
||||||
|
constructor(
|
||||||
|
hash: string,
|
||||||
|
hashFormat: string,
|
||||||
|
url: string,
|
||||||
|
public branch: string,
|
||||||
|
public regex: string,
|
||||||
|
public slug: string,
|
||||||
|
public tag: string,
|
||||||
|
) {
|
||||||
|
super(hash, hashFormat, url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CurseForgeProvider extends Provider {
|
||||||
|
constructor(
|
||||||
|
hash: string,
|
||||||
|
hashFormat: string,
|
||||||
|
public mode: string,
|
||||||
|
public fileId: number,
|
||||||
|
public projectId: number,
|
||||||
|
) {
|
||||||
|
super(hash, hashFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
get downloadUrl(): Resource {
|
||||||
|
return new Resource(
|
||||||
|
`https://www.curseforge.com/api/v1/mods/${this.projectId}/files/${this.fileId}/download`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue