Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a getter isModListOutdated #1633

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { ActionTree, GetterTree, MutationTree } from 'vuex';
import { State as RootState } from '../index';
import ExportMod from '../../model/exports/ExportMod';
import ManifestV2 from '../../model/ManifestV2';
import R2Error from "../../model/errors/R2Error";
import ThunderstoreMod from '../../model/ThunderstoreMod';
import VersionNumber from '../../model/VersionNumber';
import CdnProvider from '../../providers/generic/connection/CdnProvider';
import * as PackageDb from '../../r2mm/manager/PackageDexieStore';
import { isEmptyArray, isStringArray } from '../../utils/ArrayUtils';
import { retry } from '../../utils/Common';
import { Deprecations } from '../../utils/Deprecations';
import { fetchAndProcessBlobFile, getAxiosWithTimeouts } from '../../utils/HttpUtils';
import { fetchAndProcessBlobFile, getAxiosWithTimeouts, isNetworkError } from '../../utils/HttpUtils';

export interface CachedMod {
tsMod: ThunderstoreMod | undefined;
Expand Down Expand Up @@ -45,6 +46,7 @@ function isPackageListChunk(value: unknown): value is PackageListChunk {
}

const EXCLUSIONS = 'https://raw.githubusercontent.com/ebkr/r2modmanPlus/master/modExclusions.md';
const PARTIAL_UPDATE_ERROR = 'Failed to fully refresh the online mod list. Some mod versions might be unavailable.';

/**
* For dealing with mods listed in communities, i.e. available through
Expand Down Expand Up @@ -118,6 +120,27 @@ export const TsModsModule = {
return getters.cachedMod(mod).isLatest;
},

/*** Was the last successful mod list update more than an hour ago? */
isModListOutdated(state) {
return state.modsLastUpdated instanceof Date
&& (Date.now() - state.modsLastUpdated.getTime()) > (1000 * 60 * 60);
},

/*** A more concise version of the error message */
conciseThunderstoreModListUpdateErrorMessage(state): string|undefined {
if (!state.thunderstoreModListUpdateError) {
return undefined;
}

let conciseError = "Failed to load mod list";
if (isNetworkError(state.thunderstoreModListUpdateError)) {
conciseError = "Failed to fully refresh the online mod list due to network error"
} else if (state.thunderstoreModListUpdateError.name === PARTIAL_UPDATE_ERROR) {
conciseError = "Failed to fully refresh the online mod list";
}
return conciseError;
},

/*** Return ThunderstoreMod representation of a ManifestV2 */
tsMod: (_state, getters) => (mod: ExportMod|ManifestV2): ThunderstoreMod | undefined => {
return getters.cachedMod(mod).tsMod;
Expand Down Expand Up @@ -252,7 +275,7 @@ export const TsModsModule = {
},

async fetchAndCachePackageListChunks(
{dispatch},
{commit, dispatch},
{packageListIndex, progressCallback}: {packageListIndex: PackageListIndex, progressCallback?: ProgressCallback},
): Promise<boolean> {
const chunkCount = packageListIndex.content.length;
Expand All @@ -277,6 +300,13 @@ export const TsModsModule = {
// hash is updated in the API.
if (successes === chunkCount) {
await dispatch('cacheIndexHash', packageListIndex.hash);
} else {
commit('setThunderstoreModListUpdateError',
new R2Error(
PARTIAL_UPDATE_ERROR,
`Only ${successes} out of ${chunkCount} parts of the list were updated successfully`,
)
);
}

return successes === chunkCount;
Expand Down
Loading