fixed some formatting and added komga integration stuff
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { getLatestPlaylistSong, getLatestWatchedSeries } from '#lib/server/jellyfin';
|
||||
import { JELLYFIN_PLAYLIST_ID, JELLYFIN_LIBRARY_ID } from '$app/env/private';
|
||||
import { getLatestBook } from '#lib/server/komga';
|
||||
import { JELLYFIN_PLAYLIST_ID, JELLYFIN_LIBRARY_ID, KOMGA_LIBRARY_ID } from '$app/env/private';
|
||||
|
||||
export const load: PageServerLoad = () => {
|
||||
const latestSong = getLatestPlaylistSong(globalThis.fetch, JELLYFIN_PLAYLIST_ID);
|
||||
console.log(JELLYFIN_LIBRARY_ID);
|
||||
const latestSeries = getLatestWatchedSeries(globalThis.fetch, JELLYFIN_LIBRARY_ID);
|
||||
const latestBook = getLatestBook(globalThis.fetch, KOMGA_LIBRARY_ID);
|
||||
|
||||
latestSong.catch(() => {});
|
||||
latestSeries.catch(() => {});
|
||||
latestBook.catch(() => {});
|
||||
|
||||
return {
|
||||
streamed: {
|
||||
latestSong,
|
||||
latestSeries
|
||||
latestSeries,
|
||||
latestBook
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -108,7 +108,46 @@
|
||||
<p>{error}</p>
|
||||
{/await}
|
||||
</div>
|
||||
<div class="sub-container" style="--container-color:var(--ctp-red);">reading</div>
|
||||
<div
|
||||
class="sub-container flex items-center gap-3 overflow-hidden pr-3"
|
||||
style="--container-color:var(--ctp-red);"
|
||||
>
|
||||
{#await data.streamed.latestBook}
|
||||
<p>Loading Latest Book...</p>
|
||||
{:then book}
|
||||
<img
|
||||
src={book.coverArt}
|
||||
class="aspect-1/1 h-full w-auto shrink-0 object-contain"
|
||||
alt=""
|
||||
/>
|
||||
<div class="flex min-w-0 flex-col justify-center">
|
||||
<p class="fira-mono-medium">Currently Reading…</p>
|
||||
<div
|
||||
id="music-title-block"
|
||||
onclick={() =>
|
||||
window.open(
|
||||
`https://bookbrainz.org/search?q=${book.series} ${book.number}`,
|
||||
'_blank'
|
||||
)}
|
||||
style="cursor: pointer;"
|
||||
role="link"
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
}
|
||||
}}
|
||||
tabindex="0"
|
||||
class="pl-2"
|
||||
>
|
||||
<p class="fira-mono-bold w-full truncate text-2xl">
|
||||
{book.series}
|
||||
</p>
|
||||
<p class="fira-mono-medium w-full truncate text-xl">
|
||||
v{book.number} p{book.currentPage}/{book.totalPages}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{/await}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-[4fr_3fr] grid-rows-1 gap-4">
|
||||
|
||||
32
src/routes/books/[bookId]/+server.ts
Normal file
32
src/routes/books/[bookId]/+server.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
import { KOMGA_URL, KOMGA_API_KEY } from '$app/env/private';
|
||||
|
||||
export const GET: RequestHandler = async ({ params, fetch }) => {
|
||||
const { bookId } = params;
|
||||
|
||||
if (!/^[a-zA-Z0-9-]+$/.test(bookId)) {
|
||||
error(400, 'Invalid book ID');
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${KOMGA_URL}/api/v1/books/${encodeURIComponent(bookId)}/thumbnail`,
|
||||
{
|
||||
headers: {
|
||||
'X-API-Key': KOMGA_API_KEY
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
error(response.status, 'Book cover unavailable');
|
||||
}
|
||||
|
||||
return new Response(response.body, {
|
||||
headers: {
|
||||
'Content-Type': response.headers.get('Content-Type') ?? 'image/jpeg',
|
||||
'Cache-Control': 'private, max-age=3600'
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user