🧹 Cleaning up
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
"@types/socket.io": "^3.0.2",
|
||||
"@types/socket.io-client": "^3.0.0",
|
||||
"@types/through2": "^2.0.36",
|
||||
"airdcpp-extension": "^1.5.0",
|
||||
"airdcpp-extension-settings": "^1.2.1",
|
||||
"antd": "^4.16.5",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"better-docs": "^2.3.2",
|
||||
|
||||
@@ -1,32 +1,26 @@
|
||||
import express, { Request, Response, Router, Express } from "express";
|
||||
import bodyParser from "body-parser";
|
||||
import path, { basename, extname, join} from "path";
|
||||
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, EnumMIME } from "opds-extra/lib/const";
|
||||
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 { lookup } from 'mime-types';
|
||||
import { promises as fs } from 'fs';
|
||||
import { responseStream } from 'http-response-stream';
|
||||
|
||||
// call express
|
||||
const app: Express = express(); // define our app using express
|
||||
const router = Router();
|
||||
|
||||
|
||||
|
||||
// configure app to use bodyParser for
|
||||
// Getting data from body of requests
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
|
||||
const port: number = Number(process.env.PORT) || 8050; // set our port
|
||||
|
||||
// Send index.html on root request
|
||||
@@ -34,7 +28,6 @@ app.use(express.static("dist"));
|
||||
|
||||
export function opdsRouter() {
|
||||
const path_of_books = "/Users/rishi/work/threetwo/src/server/comics";
|
||||
console.log(path_of_books);
|
||||
router.use("/opds", async (req, res, next) => {
|
||||
return buildAsync(
|
||||
initMain({
|
||||
@@ -51,11 +44,9 @@ export function opdsRouter() {
|
||||
const ext = extname(file);
|
||||
const title = basename(file, ext);
|
||||
|
||||
const href = encodeURI(
|
||||
`/file/${file}`,
|
||||
);
|
||||
const href = encodeURI(`/file/${file}`);
|
||||
|
||||
const type = lookup(ext) || "application/octet-stream";;
|
||||
const type = lookup(ext) || "application/octet-stream";
|
||||
|
||||
const entry = Entry.deserialize<Entry>({
|
||||
title,
|
||||
@@ -78,25 +69,24 @@ export function opdsRouter() {
|
||||
},
|
||||
],
|
||||
).then((feed) => {
|
||||
console.log(feed);
|
||||
res.setHeader("Content-Type", "application/xml");
|
||||
return res.end(feed.toXML());
|
||||
});
|
||||
});
|
||||
|
||||
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`)
|
||||
})
|
||||
|
||||
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`);
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
82
yarn.lock
82
yarn.lock
@@ -2360,6 +2360,36 @@ aggregate-error@^3.0.0:
|
||||
clean-stack "^2.0.0"
|
||||
indent-string "^4.0.0"
|
||||
|
||||
airdcpp-apisocket@^2.4.1:
|
||||
version "2.4.1"
|
||||
resolved "https://registry.yarnpkg.com/airdcpp-apisocket/-/airdcpp-apisocket-2.4.1.tgz#eb2dc28eecd9d6306b25ef8239545d90d6ad005f"
|
||||
integrity sha512-3mkEvbChG4aRe8F2ZFTi2Z0FG319toex/HquRxWlo6s6Rg69s5bPo0VwGte3NlZ4fnHoBD9vk5KavHgOMkJgZg==
|
||||
dependencies:
|
||||
chalk "^4.1.0"
|
||||
events "^3.2.0"
|
||||
invariant "^2.2.4"
|
||||
is-in-browser "^1.1.3"
|
||||
promise "^8.1.0"
|
||||
|
||||
airdcpp-extension-settings@^1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/airdcpp-extension-settings/-/airdcpp-extension-settings-1.2.1.tgz#361fd8f4e52b78fb9f586d60d9d3b3d74f30d79e"
|
||||
integrity sha512-tMAkVOu3qf/w0C/GD0dhCsovDZaZOVu2gomZq8HfWknwshpXK5qEqMEyrlIVauuezaxdZJXqEfG6dZb3Y/+K+g==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.12.5"
|
||||
invariant "^2.2.4"
|
||||
|
||||
airdcpp-extension@^1.5.0:
|
||||
version "1.5.0"
|
||||
resolved "https://registry.yarnpkg.com/airdcpp-extension/-/airdcpp-extension-1.5.0.tgz#f1a2f62113b6682ddbdbbe105d45e5b4051979c6"
|
||||
integrity sha512-5hxT2xTq3Z15yxLYfBtiFs4H4zZc5uJuBvX52qYzbOHppLsOcViuS9HyLmmf+AV/5AWFAl85iAqDxwai59w71w==
|
||||
dependencies:
|
||||
airdcpp-apisocket "^2.4.1"
|
||||
chalk "^4.1.0"
|
||||
minimist "^1.2.5"
|
||||
mkdirp "^1.0.4"
|
||||
websocket "^1.0.33"
|
||||
|
||||
ajv-errors@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d"
|
||||
@@ -2702,7 +2732,7 @@ array.prototype.flatmap@^1.2.4:
|
||||
es-abstract "^1.18.0-next.1"
|
||||
function-bind "^1.1.1"
|
||||
|
||||
asap@^2.0.0, asap@~2.0.3:
|
||||
asap@^2.0.0, asap@~2.0.3, asap@~2.0.6:
|
||||
version "2.0.6"
|
||||
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
|
||||
integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=
|
||||
@@ -3439,6 +3469,13 @@ buffers@~0.1.1:
|
||||
resolved "https://registry.yarnpkg.com/buffers/-/buffers-0.1.1.tgz#b24579c3bed4d6d396aeee6d9a8ae7f5482ab7bb"
|
||||
integrity sha1-skV5w77U1tOWru5tmorn9Ugqt7s=
|
||||
|
||||
bufferutil@^4.0.1:
|
||||
version "4.0.3"
|
||||
resolved "https://registry.yarnpkg.com/bufferutil/-/bufferutil-4.0.3.tgz#66724b756bed23cd7c28c4d306d7994f9943cc6b"
|
||||
integrity sha512-yEYTwGndELGvfXsImMBLop58eaGW+YdONi1fNjTINSY98tmMmFijBG6WXgdkfuLNt4imzQNtIE+eBp1PVpMCSw==
|
||||
dependencies:
|
||||
node-gyp-build "^4.2.0"
|
||||
|
||||
builtin-modules@^1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
|
||||
@@ -7093,7 +7130,7 @@ into-stream@^3.1.0:
|
||||
from2 "^2.1.1"
|
||||
p-is-promise "^1.1.0"
|
||||
|
||||
invariant@^2.2.2:
|
||||
invariant@^2.2.2, invariant@^2.2.4:
|
||||
version "2.2.4"
|
||||
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
|
||||
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
|
||||
@@ -7347,6 +7384,11 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
|
||||
dependencies:
|
||||
is-extglob "^2.1.1"
|
||||
|
||||
is-in-browser@^1.1.3:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/is-in-browser/-/is-in-browser-1.1.3.tgz#56ff4db683a078c6082eb95dad7dc62e1d04f835"
|
||||
integrity sha1-Vv9NtoOgeMYILrldrX3GLh0E+DU=
|
||||
|
||||
is-installed-globally@^0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/is-installed-globally/-/is-installed-globally-0.1.0.tgz#0dfd98f5a9111716dd535dda6492f67bf3d25a80"
|
||||
@@ -9309,6 +9351,11 @@ node-forge@^0.10.0:
|
||||
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3"
|
||||
integrity sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==
|
||||
|
||||
node-gyp-build@^4.2.0:
|
||||
version "4.2.3"
|
||||
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739"
|
||||
integrity sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==
|
||||
|
||||
node-gyp@^7.1.0, node-gyp@^7.1.2:
|
||||
version "7.1.2"
|
||||
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-7.1.2.tgz#21a810aebb187120251c3bcec979af1587b188ae"
|
||||
@@ -10565,6 +10612,13 @@ promise@^7.0.1:
|
||||
dependencies:
|
||||
asap "~2.0.3"
|
||||
|
||||
promise@^8.1.0:
|
||||
version "8.1.0"
|
||||
resolved "https://registry.yarnpkg.com/promise/-/promise-8.1.0.tgz#697c25c3dfe7435dd79fcd58c38a135888eaf05e"
|
||||
integrity sha512-W04AqnILOL/sPRXziNicCjSNRruLAuIHEOVBazepu0545DDNGYHz7ar9ZgZ1fMU8/MA4mVxp5rkBWRi6OXIy3Q==
|
||||
dependencies:
|
||||
asap "~2.0.6"
|
||||
|
||||
prompts@^2.0.1:
|
||||
version "2.4.1"
|
||||
resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.1.tgz#befd3b1195ba052f9fd2fde8a486c4e82ee77f61"
|
||||
@@ -13787,6 +13841,13 @@ use@^3.1.0:
|
||||
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
|
||||
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==
|
||||
|
||||
utf-8-validate@^5.0.2:
|
||||
version "5.0.5"
|
||||
resolved "https://registry.yarnpkg.com/utf-8-validate/-/utf-8-validate-5.0.5.tgz#dd32c2e82c72002dc9f02eb67ba6761f43456ca1"
|
||||
integrity sha512-+pnxRYsS/axEpkrrEpzYfNZGXp0IjC/9RIxwM5gntY4Koi8SHmUGSfxfWqxZdRxrtaoVstuOzUp/rbs3JSPELQ==
|
||||
dependencies:
|
||||
node-gyp-build "^4.2.0"
|
||||
|
||||
util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
|
||||
@@ -14139,6 +14200,18 @@ websocket-extensions@>=0.1.1:
|
||||
resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42"
|
||||
integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==
|
||||
|
||||
websocket@^1.0.33:
|
||||
version "1.0.34"
|
||||
resolved "https://registry.yarnpkg.com/websocket/-/websocket-1.0.34.tgz#2bdc2602c08bf2c82253b730655c0ef7dcab3111"
|
||||
integrity sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==
|
||||
dependencies:
|
||||
bufferutil "^4.0.1"
|
||||
debug "^2.2.0"
|
||||
es5-ext "^0.10.50"
|
||||
typedarray-to-buffer "^3.1.5"
|
||||
utf-8-validate "^5.0.2"
|
||||
yaeti "^0.0.6"
|
||||
|
||||
whatwg-encoding@^1.0.5:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz#5abacf777c32166a51d085d6b4f3e7d27113ddb0"
|
||||
@@ -14393,6 +14466,11 @@ y18n@^5.0.5:
|
||||
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
|
||||
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==
|
||||
|
||||
yaeti@^0.0.6:
|
||||
version "0.0.6"
|
||||
resolved "https://registry.yarnpkg.com/yaeti/-/yaeti-0.0.6.tgz#f26f484d72684cf42bedfb76970aa1608fbf9577"
|
||||
integrity sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc=
|
||||
|
||||
yallist@^2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
|
||||
|
||||
Reference in New Issue
Block a user