From b31e9762831355e40addf2e54cd4ec1884aa357b Mon Sep 17 00:00:00 2001 From: Alvaro Bautista <67112345+alvrba@users.noreply.github.com> Date: Fri, 26 Aug 2022 15:34:44 +0200 Subject: [PATCH] refactor: include s3Url file source --- src/api/item.ts | 19 +++++++++++++++++++ src/hooks/item.ts | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/api/item.ts b/src/api/item.ts index 9f614561..c0d20a1b 100644 --- a/src/api/item.ts +++ b/src/api/item.ts @@ -248,6 +248,25 @@ export const getFileContent = async ( }), ); +export const getFileContentWithUrl = async ( + { id, replyUrl }: { id: UUID, replyUrl: boolean }, + { API_HOST }: QueryClientConfig, +) => + fallbackToPublic( + () => + axios.get(`${API_HOST}/${buildDownloadFilesRoute(id)}`, { + params: { + replyUrl + }, + }).then(({ data }) => data), + () => + axios.get(`${API_HOST}/${buildPublicDownloadFilesRoute(id)}`, { + params: { + replyUrl + }, + }), + ); + export const getRecycledItems = async ({ API_HOST }: QueryClientConfig) => verifyAuthentication(() => axios diff --git a/src/hooks/item.ts b/src/hooks/item.ts index 47335535..21c7ca6e 100644 --- a/src/hooks/item.ts +++ b/src/hooks/item.ts @@ -332,7 +332,7 @@ export default ( useFileContent: ( id?: UUID, - { enabled = true }: { enabled?: boolean } = {}, + { enabled = true, replyUrl }: { enabled?: boolean, replyUrl?: boolean } = {}, ) => useQuery({ queryKey: buildFileContentKey(id), @@ -340,6 +340,9 @@ export default ( if (!id) { throw new UndefinedArgument(); } + if (replyUrl) { + return Api.getFileContentWithUrl({ id, replyUrl }, queryConfig).then((data) => convertJs(data)); + }; return Api.getFileContent({ id }, queryConfig).then((data) => data); }, enabled: Boolean(id) && enabled,