60 lines
1.1 KiB
TypeScript
60 lines
1.1 KiB
TypeScript
import { ofetch } from 'ofetch';
|
|
|
|
export const komga = ofetch.create({
|
|
baseURL: new URL('/api', Deno.env.get('BASE_URL')!).href,
|
|
headers: {
|
|
'X-API-Key': Deno.env.get('API_KEY')!,
|
|
},
|
|
});
|
|
|
|
export const fetchLibraryMangas = async (
|
|
libraryId: string
|
|
): Promise<Record<string, any>[]> => {
|
|
const { content } = await komga('/v1/series/list', {
|
|
method: 'POST',
|
|
query: {
|
|
unpaged: true,
|
|
},
|
|
body: {
|
|
condition: {
|
|
libraryId: {
|
|
operator: 'is',
|
|
value: libraryId,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return content;
|
|
};
|
|
|
|
export const fetchMangaChapters = async (
|
|
seriesId: string
|
|
): Promise<Record<string, any>[]> => {
|
|
const { content } = await komga('/v1/books/list', {
|
|
method: 'POST',
|
|
query: {
|
|
unpaged: true,
|
|
},
|
|
body: {
|
|
condition: {
|
|
seriesId: {
|
|
operator: 'is',
|
|
value: seriesId,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return content;
|
|
};
|
|
|
|
export const updateMetadata = (
|
|
id: string,
|
|
body: Record<string, unknown>
|
|
): Promise<void> =>
|
|
komga(`/v1/books/${id}/metadata`, {
|
|
method: 'PATCH',
|
|
body,
|
|
});
|