Skip to content

The open alternative to Salesforce, designed for AI.

chore: update returned attachement fullPath (#9516)

Etienne1f1cac3b00f8
diff --git a/packages/twenty-front/src/modules/activities/components/ActivityRichTextEditor.tsx b/packages/twenty-front/src/modules/activities/components/ActivityRichTextEditor.tsx
index 24b6045905d..a39d230d8a2 100644
--- a/packages/twenty-front/src/modules/activities/components/ActivityRichTextEditor.tsx
+++ b/packages/twenty-front/src/modules/activities/components/ActivityRichTextEditor.tsx
@@ -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({
diff --git a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
index f0eca529d76..18f59b8ce00 100644
--- a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
+++ b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
@@ -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`
@@ -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>
diff --git a/packages/twenty-front/src/modules/activities/files/hooks/useUploadAttachmentFile.tsx b/packages/twenty-front/src/modules/activities/files/hooks/useUploadAttachmentFile.tsx
index bbd8d6152af..46c71f19461 100644
--- a/packages/twenty-front/src/modules/activities/files/hooks/useUploadAttachmentFile.tsx
+++ b/packages/twenty-front/src/modules/activities/files/hooks/useUploadAttachmentFile.tsx
@@ -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 => {
@@ -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 };
diff --git a/packages/twenty-front/src/modules/activities/files/utils/__tests__/downloadFile.test.ts b/packages/twenty-front/src/modules/activities/files/utils/__tests__/downloadFile.test.ts
index b25fae0e7c3..2261b584e36 100644
--- a/packages/twenty-front/src/modules/activities/files/utils/__tests__/downloadFile.test.ts
+++ b/packages/twenty-front/src/modules/activities/files/utils/__tests__/downloadFile.test.ts
@@ -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(
diff --git a/packages/twenty-front/src/modules/activities/files/utils/downloadFile.ts b/packages/twenty-front/src/modules/activities/files/utils/downloadFile.ts
index af64fed4e22..bdc5ed0fab9 100644
--- a/packages/twenty-front/src/modules/activities/files/utils/downloadFile.ts
+++ b/packages/twenty-front/src/modules/activities/files/utils/downloadFile.ts
@@ -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()
diff --git a/packages/twenty-front/src/utils/file/__tests__/getFileAbsoluteURI.test.ts b/packages/twenty-front/src/utils/file/__tests__/getFileAbsoluteURI.test.ts
deleted file mode 100644
index 01a75cecaa9..00000000000
--- a/packages/twenty-front/src/utils/file/__tests__/getFileAbsoluteURI.test.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { getFileAbsoluteURI } from '../getFileAbsoluteURI';
-import { REACT_APP_SERVER_BASE_URL } from '~/config';
-
-describe('getFileAbsoluteURI', () => {
- test('should return absolute uri', () => {
- expect(getFileAbsoluteURI('foo')).toEqual(
- `${REACT_APP_SERVER_BASE_URL}/files/foo`,
- );
- });
-});
diff --git a/packages/twenty-front/src/utils/file/getFileAbsoluteURI.ts b/packages/twenty-front/src/utils/file/getFileAbsoluteURI.ts
deleted file mode 100644
index f3777e38a92..00000000000
--- a/packages/twenty-front/src/utils/file/getFileAbsoluteURI.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { REACT_APP_SERVER_BASE_URL } from '~/config';
-
-export const getFileAbsoluteURI = (fileUrl?: string) => {
- return `${REACT_APP_SERVER_BASE_URL}/files/${fileUrl}`;
-};
diff --git a/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/handlers/attachment-query-result-getter.handler.ts b/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/handlers/attachment-query-result-getter.handler.ts
index 794657c7d26..87f9b413532 100644
--- a/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/handlers/attachment-query-result-getter.handler.ts
+++ b/packages/twenty-server/src/engine/api/graphql/workspace-query-runner/factories/query-result-getters/handlers/attachment-query-result-getter.handler.ts
@@ -23,7 +23,7 @@ export class AttachmentQueryResultGetterHandler
return {
...attachment,
- fullPath: `${attachment.fullPath}?token=${signedPayload}`,
+ fullPath: `${process.env.SERVER_URL}/files/${attachment.fullPath}?token=${signedPayload}`,
};
}
}