From 2061783ed1f0275cb88a128a49e065da5e9c7981 Mon Sep 17 00:00:00 2001 From: Evorp <3vorpgaming@gmail.com> Date: Mon, 15 Jan 2024 17:24:19 -0800 Subject: [PATCH] add pack type to search --- src/v2/controller/pack.controller.ts | 4 +++- src/v2/interfaces/packs.ts | 15 ++++++++----- .../repository/firestorm/packs.repository.ts | 22 +++++++++++++++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/v2/controller/pack.controller.ts b/src/v2/controller/pack.controller.ts index 90d36c1..03e21c3 100644 --- a/src/v2/controller/pack.controller.ts +++ b/src/v2/controller/pack.controller.ts @@ -7,6 +7,7 @@ import { Pack, PackAll, PackTag, + PackType, Packs, } from "../interfaces"; @@ -42,8 +43,9 @@ export class PackController extends Controller { @Query() tag?: PackTag, @Query() name?: string, @Query() resolution?: number, + @Query() type?: PackType, ): Promise { - return this.service.search({ tag, name, resolution }); + return this.service.search({ tag, name, resolution, type }); } /** diff --git a/src/v2/interfaces/packs.ts b/src/v2/interfaces/packs.ts index 1d1e95a..eca5dc4 100644 --- a/src/v2/interfaces/packs.ts +++ b/src/v2/interfaces/packs.ts @@ -23,6 +23,15 @@ export interface PackGitHub { export type PackTag = "vanilla" | "faithful" | "classic_faithful" | "jappa" | "progart"; +export type PackType = "submission" | "default" | "all"; + +export interface PackSearch { + tag?: PackTag; + name?: string; + resolution?: number; + type?: PackType; +} + export interface CreationPack { // either can be specified manually or serialized automatically id?: string; @@ -46,12 +55,6 @@ export interface CreationPackAll extends CreationPack { submission?: FirstCreationSubmission; } -export interface PackSearch { - tag?: PackTag; - name?: string; - resolution?: number; -} - export interface Packs extends Array {} export interface FirestormPack extends Pack { diff --git a/src/v2/repository/firestorm/packs.repository.ts b/src/v2/repository/firestorm/packs.repository.ts index fbe89af..9e4d2d4 100644 --- a/src/v2/repository/firestorm/packs.repository.ts +++ b/src/v2/repository/firestorm/packs.repository.ts @@ -11,6 +11,7 @@ import { FaithfulPack, CreationPackAll, PackSearch, + FirestormPack, } from "~/v2/interfaces"; import { packs } from "../../firestorm"; import SubmissionFirestormRepository from "./submissions.repository"; @@ -54,7 +55,7 @@ export default class PackFirestormRepository implements PackRepository { } search(params: PackSearch): Promise { - const { tag, name, resolution } = params; + const { tag, name, resolution, type } = params; const options: SearchOption[] = []; if (name) options.push({ @@ -75,7 +76,24 @@ export default class PackFirestormRepository implements PackRepository { criteria: "==", value: resolution, }); - return packs.search(options); + const prom: Promise = options.length + ? packs.search(options) + : packs.readRaw().then(Object.values); + + return prom.then(async (packs) => { + if (!type || type === "all") return packs; + const out: Packs = []; + for (const pack of packs) { + try { + await pack.submission(); + } catch { + out.push(pack); + } + } + + if (type === "default") return out; + return packs.filter((p) => !out.includes(p)); + }); } async renamePack(oldPack: AnyPack, newPack: string): Promise {