Skip to content

Commit 5d0f2fa

Browse files
committed
feat(curseforge): add find file
1 parent 32fd566 commit 5d0f2fa

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/universal/store/modules/curseforge.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Context, Module, TaskHandle } from "../store";
2+
import { Resource } from "./resource";
23

34
export namespace CurseForgeModule {
45
interface State {
@@ -7,6 +8,7 @@ export namespace CurseForgeModule {
78

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

1214
interface Mutations {

src/universal/store/modules/curseforge.js

+22
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ const mod = {
2626

2727
return false;
2828
},
29+
findFileInstalled: (state, _, rt, rg) => (file) => {
30+
/**
31+
* @param {{ source: any; }} m
32+
*/
33+
const find = (m) => {
34+
const source = m.source;
35+
if ('curseforge' in source && typeof source.curseforge === 'object') {
36+
const s = source.curseforge;
37+
if (s.href === file.href || s.fileId === file.id) return true;
38+
}
39+
return false;
40+
};
41+
let result;
42+
/* eslint-disable no-cond-assign */
43+
if (result = rg.mods.find(find)) return result;
44+
if (result = rg.resourcepacks.find(find)) return result;
45+
if (result = rg.modpacks.find(find)) return result;
46+
if (result = rg.saves.find(find)) return result;
47+
/* eslint-enable no-cond-assign */
48+
49+
return undefined;
50+
},
2951
},
3052
mutations: {
3153
startDownloadCurseforgeFile(state, p) {

0 commit comments

Comments
 (0)