Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneWizard08 committed Mar 10, 2023
1 parent 8acbbff commit 1b10be9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
11 changes: 10 additions & 1 deletion app/src/api/SpaceDock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class SpaceDockAPI {

public static getDefaultAPIUrl() {
return import.meta.env.DEV
? "/_spacedock"
? "/_spacedock/api"
: "https://spacedock.info/api";
}

Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion app/src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};
1 change: 1 addition & 0 deletions app/src/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
10 changes: 8 additions & 2 deletions app/src/routes/mods/FullMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="full-mod-container">
<div className="mod">
Expand Down Expand Up @@ -57,7 +63,7 @@ export const FullMod = () => {
</div>

<div className="actions">
<button type="button" className="action">
<button type="button" className="action" onClick={install}>
<i className="icon fa-regular fa-circle-down" />
&nbsp; Install
</button>
Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ export default defineConfig({

proxy: {
"^/_spacedock/.*": {
target: "https://spacedock.info/api",
target: "https://spacedock.info/",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/_spacedock/, ""),
followRedirects: true,
},
},

Expand Down

0 comments on commit 1b10be9

Please sign in to comment.