Fixed bundling into an exe not working as intended.
This commit is contained in:
140
electron/api/books/books.controller.js
Normal file
140
electron/api/books/books.controller.js
Normal file
@@ -0,0 +1,140 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getBook = getBook;
|
||||
exports.getTrending = getTrending;
|
||||
exports.getPopular = getPopular;
|
||||
exports.searchBooks = searchBooks;
|
||||
exports.searchBooksInExtension = searchBooksInExtension;
|
||||
exports.getChapters = getChapters;
|
||||
exports.getChapterContent = getChapterContent;
|
||||
const booksService = __importStar(require("./books.service"));
|
||||
const extensions_1 = require("../../shared/extensions");
|
||||
async function getBook(req, reply) {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const source = req.query.source;
|
||||
let book;
|
||||
if (source === 'anilist') {
|
||||
book = await booksService.getBookById(id);
|
||||
}
|
||||
else {
|
||||
const ext = (0, extensions_1.getExtension)(source);
|
||||
const result = await booksService.getBookInfoExtension(ext, id);
|
||||
book = result || null;
|
||||
}
|
||||
return book;
|
||||
}
|
||||
catch (err) {
|
||||
return { error: err.message };
|
||||
}
|
||||
}
|
||||
async function getTrending(req, reply) {
|
||||
try {
|
||||
const results = await booksService.getTrendingBooks();
|
||||
return { results };
|
||||
}
|
||||
catch (err) {
|
||||
return { results: [] };
|
||||
}
|
||||
}
|
||||
async function getPopular(req, reply) {
|
||||
try {
|
||||
const results = await booksService.getPopularBooks();
|
||||
return { results };
|
||||
}
|
||||
catch (err) {
|
||||
return { results: [] };
|
||||
}
|
||||
}
|
||||
async function searchBooks(req, reply) {
|
||||
try {
|
||||
const query = req.query.q;
|
||||
const dbResults = await booksService.searchBooksLocal(query);
|
||||
if (dbResults.length > 0) {
|
||||
return { results: dbResults };
|
||||
}
|
||||
console.log(`[Books] Local DB miss for "${query}", fetching live...`);
|
||||
const anilistResults = await booksService.searchBooksAniList(query);
|
||||
if (anilistResults.length > 0) {
|
||||
return { results: anilistResults };
|
||||
}
|
||||
return { results: [] };
|
||||
}
|
||||
catch (e) {
|
||||
const error = e;
|
||||
console.error("Search Error:", error.message);
|
||||
return { results: [] };
|
||||
}
|
||||
}
|
||||
async function searchBooksInExtension(req, reply) {
|
||||
try {
|
||||
const extensionName = req.params.extension;
|
||||
const query = req.query.q;
|
||||
const ext = (0, extensions_1.getExtension)(extensionName);
|
||||
if (!ext)
|
||||
return { results: [] };
|
||||
const results = await booksService.searchBooksInExtension(ext, extensionName, query);
|
||||
return { results };
|
||||
}
|
||||
catch (e) {
|
||||
const error = e;
|
||||
console.error("Search Error:", error.message);
|
||||
return { results: [] };
|
||||
}
|
||||
}
|
||||
async function getChapters(req, reply) {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const source = req.query.source || 'anilist';
|
||||
const isExternal = source !== 'anilist';
|
||||
return await booksService.getChaptersForBook(id, isExternal);
|
||||
}
|
||||
catch {
|
||||
return { chapters: [] };
|
||||
}
|
||||
}
|
||||
async function getChapterContent(req, reply) {
|
||||
try {
|
||||
const { bookId, chapter, provider } = req.params;
|
||||
const source = req.query.source || 'anilist';
|
||||
const content = await booksService.getChapterContent(bookId, chapter, provider, source);
|
||||
return reply.send(content);
|
||||
}
|
||||
catch (err) {
|
||||
console.error("getChapterContent error:", err.message);
|
||||
return reply.code(500).send({ error: "Error loading chapter" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user