mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
refactor: improve file browser path resolution and navigation (#193)
- Add query parameter support for file paths to handle special characters - Enable navigation above base path with proper validation - Centralize URL encoding logic for file API calls - Update path validation to use workspace base instead of repos base - Add normalizePath utility for consistent path handling
This commit is contained in:
1 parent
40a2af7521
commit
31755c23f8
10 files changed
+153
-50
No files matched your search
@@ -3,8 +3,16 @@ import { fetchWrapper, fetchWrapperBlob } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { FileInfo, ChunkedFileInfo, PatchOperation } from '@/types/files'
|
||||
|
||||
function getFileApiUrl(path: string): string {
|
||||
if (path.includes('..')) {
|
||||
return `${API_BASE_URL}/api/files/?path=${encodeURIComponent(path)}`
|
||||
}
|
||||
|
||||
return `${API_BASE_URL}/api/files/${path.split('/').map(encodeURIComponent).join('/')}`
|
||||
}
|
||||
|
||||
async function fetchFile(path: string): Promise<FileInfo> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/files/${path}`)
|
||||
return fetchWrapper(getFileApiUrl(path))
|
||||
}
|
||||
|
||||
export function useFile(path: string | undefined) {
|
||||
@@ -16,13 +24,13 @@ export function useFile(path: string | undefined) {
|
||||
}
|
||||
|
||||
export async function fetchFileRange(path: string, startLine: number, endLine: number): Promise<ChunkedFileInfo> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/files/${path}`, {
|
||||
return fetchWrapper(getFileApiUrl(path), {
|
||||
params: { startLine, endLine },
|
||||
})
|
||||
}
|
||||
|
||||
export async function applyFilePatches(path: string, patches: PatchOperation[]): Promise<{ success: boolean; totalLines: number }> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/files/${path}`, {
|
||||
return fetchWrapper(getFileApiUrl(path), {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ patches }),
|
||||
|
||||
Reference in new issue
Block a user