From 432a40497b95d418c0c65c12bf4e55ff0fc671e1 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 16 May 2024 15:46:58 +0800 Subject: [PATCH] fix: wrong base url in the api request --- src/api.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api.ts b/src/api.ts index 6797c90..8f1f1b0 100644 --- a/src/api.ts +++ b/src/api.ts @@ -16,13 +16,15 @@ interface GetContentResponse { }[] } +const baseUrl = (endpoint: string) => endpoint.replace(/\/api\/graphql$/, '') + const getContent = async ( endpoint: string, apiKey: string, libraryItemIds: string[], ): Promise => { const response = await requestUrl({ - url: `${endpoint}/api/content`, + url: `${baseUrl(endpoint)}/api/content`, method: 'POST', headers: { 'Content-Type': 'application/json', @@ -80,7 +82,7 @@ const fetchContentForItems = async ( item.content = await Promise.race([ downloadFromUrl(c.downloadUrl), new Promise( - (_, reject) => setTimeout(() => reject('Timeout'), 600_000), // 10 minutes + (_, reject) => setTimeout(() => reject('Timeout'), 60_000), // 60 seconds ), ]) }), @@ -99,7 +101,7 @@ export const getItems = async ( ): Promise<[Item[], boolean]> => { const omnivore = new Omnivore({ authToken: apiKey, - baseUrl: endpoint, + baseUrl: baseUrl(endpoint), timeoutMs: 10000, // 10 seconds }) @@ -130,7 +132,7 @@ export const deleteItem = async ( ) => { const omnivore = new Omnivore({ authToken: apiKey, - baseUrl: endpoint, + baseUrl: baseUrl(endpoint), timeoutMs: 10000, // 10 seconds })