Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mclib/src/ModQueryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ export class ModQueryService {
}
// Try to get releases for this mod ID
try {
const repoReleases = await repo.getModReleases(modRepoMeta.id);
const rawRepoReleases = await repo.getModReleases(modRepoMeta.id);
// Attach the metadata to the release
repoReleases.forEach(release => {
release.modMetadata = modRepoMeta;
});
const repoReleases = rawRepoReleases.map(release => ({ ...release, modMetadata: modRepoMeta }));
releases.push(...repoReleases);
} catch (error) {
logger.error("Error fetching mod releases for %s from %s: %s", modRepoMeta.id, repo.getRepositoryName(), error);
Expand Down
2 changes: 1 addition & 1 deletion mclib/src/finder/LocalSolutionFinder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe('SolutionFinder', () => {
loader: ModLoader.FABRIC
});
expect(result.mods).toHaveLength(1);
expect(result.mods[0].modMetadata!.id).toBe('ice-and-fire-dragons');
expect(result.mods[0].modMetadata.id).toBe('ice-and-fire-dragons');
expect(result.mods[0].modVersion).toBe('2.0.0');
});

Expand Down
1 change: 1 addition & 0 deletions mclib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export {

export type {
MCConfig,
RawModRepoRelease,
ModRepoRelease,
MCVersion,
ModReleases
Expand Down
6 changes: 3 additions & 3 deletions mclib/src/repos/CurseForgeRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IRepository } from "./IRepository";
import { ModRepoRelease, ModRepositoryName, ModLoader, ModRepoMetadata, MCVersion, ModLoaderUtil, ModReleases } from "..";
import { RawModRepoRelease, ModRepositoryName, ModLoader, ModRepoMetadata, MCVersion, ModLoaderUtil } from "..";
import { cf_fingerprint } from 'cf-fingerprint';
import { logger } from "../logger";

Expand All @@ -20,7 +20,7 @@ export class CurseForgeRepository implements IRepository {
return null;
}

async getModReleases(modId: string): Promise<ModReleases> {
async getModReleases(modId: string): Promise<RawModRepoRelease[]> {
type Data = {
data: {
displayName: string;
Expand All @@ -33,7 +33,7 @@ export class CurseForgeRepository implements IRepository {
if (!filesResp.ok) throw new Error("Could not fetch files from CurseForge");
const jsonResp: Data = await filesResp.json();

const releases: ModRepoRelease[] = jsonResp.data.map(file => {
const releases: RawModRepoRelease[] = jsonResp.data.map(file => {
const mcVersions: Set<MCVersion> = new Set();
const loaders: Set<ModLoader> = new Set();
for (let gameVersion of file.gameVersions || []) {
Expand Down
4 changes: 2 additions & 2 deletions mclib/src/repos/IRepository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ModReleases, ModRepoMetadata, ModRepositoryName } from "..";
import type { ModRepoMetadata, ModRepositoryName, RawModRepoRelease } from "..";

/**
* Interface for a mod repository
Expand All @@ -16,7 +16,7 @@ export interface IRepository {
* @param modId The ID of the mod.
* @returns A promise resolving to an array of mod releases.
*/
getModReleases(modId: string): Promise<ModReleases>;
getModReleases(modId: string): Promise<RawModRepoRelease[]>;

/**
* Search for mods by a query string.
Expand Down
6 changes: 3 additions & 3 deletions mclib/src/repos/ModrinthRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IRepository } from "./IRepository";
import { ModRepoRelease, ModRepositoryName, ModRepoMetadata, ModLoaderUtil, ModReleases } from "..";
import { ModRepositoryName, ModRepoMetadata, ModLoaderUtil, RawModRepoRelease } from "..";

export class ModrinthRepository implements IRepository {

Expand All @@ -17,7 +17,7 @@ export class ModrinthRepository implements IRepository {
return data.project_id || null;
}

async getModReleases(modId: string): Promise<ModReleases> {
async getModReleases(modId: string): Promise<RawModRepoRelease[]> {
type Data = Array<{
game_versions: string[];
version_number: string;
Expand All @@ -31,7 +31,7 @@ export class ModrinthRepository implements IRepository {
if (!versionsResp.ok) throw new Error("Could not fetch versions from Modrinth");
const jsonResp: Data = await versionsResp.json();

const releases: ModRepoRelease[] = jsonResp.map(file => {
const releases: RawModRepoRelease[] = jsonResp.map(file => {
const mcVersions = new Set(file.game_versions);
const loaders = new Set(file.loaders.map(ModLoaderUtil.from));
return {
Expand Down
10 changes: 6 additions & 4 deletions mclib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ export type MCConfig = {
loader: ModLoader;
};

/** Represents a release of a mod */
export type ModRepoRelease = {
/** Represents a release of a mod (a release is tied to a repository !) */
export type ModRepoRelease = RawModRepoRelease & {
/** Repository-specific metadata about the mod itself*/
modMetadata: ModRepoMetadata
};
export type RawModRepoRelease = {
/** List of Minecraft versions compatible with this release */
mcVersions: Set<MCVersion>;
/** Mod version */
Expand All @@ -54,8 +58,6 @@ export type ModRepoRelease = {
loaders: Set<ModLoader>;
/** Download URL for the mod release */
downloadUrl: string;

modMetadata?: ModRepoMetadata;
};

export type ModMetadata = ModRepoMetadata[];
Expand Down