Fixed default value resolution in ModrinthUploader

This commit is contained in:
Kir_Antipov 2023-05-20 15:11:48 +03:00
parent 98e9aced20
commit 4cf81648dc
2 changed files with 14 additions and 11 deletions

View file

@ -51,7 +51,7 @@ export class ModrinthUploader extends GenericPlatformUploader<ModrinthUploaderOp
*/ */
protected async uploadCore(request: ModrinthUploadRequest): Promise<ModrinthUploadReport> { protected async uploadCore(request: ModrinthUploadRequest): Promise<ModrinthUploadReport> {
const api = new ModrinthApiClient({ token: request.token.unwrap() }); const api = new ModrinthApiClient({ token: request.token.unwrap() });
const unfeatureMode = request.unfeatureMode ?? request.featured ? ModrinthUnfeatureMode.SUBSET : ModrinthUnfeatureMode.NONE; const unfeatureMode = request.unfeatureMode ?? (request.featured ? ModrinthUnfeatureMode.SUBSET : ModrinthUnfeatureMode.NONE);
const project = await this.getProject(request.id, api); const project = await this.getProject(request.id, api);
const version = await this.createVersion(request, project, api); const version = await this.createVersion(request, project, api);
@ -97,15 +97,16 @@ export class ModrinthUploader extends GenericPlatformUploader<ModrinthUploaderOp
const dependencies = await this.convertToModrinthDependencies(request.dependencies, api); const dependencies = await this.convertToModrinthDependencies(request.dependencies, api);
return await api.createVersion({ return await api.createVersion({
project_id: project.id,
name: request.name, name: request.name,
version_number: request.version, version_number: request.version,
project_id: project.id,
changelog: request.changelog, changelog: request.changelog,
version_type: request.versionType,
featured: request.featured,
game_versions: gameVersions,
loaders,
dependencies, dependencies,
game_versions: gameVersions,
version_type: request.versionType,
loaders,
featured: request.featured,
files: request.files,
}); });
} }

View file

@ -411,14 +411,16 @@ export function packModrinthVersionInit(version: ModrinthVersionInit): ModrinthV
const { files = [] } = version; const { files = [] } = version;
const data: ModrinthVersionInitData = { const data: ModrinthVersionInitData = {
// Default values
featured: true,
dependencies: [],
version_type: VersionType.RELEASE,
// Unpack the `version` // Unpack the `version`
...{ ...version, files: undefined }, ...{ ...version, files: undefined },
// Default values
name: version.name || version.version_number, name: version.name || version.version_number,
version_type: version.version_type ?? VersionType.RELEASE,
featured: version.featured ?? true,
dependencies: version.dependencies ?? [],
game_versions: version.game_versions ?? [],
loaders: version.loaders ?? [],
// Names of each file part // Names of each file part
primary_file: files.length ? "_0" : undefined, primary_file: files.length ? "_0" : undefined,