|
1 | 1 | import ThunderstoreMod from './ThunderstoreMod';
|
2 | 2 | import R2Error from './errors/R2Error';
|
3 | 3 | import ThunderstoreVersion from './ThunderstoreVersion';
|
| 4 | +import * as PackageDb from '../r2mm/manager/PackageDexieStore'; |
4 | 5 |
|
5 | 6 | export default class ThunderstoreCombo {
|
6 | 7 |
|
7 | 8 | private mod: ThunderstoreMod = new ThunderstoreMod();
|
8 | 9 | private version: ThunderstoreVersion = new ThunderstoreVersion();
|
9 | 10 |
|
10 |
| - public static fromProtocol(protocol: string, modList: ThunderstoreMod[]): ThunderstoreCombo | R2Error { |
11 |
| - // Strip out protocol information |
12 |
| - const reducedProtocol = protocol.replace(new RegExp("ror2mm://v1/install/([a-zA-Z0-9]+\.)?thunderstore\.io/"), ''); |
13 |
| - const information = reducedProtocol.split('/'); |
14 |
| - const packageName = `${information[0]}-${information[1]}`; |
15 |
| - const packageVersion = information[2]; |
16 |
| - const foundMod = modList.find((mod: ThunderstoreMod) => mod.getFullName() === packageName); |
17 |
| - if (foundMod === undefined) { |
18 |
| - return new R2Error( |
19 |
| - 'Mod does not exist', |
20 |
| - `Unable to resolve ${packageName} to a suitable Thunderstore mod`, |
21 |
| - 'Relaunch the manager to update the mod list' |
22 |
| - ); |
23 |
| - } |
24 |
| - const foundVersion = foundMod.getVersions().find((version: ThunderstoreVersion) => version.getVersionNumber().toString() === packageVersion); |
25 |
| - if (foundVersion === undefined) { |
| 11 | + public static async fromProtocol(protocol: string, community: string): Promise<ThunderstoreCombo | R2Error> { |
| 12 | + // Remove protocol information and trailing slash, leaving the package version information. |
| 13 | + const reducedProtocol = protocol |
| 14 | + .replace(new RegExp('ror2mm://v1/install/([a-zA-Z0-9]+\.)?thunderstore\.io/'), '') |
| 15 | + .replace(new RegExp('\/$'), ''); |
| 16 | + const dependencyString = reducedProtocol.split('/').join('-'); |
| 17 | + const foundMod = await PackageDb.getCombosByDependencyStrings(community, [dependencyString]); |
| 18 | + |
| 19 | + if (!foundMod.length) { |
26 | 20 | return new R2Error(
|
27 | 21 | 'Mod does not exist',
|
28 |
| - `Unable to find version ${packageVersion} of mod ${packageName}`, |
29 |
| - 'Relaunch the manager to update the mod list' |
| 22 | + `Unable to resolve ${dependencyString} to a suitable Thunderstore mod or version`, |
| 23 | + 'Relaunch the manager to update the mod list. Ensure the correct game and profile is selected before opening the link.' |
30 | 24 | );
|
31 | 25 | }
|
32 |
| - const combo = new ThunderstoreCombo(); |
33 |
| - combo.mod = foundMod; |
34 |
| - combo.version = foundVersion; |
35 |
| - return combo; |
| 26 | + |
| 27 | + return foundMod[0]; |
36 | 28 | }
|
37 | 29 |
|
38 | 30 | public getMod(): ThunderstoreMod {
|
|
0 commit comments