Skip to content

Commit

Permalink
chore: update returned attachement fullPath (#9516)
Browse files Browse the repository at this point in the history
### Solution

fullPath prop on attachement (when returned by backend) is updated to
'domain + path' (formerly 'path').

Consequently, getFileAbsoluteURI util in front is removed.

closes #8763

---------

Co-authored-by: etiennejouan <[email protected]>
  • Loading branch information
etiennejouan and etiennejou authored Jan 9, 2025
1 parent 4c8c338 commit 1f1cac3
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ export const ActivityRichTextEditor = ({
}, [activity]);

const handleEditorBuiltInUploadFile = async (file: File) => {
const { attachementAbsoluteURL } = await handleUploadAttachment(file);
const { attachmentAbsoluteURL } = await handleUploadAttachment(file);

return attachementAbsoluteURL;
return attachmentAbsoluteURL;
};

const editor = useCreateBlockNote({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { useMemo, useState } from 'react';
import { IconCalendar, OverflowingTextWithTooltip } from 'twenty-ui';

import { formatToHumanReadableDate } from '~/utils/date-utils';
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';
import { getFileNameAndExtension } from '~/utils/file/getFileNameAndExtension';

const StyledLeftContent = styled.div`
Expand Down Expand Up @@ -139,8 +138,9 @@ export const AttachmentRow = ({ attachment }: { attachment: Attachment }) => {
) : (
<StyledLinkContainer>
<StyledLink
href={getFileAbsoluteURI(attachment.fullPath)}
target="__blank"
href={attachment.fullPath}
target="_blank"
rel="noopener noreferrer"
>
<OverflowingTextWithTooltip text={attachment.name} />
</StyledLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSi
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
import { isNonEmptyString } from '@sniptt/guards';
import { FileFolder, useUploadFileMutation } from '~/generated/graphql';
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';

// Note: This is probably not the right way to do this.
export const computePathWithoutToken = (attachmentPath: string): string => {
Expand Down Expand Up @@ -56,11 +55,9 @@ export const useUploadAttachmentFile = () => {
updatedAt: new Date().toISOString(),
} as Partial<Attachment>;

await createOneAttachment(attachmentToCreate);
const createdAttachment = await createOneAttachment(attachmentToCreate);

const attachementAbsoluteURL = getFileAbsoluteURI(attachmentPath);

return { attachementAbsoluteURL };
return { attachmentAbsoluteURL: createdAttachment.fullPath };
};

return { uploadAttachmentFile };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ window.URL.revokeObjectURL = jest.fn();
describe.skip('downloadFile', () => {
it('should download a file', () => {
// Call downloadFile
downloadFile('path/to/file.pdf', 'file.pdf');
downloadFile('url/to/file.pdf', 'file.pdf');

// Assert on fetch
expect(fetch).toHaveBeenCalledWith(
process.env.REACT_APP_SERVER_BASE_URL + '/files/path/to/file.pdf',
);
expect(fetch).toHaveBeenCalledWith('url/to/file.pdf');

// Assert on element creation
const link = document.querySelector(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { saveAs } from 'file-saver';
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';

export const downloadFile = (fullPath: string, fileName: string) => {
fetch(getFileAbsoluteURI(fullPath))
fetch(fullPath)
.then((resp) =>
resp.status === 200
? resp.blob()
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions packages/twenty-front/src/utils/file/getFileAbsoluteURI.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class AttachmentQueryResultGetterHandler

return {
...attachment,
fullPath: `${attachment.fullPath}?token=${signedPayload}`,
fullPath: `${process.env.SERVER_URL}/files/${attachment.fullPath}?token=${signedPayload}`,
};
}
}

0 comments on commit 1f1cac3

Please sign in to comment.