From 5596da2f2fe8a456bacf0e2169282d918c724bd7 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Wed, 25 May 2022 09:08:46 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9D=8C=20Removed=20OPDS=20routes=20from=20th?= =?UTF-8?q?e=20UI=20facade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/components/Navbar.tsx | 4 + src/server/index.ts | 1 - src/server/route/index.ts | 3 - src/server/route/routes/opds.routes.ts | 101 ------------------------- 4 files changed, 4 insertions(+), 105 deletions(-) delete mode 100644 src/server/route/routes/opds.routes.ts diff --git a/src/client/components/Navbar.tsx b/src/client/components/Navbar.tsx index c5587c6..2edfcba 100644 --- a/src/client/components/Navbar.tsx +++ b/src/client/components/Navbar.tsx @@ -30,6 +30,10 @@ const Navbar: React.FunctionComponent = (props) => { ); + const performSearch = (searchQuery) => { + + } + const customStyles = { control: () => ({ width: 250, diff --git a/src/server/index.ts b/src/server/index.ts index 455a514..93254c6 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -1,6 +1,5 @@ import express, { Request, Response, Router, Express } from "express"; import bodyParser from "body-parser"; -import router from "./route"; import path from "path"; // call express diff --git a/src/server/route/index.ts b/src/server/route/index.ts index d9954c9..e69de29 100644 --- a/src/server/route/index.ts +++ b/src/server/route/index.ts @@ -1,3 +0,0 @@ -import opds from "./routes/opds.routes"; - -export default { opds }; diff --git a/src/server/route/routes/opds.routes.ts b/src/server/route/routes/opds.routes.ts deleted file mode 100644 index e27be6a..0000000 --- a/src/server/route/routes/opds.routes.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { basename, extname, join } from "path"; -import { lookup } from "mime-types"; -import { promises as fs } from "fs"; -import { responseStream } from "http-response-stream"; -import { isUndefined } from "lodash"; -import { buildAsync } from "calibre-opds"; -import initMain from "calibre-opds/lib/index"; -import { EnumLinkRel } from "opds-extra/lib/const"; -import { async as FastGlob } from "@bluelovers/fast-glob/bluebird"; -import { Entry, Feed } from "opds-extra/lib/v1"; -import { Link } from "opds-extra/lib/v1/core"; -import router from "../router"; -import xml2js from "xml2js"; - -const path_of_books = "/Users/rishi/work/threetwo/src/server/comics"; -router.use("/opds", async (req, res, next) => { - return buildAsync( - initMain({ - title: `title`, - subtitle: `subtitle`, - icon: "/favicon.ico", - }), - [ - async (feed: Feed) => { - feed.id = "urn:uuid:2853dacf-ed79-42f5-8e8a-a7bb3d1ae6a2"; - feed.books = feed.books || []; - await FastGlob(["*.cbr", "*.cbz", "*.cb7", "*.cba", "*.cbt"], { - cwd: path_of_books, - }).each((file, idx) => { - const ext = extname(file); - const title = basename(file, ext); - const href = encodeURI(`/api/file/${file}`); - const type = lookup(ext) || "application/octet-stream"; - - const entry = Entry.deserialize({ - title, - id: idx, - links: [ - { - rel: EnumLinkRel.ACQUISITION, - href, - type, - } as Link, - ], - }); - - if (!isUndefined(feed) && !isUndefined(feed.books)) { - feed.books.push(entry); - } - }); - - return feed; - }, - ], - ).then((feed) => { - res.setHeader("Content-Type", "application/xml"); - let data; - xml2js.parseString(feed.toXML(), (err, result) => { - result.feed.link = { - $: { - rel: "self", - href: "/opds-catalogs/root.xml", - type: "application/atom+xml;profile=opds-catalog;kind=navigation", - }, - _: "", - }; - const builder = new xml2js.Builder({ - xmldec: { - version: "1.0", - encoding: "UTF-8", - standalone: false, - }, - }); - data = builder.buildObject(result, { - renderOpts: { - pretty: true, - indent: " ", - newline: "\n", - allowEmpty: true, - }, - }); - }); - return res.end(data); - }); -}); - -router.use("/file/*", async (req, res) => { - const file: string = req.params[0]; - const ext = extname(file); - - if ([".cbr", ".cbz", ".cb7", ".cba", ".cbt"].includes(ext)) { - const content = await fs.readFile(join(path_of_books, file)); - const mime = lookup(ext) || "application/octet-stream"; - res.set("Content-Type", mime); - return responseStream(res, content); - } - - res.status(404).end(`'${file}' not exists`); -}); - -export default router;