Skip to content

Commit

Permalink
Handled api routes based on isMFE flag
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-harness committed Jan 15, 2025
1 parent a8cc11b commit da7faa3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apps/gitness/src/components-v2/file-content-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useRoutes } from '../framework/context/NavigationContext'
import { useThemeStore } from '../framework/context/ThemeContext'
import { useDownloadRawFile } from '../framework/hooks/useDownloadRawFile'
import { useGetRepoRef } from '../framework/hooks/useGetRepoPath'
import { useIsMFE } from '../framework/hooks/useIsMFE'
import useCodePathDetails from '../hooks/useCodePathDetails'
import { themes } from '../pages-v2/pipeline/pipeline-edit/theme/monaco-theme'
import { useRepoBranchesStore } from '../pages-v2/repo/stores/repo-branches-store'
Expand All @@ -33,6 +34,7 @@ interface FileContentViewerProps {
export default function FileContentViewer({ repoContent }: FileContentViewerProps) {
const routes = useRoutes()
const { spaceId, repoId } = useParams<PathParams>()
const isMFE = useIsMFE()
const fileName = repoContent?.name || ''
const language = filenameToLanguage(fileName) || ''
const fileContent = decodeGitContent(repoContent?.content?.data)
Expand All @@ -41,7 +43,7 @@ export default function FileContentViewer({ repoContent }: FileContentViewerProp
const parentPath = fullResourcePath?.split(FILE_SEPERATOR).slice(0, -1).join(FILE_SEPERATOR)
const downloadFile = useDownloadRawFile()
const navigate = useNavigate()
const rawURL = `/code/api/v1/repos/${repoRef}/raw/${fullResourcePath}?git_ref=${fullGitRef}`
const rawURL = `${isMFE ? '/code' : ''}/api/v1/repos/${repoRef}/raw/${fullResourcePath}?git_ref=${fullGitRef}`
const [view, setView] = useState<ViewTypeValue>(getDefaultView(language))
const [isDeleteFileDialogOpen, setIsDeleteFileDialogOpen] = useState(false)
const { selectedBranchTag } = useRepoBranchesStore()
Expand Down
5 changes: 4 additions & 1 deletion apps/gitness/src/framework/hooks/useDownloadRawFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useCallback } from 'react'

import { useMutation } from '@tanstack/react-query'

import { useIsMFE } from './useIsMFE'

interface UseDownloadRawFileParams {
repoRef: string
resourcePath: string
Expand All @@ -10,8 +12,9 @@ interface UseDownloadRawFileParams {
}

export function useDownloadRawFile() {
const isMFE = useIsMFE()
const mutation = useMutation(async ({ repoRef, resourcePath, gitRef }: UseDownloadRawFileParams) => {
const url = `/code/api/v1/repos/${repoRef}/raw/${resourcePath}?git_ref=${gitRef ?? ''}`
const url = `${isMFE ? '/code' : ''}/api/v1/repos/${repoRef}/raw/${resourcePath}?git_ref=${gitRef ?? ''}`

const response = await fetch(url)
if (!response.ok) {
Expand Down

0 comments on commit da7faa3

Please sign in to comment.