Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions src/store/modules/TsModsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { State as RootState } from '../index';
import ManifestV2 from '../../model/ManifestV2';
import ThunderstoreCombo from '../../model/ThunderstoreCombo';
import ThunderstoreMod from '../../model/ThunderstoreMod';
import CdnProvider from '../../providers/generic/connection/CdnProvider';
import ConnectionProvider from '../../providers/generic/connection/ConnectionProvider';
import * as PackageDb from '../../r2mm/manager/PackageDexieStore';
import { isEmptyArray, isStringArray } from '../../utils/ArrayUtils';
Expand Down Expand Up @@ -171,8 +172,8 @@ export const TsModsModule = {

actions: <ActionTree<State, RootState>>{
async fetchPackageListIndex({dispatch, rootState}): Promise<PackageListIndex> {
const indexUrl = rootState.activeGame.thunderstoreUrl;
const index = await retry(() => fetchAndProcessBlobFile(indexUrl));
const indexUrl = CdnProvider.addCdnQueryParameter(rootState.activeGame.thunderstoreUrl);
const index = await retry(() => fetchAndProcessBlobFile(indexUrl), 5, 2000);

if (!isStringArray(index.content)) {
throw new Error('Received invalid chunk index from API');
Expand Down Expand Up @@ -208,7 +209,8 @@ export const TsModsModule = {
// out due to concurrent requests competing for the bandwidth.
const chunks = [];
for (const [i, chunkUrl] of chunkUrls.entries()) {
const {content: chunk} = await retry(() => fetchAndProcessBlobFile(chunkUrl))
const url = CdnProvider.replaceCdnHost(chunkUrl);
const {content: chunk} = await retry(() => fetchAndProcessBlobFile(url));

if (chunkUrls.length > 1 && isEmptyArray(chunk)) {
throw new Error(`Chunk #${i} in multichunk response was empty`);
Expand Down
3 changes: 2 additions & 1 deletion src/utils/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const getPropertyFromPath = (object: Mappable, path: string | string[]):
export async function retry<T>(
fn: () => Promise<T>,
attempts: number = 3,
interval: number = 5000,
canRetry: () => boolean = () => true,
onError: (e: Error | unknown) => void = console.error
): Promise<T> {
Expand All @@ -43,7 +44,7 @@ export async function retry<T>(
onError(e);

if (currentAttempt < attempts) {
await sleep(5000);
await sleep(interval);
}
}
}
Expand Down
Loading