diff --git a/services/web/frontend/js/features/file-tree/util/path.ts b/services/web/frontend/js/features/file-tree/util/path.ts index d90e824a57..291c9775ab 100644 --- a/services/web/frontend/js/features/file-tree/util/path.ts +++ b/services/web/frontend/js/features/file-tree/util/path.ts @@ -3,6 +3,7 @@ import { FileTreeEntity } from '../../../../../types/file-tree-entity' import { Doc } from '../../../../../types/doc' import { FileRef } from '../../../../../types/file-ref' import { PreviewPath } from '../../../../../types/preview-path' +import { fileUrl } from '../../utils/fileUrl' type DocFindResult = { entity: Doc @@ -124,7 +125,7 @@ export function previewByPath( if (result?.type === 'fileRef') { const { name, _id: id, hash } = result.entity return { - url: `/project/${projectId}/blob/${hash}?fallback=${id}`, + url: fileUrl(projectId, id, hash), extension: name.slice(name.lastIndexOf('.') + 1), } } diff --git a/services/web/frontend/js/features/file-view/components/file-view-header.tsx b/services/web/frontend/js/features/file-view/components/file-view-header.tsx index 302037e38d..f6a9143661 100644 --- a/services/web/frontend/js/features/file-view/components/file-view-header.tsx +++ b/services/web/frontend/js/features/file-view/components/file-view-header.tsx @@ -3,6 +3,7 @@ import { Trans, useTranslation } from 'react-i18next' import Icon from '../../../shared/components/icon' import { formatTime, relativeDate } from '../../utils/format-date' +import { fileUrl } from '../../utils/fileUrl' import { useFileTreeData } from '@/shared/context/file-tree-data-context' import { useProjectContext } from '@/shared/context/project-context' @@ -84,7 +85,7 @@ export default function FileViewHeader({ file }: FileViewHeaderProps) { } diff --git a/services/web/frontend/js/features/file-view/components/file-view-image.tsx b/services/web/frontend/js/features/file-view/components/file-view-image.tsx index 990fb69add..62a1fd0159 100644 --- a/services/web/frontend/js/features/file-view/components/file-view-image.tsx +++ b/services/web/frontend/js/features/file-view/components/file-view-image.tsx @@ -1,5 +1,6 @@ import { useProjectContext } from '../../../shared/context/project-context' import { BinaryFile } from '@/features/file-view/types/binary-file' +import { fileUrl } from '../../utils/fileUrl' export default function FileViewImage({ file, @@ -11,10 +12,9 @@ export default function FileViewImage({ onError: () => void }) { const { _id: projectId } = useProjectContext() - return ( {file.name} fetchContentLengthController.abort(), 10000 diff --git a/services/web/frontend/js/features/utils/fileUrl.js b/services/web/frontend/js/features/utils/fileUrl.js new file mode 100644 index 0000000000..343b3b42c8 --- /dev/null +++ b/services/web/frontend/js/features/utils/fileUrl.js @@ -0,0 +1,10 @@ +// Helper function to compute the url for a file in history-v1 or filestore. +// This will be obsolete when the migration to history-v1 is complete. + +export function fileUrl(projectId, id, hash) { + if (hash) { + return `/project/${projectId}/blob/${hash}?fallback=${id}` + } else { + return `/project/${projectId}/file/${id}` + } +} diff --git a/services/web/test/frontend/features/file-view/components/file-view.test.jsx b/services/web/test/frontend/features/file-view/components/file-view.test.jsx index 390505dc16..be32d1fa4f 100644 --- a/services/web/test/frontend/features/file-view/components/file-view.test.jsx +++ b/services/web/test/frontend/features/file-view/components/file-view.test.jsx @@ -18,6 +18,7 @@ describe('', function () { source_entity_path: '/source-entity-path.ext', provider: 'project_file', }, + hash: '012345678901234567890123', created: new Date(2021, 1, 17, 3, 24).toISOString(), }