mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 15:04:52 +09:00
Reduce type duplication
This commit is contained in:
1 parent
25099c03ba
commit
2d62ff6689
2 files changed
+12
-39
No files matched your search
@@ -6,43 +6,16 @@ import { integerModVersion, ModInfo, ModPack, ModRecord } from "./data";
|
||||
import TypedEventEmitter from "./TypedEventEmitter";
|
||||
import { safeOutputFile } from "./file_ops";
|
||||
import { Writable } from "stream";
|
||||
import { ModPortalReleaseSchema, ModPortalDetailsSchema } from "./data/messages_mod";
|
||||
|
||||
export interface ModStoreEvents {
|
||||
/** A stored mod was created, updated or deleted */
|
||||
change: (mod: ModInfo) => void;
|
||||
}
|
||||
|
||||
interface ModDownloadRequest {
|
||||
name: string;
|
||||
version?: string;
|
||||
sha1?: string;
|
||||
}
|
||||
|
||||
interface ModRelease {
|
||||
download_url: string,
|
||||
file_name: string,
|
||||
info_json: { factorio_version: string; },
|
||||
released_at: string, // ISO 8601
|
||||
version: string,
|
||||
sha1: string;
|
||||
}
|
||||
|
||||
|
||||
interface ModDetails {
|
||||
name: string,
|
||||
title: string,
|
||||
owner: string,
|
||||
summary: string,
|
||||
downloads_count: number,
|
||||
category: string,
|
||||
score?: number,
|
||||
releases?: Array<ModRelease>,
|
||||
latest_release?: ModRelease,
|
||||
}
|
||||
|
||||
interface ModsInfoResponse {
|
||||
pagination: any,
|
||||
results: Array<ModDetails>,
|
||||
results: Array<Static<typeof ModPortalDetailsSchema>>,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +34,7 @@ interface ModPortalPagination {
|
||||
*/
|
||||
interface ModPortalResponse {
|
||||
pagination: ModPortalPagination;
|
||||
results: ModDetails[];
|
||||
results: Static<typeof ModPortalDetailsSchema>[];
|
||||
}
|
||||
|
||||
export default class ModStore extends TypedEventEmitter<keyof ModStoreEvents, ModStoreEvents> {
|
||||
@@ -182,7 +155,7 @@ export default class ModStore extends TypedEventEmitter<keyof ModStoreEvents, Mo
|
||||
return new this(modsDirectory, files);
|
||||
}
|
||||
|
||||
private async downloadModFromReleases(releases: Array<ModRelease>, version: string,
|
||||
private async downloadModFromReleases(releases: Array<Static<typeof ModPortalReleaseSchema>>, version: string,
|
||||
username: string, token: string
|
||||
) {
|
||||
const selectedRelease = releases.find(release => release.version === version);
|
||||
@@ -325,10 +298,10 @@ export default class ModStore extends TypedEventEmitter<keyof ModStoreEvents, Mo
|
||||
factorioVersion: string,
|
||||
pageSize: number,
|
||||
hide_deprecated: boolean = false
|
||||
): Promise<ModDetails[]> {
|
||||
): Promise<Static<typeof ModPortalDetailsSchema>[]> {
|
||||
logger.info(`Fetching all mods for Factorio version ${factorioVersion}...`);
|
||||
let currentPage = 1;
|
||||
let allMods: ModDetails[] = [];
|
||||
let allMods: Static<typeof ModPortalDetailsSchema>[] = [];
|
||||
let hasMorePages = true;
|
||||
|
||||
while (hasMorePages) {
|
||||
|
||||
@@ -198,7 +198,7 @@ export class ModSearchRequest {
|
||||
}
|
||||
|
||||
// Define the structure for the latest release info from the portal
|
||||
const ModPortalReleaseSchema = Type.Object({
|
||||
export const ModPortalReleaseSchema = Type.Object({
|
||||
version: Type.String(),
|
||||
// Match the structure from ModStore's ModRelease/ModDetails
|
||||
info_json: Type.Object({ factorio_version: Type.String() }),
|
||||
@@ -210,16 +210,16 @@ const ModPortalReleaseSchema = Type.Object({
|
||||
|
||||
// Define the structure for mod details returned by the portal API
|
||||
// This should align with the ModDetails interface in ModStore.ts
|
||||
const ModPortalDetailsSchema = Type.Object({
|
||||
export const ModPortalDetailsSchema = Type.Object({
|
||||
name: Type.String(),
|
||||
title: Type.String(),
|
||||
summary: Type.String(),
|
||||
owner: Type.String(),
|
||||
downloads_count: Type.Integer(),
|
||||
category: Type.Optional(Type.String()), // Add optional category
|
||||
score: Type.Optional(Type.Number()), // Add optional score
|
||||
category: Type.Optional(Type.String()),
|
||||
score: Type.Optional(Type.Number()),
|
||||
latest_release: Type.Optional(ModPortalReleaseSchema),
|
||||
// Add releases array if needed: releases: Type.Optional(Type.Array(ModPortalReleaseSchema)),
|
||||
releases: Type.Optional(Type.Array(ModPortalReleaseSchema)),
|
||||
});
|
||||
|
||||
export class ModPortalGetAllRequest {
|
||||
@@ -227,7 +227,7 @@ export class ModPortalGetAllRequest {
|
||||
static type = "request" as const;
|
||||
static src = "control" as const;
|
||||
static dst = "controller" as const;
|
||||
static permission = "core.mod.search_portal" as const; // Reuse search permission for now
|
||||
static permission = "core.mod.search_portal" as const;
|
||||
|
||||
// Define allowed Factorio versions
|
||||
static allowedVersions = [
|
||||
|
||||
Reference in new issue
Block a user