mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 14:43:25 +00:00
feat: finish api package
This commit is contained in:
55
packages/api/src/bookmarks.ts
Normal file
55
packages/api/src/bookmarks.ts
Normal 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,
|
||||
},
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user