diff options
Diffstat (limited to 'makima/frontend/src/lib/api.ts')
| -rw-r--r-- | makima/frontend/src/lib/api.ts | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/makima/frontend/src/lib/api.ts b/makima/frontend/src/lib/api.ts index a6f6c3e..ec596ce 100644 --- a/makima/frontend/src/lib/api.ts +++ b/makima/frontend/src/lib/api.ts @@ -38,3 +38,105 @@ export const LISTEN_ENDPOINT = `${WS_BASE}/api/v1/listen`; export function getEnvironment(): Environment { return env; } + +// File API types +export interface TranscriptEntry { + id: string; + speaker: string; + start: number; + end: number; + text: string; + isFinal: boolean; +} + +export interface FileSummary { + id: string; + name: string; + description: string | null; + transcriptCount: number; + duration: number | null; + createdAt: string; + updatedAt: string; +} + +export interface FileDetail { + id: string; + ownerId: string; + name: string; + description: string | null; + transcript: TranscriptEntry[]; + location: string | null; + createdAt: string; + updatedAt: string; +} + +export interface FileListResponse { + files: FileSummary[]; + total: number; +} + +export interface CreateFileRequest { + name?: string; + description?: string; + transcript: TranscriptEntry[]; + location?: string; +} + +export interface UpdateFileRequest { + name?: string; + description?: string; + transcript?: TranscriptEntry[]; +} + +// File API functions +export async function listFiles(): Promise<FileListResponse> { + const res = await fetch(`${API_BASE}/api/v1/files`); + if (!res.ok) { + throw new Error(`Failed to list files: ${res.statusText}`); + } + return res.json(); +} + +export async function getFile(id: string): Promise<FileDetail> { + const res = await fetch(`${API_BASE}/api/v1/files/${id}`); + if (!res.ok) { + throw new Error(`Failed to get file: ${res.statusText}`); + } + return res.json(); +} + +export async function createFile(data: CreateFileRequest): Promise<FileDetail> { + const res = await fetch(`${API_BASE}/api/v1/files`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }); + if (!res.ok) { + throw new Error(`Failed to create file: ${res.statusText}`); + } + return res.json(); +} + +export async function updateFile( + id: string, + data: UpdateFileRequest +): Promise<FileDetail> { + const res = await fetch(`${API_BASE}/api/v1/files/${id}`, { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data), + }); + if (!res.ok) { + throw new Error(`Failed to update file: ${res.statusText}`); + } + return res.json(); +} + +export async function deleteFile(id: string): Promise<void> { + const res = await fetch(`${API_BASE}/api/v1/files/${id}`, { + method: "DELETE", + }); + if (!res.ok) { + throw new Error(`Failed to delete file: ${res.statusText}`); + } +} |
