1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var debug_ = require("debug");
|
5 | var filehound = require("filehound");
|
6 | var fs = require("fs");
|
7 | var path = require("path");
|
8 | var lcp_1 = require("r2-lcp-js/dist/es5/src/parser/epub/lcp");
|
9 | var init_globals_1 = require("r2-opds-js/dist/es5/src/opds/init-globals");
|
10 | var init_globals_2 = require("r2-shared-js/dist/es5/src/init-globals");
|
11 | var epub_1 = require("r2-shared-js/dist/es5/src/parser/epub");
|
12 | var 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 | var debug = debug_("r2:streamer#http/server-cli");
|
18 | debug("process.cwd(): " + process.cwd());
|
19 | debug("__dirname: " + __dirname);
|
20 | var 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 | var argPath = args[0].trim();
|
27 | var 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 | var stats = fs.lstatSync(filePath);
|
44 | if (!stats.isFile() && !stats.isDirectory()) {
|
45 | debug("FILEPATH MUST BE FILE OR DIRECTORY.");
|
46 | process.exit(1);
|
47 | }
|
48 | var 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 | var isAnEPUB = epub_1.isEPUBlication(filePath);
|
68 | if (stats.isDirectory() && (isAnEPUB !== epub_1.EPUBis.LocalExploded)) {
|
69 | debug("Analysing directory...");
|
70 | (function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
71 | var files, server, url;
|
72 | return tslib_1.__generator(this, function (_a) {
|
73 | switch (_a.label) {
|
74 | case 0: return [4, filehound.create()
|
75 | .discard("node_modules")
|
76 | .depth(5)
|
77 | .paths(filePath)
|
78 | .ext([".epub", ".epub3", ".cbz", ".audiobook", ".lcpaudiobook", ".lcpa", ".divina", ".lcpdivina"])
|
79 | .find()];
|
80 | case 1:
|
81 | files = _a.sent();
|
82 | server = new server_1.Server({
|
83 | maxPrefetchLinks: maxPrefetchLinks,
|
84 | });
|
85 | server.preventRobots();
|
86 | server.addPublications(files);
|
87 | return [4, server.start(0, false)];
|
88 | case 2:
|
89 | url = _a.sent();
|
90 | debug(url);
|
91 | return [2];
|
92 | }
|
93 | });
|
94 | }); })();
|
95 | }
|
96 | else {
|
97 | (function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
98 | var server, url;
|
99 | return tslib_1.__generator(this, function (_a) {
|
100 | switch (_a.label) {
|
101 | case 0:
|
102 | server = new server_1.Server({
|
103 | maxPrefetchLinks: maxPrefetchLinks,
|
104 | });
|
105 | server.preventRobots();
|
106 | server.addPublications([filePath]);
|
107 | return [4, server.start(0, false)];
|
108 | case 1:
|
109 | url = _a.sent();
|
110 | debug(url);
|
111 | return [2];
|
112 | }
|
113 | });
|
114 | }); })();
|
115 | }
|
116 |
|
\ | No newline at end of file |