Skip to content

Commit

Permalink
refactor: include s3Url file source
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrba committed Sep 13, 2022
1 parent ee8d8a8 commit b31e976
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/api/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,17 @@ export default (

useFileContent: (
id?: UUID,
{ enabled = true }: { enabled?: boolean } = {},
{ enabled = true, replyUrl }: { enabled?: boolean, replyUrl?: boolean } = {},
) =>
useQuery({
queryKey: buildFileContentKey(id),
queryFn: () => {
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,
Expand Down

0 comments on commit b31e976

Please sign in to comment.