You've already forked AstralRinth
forked from didirus/AstralRinth
* chore: fix typo in status message * feat(labrinth): overhaul malware scanner report storage and routes * chore: address some review comments * feat: add Delphi to Docker Compose `with-delphi` profile * chore: fix unused import Clippy lint * feat(labrinth/delphi): use PAT token authorization with project read scopes * chore: expose file IDs in version queries * fix: accept null decompiled source payloads from Delphi * tweak(labrinth): expose base62 file IDs more consistently for Delphi * feat(labrinth/delphi): support new Delphi report severity field * chore(labrinth): run `cargo sqlx prepare` to fix Docker build errors * tweak: add route for fetching Delphi issue type schema, abstract Labrinth away from issue types * chore: run `cargo sqlx prepare` * chore: fix typo on frontend generated state file message * feat: update to use new Delphi issue schema * wip: tech review endpoints * wip: add ToSchema for dependent types * wip: report issues return * wip * wip: returning more data * wip * Fix up db query * Delphi configuration to talk to Labrinth * Get Delphi working with Labrinth * Add Delphi dummy fixture * Better Delphi logging * Improve utoipa for tech review routes * Add more sorting options for tech review queue * Oops join * New routes for fetching issues and reports * Fix which kind of ID is returned in tech review endpoints * Deduplicate tech review report rows * Reduce info sent for projects * Fetch more thread info * Address PR comments * fix ci * fix postgres version mismatch * fix version creation * Implement routes * fix up tech review * Allow adding a moderation comment to Delphi rejections * fix up rebase * exclude rejected projects from tech review * add status change msg to tech review thread * cargo sqlx prepare * also ignore withheld projects * More filtering on issue search * wip: report routes * Fix up for build * cargo sqlx prepare * fix thread message privacy * New tech review search route * submit route * details have statuses now * add default to drid status * dedup issue details * fix sqlx query on empty files * fixes * Dedupe issue detail statuses and message on entering tech rev * Fix qa issues * Fix qa issues * fix review comments * typos * fix ci * feat: tech review frontend (#4781) * chore: fix typo in status message * feat(labrinth): overhaul malware scanner report storage and routes * chore: address some review comments * feat: add Delphi to Docker Compose `with-delphi` profile * chore: fix unused import Clippy lint * feat(labrinth/delphi): use PAT token authorization with project read scopes * chore: expose file IDs in version queries * fix: accept null decompiled source payloads from Delphi * tweak(labrinth): expose base62 file IDs more consistently for Delphi * feat(labrinth/delphi): support new Delphi report severity field * chore(labrinth): run `cargo sqlx prepare` to fix Docker build errors * tweak: add route for fetching Delphi issue type schema, abstract Labrinth away from issue types * chore: run `cargo sqlx prepare` * chore: fix typo on frontend generated state file message * feat: update to use new Delphi issue schema * wip: tech review endpoints * wip: add ToSchema for dependent types * wip: report issues return * wip * wip: returning more data * wip * Fix up db query * Delphi configuration to talk to Labrinth * Get Delphi working with Labrinth * Add Delphi dummy fixture * Better Delphi logging * Improve utoipa for tech review routes * Add more sorting options for tech review queue * Oops join * New routes for fetching issues and reports * Fix which kind of ID is returned in tech review endpoints * Deduplicate tech review report rows * Reduce info sent for projects * Fetch more thread info * Address PR comments * fix ci * fix ci * fix postgres version mismatch * fix version creation * Implement routes * feat: batch scan alert * feat: layout * feat: introduce surface variables * fix: theme selector * feat: rough draft of tech review card * feat: tab switcher * feat: batch scan btn * feat: api-client module for tech review * draft: impl * feat: auto icons * fix: layout issues * feat: fixes to code blocks + flag labels * feat: temp remove mock data * fix: search sort types * fix: intl & lint * chore: re-enable mock data * fix: flag badges + auto open first issue in file tab * feat: update for new routes * fix: more qa issues * feat: lazy load sources * fix: re-enable auth middleware * feat: impl threads * fix: lint & severity * feat: download btn + switch to using NavTabs with new local mode option * feat: re-add toplevel btns * feat: reports page consistency * fix: consistency on project queue * fix: icons + sizing * fix: colors and gaps * fix: impl endpoints * feat: load all flags on file tab * feat: thread generics changes * feat: more qa * feat: fix collapse * fix: qa * feat: msg modal * fix: ISO import * feat: qa fixes * fix: empty state basic * fix: collapsible region * fix: collapse thread by default * feat: rough draft of new process/flow * fix labrinth build * fix thread message privacy * New tech review search route * feat: qa fixes * feat: QA changes * fix: verdict on detail not whole issue * fix: lint + intl * fix: lint * fix: thread message for tech rev verdict * feat: use anim frames * fix: exports + typecheck * polish: qa changes * feat: qa * feat: qa polish * feat: fix malic modal * fix: lint * fix: qa + lint * fix: pagination * fix: lint * fix: qa * intl extract * fix ci --------- Signed-off-by: Calum H. <contact@cal.engineer> Co-authored-by: Alejandro González <me@alegon.dev> Co-authored-by: aecsocket <aecsocket@tutanota.com> --------- Signed-off-by: Calum H. <contact@cal.engineer> Co-authored-by: Alejandro González <me@alegon.dev> Co-authored-by: Calum H. <contact@cal.engineer>
129 lines
4.3 KiB
TypeScript
129 lines
4.3 KiB
TypeScript
import type { AbstractModrinthClient } from '../core/abstract-client'
|
|
import type { AbstractModule } from '../core/abstract-module'
|
|
import { ArchonBackupsV0Module } from './archon/backups/v0'
|
|
import { ArchonBackupsV1Module } from './archon/backups/v1'
|
|
import { ArchonServersV0Module } from './archon/servers/v0'
|
|
import { ArchonServersV1Module } from './archon/servers/v1'
|
|
import { ISO3166Module } from './iso3166'
|
|
import { KyrosFilesV0Module } from './kyros/files/v0'
|
|
import { LabrinthVersionsV3Module } from './labrinth'
|
|
import { LabrinthBillingInternalModule } from './labrinth/billing/internal'
|
|
import { LabrinthCollectionsModule } from './labrinth/collections'
|
|
import { LabrinthProjectsV2Module } from './labrinth/projects/v2'
|
|
import { LabrinthProjectsV3Module } from './labrinth/projects/v3'
|
|
import { LabrinthStateModule } from './labrinth/state'
|
|
import { LabrinthTechReviewInternalModule } from './labrinth/tech-review/internal'
|
|
|
|
type ModuleConstructor = new (client: AbstractModrinthClient) => AbstractModule
|
|
|
|
/**
|
|
* To add a new module:
|
|
* 1. Create your module class extending AbstractModule
|
|
* 2. Add one line here: `<api>_<module>: YourModuleClass`
|
|
*
|
|
* TypeScript will automatically infer the client's field structure from this registry.
|
|
*
|
|
* TODO: Better way? Probably not
|
|
*/
|
|
export const MODULE_REGISTRY = {
|
|
archon_backups_v0: ArchonBackupsV0Module,
|
|
archon_backups_v1: ArchonBackupsV1Module,
|
|
archon_servers_v0: ArchonServersV0Module,
|
|
archon_servers_v1: ArchonServersV1Module,
|
|
iso3166_data: ISO3166Module,
|
|
kyros_files_v0: KyrosFilesV0Module,
|
|
labrinth_billing_internal: LabrinthBillingInternalModule,
|
|
labrinth_collections: LabrinthCollectionsModule,
|
|
labrinth_projects_v2: LabrinthProjectsV2Module,
|
|
labrinth_projects_v3: LabrinthProjectsV3Module,
|
|
labrinth_state: LabrinthStateModule,
|
|
labrinth_tech_review_internal: LabrinthTechReviewInternalModule,
|
|
labrinth_versions_v3: LabrinthVersionsV3Module,
|
|
} as const satisfies Record<string, ModuleConstructor>
|
|
|
|
export type ModuleID = keyof typeof MODULE_REGISTRY
|
|
|
|
/**
|
|
* Parse a module ID into [api, moduleName] tuple
|
|
*
|
|
* @param id - Module ID in format `<api>_<module>` (e.g., 'labrinth_projects_v2')
|
|
* @returns Tuple of [api, moduleName] (e.g., ['labrinth', 'projects_v2'])
|
|
* @throws Error if module ID doesn't match expected format
|
|
*/
|
|
export function parseModuleID(id: string): [string, string] {
|
|
const parts = id.split('_')
|
|
if (parts.length < 2) {
|
|
throw new Error(
|
|
`Invalid module ID "${id}". Expected format: <api>_<module> (e.g., "labrinth_projects_v2")`,
|
|
)
|
|
}
|
|
const api = parts[0]
|
|
const moduleName = parts.slice(1).join('_')
|
|
return [api, moduleName]
|
|
}
|
|
|
|
/**
|
|
* Build nested module structure from flat registry
|
|
*
|
|
* Transforms:
|
|
* ```
|
|
* { labrinth_projects_v2: Constructor, labrinth_users_v2: Constructor }
|
|
* ```
|
|
* Into:
|
|
* ```
|
|
* { labrinth: { projects_v2: Constructor, users_v2: Constructor } }
|
|
* ```
|
|
*
|
|
* @returns Nested structure organized by API namespace
|
|
*/
|
|
export function buildModuleStructure(): Record<string, Record<string, ModuleConstructor>> {
|
|
const structure: Record<string, Record<string, ModuleConstructor>> = {}
|
|
|
|
for (const [id, constructor] of Object.entries(MODULE_REGISTRY)) {
|
|
const [api, moduleName] = parseModuleID(id)
|
|
|
|
if (!structure[api]) {
|
|
structure[api] = {}
|
|
}
|
|
|
|
structure[api][moduleName] = constructor
|
|
}
|
|
|
|
return structure
|
|
}
|
|
|
|
/**
|
|
* Extract API name from module ID
|
|
* @example ParseAPI<'labrinth_projects_v2'> = 'labrinth'
|
|
*/
|
|
type ParseAPI<T extends string> = T extends `${infer API}_${string}` ? API : never
|
|
|
|
/**
|
|
* Extract module name for a given API
|
|
* @example ParseModule<'labrinth_projects_v2', 'labrinth'> = 'projects_v2'
|
|
*/
|
|
type ParseModule<T extends string, API extends string> = T extends `${API}_${infer Module}`
|
|
? Module
|
|
: never
|
|
|
|
/**
|
|
* Group registry modules by API namespace
|
|
*
|
|
* Transforms flat registry into nested structure at the type level:
|
|
* ```
|
|
* { labrinth_projects_v2: ModuleClass } → { labrinth: { projects_v2: ModuleInstance } }
|
|
* ```
|
|
*/
|
|
type GroupByAPI<Registry extends Record<string, ModuleConstructor>> = {
|
|
[API in ParseAPI<keyof Registry & string>]: {
|
|
[Module in ParseModule<keyof Registry & string, API>]: InstanceType<
|
|
Registry[`${API}_${Module}`]
|
|
>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Inferred client module structure
|
|
**/
|
|
export type InferredClientModules = GroupByAPI<typeof MODULE_REGISTRY>
|