refactor hash-format and add Side enum
This commit is contained in:
parent
6b6a5f3cfb
commit
f84576b6be
4 changed files with 24 additions and 5 deletions
17
src/enums/side.ts
Normal file
17
src/enums/side.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
export enum Side {
|
||||
"Both" = "both",
|
||||
"Client" = "client",
|
||||
"Server" = "server",
|
||||
}
|
||||
|
||||
export function isValidSide(side: string | undefined): Side {
|
||||
if (side == undefined) {
|
||||
return Side.Both;
|
||||
}
|
||||
|
||||
if (Object.values(Side).includes(side.toLowerCase() as Side)) {
|
||||
return side.toLowerCase() as Side;
|
||||
} else {
|
||||
throw new Error("Invalid side!");
|
||||
}
|
||||
}
|
|
@ -6,12 +6,13 @@ import {
|
|||
CurseForgeProvider,
|
||||
GitHubProvider,
|
||||
} from "./provider";
|
||||
import { HashFormat, isValidHashFormat } from "./hashFormat";
|
||||
import { HashFormat, isValidHashFormat } from "./enums/hash-format";
|
||||
import { isValidSide, type Side } from "./enums/side";
|
||||
|
||||
export interface Metafile {
|
||||
name: string;
|
||||
filename: string;
|
||||
side: "server" | "client" | "both" | undefined;
|
||||
side: Side;
|
||||
provider: UrlProvider;
|
||||
option: Option;
|
||||
}
|
||||
|
@ -50,11 +51,12 @@ export class IndexFileEntry {
|
|||
}
|
||||
const fileContent = await this.file.fetchContents();
|
||||
const parsed = toml.parse(fileContent);
|
||||
const side = isValidSide(parsed.side);
|
||||
|
||||
const metafile: Metafile = {
|
||||
name: parsed.name,
|
||||
filename: parsed.filename,
|
||||
side: parsed.side,
|
||||
side: side,
|
||||
provider: this.parseProvider(parsed),
|
||||
option: {
|
||||
optional: parsed.option?.optional || false,
|
||||
|
@ -136,7 +138,7 @@ export async function parsePackwizIndex(
|
|||
(file: {
|
||||
file: string;
|
||||
hash: string;
|
||||
hashFormat: HashFormats;
|
||||
hashFormat: HashFormat;
|
||||
alias?: string;
|
||||
metafile?: boolean;
|
||||
preserve?: boolean;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Resource from "./resource";
|
||||
import { HashFormat } from "./hashFormat";
|
||||
import { HashFormat } from "./enums/hash-format";
|
||||
|
||||
export class UrlProvider {
|
||||
constructor(
|
||||
|
|
Reference in a new issue