Skip to content

Commit

Permalink
fixup! feat: use lapisV2 as backend
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Dec 21, 2023
1 parent 00926b2 commit c77e673
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/data/api-lapis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ACCESS_KEY = process.env.REACT_APP_LAPIS_ACCESS_KEY;

let currentLapisDataVersion: number | undefined = undefined;

export const get = async (endpoint: string, signal?: AbortSignal, omitDataVersion = false) => {
export const get = async (endpoint: string, signal?: AbortSignal) => {
let url = `${HOST}/sample${endpoint}`;

const requestInit =
Expand All @@ -50,14 +50,7 @@ export const get = async (endpoint: string, signal?: AbortSignal, omitDataVersio
method: 'GET',
signal: signal,
};
const res = await fetch(url, requestInit);
const dataVersion = res.headers.get('Lapis-Data-Version') ?? undefined;

if (currentLapisDataVersion !== dataVersion) {
currentLapisDataVersion = dataVersion ? parseInt(dataVersion) : undefined;
window.location.reload();
}
return res;
return await fetch(url, requestInit);
};

export async function fetchLapisDataVersion(signal?: AbortSignal): Promise<string> {
Expand All @@ -79,7 +72,7 @@ export async function fetchNextcladeDatasetInfo(signal?: AbortSignal): Promise<N
if (ACCESS_KEY) {
url += '&accessKey=' + ACCESS_KEY;
}
const response = await get(url, signal, true);
const response = await get(url, signal);
if (!response.ok) {
throw new Error('Error fetching Nextclade dataset info');
}
Expand Down Expand Up @@ -383,7 +376,11 @@ function _extractLapisData<T>(response: LapisResponse<T>): T {
if (currentLapisDataVersion === undefined) {
currentLapisDataVersion = response.info.dataVersion;
} else if (currentLapisDataVersion !== response.info.dataVersion) {
// Refresh the website if there are new data
console.log(
`LAPIS has new data. Old version: ${currentLapisDataVersion}, new version: ${response.info.dataVersion}. ` +
`The website will be reloaded.`
);

window.location.reload();
throw new Error(
`LAPIS has new data. Old version: ${currentLapisDataVersion}, new version: ${response.info.dataVersion}. ` +
Expand Down

0 comments on commit c77e673

Please sign in to comment.