26 lines
862 B
TypeScript
26 lines
862 B
TypeScript
import type { BookFile } from '../types'
|
|
|
|
export function fetchBookFiles(bookId: number): Promise<BookFile[]> {
|
|
return fetch(`/api/books/${bookId}/files`).then(r => r.json())
|
|
}
|
|
|
|
export function fetchUnmatchedFiles(): Promise<BookFile[]> {
|
|
return fetch('/api/files?unmatched=true').then(r => r.json())
|
|
}
|
|
|
|
export function assignFile(id: number, bookId: number | null, editionId: number | null): Promise<BookFile> {
|
|
return fetch(`/api/files/${id}`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ bookId, editionId }),
|
|
}).then(r => r.json())
|
|
}
|
|
|
|
export function deleteFile(id: number): Promise<void> {
|
|
return fetch(`/api/files/${id}`, { method: 'DELETE' }).then(() => undefined)
|
|
}
|
|
|
|
export function triggerScan(): Promise<void> {
|
|
return fetch('/api/scan', { method: 'POST' }).then(() => undefined)
|
|
}
|