Skip to content

Commit

Permalink
Merge pull request #48 from discretize/revert-api-fallback
Browse files Browse the repository at this point in the history
Revert "Implement mirrored fallback"
  • Loading branch information
gw2princeps authored Jul 27, 2024
2 parents 2ff6709 + e3be0e0 commit a9e61b3
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions gw2-ui/src/gw2api/cache.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
import { APILanguage } from '../i18n';

interface ApiRoute {
name: string;
is_available: boolean;
create_url: (path: string, ids: number[], language: APILanguage) => string;
}

const api_routes: ApiRoute[] = [
{
name: 'Official GW2 API',
is_available: true,
create_url: (path, ids, language) =>
`https://api.guildwars2.com${path}?ids=${ids.join(',')}&lang=${language}`,
},
{
name: 'Princeps API Mirror',
is_available: true,
create_url: (path, ids, language) =>
`https://api.princeps.biz${path}?ids=${ids.join(',')}&lang=${language}`,
},
];
const GW2_API_URL = 'https://api.guildwars2.com';

// An error occurred when connecting to the API
export const API_ERROR_NETWORK = 500;
Expand Down Expand Up @@ -240,10 +221,13 @@ export default class APICache<T extends { id: Id }> {
try {
ids.sort((a, b) => a - b);

const api_route =
api_routes.find(({ is_available }) => is_available) ?? api_routes[0];

const url = api_route.create_url(this.path, ids, this.language);
const url =
GW2_API_URL +
this.path +
'?ids=' +
ids.join(',') +
'&lang=' +
this.language;
const res = await fetch(url, FETCH_OPTIONS);

if (res.status === 503) {
Expand Down

0 comments on commit a9e61b3

Please sign in to comment.