feat: finish api package

This commit is contained in:
Adrian Castro
2024-04-18 17:34:40 +02:00
parent 4f833bee46
commit 3fb2567ae1
12 changed files with 615 additions and 82 deletions

View File

@@ -0,0 +1,55 @@
import { ofetch } from "ofetch";
import type {
AccountWithToken,
BookmarkInput,
BookmarkMediaItem,
BookmarkResponse,
} from "./types";
import { getAuthHeaders } from "./auth";
export function bookmarkMediaToInput(
tmdbId: string,
item: BookmarkMediaItem,
): BookmarkInput {
return {
meta: {
title: item.title,
type: item.type,
poster: item.poster,
year: item.year ?? 0,
},
tmdbId,
};
}
export async function addBookmark(
url: string,
account: AccountWithToken,
input: BookmarkInput,
) {
return ofetch<BookmarkResponse>(
`/users/${account.userId}/bookmarks/${input.tmdbId}`,
{
method: "POST",
headers: getAuthHeaders(account.token),
baseURL: url,
body: input,
},
);
}
export async function removeBookmark(
url: string,
account: AccountWithToken,
id: string,
) {
return ofetch<{ tmdbId: string }>(
`/users/${account.userId}/bookmarks/${id}`,
{
method: "DELETE",
headers: getAuthHeaders(account.token),
baseURL: url,
},
);
}