enhanced book backend
This commit is contained in:
@@ -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}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,10 +126,15 @@ async function loadChapter() {
|
||||
</div>
|
||||
`;
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
let source = urlParams.get('source');
|
||||
if (!source) {
|
||||
source = 'anilist';
|
||||
}
|
||||
const newEndpoint = `/api/book/${bookId}/${chapter}/${provider}?source=${source}`;
|
||||
|
||||
try {
|
||||
let ext = ""
|
||||
if(hasQuery) ext = "?ext=yes"
|
||||
const res = await fetch(`/api/book/${bookId}/${chapter}/${provider}${ext}`);
|
||||
const res = await fetch(newEndpoint);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.title) {
|
||||
@@ -480,12 +485,13 @@ document.getElementById('back-btn').addEventListener('click', () => {
|
||||
const provider = parts[2];
|
||||
const mangaId = parts[4];
|
||||
|
||||
const isInt = Number.isInteger(Number(mangaId));
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
let source = urlParams.get('source');
|
||||
|
||||
if (isInt) {
|
||||
if (!source) {
|
||||
window.location.href = `/book/${mangaId}`;
|
||||
} else {
|
||||
window.location.href = `/book/${provider}/${mangaId}`;
|
||||
window.location.href = `/book/${source}/${mangaId}`;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user