fix attachment upload (#6574)

## Context
UploadFile now returns the file token which we don't want when we save
the attachment in the DB due to its non-persistence so now the FE
removes the token query param before saving the attachment. This is most
likely not the right way to do it, we will need to refactor this part
before.

Also made sure we don't save the token in the DB for rich_text as well
and remove it before saving.
This commit is contained in:
Weiko
2024-08-07 19:34:57 +02:00
committed by GitHub
parent e265efcf90
commit 1b9f63b3ad
3 changed files with 49 additions and 4 deletions

View File

@ -139,6 +139,32 @@ export const RichTextEditor = ({
return getFileAbsoluteURI(result.data.uploadFile);
};
const prepareBody = (newStringifiedBody: string) => {
if (!newStringifiedBody) return newStringifiedBody;
const body = JSON.parse(newStringifiedBody);
const bodyWithSignedPayload = body.map((block: any) => {
if (block.type !== 'image' || !block.props.url) {
return block;
}
const imageProps = block.props;
const imageUrl = new URL(imageProps.url);
imageUrl.searchParams.delete('token');
return {
...block,
props: {
...imageProps,
url: `${imageUrl.toString()}`,
},
};
});
return JSON.stringify(bodyWithSignedPayload);
};
const handlePersistBody = useCallback(
(activityBody: string) => {
if (!canCreateActivity) {
@ -148,7 +174,7 @@ export const RichTextEditor = ({
if (!activityTitleHasBeenSet && fillTitleFromBody) {
updateTitleAndBody(activityBody);
} else {
persistBodyDebounced(activityBody);
persistBodyDebounced(prepareBody(activityBody));
}
},
[