1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const debug_ = require("debug");
|
5 | const filehound = require("filehound");
|
6 | const fs = require("fs");
|
7 | const path = require("path");
|
8 | const lcp_1 = require("r2-lcp-js/dist/es7-es2016/src/parser/epub/lcp");
|
9 | const init_globals_1 = require("r2-opds-js/dist/es7-es2016/src/opds/init-globals");
|
10 | const init_globals_2 = require("r2-shared-js/dist/es7-es2016/src/init-globals");
|
11 | const epub_1 = require("r2-shared-js/dist/es7-es2016/src/parser/epub");
|
12 | const server_1 = require("./server");
|
13 | init_globals_1.initGlobalConverters_OPDS();
|
14 | init_globals_2.initGlobalConverters_SHARED();
|
15 | init_globals_2.initGlobalConverters_GENERIC();
|
16 | lcp_1.setLcpNativePluginPath(path.join(process.cwd(), "LCP", "lcp.node"));
|
17 | const debug = debug_("r2:streamer#http/server-cli");
|
18 | debug(`process.cwd(): ${process.cwd()}`);
|
19 | debug(`__dirname: ${__dirname}`);
|
20 | const args = process.argv.slice(2);
|
21 | debug("process.argv.slice(2): %o", args);
|
22 | if (!args[0]) {
|
23 | debug("FILEPATH ARGUMENT IS MISSING.");
|
24 | process.exit(1);
|
25 | }
|
26 | const argPath = args[0].trim();
|
27 | let filePath = argPath;
|
28 | debug(`path: ${filePath}`);
|
29 | if (!fs.existsSync(filePath)) {
|
30 | filePath = path.join(__dirname, argPath);
|
31 | debug(`path: ${filePath}`);
|
32 | if (!fs.existsSync(filePath)) {
|
33 | filePath = path.join(process.cwd(), argPath);
|
34 | debug(`path: ${filePath}`);
|
35 | if (!fs.existsSync(filePath)) {
|
36 | debug("FILEPATH DOES NOT EXIST.");
|
37 | process.exit(1);
|
38 | }
|
39 | }
|
40 | }
|
41 | filePath = fs.realpathSync(filePath);
|
42 | debug(`path (normalized): ${filePath}`);
|
43 | const stats = fs.lstatSync(filePath);
|
44 | if (!stats.isFile() && !stats.isDirectory()) {
|
45 | debug("FILEPATH MUST BE FILE OR DIRECTORY.");
|
46 | process.exit(1);
|
47 | }
|
48 | let maxPrefetchLinks = server_1.MAX_PREFETCH_LINKS;
|
49 | if (args[1]) {
|
50 | args[1] = args[1].trim();
|
51 | if (args[1].length && args[1][0] === "-") {
|
52 | maxPrefetchLinks = -1;
|
53 | }
|
54 | else {
|
55 | try {
|
56 | maxPrefetchLinks = parseInt(args[1], 10);
|
57 | }
|
58 | catch (err) {
|
59 | debug(err);
|
60 | }
|
61 | if (isNaN(maxPrefetchLinks)) {
|
62 | maxPrefetchLinks = server_1.MAX_PREFETCH_LINKS;
|
63 | }
|
64 | }
|
65 | }
|
66 | debug(`maxPrefetchLinks: ${maxPrefetchLinks}`);
|
67 | const isAnEPUB = epub_1.isEPUBlication(filePath);
|
68 | if (stats.isDirectory() && (isAnEPUB !== epub_1.EPUBis.LocalExploded)) {
|
69 | debug("Analysing directory...");
|
70 | (() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
71 | const files = yield filehound.create()
|
72 | .discard("node_modules")
|
73 | .depth(5)
|
74 | .paths(filePath)
|
75 | .ext([".epub", ".epub3", ".cbz", ".audiobook", ".lcpaudiobook", ".lcpa", ".divina", ".lcpdivina"])
|
76 | .find();
|
77 | const server = new server_1.Server({
|
78 | maxPrefetchLinks,
|
79 | });
|
80 | server.preventRobots();
|
81 | server.addPublications(files);
|
82 | const url = yield server.start(0, false);
|
83 | debug(url);
|
84 | }))();
|
85 | }
|
86 | else {
|
87 | (() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
88 | const server = new server_1.Server({
|
89 | maxPrefetchLinks,
|
90 | });
|
91 | server.preventRobots();
|
92 | server.addPublications([filePath]);
|
93 | const url = yield server.start(0, false);
|
94 | debug(url);
|
95 | }))();
|
96 | }
|
97 |
|
\ | No newline at end of file |