enhanced book backend

This commit is contained in:
2025-12-03 21:43:19 +01:00
parent 920ce19cc2
commit bf27d173e9
5 changed files with 53 additions and 37 deletions

View File

@@ -6,6 +6,14 @@ const itemsPerPage = 12;
let extensionName = null;
let bookSlug = null;
function getBookUrl(id, source = 'anilist') {
return `/api/book/${id}?source=${source}`;
}
function getChaptersUrl(id, source = 'anilist') {
return `/api/book/${id}/chapters?source=${source}`;
}
async function init() {
try {
const path = window.location.pathname;
@@ -24,9 +32,10 @@ async function init() {
const idForFetch = currentBookId;
const fetchUrl = extensionName
? `/api/book/${idForFetch}?ext=${extensionName}`
: `/api/book/${idForFetch}`;
const fetchUrl = getBookUrl(
idForFetch,
extensionName || 'anilist'
);
const res = await fetch(fetchUrl);
const data = await res.json();
@@ -129,9 +138,10 @@ async function loadChapters(idForFetch) {
try {
const fetchUrl = extensionName
? `/api/book/${idForFetch}/chapters?ext=${extensionName}`
: `/api/book/${idForFetch}/chapters`;
const fetchUrl = getChaptersUrl(
idForFetch,
extensionName || 'anilist'
);
const res = await fetch(fetchUrl);
const data = await res.json();
@@ -174,7 +184,7 @@ function populateProviderFilter() {
if (providers.length > 0) {
select.style.display = 'inline-block';
select.innerHTML = '';
select.innerHTML = '<option value="all">All Providers</option>';
providers.forEach(prov => {
const opt = document.createElement('option');
@@ -236,7 +246,7 @@ function renderTable(idForFetch) {
<td>${ch.title || 'Chapter ' + ch.number}</td>
<td><span class="pill" style="font-size:0.75rem;">${ch.provider}</span></td>
<td>
<button class="read-btn-small" onclick="openReader('${bookId}', '${realIndex}', '${ch.provider}')">
<button class="read-btn-small" onclick="openReader('${bookId}', '${ch.index}', '${ch.provider}')">
Read
</button>
</td>
@@ -276,8 +286,8 @@ function updatePagination() {
function openReader(bookId, chapterId, provider) {
const c = encodeURIComponent(chapterId);
const p = encodeURIComponent(provider);
let extension = "";
if (extensionName) extension = "?" + extensionName;
let extension = "?source=anilist";
if (extensionName) extension = "?source=" + extensionName;
window.location.href = `/read/${p}/${c}/${bookId}${extension}`;
}