fix: [CODE-3459] Raw URL for LFS files in non standalone (#3627)

* ui lints prettier
* ui lint fix
* ui: fix raw url on lfs files
main
Atefeh Mohseni Ejiyeh 2025-04-04 00:48:14 +00:00 committed by Harness
parent 970a9e8a04
commit 808a9b5847
2 changed files with 10 additions and 23 deletions

View File

@ -61,7 +61,6 @@ import { useAppContext } from 'AppContext'
import { LatestCommitForFile } from 'components/LatestCommit/LatestCommit'
import { useCommitModal } from 'components/CommitModalButton/CommitModalButton'
import { useStrings } from 'framework/strings'
import { getConfig } from 'services/config'
import { OptionsMenuButton } from 'components/OptionsMenuButton/OptionsMenuButton'
import { PlainButton } from 'components/PlainButton/PlainButton'
import { CommitsView } from 'components/CommitsView/CommitsView'
@ -210,10 +209,6 @@ export function FileContent({
}
}
const fullRawURL = standalone
? `${window.location.origin}${rawURL.replace(/^\/code/, '')}`
: `${window.location.origin}${getConfig(rawURL)}`.replace('//', '/')
return (
<Container className={css.tabsContainer} ref={ref}>
<Tabs
@ -285,9 +280,7 @@ export function FileContent({
iconName: 'arrow-right',
text: getString('viewRaw'),
onClick: () => {
const url = standalone
? rawURL.replace(/^\/code/, '')
: getConfig(rawURL).replace('//', '/')
const url = rawURL
window.open(url, '_blank')
}
},
@ -427,9 +420,7 @@ export function FileContent({
<Match expr={category}>
<Case val={FileCategory.SVG}>
<img
src={
isFileLFS ? `${fullRawURL}` : `data:image/svg+xml;base64,${base64Data}`
}
src={isFileLFS ? `${rawURL}` : `data:image/svg+xml;base64,${base64Data}`}
alt={filename}
style={{ maxWidth: '100%', maxHeight: '100%' }}
/>
@ -437,9 +428,7 @@ export function FileContent({
<Case val={FileCategory.IMAGE}>
<img
src={
isFileLFS
? `${fullRawURL}`
: `data:image/${extension};base64,${base64Data}`
isFileLFS ? `${rawURL}` : `data:image/${extension};base64,${base64Data}`
}
alt={filename}
style={{ maxWidth: '100%', maxHeight: '100%' }}
@ -447,7 +436,7 @@ export function FileContent({
</Case>
<Case val={FileCategory.PDF}>
<Document
file={isFileLFS ? fullRawURL : `data:application/pdf;base64,${base64Data}`}
file={isFileLFS ? rawURL : `data:application/pdf;base64,${base64Data}`}
options={{
// TODO: Configure this to use a local worker/webpack loader
cMapUrl: `https://unpkg.com/pdfjs-dist@${pdfjs.version}/cmaps/`,
@ -469,18 +458,14 @@ export function FileContent({
<Case val={FileCategory.AUDIO}>
<audio controls>
<source
src={
isFileLFS ? fullRawURL : `data:audio/${extension};base64,${base64Data}`
}
src={isFileLFS ? rawURL : `data:audio/${extension};base64,${base64Data}`}
/>
</audio>
</Case>
<Case val={FileCategory.VIDEO}>
<video controls height={500}>
<source
src={
isFileLFS ? fullRawURL : `data:video/${extension};base64,${base64Data}`
}
src={isFileLFS ? rawURL : `data:video/${extension};base64,${base64Data}`}
/>
</video>
</Case>
@ -488,7 +473,7 @@ export function FileContent({
<SourceCodeViewer
editorDidMount={onEditorMount}
language={filenameToLanguage(filename)}
source={isFileLFS ? fullRawURL : decodeGitContent(base64Data)}
source={isFileLFS ? rawURL : decodeGitContent(base64Data)}
/>
</Case>
<Case val={FileCategory.SUBMODULE}>

View File

@ -18,6 +18,7 @@ import { useMemo } from 'react'
import { pdfjs } from 'react-pdf'
import { useAppContext } from 'AppContext'
import type { RepoFileContent } from 'services/code'
import { getConfig } from 'services/config'
import type { GitInfoProps } from './GitUtils'
// TODO: Configure this to use a local worker/webpack loader
@ -105,7 +106,8 @@ export function useFileContentViewerDecision({
resourceData?.lfs_object_size > MAX_VIEWABLE_FILE_SIZE
: resourceData?.data_size && resourceData?.size && resourceData?.data_size !== resourceData?.size) || false
const rawURL = `/code/api/v1/repos/${repoMetadata?.path}/+/raw/${resourcePath}?routingId=${routingId}&git_ref=${gitRef}`
const base = getConfig('code/api/v1')
const rawURL = `${base}/repos/${repoMetadata?.path}/+/raw/${resourcePath}?routingId=${routingId}&git_ref=${gitRef}`
return {
category,