Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed api route for download file and view raw file #677

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = `/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 = `/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