Skip to content

Commit

Permalink
feat(curseforge): add find file
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jul 30, 2019
1 parent 32fd566 commit 5d0f2fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/universal/store/modules/curseforge.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Context, Module, TaskHandle } from "../store";
import { Resource } from "./resource";

export namespace CurseForgeModule {
interface State {
Expand All @@ -7,6 +8,7 @@ export namespace CurseForgeModule {

interface Getters {
isFileInstalled: (file: Pick<Download, "id" | "href">) => boolean;
findFileInstalled: (file: Pick<Download, "id" | "href">) => Resource<any> | undefined;
}

interface Mutations {
Expand Down
22 changes: 22 additions & 0 deletions src/universal/store/modules/curseforge.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ const mod = {

return false;
},
findFileInstalled: (state, _, rt, rg) => (file) => {
/**
* @param {{ source: any; }} m
*/
const find = (m) => {
const source = m.source;
if ('curseforge' in source && typeof source.curseforge === 'object') {
const s = source.curseforge;
if (s.href === file.href || s.fileId === file.id) return true;
}
return false;
};
let result;
/* eslint-disable no-cond-assign */
if (result = rg.mods.find(find)) return result;
if (result = rg.resourcepacks.find(find)) return result;
if (result = rg.modpacks.find(find)) return result;
if (result = rg.saves.find(find)) return result;
/* eslint-enable no-cond-assign */

return undefined;
},
},
mutations: {
startDownloadCurseforgeFile(state, p) {
Expand Down

0 comments on commit 5d0f2fa

Please sign in to comment.