summaryrefslogtreecommitdiff
path: root/makima/frontend/src/lib/api.ts
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2025-12-23 02:14:58 +0000
committersoryu <soryu@soryu.co>2025-12-23 14:47:18 +0000
commita32dc56d2e5447ef8988cb98b8686476cc94e70c (patch)
tree61307503c4af82103cea2360fe95d3ea324968d6 /makima/frontend/src/lib/api.ts
parent73649d135efccda7e446775db773e21b458de202 (diff)
downloadsoryu-a32dc56d2e5447ef8988cb98b8686476cc94e70c.tar.gz
soryu-a32dc56d2e5447ef8988cb98b8686476cc94e70c.zip
Add Postgres for persistence and File cabinet
Migrations are local only currently, and must be run manually by setting POSTGRES_CONNECTION_URI
Diffstat (limited to 'makima/frontend/src/lib/api.ts')
-rw-r--r--makima/frontend/src/lib/api.ts102
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}`);
+ }
+}