diff --git a/app/src/api/SpaceDock.ts b/app/src/api/SpaceDock.ts index 86c5520..2d37ed5 100644 --- a/app/src/api/SpaceDock.ts +++ b/app/src/api/SpaceDock.ts @@ -12,7 +12,7 @@ export class SpaceDockAPI { public static getDefaultAPIUrl() { return import.meta.env.DEV - ? "/_spacedock" + ? "/_spacedock/api" : "https://spacedock.info/api"; } @@ -30,6 +30,15 @@ export class SpaceDockAPI { return finishFullModInfo(response.data); } + public async getModDownload(id: string | number) { + const response = await axios.get(`${this.base}/mod/${id}/latest`); + + return ( + (this.base == "/_spacedock/api" ? "/_spacedock" : this.base) + + response.data.download_path + ); + } + public async getModsForGame(gameId: number, page = 1, count = 30) { // This is not implemented yet! To look at the implementation, see this PR: // KSP-SpaceDock/SpaceDock#466 diff --git a/app/src/dev.ts b/app/src/dev.ts index 1bca673..bdbc966 100644 --- a/app/src/dev.ts +++ b/app/src/dev.ts @@ -73,7 +73,10 @@ export const createMockAPI = () => { return await new SpaceDockAPI().getModsForGame(22407, args.page, args.count); case "get_mod": - return await new SpaceDockAPI().getMod(args.modId); + return await new SpaceDockAPI().getMod(args.mod_id); + + case "get_mod_download": + return await new SpaceDockAPI().getModDownload(args.mod_id); } }); }; diff --git a/app/src/invoke.ts b/app/src/invoke.ts index 77e1177..913c59d 100644 --- a/app/src/invoke.ts +++ b/app/src/invoke.ts @@ -37,6 +37,7 @@ export interface InvokeFunction { get_instance_info: [InstanceArgs, InstanceInfo]; get_mod: [ModArgs, FullModInfo]; + get_mod_download: [ModArgs, string]; get_mods: [ModsArgs, BrowseResult]; } diff --git a/app/src/routes/mods/FullMod.tsx b/app/src/routes/mods/FullMod.tsx index 824872b..40a1c07 100644 --- a/app/src/routes/mods/FullMod.tsx +++ b/app/src/routes/mods/FullMod.tsx @@ -15,12 +15,18 @@ export const FullMod = () => { (async () => { setModInfo( await invoke_proxy("get_mod", { - modId: parseInt(modId || "-1", 10), + mod_id: parseInt(modId || "-1", 10), }) ); })(); }, [modId]); + const install = async () => { + window.open(await invoke_proxy("get_mod_download", { + mod_id: parseInt(modId || "-1", 10), + })); + }; + return (