mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 16: Phase 16: Documentation, container ports and full repository checks
This commit is contained in:
1 parent
81a9f0c8ef
commit
a383e57bc5
55 files changed
+4095
-59
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import type { CreatePreviewSessionResponse, PreviewPortsResponse } from '@opencode-manager/shared/types'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
|
||||
function directoryQuery(directory: string | undefined): string {
|
||||
return directory ? `?${new URLSearchParams({ directory }).toString()}` : ''
|
||||
}
|
||||
|
||||
export function previewPortsQueryKey(directory: string | undefined) {
|
||||
return ['previewPorts', directory ?? null] as const
|
||||
}
|
||||
|
||||
export function listPreviewPorts(directory?: string): Promise<PreviewPortsResponse> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/preview/ports${directoryQuery(directory)}`)
|
||||
}
|
||||
|
||||
export function createPreviewSession(port: number): Promise<CreatePreviewSessionResponse> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/preview/sessions`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ port }),
|
||||
})
|
||||
}
|
||||
|
||||
export interface UsePreviewPortsOptions {
|
||||
enabled: boolean
|
||||
refetchInterval?: number | false
|
||||
}
|
||||
|
||||
export function usePreviewPorts(directory: string | undefined, options: UsePreviewPortsOptions) {
|
||||
return useQuery({
|
||||
queryKey: previewPortsQueryKey(directory),
|
||||
queryFn: () => listPreviewPorts(directory),
|
||||
enabled: options.enabled,
|
||||
refetchInterval: options.refetchInterval,
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user