Compare commits
139 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35ded81713 | ||
|
|
07c85280cd | ||
|
|
43f1d86be0 | ||
|
|
82f5ed4c44 | ||
|
|
0b53ad4b4d | ||
|
|
56ad41d10c | ||
|
|
249a4564e0 | ||
|
|
efb2413720 | ||
|
|
1226acefd6 | ||
|
|
76f7d7bc90 | ||
|
|
a5cb2641fd | ||
|
|
57fc64af79 | ||
|
|
f8b7b8b698 | ||
|
|
3da6befe10 | ||
|
|
a50d61c3ce | ||
|
|
b7568975e7 | ||
|
|
4b9475310f | ||
|
|
639f726c83 | ||
|
|
7997c486cf | ||
|
|
2569d00bd0 | ||
|
|
2cd80d8fa1 | ||
|
|
eedca4db9b | ||
|
|
1d352a76ce | ||
|
|
17670aabf9 | ||
|
|
3456b3d90e | ||
|
|
f3da5a9026 | ||
|
|
00cc63b7cd | ||
|
|
8df80ce738 | ||
|
|
12e7a783b0 | ||
|
|
be86a15351 | ||
|
|
2c5022e7b4 | ||
|
|
f4a996fcb9 | ||
|
|
fdbf508bbf | ||
|
|
500fafa5b2 | ||
|
|
bfa315c68b | ||
|
|
4972f085a3 | ||
|
|
9c13261929 | ||
|
|
e36dc4a913 | ||
|
|
4cccb56ee3 | ||
|
|
3199af570d | ||
|
|
7dad47b3c8 | ||
|
|
fbd50bad1d | ||
|
|
10469bae7b | ||
|
|
b6a000a001 | ||
|
|
59539e7e90 | ||
|
|
a2c41bc5ec | ||
|
|
c4a06858fb | ||
|
|
15b0f05a05 | ||
|
|
67feee9aa1 | ||
|
|
185fb57b8c | ||
|
|
e9039f8208 | ||
|
|
440d1b3ba0 | ||
|
|
9c7a6c64b0 | ||
|
|
7cc63fe849 | ||
|
|
5647e8219d | ||
|
|
81629fab7a | ||
|
|
992d2033f3 | ||
|
|
d52d4a1278 | ||
|
|
57a44c5952 | ||
|
|
a04161ac7c | ||
|
|
47e46f13c3 | ||
|
|
5535bd91c8 | ||
|
|
8747a00de6 | ||
|
|
c926b86926 | ||
|
|
010ac9aa7c | ||
|
|
4ab0c337f1 | ||
|
|
f814c42fdd | ||
|
|
02aee3e625 | ||
|
|
52a32cfdd1 | ||
|
|
6faa7b2efe | ||
|
|
f8481413c9 | ||
|
|
0951d01383 | ||
|
|
da34472a6f | ||
|
|
e89b6e3ea0 | ||
|
|
977bab4745 | ||
|
|
26c73109fe | ||
|
|
65f911ad51 | ||
|
|
f8ed5ebd6a | ||
|
|
e4cb61bebe | ||
|
|
7d5310af42 | ||
|
|
f68c610c0d | ||
|
|
ccfb6a6d73 | ||
|
|
da55996e22 | ||
|
|
ecd8400a34 | ||
|
|
03914883bc | ||
|
|
9981e1f3bd | ||
|
|
4d1df66025 | ||
|
|
a0f64e188b | ||
|
|
08407a1094 | ||
|
|
445ea3bb2e | ||
|
|
0e0aab98b1 | ||
|
|
721d5eb0c1 | ||
|
|
6d99dbc3a7 | ||
|
|
2be31f649b | ||
|
|
828ac27c03 | ||
|
|
b3d614002f | ||
|
|
2b2000ca10 | ||
|
|
8d7428d099 | ||
|
|
57f8322f31 | ||
|
|
bee7bc4294 | ||
|
|
28702065bc | ||
|
|
c248057081 | ||
|
|
6186f5e138 | ||
|
|
2201d8176d | ||
|
|
2ba6819876 | ||
|
|
a393b2a370 | ||
|
|
59fe713df2 | ||
|
|
4b8efaca9a | ||
|
|
a26100a8d0 | ||
|
|
8c52f4718c | ||
|
|
85b5c3c4ec | ||
|
|
4fd559e4c7 | ||
|
|
a337d0ddc7 | ||
|
|
9e4cb7071e | ||
|
|
c3f1707343 | ||
|
|
1ed058a553 | ||
|
|
0500a8178d | ||
|
|
7d0059f573 | ||
|
|
4e3b882362 | ||
|
|
13cf47873e | ||
|
|
7ee23ec38f | ||
|
|
eebf17c42c | ||
|
|
f84536788b | ||
|
|
4bbfdc2cb2 | ||
|
|
211fec35e3 | ||
|
|
b8214a46ae | ||
|
|
549ef91c81 | ||
|
|
cede65313b | ||
|
|
d897a7400f | ||
|
|
47f059213f | ||
|
|
8af51bbf08 | ||
|
|
53d9f5ddc6 | ||
|
|
06fffdccc8 | ||
|
|
aa13dc68fc | ||
|
|
813876dd90 | ||
|
|
596c7d65c5 | ||
|
|
ce8dcb75bf | ||
|
|
1bd51b5565 | ||
|
|
1f9ec305b4 |
106
LICENSE.md
Normal file
106
LICENSE.md
Normal file
@@ -0,0 +1,106 @@
|
||||
# CC0 1.0 Universal
|
||||
|
||||
## Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator and
|
||||
subsequent owner(s) (each and all, an “owner”) of an original work of
|
||||
authorship and/or a database (each, a “Work”).
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for the
|
||||
purpose of contributing to a commons of creative, cultural and scientific works
|
||||
(“Commons”) that the public can reliably and without fear of later claims of
|
||||
infringement build upon, modify, incorporate in other works, reuse and
|
||||
redistribute as freely as possible in any form whatsoever and for any purposes,
|
||||
including without limitation commercial purposes. These owners may contribute
|
||||
to the Commons to promote the ideal of a free culture and the further
|
||||
production of creative, cultural and scientific works, or to gain reputation or
|
||||
greater distribution for their Work in part through the use and efforts of
|
||||
others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any expectation of
|
||||
additional consideration or compensation, the person associating CC0 with a
|
||||
Work (the “Affirmer”), to the extent that he or she is an owner of Copyright
|
||||
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and
|
||||
publicly distribute the Work under its terms, with knowledge of his or her
|
||||
Copyright and Related Rights in the Work and the meaning and intended legal
|
||||
effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights (“Copyright and
|
||||
Related Rights”). Copyright and Related Rights include, but are not limited
|
||||
to, the following:
|
||||
1. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
2. moral rights retained by the original author(s) and/or performer(s);
|
||||
3. publicity and privacy rights pertaining to a person’s image or likeness
|
||||
depicted in a Work;
|
||||
4. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(i), below;
|
||||
5. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
6. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation thereof,
|
||||
including any amended or successor version of such directive); and
|
||||
7. other similar, equivalent or corresponding rights throughout the world
|
||||
based on applicable law or treaty, and any national implementations
|
||||
thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
||||
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
||||
unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright
|
||||
and Related Rights and associated claims and causes of action, whether now
|
||||
known or unknown (including existing as well as future claims and causes of
|
||||
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
||||
duration provided by applicable law or treaty (including future time
|
||||
extensions), (iii) in any current or future medium and for any number of
|
||||
copies, and (iv) for any purpose whatsoever, including without limitation
|
||||
commercial, advertising or promotional purposes (the “Waiver”). Affirmer makes
|
||||
the Waiver for the benefit of each member of the public at large and to the
|
||||
detriment of Affirmer’s heirs and successors, fully intending that such Waiver
|
||||
shall not be subject to revocation, rescission, cancellation, termination, or
|
||||
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
||||
by the public as contemplated by Affirmer’s express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason be
|
||||
judged legally invalid or ineffective under applicable law, then the Waiver
|
||||
shall be preserved to the maximum extent permitted taking into account
|
||||
Affirmer’s express Statement of Purpose. In addition, to the extent the Waiver
|
||||
is so judged Affirmer hereby grants to each affected person a royalty-free, non
|
||||
transferable, non sublicensable, non exclusive, irrevocable and unconditional
|
||||
license to exercise Affirmer’s Copyright and Related Rights in the Work (i) in
|
||||
all territories worldwide, (ii) for the maximum duration provided by applicable
|
||||
law or treaty (including future time extensions), (iii) in any current or
|
||||
future medium and for any number of copies, and (iv) for any purpose
|
||||
whatsoever, including without limitation commercial, advertising or promotional
|
||||
purposes (the “License”). The License shall be deemed effective as of the date
|
||||
CC0 was applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder of the
|
||||
License, and in such case Affirmer hereby affirms that he or she will not (i)
|
||||
exercise any of his or her remaining Copyright and Related Rights in the Work
|
||||
or (ii) assert any associated claims and causes of action with respect to the
|
||||
Work, in either case contrary to Affirmer’s express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
1. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
2. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied, statutory
|
||||
or otherwise, including without limitation warranties of title,
|
||||
merchantability, fitness for a particular purpose, non infringement, or
|
||||
the absence of latent or other defects, accuracy, or the present or
|
||||
absence of errors, whether or not discoverable, all to the greatest
|
||||
extent permissible under applicable law.
|
||||
3. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person’s Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the Work.
|
||||
4. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
||||
|
||||
For more information, please see
|
||||
http://creativecommons.org/publicdomain/zero/1.0/.
|
||||
42
README.md
42
README.md
@@ -1,3 +1,43 @@
|
||||
# Liberama
|
||||
|
||||
Свободный обмен книгами в формате fb2
|
||||
Браузерная онлайн-читалка книг и децентрализованная библиотека.
|
||||
|
||||
Читалка [OmniReader](https://omnireader.ru) является частью данного проекта, размещенной на VPS:
|
||||
|
||||

|
||||

|
||||
|
||||
## VPS
|
||||
Для разворачивания читалки на чистом VPS с нуля смотрите [docs/omnireader](docs/omnireader/README.md)
|
||||
|
||||
## Сборка проекта
|
||||
Необходима версия node.js не ниже 10.
|
||||
|
||||
```
|
||||
$ git clone https://github.com/bookpauk/liberama
|
||||
$ cd liberama
|
||||
$ npm i
|
||||
```
|
||||
|
||||
### Windows
|
||||
```
|
||||
$ npm run build:win
|
||||
```
|
||||
|
||||
### Linux
|
||||
```
|
||||
$ npm run build:linux
|
||||
```
|
||||
|
||||
Результат сборки будет доступен в каталоге `dist/linux|win` в виде исполнимого (standalone) файла
|
||||
|
||||
### Разработка
|
||||
```
|
||||
$ npm run dev
|
||||
```
|
||||
|
||||
## Помочь проекту
|
||||
|
||||
* bitcoin: 3EbgZ7MK1UVaN38Gty5DCBtS4PknM4Ut85
|
||||
* litecoin: MP39Riec4oSNB3XMjiquKoLWxbufRYNXxZ
|
||||
* monero: 8BQPnvHcPSHM5gMQsmuypDgx9NNsYqwXKfDDuswEyF2Q2ewQSfd2pkK6ydH2wmMyq2JViZvy9DQ35hLMx7g72mFWNJTPtnz
|
||||
|
||||
@@ -24,8 +24,8 @@ async function main() {
|
||||
await fs.ensureDir(tempDownloadDir);
|
||||
|
||||
//sqlite3
|
||||
const sqliteRemoteUrl = 'https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.0.4/node-v64-linux-x64.tar.gz';
|
||||
const sqliteDecompressedFilename = `${tempDownloadDir}/node-v64-linux-x64/node_sqlite3.node`;
|
||||
const sqliteRemoteUrl = 'https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.1/node-v72-linux-x64.tar.gz';
|
||||
const sqliteDecompressedFilename = `${tempDownloadDir}/node-v72-linux-x64/node_sqlite3.node`;
|
||||
|
||||
if (!await fs.pathExists(sqliteDecompressedFilename)) {
|
||||
// Скачиваем node_sqlite3.node для винды, т.к. pkg не включает его в сборку
|
||||
|
||||
@@ -24,8 +24,8 @@ async function main() {
|
||||
await fs.ensureDir(tempDownloadDir);
|
||||
|
||||
//sqlite3
|
||||
const sqliteRemoteUrl = 'https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.0.4/node-v64-win32-x64.tar.gz';
|
||||
const sqliteDecompressedFilename = `${tempDownloadDir}/node-v64-win32-x64/node_sqlite3.node`;
|
||||
const sqliteRemoteUrl = 'https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.1.1/node-v72-win32-x64.tar.gz';
|
||||
const sqliteDecompressedFilename = `${tempDownloadDir}/node-v72-win32-x64/node_sqlite3.node`;
|
||||
|
||||
if (!await fs.pathExists(sqliteDecompressedFilename)) {
|
||||
// Скачиваем node_sqlite3.node для винды, т.к. pkg не включает его в сборку
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import wsc from './webSocketConnection';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api'
|
||||
@@ -6,9 +7,20 @@ const api = axios.create({
|
||||
|
||||
class Misc {
|
||||
async loadConfig() {
|
||||
const response = await api.post('/config', {params: [
|
||||
|
||||
const query = {params: [
|
||||
'name', 'version', 'mode', 'maxUploadFileSize', 'useExternalBookConverter', 'branch',
|
||||
]});
|
||||
]};
|
||||
|
||||
try {
|
||||
await wsc.open();
|
||||
return await wsc.message(wsc.send(Object.assign({action: 'get-config'}, query)));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
//если с WebSocket проблема, работаем по http
|
||||
const response = await api.post('/config', query);
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import axios from 'axios';
|
||||
|
||||
import * as utils from '../share/utils';
|
||||
import wsc from './webSocketConnection';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api/reader'
|
||||
@@ -11,8 +11,67 @@ const workerApi = axios.create({
|
||||
});
|
||||
|
||||
class Reader {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
async getWorkerStateFinish(workerId, callback) {
|
||||
if (!callback) callback = () => {};
|
||||
|
||||
let response = {};
|
||||
|
||||
try {
|
||||
await wsc.open();
|
||||
const requestId = wsc.send({action: 'worker-get-state-finish', workerId});
|
||||
|
||||
while (1) {// eslint-disable-line no-constant-condition
|
||||
response = await wsc.message(requestId);
|
||||
callback(response);
|
||||
|
||||
if (!response.state)
|
||||
throw new Error('Неверный ответ api');
|
||||
|
||||
if (response.state == 'finish' || response.state == 'error') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return response;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
//если с WebSocket проблема, работаем по http
|
||||
const refreshPause = 500;
|
||||
let i = 0;
|
||||
response = {};
|
||||
while (1) {// eslint-disable-line no-constant-condition
|
||||
const prevProgress = response.progress || 0;
|
||||
const prevState = response.state || 0;
|
||||
response = await workerApi.post('/get-state', {workerId});
|
||||
response = response.data;
|
||||
callback(response);
|
||||
|
||||
if (!response.state)
|
||||
throw new Error('Неверный ответ api');
|
||||
|
||||
if (response.state == 'finish' || response.state == 'error') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (i > 0)
|
||||
await utils.sleep(refreshPause);
|
||||
|
||||
i++;
|
||||
if (i > 120*1000/refreshPause) {//2 мин ждем телодвижений воркера
|
||||
throw new Error('Слишком долгое время ожидания');
|
||||
}
|
||||
//проверка воркера
|
||||
i = (prevProgress != response.progress || prevState != response.state ? 1 : i);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async loadBook(opts, callback) {
|
||||
const refreshPause = 300;
|
||||
if (!callback) callback = () => {};
|
||||
|
||||
let response = await api.post('/load-book', opts);
|
||||
@@ -22,58 +81,90 @@ class Reader {
|
||||
throw new Error('Неверный ответ api');
|
||||
|
||||
callback({totalSteps: 4});
|
||||
callback(response.data);
|
||||
|
||||
let i = 0;
|
||||
while (1) {// eslint-disable-line no-constant-condition
|
||||
callback(response.data);
|
||||
response = await this.getWorkerStateFinish(workerId, callback);
|
||||
|
||||
if (response.data.state == 'finish') {//воркер закончил работу, можно скачивать кешированный на сервере файл
|
||||
if (response) {
|
||||
if (response.state == 'finish') {//воркер закончил работу, можно скачивать кешированный на сервере файл
|
||||
callback({step: 4});
|
||||
const book = await this.loadCachedBook(response.data.path, callback);
|
||||
return Object.assign({}, response.data, {data: book.data});
|
||||
const book = await this.loadCachedBook(response.path, callback, response.size);
|
||||
return Object.assign({}, response, {data: book.data});
|
||||
}
|
||||
if (response.data.state == 'error') {
|
||||
let errMes = response.data.error;
|
||||
|
||||
if (response.state == 'error') {
|
||||
let errMes = response.error;
|
||||
if (errMes.indexOf('getaddrinfo') >= 0 ||
|
||||
errMes.indexOf('ECONNRESET') >= 0 ||
|
||||
errMes.indexOf('EINVAL') >= 0 ||
|
||||
errMes.indexOf('404') >= 0)
|
||||
errMes = `Ресурс не найден по адресу: ${response.data.url}`;
|
||||
errMes = `Ресурс не найден по адресу: ${response.url}`;
|
||||
throw new Error(errMes);
|
||||
}
|
||||
if (i > 0)
|
||||
await utils.sleep(refreshPause);
|
||||
|
||||
i++;
|
||||
if (i > 120*1000/refreshPause) {//2 мин ждем телодвижений воркера
|
||||
throw new Error('Слишком долгое время ожидания');
|
||||
}
|
||||
//проверка воркера
|
||||
const prevProgress = response.data.progress;
|
||||
const prevState = response.data.state;
|
||||
response = await workerApi.post('/get-state', {workerId});
|
||||
i = (prevProgress != response.data.progress || prevState != response.data.state ? 1 : i);
|
||||
} else {
|
||||
throw new Error('Пустой ответ сервера');
|
||||
}
|
||||
}
|
||||
|
||||
async loadCachedBook(url, callback){
|
||||
const response = await axios.head(url);
|
||||
async checkCachedBook(url) {
|
||||
let estSize = -1;
|
||||
try {
|
||||
const response = await axios.head(url, {headers: {'Cache-Control': 'no-cache'}});
|
||||
|
||||
let estSize = 1000000;
|
||||
if (response.headers['content-length']) {
|
||||
estSize = response.headers['content-length'];
|
||||
if (response.headers['content-length']) {
|
||||
estSize = response.headers['content-length'];
|
||||
}
|
||||
} catch (e) {
|
||||
//восстановим при необходимости файл на сервере из удаленного облака
|
||||
let response = null
|
||||
|
||||
try {
|
||||
await wsc.open();
|
||||
response = await wsc.message(wsc.send({action: 'reader-restore-cached-file', path: url}));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
//если с WebSocket проблема, работаем по http
|
||||
response = await api.post('/restore-cached-file', {path: url});
|
||||
response = response.data;
|
||||
}
|
||||
|
||||
const workerId = response.workerId;
|
||||
if (!workerId)
|
||||
throw new Error('Неверный ответ api');
|
||||
|
||||
response = await this.getWorkerStateFinish(workerId);
|
||||
if (response.state == 'error') {
|
||||
throw new Error(response.error);
|
||||
}
|
||||
if (response.size && estSize < 0) {
|
||||
estSize = response.size;
|
||||
}
|
||||
}
|
||||
|
||||
return estSize;
|
||||
}
|
||||
|
||||
async loadCachedBook(url, callback, estSize = -1) {
|
||||
if (!callback) callback = () => {};
|
||||
|
||||
callback({state: 'loading', progress: 0});
|
||||
|
||||
//получение размера файла
|
||||
if (estSize && estSize < 0) {
|
||||
estSize = await this.checkCachedBook(url);
|
||||
}
|
||||
|
||||
//получение файла
|
||||
estSize = (estSize > 0 ? estSize : 1000000);
|
||||
const options = {
|
||||
onDownloadProgress: progress => {
|
||||
onDownloadProgress: (progress) => {
|
||||
while (progress.loaded > estSize) estSize *= 1.5;
|
||||
|
||||
if (callback)
|
||||
callback({progress: Math.round((progress.loaded*100)/estSize)});
|
||||
}
|
||||
}
|
||||
//загрузка
|
||||
|
||||
return await axios.get(url, options);
|
||||
}
|
||||
|
||||
@@ -110,13 +201,22 @@ class Reader {
|
||||
}
|
||||
|
||||
async storage(request) {
|
||||
let response = await api.post('/storage', request);
|
||||
let response = null;
|
||||
try {
|
||||
await wsc.open();
|
||||
response = await wsc.message(wsc.send({action: 'reader-storage', body: request}));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
//если с WebSocket проблема, работаем по http
|
||||
response = await api.post('/storage', request);
|
||||
response = response.data;
|
||||
}
|
||||
|
||||
const state = response.data.state;
|
||||
const state = response.state;
|
||||
if (!state)
|
||||
throw new Error('Неверный ответ api');
|
||||
|
||||
return response.data;
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
176
client/api/webSocketConnection.js
Normal file
176
client/api/webSocketConnection.js
Normal file
@@ -0,0 +1,176 @@
|
||||
const cleanPeriod = 60*1000;//1 минута
|
||||
|
||||
class WebSocketConnection {
|
||||
//messageLifeTime в минутах (cleanPeriod)
|
||||
constructor(messageLifeTime = 5) {
|
||||
this.ws = null;
|
||||
this.timer = null;
|
||||
this.listeners = [];
|
||||
this.messageQueue = [];
|
||||
this.messageLifeTime = messageLifeTime;
|
||||
this.requestId = 0;
|
||||
}
|
||||
|
||||
addListener(listener) {
|
||||
if (this.listeners.indexOf(listener) < 0)
|
||||
this.listeners.push(Object.assign({regTime: Date.now()}, listener));
|
||||
}
|
||||
|
||||
//рассылаем сообщение и удаляем те обработчики, которые его получили
|
||||
emit(mes, isError) {
|
||||
const len = this.listeners.length;
|
||||
if (len > 0) {
|
||||
let newListeners = [];
|
||||
for (const listener of this.listeners) {
|
||||
let emitted = false;
|
||||
if (isError) {
|
||||
if (listener.onError)
|
||||
listener.onError(mes);
|
||||
emitted = true;
|
||||
} else {
|
||||
if (listener.onMessage) {
|
||||
if (listener.requestId) {
|
||||
if (listener.requestId === mes.requestId) {
|
||||
listener.onMessage(mes);
|
||||
emitted = true;
|
||||
}
|
||||
} else {
|
||||
listener.onMessage(mes);
|
||||
emitted = true;
|
||||
}
|
||||
} else {
|
||||
emitted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!emitted)
|
||||
newListeners.push(listener);
|
||||
}
|
||||
this.listeners = newListeners;
|
||||
}
|
||||
|
||||
return this.listeners.length != len;
|
||||
}
|
||||
|
||||
open(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.ws && this.ws.readyState == WebSocket.OPEN) {
|
||||
resolve(this.ws);
|
||||
} else {
|
||||
let protocol = 'ws:';
|
||||
if (window.location.protocol == 'https:') {
|
||||
protocol = 'wss:'
|
||||
}
|
||||
|
||||
url = url || `${protocol}//${window.location.host}/ws`;
|
||||
|
||||
this.ws = new WebSocket(url);
|
||||
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
this.timer = setTimeout(() => { this.periodicClean(); }, cleanPeriod);
|
||||
|
||||
let resolved = false;
|
||||
this.ws.onopen = (e) => {
|
||||
resolved = true;
|
||||
resolve(e);
|
||||
};
|
||||
|
||||
this.ws.onmessage = (e) => {
|
||||
try {
|
||||
const mes = JSON.parse(e.data);
|
||||
this.messageQueue.push({regTime: Date.now(), mes});
|
||||
|
||||
let newMessageQueue = [];
|
||||
for (const message of this.messageQueue) {
|
||||
if (!this.emit(message.mes)) {
|
||||
newMessageQueue.push(message);
|
||||
}
|
||||
}
|
||||
|
||||
this.messageQueue = newMessageQueue;
|
||||
} catch (e) {
|
||||
this.emit(e.message, true);
|
||||
}
|
||||
};
|
||||
|
||||
this.ws.onerror = (e) => {
|
||||
this.emit(e.message, true);
|
||||
if (!resolved)
|
||||
reject(e);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//timeout в минутах (cleanPeriod)
|
||||
message(requestId, timeout = 2) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.addListener({
|
||||
requestId,
|
||||
timeout,
|
||||
onMessage: (mes) => {
|
||||
if (mes.error) {
|
||||
reject(mes.error);
|
||||
} else {
|
||||
resolve(mes);
|
||||
}
|
||||
},
|
||||
onError: (e) => {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
send(req) {
|
||||
if (this.ws && this.ws.readyState == WebSocket.OPEN) {
|
||||
const requestId = ++this.requestId;
|
||||
this.ws.send(JSON.stringify(Object.assign({requestId}, req)));
|
||||
return requestId;
|
||||
} else {
|
||||
throw new Error('WebSocket connection is not ready');
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
if (this.ws && this.ws.readyState == WebSocket.OPEN) {
|
||||
this.ws.close();
|
||||
}
|
||||
}
|
||||
|
||||
periodicClean() {
|
||||
try {
|
||||
this.timer = null;
|
||||
|
||||
const now = Date.now();
|
||||
//чистка listeners
|
||||
let newListeners = [];
|
||||
for (const listener of this.listeners) {
|
||||
if (now - listener.regTime < listener.timeout*cleanPeriod - 50) {
|
||||
newListeners.push(listener);
|
||||
} else {
|
||||
if (listener.onError)
|
||||
listener.onError('Время ожидания ответа истекло');
|
||||
}
|
||||
}
|
||||
this.listeners = newListeners;
|
||||
|
||||
//чистка messageQueue
|
||||
let newMessageQueue = [];
|
||||
for (const message of this.messageQueue) {
|
||||
if (now - message.regTime < this.messageLifeTime*cleanPeriod - 50) {
|
||||
newMessageQueue.push(message);
|
||||
}
|
||||
}
|
||||
this.messageQueue = newMessageQueue;
|
||||
} finally {
|
||||
if (this.ws.readyState == WebSocket.OPEN) {
|
||||
this.timer = setTimeout(() => { this.periodicClean(); }, cleanPeriod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new WebSocketConnection();
|
||||
@@ -1,3 +1,2 @@
|
||||
User-agent: *
|
||||
Disallow: /?*url=
|
||||
Disallow: /#/
|
||||
@@ -215,22 +215,6 @@ class App extends Vue {
|
||||
window.history.replaceState({}, '', '/');
|
||||
this.$router.replace({ path: '/reader', query: q });
|
||||
}
|
||||
|
||||
//yandex-метрика для omnireader
|
||||
if (this.config.branch == 'production' && this.mode == 'omnireader' && !this.yaMetricsDone) {
|
||||
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
||||
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
|
||||
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");// eslint-disable-line no-unexpected-multiline
|
||||
|
||||
ym(52347334, "init", {// eslint-disable-line no-undef
|
||||
id:52347334,
|
||||
clickmap:true,
|
||||
trackLinks:true,
|
||||
accurateTrackBounce:true
|
||||
});
|
||||
|
||||
this.yaMetricsDone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,30 +1,54 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="box">
|
||||
<p class="p">Проект существует исключительно на личном энтузиазме.</p>
|
||||
<p class="p">Чтобы энтузиазма было побольше, вы можете пожертвовать на развитие проекта любую сумму:</p>
|
||||
<p class="p">Вы можете пожертвовать на развитие проекта любую сумму:</p>
|
||||
<div class="address">
|
||||
<img class="logo" src="./assets/yandex.png">
|
||||
<el-button class="button" @click="donateYandexMoney">Пожертвовать</el-button><br>
|
||||
<div class="para">{{ yandexAddress }}</div>
|
||||
<div class="para">{{ yandexAddress }}
|
||||
<el-tooltip :open-delay="500" effect="light">
|
||||
<template slot="content">
|
||||
Скопировать
|
||||
</template>
|
||||
<i class="el-icon-copy-document copy-icon" @click="copyAddress(yandexAddress, 'Яндекс кошелек')"></i>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="address">
|
||||
<img class="logo" src="./assets/bitcoin.png">
|
||||
<el-button class="button" @click="copyAddress(bitcoinAddress, 'Bitcoin')">Скопировать</el-button><br>
|
||||
<div class="para">{{ bitcoinAddress }}</div>
|
||||
<div class="para">{{ bitcoinAddress }}
|
||||
<el-tooltip :open-delay="500" effect="light">
|
||||
<template slot="content">
|
||||
Скопировать
|
||||
</template>
|
||||
<i class="el-icon-copy-document copy-icon" @click="copyAddress(bitcoinAddress, 'Bitcoin-адрес')"></i>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="address">
|
||||
<img class="logo" src="./assets/litecoin.png">
|
||||
<el-button class="button" @click="copyAddress(litecoinAddress, 'Litecoin')">Скопировать</el-button><br>
|
||||
<div class="para">{{ litecoinAddress }}</div>
|
||||
<div class="para">{{ litecoinAddress }}
|
||||
<el-tooltip :open-delay="500" effect="light">
|
||||
<template slot="content">
|
||||
Скопировать
|
||||
</template>
|
||||
<i class="el-icon-copy-document copy-icon" @click="copyAddress(litecoinAddress, 'Litecoin-адрес')"></i>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="address">
|
||||
<img class="logo" src="./assets/monero.png">
|
||||
<el-button class="button" @click="copyAddress(moneroAddress, 'Monero')">Скопировать</el-button><br>
|
||||
<div class="para">{{ moneroAddress }}</div>
|
||||
<div class="para">{{ moneroAddress }}
|
||||
<el-tooltip :open-delay="500" effect="light">
|
||||
<template slot="content">
|
||||
Скопировать
|
||||
</template>
|
||||
<i class="el-icon-copy-document copy-icon" @click="copyAddress(moneroAddress, 'Monero-адрес')"></i>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -54,7 +78,7 @@ class DonateHelpPage extends Vue {
|
||||
async copyAddress(address, prefix) {
|
||||
const result = await copyTextToClipboard(address);
|
||||
if (result)
|
||||
this.$notify.success({message: `${prefix}-адрес ${address} успешно скопирован в буфер обмена`});
|
||||
this.$notify.success({message: `${prefix} ${address} успешно скопирован в буфер обмена`});
|
||||
else
|
||||
this.$notify.error({message: 'Копирование не удалось'});
|
||||
}
|
||||
@@ -106,4 +130,10 @@ h5 {
|
||||
position: relative;
|
||||
top: 10px;
|
||||
}
|
||||
|
||||
.copy-icon {
|
||||
margin-left: 10px;
|
||||
cursor: pointer;
|
||||
font-size: 120%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<template>
|
||||
<div id="vue-github-corner">
|
||||
<a :href="url" id="github-corner" target="_blank" aria-label="View source on Github" >
|
||||
<svg id="github-corner-svg"
|
||||
aria-hidden="true"
|
||||
viewBox="0 0 250 250"
|
||||
:width="size" :height="size"
|
||||
:style="svgStyle" >
|
||||
<path :d="svgPath1" @mouseenter="flipColor" @mouseleave="flipColor"></path>
|
||||
<path :d="svgPath2" :style="gitStyle" class="octo-arm"></path>
|
||||
<path :d="svgPath3" :style="gitStyle" class="octo-body"></path>
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'GithubCorner',
|
||||
props: {
|
||||
url: {
|
||||
type: String,
|
||||
default: '/'
|
||||
},
|
||||
size: {
|
||||
type: Number,
|
||||
default: 80
|
||||
},
|
||||
colorScheme: {
|
||||
type: String,
|
||||
default: 'auto'
|
||||
},
|
||||
cornerColor: {
|
||||
type: String,
|
||||
default: '#625D5D'
|
||||
},
|
||||
gitColor: {
|
||||
type: String,
|
||||
default: 'PeachPuff'
|
||||
},
|
||||
leftCorner: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
flipOnHover: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
svgStyle: {
|
||||
fill: this.cornerColor,
|
||||
right: (this.leftCorner ? 'auto' : '0'),
|
||||
left: (this.leftCorner ? '0' : 'auto'),
|
||||
transform: (this.leftCorner ? 'scale(-1, 1)' : 'none')
|
||||
},
|
||||
gitStyle: {
|
||||
fill: this.gitColor
|
||||
},
|
||||
flipped: false,
|
||||
svgPath1: 'M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z',
|
||||
svgPath2: 'M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2',
|
||||
svgPath3: 'M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
flipColor: function() {
|
||||
if (this.flipOnHover) {
|
||||
let holdSvgFill = this.svgStyle.fill
|
||||
this.svgStyle.fill = this.gitStyle.fill
|
||||
this.gitStyle.fill = holdSvgFill
|
||||
}
|
||||
}
|
||||
},
|
||||
beforeMount: function() {
|
||||
if (this.colorScheme != 'auto') {
|
||||
let sch = this.colorScheme
|
||||
this.gitStyle.fill = '#fff'
|
||||
|
||||
if (sch.toLowerCase() == 'black') {
|
||||
this.svgStyle.fill = '#151513'
|
||||
}
|
||||
if (sch.toLowerCase() == 'green') {
|
||||
this.svgStyle.fill = '#64CEAA'
|
||||
}
|
||||
if (sch.toLowerCase() == 'red') {
|
||||
this.svgStyle.fill = '#FD6C6C'
|
||||
}
|
||||
if (sch.toLowerCase() == 'blue') {
|
||||
this.svgStyle.fill = '#70B7FD'
|
||||
}
|
||||
if (sch.toLowerCase() == 'white') {
|
||||
this.svgStyle.fill = '#fff'
|
||||
this.gitStyle.fill = '#151513'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
#github-corner .octo-arm {
|
||||
transform-origin: 130px 106px
|
||||
}
|
||||
#github-corner:hover .octo-arm {
|
||||
animation: octocat-wave 560ms ease-in-out;
|
||||
}
|
||||
|
||||
@keyframes octocat-wave {
|
||||
0% { transform: rotate(0deg); }
|
||||
20% { transform: rotate(-25deg); }
|
||||
40% { transform: rotate(10deg); }
|
||||
60% { transform: rotate(-25deg); }
|
||||
80% { transform: rotate(10deg); }
|
||||
100% { transform: rotate(0deg); }
|
||||
}
|
||||
|
||||
#github-corner-svg {
|
||||
color: #fff;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
border: 0;
|
||||
}
|
||||
#github-corner-svg, #github-corner-svg .octo-arm, #github-corner-svg .octo-body {
|
||||
transition: fill 1s ease;
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<div ref="main" class="main">
|
||||
<GithubCorner url="https://github.com/bookpauk/liberama" cornerColor="#1B695F"></GithubCorner>
|
||||
<div class="part top">
|
||||
<span class="greeting bold-font">{{ title }}</span>
|
||||
<div class="space"></div>
|
||||
@@ -54,11 +55,14 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
import Vue from 'vue';
|
||||
import Component from 'vue-class-component';
|
||||
import GithubCorner from './GithubCorner/GithubCorner.vue';
|
||||
|
||||
import PasteTextPage from './PasteTextPage/PasteTextPage.vue';
|
||||
import {versionHistory} from '../versionHistory';
|
||||
|
||||
export default @Component({
|
||||
components: {
|
||||
GithubCorner,
|
||||
PasteTextPage,
|
||||
},
|
||||
})
|
||||
@@ -108,7 +112,7 @@ class LoaderPage extends Vue {
|
||||
|
||||
submitUrl() {
|
||||
if (this.bookUrl) {
|
||||
this.$emit('load-book', {url: this.bookUrl});
|
||||
this.$emit('load-book', {url: this.bookUrl, force: true});
|
||||
this.bookUrl = '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ const ruMessage = {
|
||||
'start': ' ',
|
||||
'finish': ' ',
|
||||
'error': ' ',
|
||||
'queue': 'очередь',
|
||||
'download': 'скачивание',
|
||||
'decompress': 'распаковка',
|
||||
'convert': 'конвертирование',
|
||||
@@ -49,8 +50,13 @@ class ProgressPage extends Vue {
|
||||
}
|
||||
|
||||
setState(state) {
|
||||
if (state.state)
|
||||
this.text = (ruMessage[state.state] ? ruMessage[state.state] : state.state);
|
||||
if (state.state) {
|
||||
if (state.state == 'queue') {
|
||||
this.text = 'Номер в очереди: ' + (state.place ? state.place : '');
|
||||
} else {
|
||||
this.text = (ruMessage[state.state] ? ruMessage[state.state] : state.state);
|
||||
}
|
||||
}
|
||||
this.step = (state.step ? state.step : this.step);
|
||||
this.totalSteps = (state.totalSteps > this.totalSteps ? state.totalSteps : this.totalSteps);
|
||||
this.progress = state.progress || 0;
|
||||
|
||||
@@ -91,88 +91,53 @@
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
title="Внимание!"
|
||||
:visible.sync="migrationVisible1"
|
||||
title="Здравствуйте, уважаемые читатели!"
|
||||
:visible.sync="donationVisible"
|
||||
width="90%">
|
||||
<div>
|
||||
Появилась httpS-версия сайта по адресу <a href="https://omnireader.ru" target="_blank">https://omnireader.ru</a><br>
|
||||
Работа по httpS-протоколу, помимо безопасности соединения, позволяет воспользоваться всеми возможностями
|
||||
современных браузеров, а именно, применительно к нашему ресурсу:
|
||||
<div style="word-break: normal">
|
||||
Стартовала ежегодная акция "Оплатим хостинг вместе".<br><br>
|
||||
|
||||
Для оплаты годового хостинга читалки, необходимо собрать около 2000 рублей.
|
||||
В настоящий момент у автора эта сумма есть в наличии. Однако будет справедливо, если каждый
|
||||
сможет проголосовать рублем за то, чтобы читалка так и оставалась:
|
||||
|
||||
<ul>
|
||||
<li>возможность автономной работы с читалкой (без доступа к интернету), кеширование сайта через appcache</li>
|
||||
<li>безопасная передача на сервер данных о настройках и читаемых книгах при включенной синхронизации; все данные шифруются на стороне
|
||||
браузера ключом доступа и никто (в т.ч. администратор) не имеет возможности их прочитать
|
||||
<li>использование встроенных в JS функций шифрования и других</li>
|
||||
<li>непрерывно улучшаемой</li>
|
||||
<li>без рекламы</li>
|
||||
<li>без регистрации</li>
|
||||
<li>Open Source</li>
|
||||
</ul>
|
||||
|
||||
Для того, чтобы перейти на новую версию с сохранением настроек и читаемых книг необходимо синхронизировать обе читалки:
|
||||
<ul>
|
||||
<li>зайти в "Настройки"->"Профили" и поставить галочку "Включить синхронизацию с сервером"</li>
|
||||
<li>там же добавить профиль устройства с любым именем для синхронизации настроек<br>
|
||||
<span style="margin-left: 20px"><i style="font-size: 90%" class="el-icon-info"></i>
|
||||
после этого все данные будут автоматически сохранены на сервер
|
||||
</span>
|
||||
</li>
|
||||
<li>далее нажать на кнопку "Показать ключ доступа" и кликнуть по ссылке "Ссылка для ввода ключа"<br>
|
||||
<span style="margin-left: 20px"><i style="font-size: 90%" class="el-icon-info"></i>
|
||||
произойдет переход на https-версию читалки и откроется окно для ввода ключа
|
||||
</span><br>
|
||||
<span style="margin-left: 20px"><i style="font-size: 90%" class="el-icon-info"></i>
|
||||
подтвердив ввод ключа нажатием "OK", включив синхронизацию с сервером и выбрав профиль устройства, вы восстановите все ваши настройки в новой версии
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
Автор также обращается с просьбой о помощи в распространении
|
||||
<a href="https://omnireader.ru" target="_blank">ссылки</a>
|
||||
<el-tooltip :open-delay="500" effect="light">
|
||||
<template slot="content">
|
||||
Скопировать
|
||||
</template>
|
||||
<i class="el-icon-copy-document" style="cursor: pointer; font-size: 100%" @click="copyLink('https://omnireader.ru')"></i>
|
||||
</el-tooltip>
|
||||
на читалку через тематические форумы, соцсети, мессенджеры и пр.
|
||||
Чем нас больше, тем легче оставаться на плаву и тем больше мотивации у разработчика, чтобы продолжать работать над проектом.
|
||||
|
||||
<br><br>
|
||||
Если соберется бóльшая сумма, то разработка децентрализованной библиотеки для свободного обмена книгами будет по возможности ускорена.
|
||||
<br><br>
|
||||
P.S. При необходимости можно воспользоваться подходящим обменником на <a href="https://www.bestchange.ru" target="_blank">bestchange.ru</a>
|
||||
|
||||
Старая http-версия сайта будет доступна до конца 2019 года.<br>
|
||||
Приносим извинения за доставленные неудобства.
|
||||
<br><br>
|
||||
<el-row type="flex" justify="center">
|
||||
<el-button type="success" round @click="openDonate">Помочь проекту</el-button>
|
||||
</el-row>
|
||||
</div>
|
||||
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="migrationDialogDisable">Больше не показывать</el-button>
|
||||
<el-button @click="migrationDialogRemind">Напомнить позже</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
title="Внимание!"
|
||||
:visible.sync="migrationVisible2"
|
||||
width="90%">
|
||||
<div>
|
||||
Информация для пользователей старой версии читалки по адресу <a href="http://omnireader.ru" target="_blank">http://omnireader.ru</a><br>
|
||||
Для того, чтобы перейти на новую httpS-версию с сохранением настроек и читаемых книг необходимо синхронизировать обе читалки:
|
||||
<ul>
|
||||
<li>перейти на старую версию ресурса <a href="http://omnireader.ru" target="_blank">http://omnireader.ru</a></li>
|
||||
<li>зайти в "Настройки"->"Профили" и поставить галочку "Включить синхронизацию с сервером"</li>
|
||||
<li>там же добавить профиль устройства с любым именем для синхронизации настроек<br>
|
||||
<span style="margin-left: 20px"><i style="font-size: 90%" class="el-icon-info"></i>
|
||||
после этого все данные будут автоматически сохранены на сервер
|
||||
</span>
|
||||
</li>
|
||||
<li>далее нажать на кнопку "Показать ключ доступа" и кликнуть по ссылке "Ссылка для ввода ключа"<br>
|
||||
<span style="margin-left: 20px"><i style="font-size: 90%" class="el-icon-info"></i>
|
||||
произойдет переход на https-версию читалки и откроется окно для ввода ключа
|
||||
</span><br>
|
||||
<span style="margin-left: 20px"><i style="font-size: 90%" class="el-icon-info"></i>
|
||||
подтвердив ввод ключа нажатием "OK", включив синхронизацию с сервером и выбрав профиль устройства, вы восстановите все ваши настройки в новой версии
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
Старая http-версия сайта будет доступна до конца 2019 года.<br>
|
||||
Приносим извинения за доставленные неудобства.
|
||||
</div>
|
||||
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="migrationDialogDisable">Больше не показывать</el-button>
|
||||
<el-button @click="migrationDialogRemind">Напомнить позже</el-button>
|
||||
<span class="clickable" style="font-size: 60%; color: grey" @click="donationDialogDisable">Больше не показывать</span>
|
||||
<br><br>
|
||||
<el-button @click="donationDialogRemind">Напомнить позже</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
</el-main>
|
||||
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
@@ -282,8 +247,7 @@ class Reader extends Vue {
|
||||
|
||||
whatsNewVisible = false;
|
||||
whatsNewContent = '';
|
||||
migrationVisible1 = false;
|
||||
migrationVisible2 = false;
|
||||
donationVisible = false;
|
||||
|
||||
created() {
|
||||
this.loading = true;
|
||||
@@ -320,15 +284,6 @@ class Reader extends Vue {
|
||||
});
|
||||
|
||||
this.loadSettings();
|
||||
|
||||
//TODO: убрать в будущем
|
||||
if (this.showToolButton['history']) {
|
||||
const newShowToolButton = Object.assign({}, this.showToolButton);
|
||||
newShowToolButton['recentBooks'] = true;
|
||||
delete newShowToolButton['history'];
|
||||
const newSettings = Object.assign({}, this.settings, { showToolButton: newShowToolButton });
|
||||
this.commit('reader/setSettings', newSettings);
|
||||
}
|
||||
}
|
||||
|
||||
mounted() {
|
||||
@@ -351,10 +306,10 @@ class Reader extends Vue {
|
||||
this.checkActivateDonateHelpPage();
|
||||
this.loading = false;
|
||||
|
||||
await this.showWhatsNew();
|
||||
await this.showMigration();
|
||||
|
||||
this.updateRoute();
|
||||
|
||||
await this.showWhatsNew();
|
||||
await this.showDonation();
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -366,7 +321,7 @@ class Reader extends Vue {
|
||||
this.clickControl = settings.clickControl;
|
||||
this.blinkCachedLoad = settings.blinkCachedLoad;
|
||||
this.showWhatsNewDialog = settings.showWhatsNewDialog;
|
||||
this.showMigrationDialog = settings.showMigrationDialog;
|
||||
this.showDonationDialog2020 = settings.showDonationDialog2020;
|
||||
this.showToolButton = settings.showToolButton;
|
||||
this.enableSitesFilter = settings.enableSitesFilter;
|
||||
|
||||
@@ -432,31 +387,39 @@ class Reader extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
async showMigration() {
|
||||
async showDonation() {
|
||||
await utils.sleep(3000);
|
||||
if (!this.settingsActive &&
|
||||
this.mode == 'omnireader' && this.showMigrationDialog && this.migrationRemindDate != utils.formatDate(new Date(), 'coDate')) {
|
||||
if (window.location.protocol == 'http:') {
|
||||
this.migrationVisible1 = true;
|
||||
} else if (window.location.protocol == 'https:') {
|
||||
this.migrationVisible2 = true;
|
||||
}
|
||||
const today = utils.formatDate(new Date(), 'coDate');
|
||||
|
||||
if (this.mode == 'omnireader' && today < '2020-03-01' && this.showDonationDialog2020 && this.donationRemindDate != today) {
|
||||
this.donationVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
migrationDialogDisable() {
|
||||
this.migrationVisible1 = false;
|
||||
this.migrationVisible2 = false;
|
||||
if (this.showMigrationDialog) {
|
||||
const newSettings = Object.assign({}, this.settings, { showMigrationDialog: false });
|
||||
donationDialogDisable() {
|
||||
this.donationVisible = false;
|
||||
if (this.showDonationDialog2020) {
|
||||
const newSettings = Object.assign({}, this.settings, { showDonationDialog2020: false });
|
||||
this.commit('reader/setSettings', newSettings);
|
||||
}
|
||||
}
|
||||
|
||||
migrationDialogRemind() {
|
||||
this.migrationVisible1 = false;
|
||||
this.migrationVisible2 = false;
|
||||
this.commit('reader/setMigrationRemindDate', utils.formatDate(new Date(), 'coDate'));
|
||||
donationDialogRemind() {
|
||||
this.donationVisible = false;
|
||||
this.commit('reader/setDonationRemindDate', utils.formatDate(new Date(), 'coDate'));
|
||||
}
|
||||
|
||||
openDonate() {
|
||||
this.donationVisible = false;
|
||||
this.donateToggle();
|
||||
}
|
||||
|
||||
async copyLink(link) {
|
||||
const result = await utils.copyTextToClipboard(link);
|
||||
if (result)
|
||||
this.$notify.success({message: `Ссылка ${link} успешно скопирована в буфер обмена`});
|
||||
else
|
||||
this.$notify.error({message: 'Копирование не удалось'});
|
||||
}
|
||||
|
||||
openVersionHistory() {
|
||||
@@ -577,8 +540,8 @@ class Reader extends Vue {
|
||||
return this.$store.state.reader.whatsNewContentHash;
|
||||
}
|
||||
|
||||
get migrationRemindDate() {
|
||||
return this.$store.state.reader.migrationRemindDate;
|
||||
get donationRemindDate() {
|
||||
return this.$store.state.reader.donationRemindDate;
|
||||
}
|
||||
|
||||
addAction(pos) {
|
||||
@@ -845,15 +808,16 @@ class Reader extends Vue {
|
||||
case 'scrolling':
|
||||
case 'search':
|
||||
case 'copyText':
|
||||
case 'recentBooks':
|
||||
case 'refresh':
|
||||
case 'offlineMode':
|
||||
case 'recentBooks':
|
||||
case 'settings':
|
||||
if (this[`${button}Active`])
|
||||
if (this.progressActive) {
|
||||
classResult = classDisabled;
|
||||
} else if (this[`${button}Active`]) {
|
||||
classResult = classActive;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (button) {
|
||||
case 'undoAction':
|
||||
if (this.actionCur <= 0)
|
||||
classResult = classDisabled;
|
||||
@@ -950,7 +914,8 @@ class Reader extends Vue {
|
||||
return;
|
||||
}
|
||||
|
||||
let url = opts.url;
|
||||
let url = encodeURI(decodeURI(opts.url));
|
||||
|
||||
if ((url.indexOf('http://') != 0) && (url.indexOf('https://') != 0) &&
|
||||
(url.indexOf('file://') != 0))
|
||||
url = 'http://' + url;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<span v-show="loading"><i class="el-icon-loading" style="font-size: 25px"></i> <span style="position: relative; top: -4px">Список загружается</span></span>
|
||||
</template>
|
||||
|
||||
<a ref="download" style='display: none;'></a>
|
||||
<el-table
|
||||
:data="tableData"
|
||||
style="width: 570px"
|
||||
@@ -72,7 +73,7 @@
|
||||
>
|
||||
<template slot-scope="scope">
|
||||
<a v-show="isUrl(scope.row.url)" :href="scope.row.url" target="_blank">Оригинал</a><br>
|
||||
<a :href="scope.row.path" :download="getFileNameFromPath(scope.row.path)">Скачать FB2</a>
|
||||
<a :href="scope.row.path" @click.prevent="downloadBook(scope.row.path)">Скачать FB2</a>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
@@ -104,6 +105,7 @@ import _ from 'lodash';
|
||||
import * as utils from '../../../share/utils';
|
||||
import Window from '../../share/Window.vue';
|
||||
import bookManager from '../share/bookManager';
|
||||
import readerApi from '../../../api/reader';
|
||||
|
||||
export default @Component({
|
||||
components: {
|
||||
@@ -209,7 +211,7 @@ class RecentBooksPage extends Vue {
|
||||
a.middleName
|
||||
]).join(' '));
|
||||
author = authorNames.join(', ');
|
||||
} else {
|
||||
} else {//TODO: убрать в будущем
|
||||
author = _.compact([
|
||||
fb2.lastName,
|
||||
fb2.firstName,
|
||||
@@ -268,8 +270,20 @@ class RecentBooksPage extends Vue {
|
||||
return result;
|
||||
}
|
||||
|
||||
getFileNameFromPath(fb2Path) {
|
||||
return path.basename(fb2Path).substr(0, 10) + '.fb2';
|
||||
async downloadBook(fb2path) {
|
||||
try {
|
||||
await readerApi.checkCachedBook(fb2path);
|
||||
|
||||
const d = this.$refs.download;
|
||||
d.href = fb2path;
|
||||
d.download = path.basename(fb2path).substr(0, 10) + '.fb2';
|
||||
d.click();
|
||||
} catch (e) {
|
||||
let errMes = e.message;
|
||||
if (errMes.indexOf('404') >= 0)
|
||||
errMes = 'Файл не найден на сервере (возможно был удален как устаревший)';
|
||||
this.$alert(errMes, 'Ошибка', {type: 'error'});
|
||||
}
|
||||
}
|
||||
|
||||
openOriginal(url) {
|
||||
|
||||
@@ -474,15 +474,15 @@
|
||||
<el-form-item label="Уведомление">
|
||||
<el-tooltip :open-delay="500" effect="light">
|
||||
<template slot="content">
|
||||
Показывать диалог о переходе на httpS-версию
|
||||
Показывать уведомление "Оплатим хостинг вместе"
|
||||
</template>
|
||||
<el-checkbox v-model="showMigrationDialog">Уведомлять о переходе на httpS-версию</el-checkbox>
|
||||
<el-checkbox v-model="showDonationDialog2020">Показывать "Оплатим хостинг вместе"</el-checkbox>
|
||||
</el-tooltip>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
|
||||
<div class="partHeader">Прочее</div>
|
||||
<div class="partHeader">Другое</div>
|
||||
|
||||
<el-form-item label="Парам. в URL">
|
||||
<el-tooltip :open-delay="500" effect="light">
|
||||
|
||||
@@ -225,30 +225,23 @@ class TextPage extends Vue {
|
||||
|
||||
//scrolling page
|
||||
const pageSpace = this.scrollHeight - this.pageLineCount*this.lineHeight;
|
||||
let y = pageSpace/2;
|
||||
let top = pageSpace/2;
|
||||
if (this.showStatusBar)
|
||||
y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
||||
let page1 = this.$refs.scrollBox1;
|
||||
let page2 = this.$refs.scrollBox2;
|
||||
top += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
||||
let page1 = this.$refs.scrollBox1.style;
|
||||
let page2 = this.$refs.scrollBox2.style;
|
||||
|
||||
page1.style.perspective = '3072px';
|
||||
page2.style.perspective = '3072px';
|
||||
page1.perspective = page2.perspective = '3072px';
|
||||
|
||||
page1.style.width = this.w + this.indentLR + 'px';
|
||||
page2.style.width = this.w + this.indentLR + 'px';
|
||||
page1.style.height = this.scrollHeight - (pageSpace > 0 ? pageSpace : 0) + 'px';
|
||||
page2.style.height = this.scrollHeight - (pageSpace > 0 ? pageSpace : 0) + 'px';
|
||||
page1.style.top = y + 'px';
|
||||
page2.style.top = y + 'px';
|
||||
page1.style.left = this.indentLR + 'px';
|
||||
page2.style.left = this.indentLR + 'px';
|
||||
page1.width = page2.width = this.w + this.indentLR + 'px';
|
||||
page1.height = page2.height = this.scrollHeight - (pageSpace > 0 ? pageSpace : 0) + 'px';
|
||||
page1.top = page2.top = top + 'px';
|
||||
page1.left = page2.left = this.indentLR + 'px';
|
||||
|
||||
page1 = this.$refs.scrollingPage1;
|
||||
page2 = this.$refs.scrollingPage2;
|
||||
page1.style.width = this.w + this.indentLR + 'px';
|
||||
page2.style.width = this.w + this.indentLR + 'px';
|
||||
page1.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||
page2.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||
page1 = this.$refs.scrollingPage1.style;
|
||||
page2 = this.$refs.scrollingPage2.style;
|
||||
page1.width = page2.width = this.w + this.indentLR + 'px';
|
||||
page1.height = page2.height = this.scrollHeight + this.lineHeight + 'px';
|
||||
}
|
||||
|
||||
async checkLoadedFonts() {
|
||||
@@ -334,13 +327,15 @@ class TextPage extends Vue {
|
||||
|
||||
this.draw();
|
||||
|
||||
// шрифты хрен знает когда подгружаются в div, поэтому
|
||||
const parsed = this.parsed;
|
||||
await sleep(5000);
|
||||
if (this.parsed === parsed) {
|
||||
parsed.force = true;
|
||||
this.draw();
|
||||
parsed.force = false;
|
||||
// ширина шрифта некоторое время выдается неверно, поэтому
|
||||
if (!omitLoadFonts) {
|
||||
const parsed = this.parsed;
|
||||
await sleep(100);
|
||||
if (this.parsed === parsed) {
|
||||
parsed.force = true;
|
||||
this.draw();
|
||||
parsed.force = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,6 @@ export default class BookParser {
|
||||
|
||||
//defaults
|
||||
let fb2 = {
|
||||
firstName: '',
|
||||
middleName: '',
|
||||
lastName: '',
|
||||
bookTitle: '',
|
||||
};
|
||||
|
||||
@@ -240,6 +237,7 @@ export default class BookParser {
|
||||
newParagraph(' ', 1);
|
||||
isFirstTitlePara = true;
|
||||
bold = true;
|
||||
center = true;
|
||||
}
|
||||
|
||||
if (tag == 'epigraph') {
|
||||
@@ -282,6 +280,7 @@ export default class BookParser {
|
||||
if (tag == 'subtitle') {
|
||||
isFirstTitlePara = false;
|
||||
bold = false;
|
||||
center = false;
|
||||
}
|
||||
|
||||
if (tag == 'epigraph') {
|
||||
@@ -367,11 +366,10 @@ export default class BookParser {
|
||||
tClose += (bold ? '</strong>' : '');
|
||||
tClose += (center ? '</center>' : '');
|
||||
|
||||
if (path.indexOf('/fictionbook/body/title') == 0) {
|
||||
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
||||
}
|
||||
|
||||
if (path.indexOf('/fictionbook/body/section') == 0) {
|
||||
if (path.indexOf('/fictionbook/body/title') == 0 ||
|
||||
path.indexOf('/fictionbook/body/section') == 0 ||
|
||||
path.indexOf('/fictionbook/body/epigraph') == 0
|
||||
) {
|
||||
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
||||
}
|
||||
|
||||
|
||||
@@ -319,7 +319,6 @@ class BookManager {
|
||||
|
||||
metaOnly(book) {
|
||||
let result = Object.assign({}, book);
|
||||
delete result.data;//можно будет убрать эту строку со временем
|
||||
delete result.parsed;
|
||||
return result;
|
||||
}
|
||||
@@ -465,7 +464,7 @@ class BookManager {
|
||||
|
||||
addEventListener(listener) {
|
||||
if (this.eventListeners.indexOf(listener) < 0)
|
||||
this.eventListeners.push(listener);
|
||||
this.eventListeners.push(listener);
|
||||
}
|
||||
|
||||
removeEventListener(listener) {
|
||||
|
||||
@@ -1,4 +1,75 @@
|
||||
export const versionHistory = [
|
||||
{
|
||||
showUntil: '2020-01-27',
|
||||
header: '0.8.3 (2020-01-28)',
|
||||
content:
|
||||
`
|
||||
<ul>
|
||||
<li>добавлено всплывающее окно с акцией "Оплатим хостинг вместе"</li>
|
||||
<li>внутренние оптимизации</li>
|
||||
</ul>
|
||||
`
|
||||
},
|
||||
|
||||
{
|
||||
showUntil: '2020-01-19',
|
||||
header: '0.8.2 (2020-01-20)',
|
||||
content:
|
||||
`
|
||||
<ul>
|
||||
<li>внутренние оптимизации</li>
|
||||
</ul>
|
||||
`
|
||||
},
|
||||
|
||||
{
|
||||
showUntil: '2020-01-06',
|
||||
header: '0.8.1 (2020-01-07)',
|
||||
content:
|
||||
`
|
||||
<ul>
|
||||
<li>добавлена частичная поддержка формата FB3</li>
|
||||
<li>исправлен баг "Request path contains unescaped characters"</li>
|
||||
</ul>
|
||||
`
|
||||
},
|
||||
|
||||
{
|
||||
showUntil: '2020-01-05',
|
||||
header: '0.8.0 (2020-01-02)',
|
||||
content:
|
||||
`
|
||||
<ul>
|
||||
<li>окончательный переход на https</li>
|
||||
<li>код проекта теперь Open Source: <a href="https://github.com/bookpauk/liberama" target="_blank">https://github.com/bookpauk/liberama</a></li>
|
||||
</ul>
|
||||
`
|
||||
},
|
||||
|
||||
{
|
||||
showUntil: '2019-11-26',
|
||||
header: '0.7.9 (2019-11-27)',
|
||||
content:
|
||||
`
|
||||
<ul>
|
||||
<li>добавлен неубираемый баннер для http-версии о переходе на httpS</li>
|
||||
<li>исправления багов</li>
|
||||
</ul>
|
||||
`
|
||||
},
|
||||
|
||||
{
|
||||
showUntil: '2019-11-24',
|
||||
header: '0.7.8 (2019-11-25)',
|
||||
content:
|
||||
`
|
||||
<ul>
|
||||
<li>улучшение html-фильтров для сайтов</li>
|
||||
<li>исправления багов</li>
|
||||
</ul>
|
||||
`
|
||||
},
|
||||
|
||||
{
|
||||
showUntil: '2019-11-10',
|
||||
header: '0.7.7 (2019-11-06)',
|
||||
|
||||
@@ -19,6 +19,7 @@ import ElCheckbox from 'element-ui/lib/checkbox';
|
||||
import ElTabs from 'element-ui/lib/tabs';
|
||||
import ElTabPane from 'element-ui/lib/tab-pane';
|
||||
import ElTooltip from 'element-ui/lib/tooltip';
|
||||
import ElRow from 'element-ui/lib/row';
|
||||
import ElCol from 'element-ui/lib/col';
|
||||
import ElContainer from 'element-ui/lib/container';
|
||||
import ElAside from 'element-ui/lib/aside';
|
||||
@@ -43,7 +44,7 @@ import MessageBox from 'element-ui/lib/message-box';
|
||||
|
||||
const components = {
|
||||
ElMenu, ElMenuItem, ElButton, ElButtonGroup, ElCheckbox, ElTabs, ElTabPane, ElTooltip,
|
||||
ElCol, ElContainer, ElAside, ElMain, ElHeader,
|
||||
ElRow, ElCol, ElContainer, ElAside, ElMain, ElHeader,
|
||||
ElInput, ElInputNumber, ElSelect, ElOption, ElTable, ElTableColumn,
|
||||
ElProgress, ElSlider, ElForm, ElFormItem,
|
||||
ElColorPicker, ElDialog,
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<meta name="description" content="браузерная онлайн-читалка книг из интернета и библиотека">
|
||||
<meta name="keywords" content="библиотека,онлайн,читалка,книги,читать,браузер,интернет">
|
||||
<meta name="description" content="Браузерная онлайн-читалка книг. Поддерживаются форматы: fb2, html, txt, rtf, doc, docx, pdf, epub, mobi.">
|
||||
<meta name="keywords" content="онлайн,читалка,fb2,книги,читать,браузер,интернет">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -182,7 +182,7 @@ const settingDefaults = {
|
||||
imageFitWidth: true,
|
||||
showServerStorageMessages: true,
|
||||
showWhatsNewDialog: true,
|
||||
showMigrationDialog: true,
|
||||
showDonationDialog2020: true,
|
||||
enableSitesFilter: true,
|
||||
|
||||
fontShifts: {},
|
||||
@@ -205,7 +205,7 @@ const state = {
|
||||
profilesRev: 0,
|
||||
allowProfilesSave: false,//подстраховка для разработки
|
||||
whatsNewContentHash: '',
|
||||
migrationRemindDate: '',
|
||||
donationRemindDate: '',
|
||||
currentProfile: '',
|
||||
settings: Object.assign({}, settingDefaults),
|
||||
settingsRev: {},
|
||||
@@ -240,8 +240,8 @@ const mutations = {
|
||||
setWhatsNewContentHash(state, value) {
|
||||
state.whatsNewContentHash = value;
|
||||
},
|
||||
setMigrationRemindDate(state, value) {
|
||||
state.migrationRemindDate = value;
|
||||
setDonationRemindDate(state, value) {
|
||||
state.donationRemindDate = value;
|
||||
},
|
||||
setCurrentProfile(state, value) {
|
||||
state.currentProfile = value;
|
||||
|
||||
BIN
docs/assets/face.jpg
Normal file
BIN
docs/assets/face.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
BIN
docs/assets/reader.jpg
Normal file
BIN
docs/assets/reader.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
84
docs/omnireader/README.md
Normal file
84
docs/omnireader/README.md
Normal file
@@ -0,0 +1,84 @@
|
||||
## Разворачивание сервера OmniReader в Ubuntu:
|
||||
|
||||
### git, clone
|
||||
```
|
||||
sudo apt install ssh git
|
||||
git clone https://github.com/bookpauk/liberama
|
||||
```
|
||||
|
||||
### node.js
|
||||
```
|
||||
sudo apt install -y curl
|
||||
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
|
||||
sudo apt install -y nodejs
|
||||
```
|
||||
|
||||
### install packages
|
||||
```
|
||||
cd liberama
|
||||
npm i
|
||||
```
|
||||
|
||||
### create public dir
|
||||
```
|
||||
sudo mkdir /home/liberama
|
||||
sudo chown www-data.www-data /home/liberama
|
||||
```
|
||||
|
||||
### external converter `calibre`, download from https://download.calibre-ebook.com/
|
||||
```
|
||||
wget "https://download.calibre-ebook.com/3.39.1/calibre-3.39.1-x86_64.txz"
|
||||
sudo -u www-data mkdir -p /home/liberama/data/calibre
|
||||
sudo -u www-data tar xvf calibre-3.39.1-x86_64.txz -C /home/liberama/data/calibre
|
||||
```
|
||||
|
||||
### external converters
|
||||
```
|
||||
sudo apt install libreoffice
|
||||
sudo apt install poppler-utils
|
||||
```
|
||||
|
||||
### nginx, server config
|
||||
Для своего домена необходимо будет подправить docs/omnireader/omnireader.
|
||||
Можно также настроить сервер для HTTP, без SSL.
|
||||
```
|
||||
sudo apt install nginx
|
||||
sudo cp docs/omnireader/omnireader /etc/nginx/sites-available/omnireader
|
||||
sudo ln -s /etc/nginx/sites-available/omnireader /etc/nginx/sites-enabled/omnireader
|
||||
sudo rm /etc/nginx/sites-enabled/default
|
||||
sudo service nginx reload
|
||||
sudo chown -R www-data.www-data /var/www
|
||||
```
|
||||
|
||||
### certbot
|
||||
Следовать инструкции установки certbot https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx
|
||||
### old.omnireader
|
||||
```
|
||||
sudo apt install php7.2 php7.2-curl php7.2-mbstring php7.2-fpm
|
||||
sudo service php7.2-fpm restart
|
||||
|
||||
sudo mkdir /home/oldreader
|
||||
sudo chown www-data.www-data /home/oldreader
|
||||
sudo -u www-data cp -r docs/omnireader/old/* /home/oldreader
|
||||
```
|
||||
|
||||
## Деплой и запуск
|
||||
```
|
||||
cd docs/omnireader
|
||||
./deploy.sh
|
||||
./run_server.sh
|
||||
```
|
||||
|
||||
После первого запуска будет создан конфигурационный файл `/home/liberama/data/config.json`.
|
||||
Необходимо переключить приложение в режим `omnireader`, отредактировав опцию `servers`:
|
||||
```
|
||||
"servers": [
|
||||
{
|
||||
"serverName": "1",
|
||||
"mode": "omnireader",
|
||||
"ip": "0.0.0.0",
|
||||
"port": "44081"
|
||||
}
|
||||
]
|
||||
```
|
||||
и перезапустить `run_server.sh`
|
||||
@@ -1,2 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
npm run build:linux
|
||||
sudo -u www-data cp -r ../../dist/linux/* /home/liberama
|
||||
|
||||
@@ -8,6 +8,7 @@ server {
|
||||
server_name omnireader.ru;
|
||||
|
||||
client_max_body_size 50m;
|
||||
proxy_read_timeout 1h;
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1024;
|
||||
@@ -18,6 +19,13 @@ server {
|
||||
proxy_pass http://127.0.0.1:44081;
|
||||
}
|
||||
|
||||
location /ws {
|
||||
proxy_pass http://127.0.0.1:44081;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
}
|
||||
|
||||
location / {
|
||||
root /home/liberama/public;
|
||||
|
||||
@@ -36,26 +44,7 @@ server {
|
||||
listen 80;
|
||||
server_name omnireader.ru;
|
||||
|
||||
client_max_body_size 50m;
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1024;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_types *;
|
||||
|
||||
location /api {
|
||||
proxy_pass http://127.0.0.1:44081;
|
||||
}
|
||||
|
||||
location /tmp {
|
||||
root /home/liberama/public;
|
||||
add_header Content-Type text/xml;
|
||||
add_header Content-Encoding gzip;
|
||||
}
|
||||
|
||||
location / {
|
||||
root /home/liberama/public;
|
||||
}
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
|
||||
59
docs/omnireader/omnireader_http
Normal file
59
docs/omnireader/omnireader_http
Normal file
@@ -0,0 +1,59 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name omnireader.ru;
|
||||
|
||||
client_max_body_size 50m;
|
||||
proxy_read_timeout 1h;
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1024;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_types *;
|
||||
|
||||
location /api {
|
||||
proxy_pass http://127.0.0.1:44081;
|
||||
}
|
||||
|
||||
location /ws {
|
||||
proxy_pass http://127.0.0.1:44081;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
}
|
||||
|
||||
location / {
|
||||
root /home/liberama/public;
|
||||
|
||||
location /tmp {
|
||||
add_header Content-Type text/xml;
|
||||
add_header Content-Encoding gzip;
|
||||
}
|
||||
|
||||
location ~* \.(?:manifest|appcache|html)$ {
|
||||
expires -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name old.omnireader.ru;
|
||||
|
||||
client_max_body_size 50m;
|
||||
|
||||
gzip on;
|
||||
gzip_min_length 1024;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_types *;
|
||||
|
||||
root /home/oldreader;
|
||||
|
||||
index index.html;
|
||||
|
||||
# Обработка php файлов с помощью fpm
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
include /etc/nginx/fastcgi.conf;
|
||||
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
sudo bash
|
||||
|
||||
mkdir /home/liberama
|
||||
chown www-data.www-data /home/liberama
|
||||
|
||||
### oldreader
|
||||
# ubuntu 18
|
||||
apt install php7.2 php7.2-curl php7.2-mbstring php7.2-fpm
|
||||
service php7.2-fpm restart
|
||||
|
||||
mkdir /home/oldreader
|
||||
chown www-data /home/oldreader
|
||||
chgrp www-data /home/oldreader
|
||||
sudo -u www-data cp -r ./old/* /home/oldreader
|
||||
###
|
||||
|
||||
### external converter
|
||||
# calibre releases https://download.calibre-ebook.com/
|
||||
# download, unpack to data/calibre
|
||||
# 3.39.1
|
||||
wget "https://download.calibre-ebook.com/3.39.1/calibre-3.39.1-x86_64.txz"
|
||||
sudo -u www-data mkdir -p /home/liberama/data/calibre
|
||||
sudo -u www-data tar xvf calibre-3.39.1-x86_64.txz -C /home/liberama/data/calibre
|
||||
|
||||
apt install libreoffice
|
||||
apt install poppler-utils
|
||||
###
|
||||
|
||||
apt install nginx
|
||||
|
||||
cp omnireader /etc/nginx/sites-available/omnireader
|
||||
ln -s /etc/nginx/sites-available/omnireader /etc/nginx/sites-enabled/omnireader
|
||||
rm /etc/nginx/sites-enabled/default
|
||||
service nginx reload
|
||||
|
||||
chown -R www-data.www-data /var/www
|
||||
|
||||
exit
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
sudo -H -u www-data sh -c "cd /var/www; /home/liberama/liberama"
|
||||
@@ -1,12 +0,0 @@
|
||||
# Разворачивание среды:
|
||||
|
||||
# GIT REPO
|
||||
sudo apt install ssh git
|
||||
git clone
|
||||
|
||||
#nodejs
|
||||
sudo apt install -y curl
|
||||
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
|
||||
sudo apt install -y nodejs
|
||||
npm i
|
||||
|
||||
936
package-lock.json
generated
936
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@@ -1,6 +1,9 @@
|
||||
{
|
||||
"name": "Liberama",
|
||||
"version": "0.7.7",
|
||||
"version": "0.8.3",
|
||||
"author": "Book Pauk <bookpauk@gmail.com>",
|
||||
"license": "CC0-1.0",
|
||||
"repository": "bookpauk/liberama",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
@@ -27,21 +30,18 @@
|
||||
"babel-plugin-transform-decorators-legacy": "^1.3.5",
|
||||
"babel-preset-env": "^1.3.2",
|
||||
"clean-webpack-plugin": "^1.0.1",
|
||||
"copy-webpack-plugin": "^4.6.0",
|
||||
"copy-webpack-plugin": "^5.1.1",
|
||||
"css-loader": "^1.0.0",
|
||||
"disable-output-webpack-plugin": "^1.0.1",
|
||||
"element-theme-chalk": "^2.12.0",
|
||||
"eslint": "^5.16.0",
|
||||
"eslint-plugin-html": "^5.0.5",
|
||||
"eslint-plugin-node": "^8.0.0",
|
||||
"eslint-plugin-vue": "^5.2.3",
|
||||
"event-hooks-webpack-plugin": "^2.1.4",
|
||||
"file-loader": "^3.0.1",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"mini-css-extract-plugin": "^0.5.0",
|
||||
"null-loader": "^0.1.1",
|
||||
"optimize-css-assets-webpack-plugin": "^5.0.3",
|
||||
"pkg": "4.3.7",
|
||||
"pkg": "^4.4.2",
|
||||
"terser-webpack-plugin": "^1.4.1",
|
||||
"url-loader": "^1.1.2",
|
||||
"vue-class-component": "^6.3.2",
|
||||
@@ -77,13 +77,15 @@
|
||||
"safe-buffer": "^5.2.0",
|
||||
"sjcl": "^1.0.8",
|
||||
"sql-template-strings": "^2.2.2",
|
||||
"sqlite": "3.0.0",
|
||||
"sqlite": "^3.0.3",
|
||||
"tar-fs": "^2.0.0",
|
||||
"unbzip2-stream": "^1.3.3",
|
||||
"vue": "github:paulkamer/vue#fix_palemoon_clickhandlers_dist",
|
||||
"vue-router": "^3.1.3",
|
||||
"vuex": "^3.1.1",
|
||||
"vuex-persistedstate": "^2.5.4",
|
||||
"webdav": "^2.10.1",
|
||||
"ws": "^7.2.1",
|
||||
"zip-stream": "^2.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ module.exports = {
|
||||
maxTempPublicDirSize: 512*1024*1024,//512Мб
|
||||
maxUploadPublicDirSize: 200*1024*1024,//100Мб
|
||||
|
||||
useExternalBookConverter: false,
|
||||
useExternalBookConverter: false,
|
||||
|
||||
db: [
|
||||
{
|
||||
@@ -45,5 +45,14 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
|
||||
remoteWebDavStorage: false,
|
||||
/*
|
||||
remoteWebDavStorage: {
|
||||
url: '127.0.0.1:1900',
|
||||
username: '',
|
||||
password: '',
|
||||
},
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ const propsToSave = [
|
||||
'useExternalBookConverter',
|
||||
|
||||
'servers',
|
||||
'remoteWebDavStorage',
|
||||
];
|
||||
|
||||
let instance = null;
|
||||
@@ -41,9 +42,9 @@ class ConfigManager {
|
||||
process.env.NODE_ENV = this.branch;
|
||||
|
||||
this.branchConfigFile = __dirname + `/${this.branch}.js`;
|
||||
await fs.access(this.branchConfigFile);
|
||||
this._config = require(this.branchConfigFile);
|
||||
|
||||
await fs.ensureDir(this._config.dataDir);
|
||||
this._userConfigFile = `${this._config.dataDir}/config.json`;
|
||||
|
||||
this.inited = true;
|
||||
@@ -83,6 +84,7 @@ class ConfigManager {
|
||||
async save() {
|
||||
if (!this.inited)
|
||||
throw new Error('not inited');
|
||||
|
||||
const dataToSave = _.pick(this._config, propsToSave);
|
||||
await fs.writeFile(this.userConfigFile, JSON.stringify(dataToSave, null, 4));
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ class ReaderController extends BaseController {
|
||||
const request = req.body;
|
||||
let error = '';
|
||||
try {
|
||||
if (!request.action)
|
||||
if (!request.action)
|
||||
throw new Error(`key 'action' is empty`);
|
||||
if (!request.items || Array.isArray(request.data))
|
||||
if (!request.items || Array.isArray(request.data))
|
||||
throw new Error(`key 'items' is empty`);
|
||||
|
||||
return await this.readerStorage.doAction(request);
|
||||
@@ -62,6 +62,24 @@ class ReaderController extends BaseController {
|
||||
res.status(400).send({error});
|
||||
return false;
|
||||
}
|
||||
|
||||
async restoreCachedFile(req, res) {
|
||||
const request = req.body;
|
||||
let error = '';
|
||||
try {
|
||||
if (!request.path)
|
||||
throw new Error(`key 'path' is empty`);
|
||||
|
||||
const workerId = this.readerWorker.restoreCachedFile(request.path);
|
||||
const state = this.workerState.getState(workerId);
|
||||
return (state ? state : {});
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
//bad request
|
||||
res.status(400).send({error});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ReaderController;
|
||||
|
||||
164
server/controllers/WebSocketController.js
Normal file
164
server/controllers/WebSocketController.js
Normal file
@@ -0,0 +1,164 @@
|
||||
const WebSocket = require ('ws');
|
||||
const _ = require('lodash');
|
||||
|
||||
const ReaderWorker = require('../core/Reader/ReaderWorker');//singleton
|
||||
const ReaderStorage = require('../core/Reader/ReaderStorage');//singleton
|
||||
const WorkerState = require('../core/WorkerState');//singleton
|
||||
const log = new (require('../core/AppLogger'))().log;//singleton
|
||||
const utils = require('../core/utils');
|
||||
|
||||
const cleanPeriod = 1*60*1000;//1 минута
|
||||
const closeSocketOnIdle = 5*60*1000;//5 минут
|
||||
|
||||
class WebSocketController {
|
||||
constructor(wss, config) {
|
||||
this.config = config;
|
||||
this.isDevelopment = (config.branch == 'development');
|
||||
|
||||
this.readerStorage = new ReaderStorage();
|
||||
this.readerWorker = new ReaderWorker(config);
|
||||
this.workerState = new WorkerState();
|
||||
|
||||
this.wss = wss;
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
ws.on('message', (message) => {
|
||||
this.onMessage(ws, message);
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(() => { this.periodicClean(); }, cleanPeriod);
|
||||
}
|
||||
|
||||
periodicClean() {
|
||||
try {
|
||||
const now = Date.now();
|
||||
this.wss.clients.forEach((ws) => {
|
||||
if (!ws.lastActivity || now - ws.lastActivity > closeSocketOnIdle - 50) {
|
||||
ws.terminate();
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
setTimeout(() => { this.periodicClean(); }, cleanPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
async onMessage(ws, message) {
|
||||
let req = {};
|
||||
try {
|
||||
if (this.isDevelopment) {
|
||||
log(`WebSocket-IN: ${message.substr(0, 4000)}`);
|
||||
}
|
||||
|
||||
ws.lastActivity = Date.now();
|
||||
req = JSON.parse(message);
|
||||
switch (req.action) {
|
||||
case 'test':
|
||||
await this.test(req, ws); break;
|
||||
case 'get-config':
|
||||
await this.getConfig(req, ws); break;
|
||||
case 'worker-get-state':
|
||||
await this.workerGetState(req, ws); break;
|
||||
case 'worker-get-state-finish':
|
||||
await this.workerGetStateFinish(req, ws); break;
|
||||
case 'reader-restore-cached-file':
|
||||
await this.readerRestoreCachedFile(req, ws); break;
|
||||
case 'reader-storage':
|
||||
await this.readerStorageDo(req, ws); break;
|
||||
|
||||
default:
|
||||
throw new Error(`Action not found: ${req.action}`);
|
||||
}
|
||||
} catch (e) {
|
||||
this.send({error: e.message}, req, ws);
|
||||
}
|
||||
}
|
||||
|
||||
send(res, req, ws) {
|
||||
if (ws.readyState == WebSocket.OPEN) {
|
||||
ws.lastActivity = Date.now();
|
||||
let r = res;
|
||||
if (req.requestId)
|
||||
r = Object.assign({requestId: req.requestId}, r);
|
||||
|
||||
const message = JSON.stringify(r);
|
||||
ws.send(message);
|
||||
|
||||
if (this.isDevelopment) {
|
||||
log(`WebSocket-OUT: ${message.substr(0, 4000)}`);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Actions ------------------------------------------------------------------
|
||||
async test(req, ws) {
|
||||
this.send({message: 'Liberama project is awesome'}, req, ws);
|
||||
}
|
||||
|
||||
async getConfig(req, ws) {
|
||||
if (Array.isArray(req.params)) {
|
||||
this.send(_.pick(this.config, req.params), req, ws);
|
||||
} else {
|
||||
throw new Error('params is not an array');
|
||||
}
|
||||
}
|
||||
|
||||
async workerGetState(req, ws) {
|
||||
if (!req.workerId)
|
||||
throw new Error(`key 'workerId' is wrong`);
|
||||
|
||||
const state = this.workerState.getState(req.workerId);
|
||||
this.send((state ? state : {}), req, ws);
|
||||
}
|
||||
|
||||
async workerGetStateFinish(req, ws) {
|
||||
if (!req.workerId)
|
||||
throw new Error(`key 'workerId' is wrong`);
|
||||
|
||||
const refreshPause = 200;
|
||||
let i = 0;
|
||||
let state = {};
|
||||
while (1) {// eslint-disable-line no-constant-condition
|
||||
const prevProgress = state.progress || -1;
|
||||
const prevState = state.state || '';
|
||||
state = this.workerState.getState(req.workerId);
|
||||
|
||||
this.send((state ? state : {}), req, ws);
|
||||
if (!state) break;
|
||||
|
||||
if (state.state != 'finish' && state.state != 'error')
|
||||
await utils.sleep(refreshPause);
|
||||
else
|
||||
break;
|
||||
|
||||
i++;
|
||||
if (i > 2*60*1000/refreshPause) {//2 мин ждем телодвижений воркера
|
||||
this.send({state: 'error', error: 'Время ожидания процесса истекло'}, req, ws);
|
||||
}
|
||||
i = (prevProgress != state.progress || prevState != state.state ? 1 : i);
|
||||
}
|
||||
}
|
||||
|
||||
async readerRestoreCachedFile(req, ws) {
|
||||
if (!req.path)
|
||||
throw new Error(`key 'path' is empty`);
|
||||
|
||||
const workerId = this.readerWorker.restoreCachedFile(req.path);
|
||||
const state = this.workerState.getState(workerId);
|
||||
this.send((state ? state : {}), req, ws);
|
||||
}
|
||||
|
||||
async readerStorageDo(req, ws) {
|
||||
if (!req.body)
|
||||
throw new Error(`key 'body' is empty`);
|
||||
if (!req.body.action)
|
||||
throw new Error(`key 'action' is empty`);
|
||||
if (!req.body.items || Array.isArray(req.body.data))
|
||||
throw new Error(`key 'items' is empty`);
|
||||
|
||||
this.send(await this.readerStorage.doAction(req.body), req, ws);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WebSocketController;
|
||||
@@ -1,5 +1,6 @@
|
||||
const BaseController = require('./BaseController');
|
||||
const WorkerState = require('../core/WorkerState');//singleton
|
||||
const utils = require('../core/utils');
|
||||
|
||||
class WorkerController extends BaseController {
|
||||
constructor(config) {
|
||||
@@ -15,6 +16,7 @@ class WorkerController extends BaseController {
|
||||
throw new Error(`key 'workerId' is wrong`);
|
||||
|
||||
const state = this.workerState.getState(request.workerId);
|
||||
|
||||
return (state ? state : {});
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
@@ -23,6 +25,60 @@ class WorkerController extends BaseController {
|
||||
res.status(400).send({error});
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO: удалить бесполезную getStateFinish
|
||||
async getStateFinish(req, res) {
|
||||
const request = req.body;
|
||||
let error = '';
|
||||
try {
|
||||
if (!request.workerId)
|
||||
throw new Error(`key 'workerId' is wrong`);
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/json; charset=utf-8',
|
||||
});
|
||||
|
||||
const splitter = '-- aod2t5hDXU32bUFyqlFE next status --';
|
||||
const refreshPause = 200;
|
||||
let i = 0;
|
||||
let prevProgress = -1;
|
||||
let prevState = '';
|
||||
let state;
|
||||
while (1) {// eslint-disable-line no-constant-condition
|
||||
state = this.workerState.getState(request.workerId);
|
||||
if (!state) break;
|
||||
|
||||
res.write(splitter + JSON.stringify(state));
|
||||
res.flush();
|
||||
|
||||
if (state.state != 'finish' && state.state != 'error')
|
||||
await utils.sleep(refreshPause);
|
||||
else
|
||||
break;
|
||||
|
||||
i++;
|
||||
if (i > 2*60*1000/refreshPause) {//2 мин ждем телодвижений воркера
|
||||
res.write(splitter + JSON.stringify({state: 'error', error: 'Слишком долгое время ожидания'}));
|
||||
break;
|
||||
}
|
||||
i = (prevProgress != state.progress || prevState != state.state ? 1 : i);
|
||||
prevProgress = state.progress;
|
||||
prevState = state.state;
|
||||
}
|
||||
|
||||
if (!state) {
|
||||
res.write(splitter + JSON.stringify({}));
|
||||
}
|
||||
|
||||
res.end();
|
||||
return false;
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
//bad request
|
||||
res.status(400).send({error});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WorkerController;
|
||||
|
||||
@@ -2,4 +2,5 @@ module.exports = {
|
||||
MiscController: require('./MiscController'),
|
||||
ReaderController: require('./ReaderController'),
|
||||
WorkerController: require('./WorkerController'),
|
||||
WebSocketController: require('./WebSocketController'),
|
||||
}
|
||||
@@ -5,12 +5,14 @@ const unbzip2Stream = require('unbzip2-stream');
|
||||
const tar = require('tar-fs');
|
||||
const ZipStreamer = require('./ZipStreamer');
|
||||
|
||||
const appLogger = new (require('./AppLogger'))();//singleton
|
||||
const utils = require('./utils');
|
||||
const FileDetector = require('./FileDetector');
|
||||
|
||||
class FileDecompressor {
|
||||
constructor() {
|
||||
constructor(limitFileSize = 0) {
|
||||
this.detector = new FileDetector();
|
||||
this.limitFileSize = limitFileSize;
|
||||
}
|
||||
|
||||
async decompressNested(filename, outputDir) {
|
||||
@@ -112,7 +114,7 @@ class FileDecompressor {
|
||||
|
||||
async unZip(filename, outputDir) {
|
||||
const zip = new ZipStreamer();
|
||||
return await zip.unpack(filename, outputDir);
|
||||
return await zip.unpack(filename, outputDir, null, this.limitFileSize);
|
||||
}
|
||||
|
||||
unBz2(filename, outputDir) {
|
||||
@@ -124,9 +126,16 @@ class FileDecompressor {
|
||||
}
|
||||
|
||||
unTar(filename, outputDir) {
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, reject) => { (async() => {
|
||||
const files = [];
|
||||
|
||||
if (this.limitFileSize) {
|
||||
if ((await fs.stat(filename)).size > this.limitFileSize) {
|
||||
reject('Файл слишком большой');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const tarExtract = tar.extract(outputDir, {
|
||||
map: (header) => {
|
||||
files.push({path: header.name, size: header.size});
|
||||
@@ -148,7 +157,7 @@ class FileDecompressor {
|
||||
});
|
||||
|
||||
inputStream.pipe(tarExtract);
|
||||
});
|
||||
})().catch(reject); });
|
||||
}
|
||||
|
||||
decompressByStream(stream, filename, outputDir) {
|
||||
@@ -173,6 +182,16 @@ class FileDecompressor {
|
||||
});
|
||||
|
||||
stream.on('error', reject);
|
||||
|
||||
if (this.limitFileSize) {
|
||||
let readSize = 0;
|
||||
stream.on('data', (buffer) => {
|
||||
readSize += buffer.length;
|
||||
if (readSize > this.limitFileSize)
|
||||
stream.destroy(new Error('Файл слишком большой'));
|
||||
});
|
||||
}
|
||||
|
||||
inputStream.on('error', reject);
|
||||
outputStream.on('error', reject);
|
||||
|
||||
@@ -189,9 +208,9 @@ class FileDecompressor {
|
||||
});
|
||||
}
|
||||
|
||||
async gzipFile(inputFile, outputFile) {
|
||||
async gzipFile(inputFile, outputFile, level = 1) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const gzip = zlib.createGzip({level: 1});
|
||||
const gzip = zlib.createGzip({level});
|
||||
const input = fs.createReadStream(inputFile);
|
||||
const output = fs.createWriteStream(outputFile);
|
||||
|
||||
@@ -208,7 +227,21 @@ class FileDecompressor {
|
||||
const outFilename = `${outDir}/${hash}`;
|
||||
|
||||
if (!await fs.pathExists(outFilename)) {
|
||||
await this.gzipFile(filename, outFilename);
|
||||
await this.gzipFile(filename, outFilename, 1);
|
||||
|
||||
// переупакуем через некоторое время на максималках
|
||||
const filenameCopy = `${filename}.copy`;
|
||||
await fs.copy(filename, filenameCopy);
|
||||
|
||||
(async() => {
|
||||
await utils.sleep(5000);
|
||||
const filenameGZ = `${filename}.gz`;
|
||||
await this.gzipFile(filenameCopy, filenameGZ, 9);
|
||||
|
||||
await fs.move(filenameGZ, outFilename, {overwrite: true});
|
||||
|
||||
await fs.remove(filenameCopy);
|
||||
})().catch((e) => { if (appLogger.inited) appLogger.log(LM_ERR, `FileDecompressor.gzipFileIfNotExists: ${e.message}`) });
|
||||
} else {
|
||||
await utils.touchFile(outFilename);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
const got = require('got');
|
||||
|
||||
const maxDownloadSize = 50*1024*1024;
|
||||
|
||||
class FileDownloader {
|
||||
constructor() {
|
||||
constructor(limitDownloadSize = 0) {
|
||||
this.limitDownloadSize = limitDownloadSize;
|
||||
}
|
||||
|
||||
async load(url, callback) {
|
||||
async load(url, callback, abort) {
|
||||
let errMes = '';
|
||||
const options = {
|
||||
encoding: null,
|
||||
@@ -23,10 +22,14 @@ class FileDownloader {
|
||||
}
|
||||
|
||||
let prevProg = 0;
|
||||
const request = got(url, options).on('downloadProgress', progress => {
|
||||
if (progress.transferred > maxDownloadSize) {
|
||||
errMes = 'file too big';
|
||||
request.cancel();
|
||||
const request = got(url, options);
|
||||
|
||||
request.on('downloadProgress', progress => {
|
||||
if (this.limitDownloadSize) {
|
||||
if (progress.transferred > this.limitDownloadSize) {
|
||||
errMes = 'Файл слишком большой';
|
||||
request.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
let prog = 0;
|
||||
@@ -38,8 +41,12 @@ class FileDownloader {
|
||||
if (prog != prevProg && callback)
|
||||
callback(prog);
|
||||
prevProg = prog;
|
||||
});
|
||||
|
||||
if (abort && abort()) {
|
||||
errMes = 'abort';
|
||||
request.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
return (await request).body;
|
||||
|
||||
119
server/core/LimitedQueue.js
Normal file
119
server/core/LimitedQueue.js
Normal file
@@ -0,0 +1,119 @@
|
||||
class LimitedQueue {
|
||||
constructor(enqueueAfter = 10, size = 100, timeout = 60*60*1000) {//timeout в ms
|
||||
this.size = size;
|
||||
this.timeout = timeout;
|
||||
|
||||
this.abortCount = 0;
|
||||
this.enqueueAfter = enqueueAfter;
|
||||
this.freed = enqueueAfter;
|
||||
this.listeners = [];
|
||||
}
|
||||
|
||||
_addListener(listener) {
|
||||
this.listeners.push(listener);
|
||||
}
|
||||
|
||||
//отсылаем сообщение первому ожидающему и удаляем его из списка
|
||||
_emitFree() {
|
||||
if (this.listeners.length > 0) {
|
||||
let listener = this.listeners.shift();
|
||||
listener.onFree();
|
||||
|
||||
for (let i = 0; i < this.listeners.length; i++) {
|
||||
this.listeners[i].onPlaceChange(i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get(onPlaceChange) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.destroyed)
|
||||
reject('destroyed');
|
||||
|
||||
const take = () => {
|
||||
if (this.freed <= 0)
|
||||
throw new Error('Ошибка получения ресурсов в очереди ожидания');
|
||||
|
||||
this.freed--;
|
||||
this.resetTimeout();
|
||||
|
||||
let aCount = this.abortCount;
|
||||
return {
|
||||
ret: () => {
|
||||
if (aCount == this.abortCount) {
|
||||
this.freed++;
|
||||
this._emitFree();
|
||||
aCount = -1;
|
||||
this.resetTimeout();
|
||||
}
|
||||
},
|
||||
abort: () => {
|
||||
return (aCount != this.abortCount);
|
||||
},
|
||||
resetTimeout: this.resetTimeout.bind(this)
|
||||
};
|
||||
};
|
||||
|
||||
if (this.freed > 0) {
|
||||
resolve(take());
|
||||
} else {
|
||||
if (this.listeners.length < this.size) {
|
||||
this._addListener({
|
||||
onFree: () => {
|
||||
resolve(take());
|
||||
},
|
||||
onError: (err) => {
|
||||
reject(err);
|
||||
},
|
||||
onPlaceChange: (i) => {
|
||||
if (onPlaceChange)
|
||||
onPlaceChange(i);
|
||||
}
|
||||
});
|
||||
if (onPlaceChange)
|
||||
onPlaceChange(this.listeners.length);
|
||||
} else {
|
||||
reject('Превышен размер очереди ожидания');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
resetTimeout() {
|
||||
if (this.timer)
|
||||
clearTimeout(this.timer);
|
||||
this.timer = setTimeout(() => { this.clean(); }, this.timeout);
|
||||
}
|
||||
|
||||
clean() {
|
||||
this.timer = null;
|
||||
|
||||
if (this.freed < this.enqueueAfter) {
|
||||
this.abortCount++;
|
||||
//чистка listeners
|
||||
for (const listener of this.listeners) {
|
||||
listener.onError('Время ожидания в очереди истекло');
|
||||
}
|
||||
this.listeners = [];
|
||||
|
||||
this.freed = this.enqueueAfter;
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
|
||||
for (const listener of this.listeners) {
|
||||
listener.onError('destroy');
|
||||
}
|
||||
this.listeners = [];
|
||||
this.abortCount++;
|
||||
|
||||
this.destroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LimitedQueue;
|
||||
@@ -3,10 +3,11 @@ const iconv = require('iconv-lite');
|
||||
const chardet = require('chardet');
|
||||
const he = require('he');
|
||||
|
||||
const LimitedQueue = require('../../LimitedQueue');
|
||||
const textUtils = require('./textUtils');
|
||||
const utils = require('../../utils');
|
||||
|
||||
let execConverterCounter = 0;
|
||||
const queue = new LimitedQueue(2, 20, 3*60*1000);//3 минуты ожидание подвижек
|
||||
|
||||
class ConvertBase {
|
||||
constructor(config) {
|
||||
@@ -32,13 +33,24 @@ class ConvertBase {
|
||||
throw new Error('Внешний конвертер pdftohtml не найден');
|
||||
}
|
||||
|
||||
async execConverter(path, args, onData) {
|
||||
execConverterCounter++;
|
||||
async execConverter(path, args, onData, abort) {
|
||||
let q = null;
|
||||
try {
|
||||
if (execConverterCounter > 10)
|
||||
throw new Error('Слишком большая очередь конвертирования. Пожалуйста, попробуйте позже.');
|
||||
q = await queue.get(() => {onData();});
|
||||
} catch (e) {
|
||||
throw new Error('Слишком большая очередь конвертирования. Пожалуйста, попробуйте позже.');
|
||||
}
|
||||
|
||||
const result = await utils.spawnProcess(path, {args, onData});
|
||||
try {
|
||||
const result = await utils.spawnProcess(path, {
|
||||
killAfter: 600,
|
||||
args,
|
||||
onData: (data) => {
|
||||
q.resetTimeout();
|
||||
onData(data);
|
||||
},
|
||||
abort
|
||||
});
|
||||
if (result.code != 0) {
|
||||
let error = result.code;
|
||||
if (this.config.branch == 'development')
|
||||
@@ -48,13 +60,15 @@ class ConvertBase {
|
||||
} catch(e) {
|
||||
if (e.status == 'killed') {
|
||||
throw new Error('Слишком долгое ожидание конвертера');
|
||||
} else if (e.status == 'abort') {
|
||||
throw new Error('abort');
|
||||
} else if (e.status == 'error') {
|
||||
throw new Error(e.error);
|
||||
} else {
|
||||
throw new Error(e);
|
||||
}
|
||||
} finally {
|
||||
execConverterCounter--;
|
||||
q.ret();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class ConvertDoc extends ConvertDocX {
|
||||
return false;
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback} = opts;
|
||||
const {inputFiles, callback, abort} = opts;
|
||||
|
||||
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||
const docFile = `${outFile}.doc`;
|
||||
@@ -24,9 +24,9 @@ class ConvertDoc extends ConvertDocX {
|
||||
const fb2File = `${outFile}.fb2`;
|
||||
|
||||
await fs.copy(inputFiles.sourceFile, docFile);
|
||||
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.filesDir, docFile]);
|
||||
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.filesDir, docFile], null, abort);
|
||||
|
||||
return await super.convert(docxFile, fb2File, callback);
|
||||
return await super.convert(docxFile, fb2File, callback, abort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,15 @@ const path = require('path');
|
||||
const ConvertBase = require('./ConvertBase');
|
||||
|
||||
class ConvertDocX extends ConvertBase {
|
||||
check(data, opts) {
|
||||
async check(data, opts) {
|
||||
const {inputFiles} = opts;
|
||||
if (this.config.useExternalBookConverter &&
|
||||
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'zip') {
|
||||
//ищем файл '[Content_Types].xml'
|
||||
for (const file of inputFiles.files) {
|
||||
if (file.path == '[Content_Types].xml') {
|
||||
return true;
|
||||
const contentTypes = await fs.readFile(`${inputFiles.filesDir}/${file.path}`, 'utf8');
|
||||
return contentTypes.indexOf('/word/document.xml') >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,22 +20,22 @@ class ConvertDocX extends ConvertBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
async convert(docxFile, fb2File, callback) {
|
||||
async convert(docxFile, fb2File, callback, abort) {
|
||||
let perc = 0;
|
||||
await this.execConverter(this.calibrePath, [docxFile, fb2File], () => {
|
||||
perc = (perc < 100 ? perc + 5 : 50);
|
||||
await this.execConverter(this.calibrePath, [docxFile, fb2File, '-vv'], () => {
|
||||
perc = (perc < 100 ? perc + 1 : 50);
|
||||
callback(perc);
|
||||
});
|
||||
}, abort);
|
||||
|
||||
return await fs.readFile(fb2File);
|
||||
}
|
||||
|
||||
async run(data, opts) {
|
||||
if (!this.check(data, opts))
|
||||
if (!(await this.check(data, opts)))
|
||||
return false;
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback} = opts;
|
||||
const {inputFiles, callback, abort} = opts;
|
||||
|
||||
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||
const docxFile = `${outFile}.docx`;
|
||||
@@ -42,7 +43,7 @@ class ConvertDocX extends ConvertBase {
|
||||
|
||||
await fs.copy(inputFiles.sourceFile, docxFile);
|
||||
|
||||
return await this.convert(docxFile, fb2File, callback);
|
||||
return await this.convert(docxFile, fb2File, callback, abort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class ConvertEpub extends ConvertBase {
|
||||
return false;
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback} = opts;
|
||||
const {inputFiles, callback, abort} = opts;
|
||||
|
||||
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||
const epubFile = `${outFile}.epub`;
|
||||
@@ -37,10 +37,10 @@ class ConvertEpub extends ConvertBase {
|
||||
await fs.copy(inputFiles.sourceFile, epubFile);
|
||||
|
||||
let perc = 0;
|
||||
await this.execConverter(this.calibrePath, [epubFile, fb2File], () => {
|
||||
perc = (perc < 100 ? perc + 5 : 50);
|
||||
await this.execConverter(this.calibrePath, [epubFile, fb2File, '-vv'], () => {
|
||||
perc = (perc < 100 ? perc + 1 : 50);
|
||||
callback(perc);
|
||||
});
|
||||
}, abort);
|
||||
|
||||
return await fs.readFile(fb2File);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class ConvertFb2 extends ConvertBase {
|
||||
const right = data.indexOf('?>', left);
|
||||
if (right >= 0) {
|
||||
const head = data.slice(left, right + 2).toString();
|
||||
const m = head.match(/encoding="(.*)"/);
|
||||
const m = head.match(/encoding="(.*?)"/);
|
||||
if (m) {
|
||||
let encoding = m[1].toLowerCase();
|
||||
if (encoding != 'utf-8') {
|
||||
|
||||
51
server/core/Reader/BookConverter/ConvertFb3.js
Normal file
51
server/core/Reader/BookConverter/ConvertFb3.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const fs = require('fs-extra');
|
||||
|
||||
const ConvertHtml = require('./ConvertHtml');
|
||||
|
||||
class ConvertDocX extends ConvertHtml {
|
||||
async check(data, opts) {
|
||||
const {inputFiles} = opts;
|
||||
if (this.config.useExternalBookConverter &&
|
||||
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'zip') {
|
||||
//ищем файл '[Content_Types].xml'
|
||||
for (const file of inputFiles.files) {
|
||||
if (file.path == '[Content_Types].xml') {
|
||||
const contentTypes = await fs.readFile(`${inputFiles.filesDir}/${file.path}`, 'utf8');
|
||||
return contentTypes.indexOf('/fb3/body.xml') >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getTitle(text) {
|
||||
let title = '';
|
||||
const m = text.match(/<title>([\s\S]*?)<\/title>/);
|
||||
if (m)
|
||||
title = m[1];
|
||||
|
||||
return title.trim();
|
||||
}
|
||||
|
||||
async run(data, opts) {
|
||||
if (!(await this.check(data, opts)))
|
||||
return false;
|
||||
|
||||
const {inputFiles} = opts;
|
||||
|
||||
let text = await fs.readFile(`${inputFiles.filesDir}/fb3/body.xml`, 'utf8');
|
||||
|
||||
const title = this.getTitle(text)
|
||||
.replace(/<\/?p>/g, '')
|
||||
;
|
||||
text = `<title>${title}</title>` + text
|
||||
.replace(/<title>/g, '<br><b>')
|
||||
.replace(/<\/title>/g, '</b><br>')
|
||||
.replace(/<subtitle>/g, '<br><br><subtitle>')
|
||||
;
|
||||
return await super.run(Buffer.from(text), {skipCheck: true, cutTitle: true});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConvertDocX;
|
||||
@@ -39,16 +39,19 @@ class ConvertHtml extends ConvertBase {
|
||||
|
||||
let title = '';
|
||||
let inTitle = false;
|
||||
let inSubTitle = false;
|
||||
let inImage = false;
|
||||
let image = {};
|
||||
let bold = false;
|
||||
let italic = false;
|
||||
let begining = true;
|
||||
|
||||
let spaceCounter = [];
|
||||
|
||||
const repCrLfTab = (text) => text.replace(/[\n\r]/g, '').replace(/\t/g, ' ');
|
||||
|
||||
const newParagraph = () => {
|
||||
begining = false;
|
||||
pars.push({_n: 'p', _t: ''});
|
||||
};
|
||||
|
||||
@@ -58,6 +61,8 @@ class ConvertHtml extends ConvertBase {
|
||||
|
||||
const l = pars.length;
|
||||
pars[l - 1]._t += text;
|
||||
if (inSubTitle)
|
||||
pars[l - 1]._n = '';
|
||||
|
||||
//посчитаем отступы у текста, чтобы выделить потом параграфы
|
||||
const lines = text.split('\n');
|
||||
@@ -77,16 +82,21 @@ class ConvertHtml extends ConvertBase {
|
||||
}
|
||||
};
|
||||
|
||||
const newPara = new Set(['tr', '/table', 'hr', 'br', 'br/', 'li', 'dt', 'dd', 'p', 'title', '/title', 'h1', 'h2', 'h3', '/h1', '/h2', '/h3']);
|
||||
const newPara = new Set(['tr', '/table', 'hr', 'br', 'br/', 'li', 'dt', 'dd', 'p', 'title', '/title', 'ul', '/ul', 'h1', 'h2', 'h3', 'h4', 'h5', '/h1', '/h2', '/h3', '/h4', '/h5']);
|
||||
const newPara2 = new Set(['h1', 'h2', 'h3', 'h4', 'h5']);
|
||||
|
||||
const onTextNode = (text, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||
text = this.escapeEntities(text);
|
||||
|
||||
if (!cutCounter && !(cutTitle && inTitle)) {
|
||||
let tOpen = (bold ? '<strong>' : '');
|
||||
let tOpen = '';
|
||||
tOpen += (inSubTitle ? '<subtitle>' : '');
|
||||
tOpen += (bold ? '<strong>' : '');
|
||||
tOpen += (italic ? '<emphasis>' : '');
|
||||
let tClose = (italic ? '</emphasis>' : '');
|
||||
let tClose = ''
|
||||
tClose += (italic ? '</emphasis>' : '');
|
||||
tClose += (bold ? '</strong>' : '');
|
||||
tClose += (inSubTitle ? '</subtitle>' : '');
|
||||
|
||||
growParagraph(`${tOpen}${text}${tClose}`);
|
||||
}
|
||||
@@ -106,6 +116,8 @@ class ConvertHtml extends ConvertBase {
|
||||
|
||||
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||
if (!cutCounter) {
|
||||
if (newPara2.has(tag) && !begining)
|
||||
newParagraph();
|
||||
if (newPara.has(tag))
|
||||
newParagraph();
|
||||
|
||||
@@ -130,6 +142,10 @@ class ConvertHtml extends ConvertBase {
|
||||
cutTitle = true;
|
||||
}
|
||||
|
||||
if (tag == 'subtitle') {
|
||||
inSubTitle = true;
|
||||
}
|
||||
|
||||
if (tag == 'fb2-image') {
|
||||
inImage = true;
|
||||
const attrs = sax.getAttrsSync(tail);
|
||||
@@ -141,6 +157,8 @@ class ConvertHtml extends ConvertBase {
|
||||
if (!cutCounter) {
|
||||
if (newPara.has('/' + tag))
|
||||
newParagraph();
|
||||
if (newPara2.has('/' + tag))
|
||||
newParagraph();
|
||||
|
||||
switch (tag) {
|
||||
case 'i':
|
||||
@@ -160,6 +178,9 @@ class ConvertHtml extends ConvertBase {
|
||||
if (tag == 'title' || tag == 'cut-title')
|
||||
inTitle = false;
|
||||
|
||||
if (tag == 'subtitle')
|
||||
inSubTitle = false;
|
||||
|
||||
if (tag == 'fb2-image')
|
||||
inImage = false;
|
||||
};
|
||||
@@ -197,7 +218,8 @@ class ConvertHtml extends ConvertBase {
|
||||
while (i > 0 && (!spaceCounter[i] || spaceCounter[i] < total)) i--;
|
||||
}
|
||||
|
||||
const parIndent = (i > 0 ? i : 0);
|
||||
let parIndent = (i > 0 ? i : 0);
|
||||
if (parIndent > 2) parIndent--;
|
||||
|
||||
let newPars = [];
|
||||
const newPar = () => {
|
||||
@@ -233,7 +255,7 @@ class ConvertHtml extends ConvertBase {
|
||||
l++;
|
||||
}
|
||||
|
||||
if (l >= parIndent) {
|
||||
if (l >= parIndent || line == '') {
|
||||
if (j > 0)
|
||||
newPar();
|
||||
j++;
|
||||
@@ -250,6 +272,7 @@ class ConvertHtml extends ConvertBase {
|
||||
//убираем лишнее, делаем валидный fb2, т.к. в рез-те разбиения на параграфы бьются теги
|
||||
bold = false;
|
||||
italic = false;
|
||||
inSubTitle = false;
|
||||
pars = body.section._a[0];
|
||||
for (let i = 0; i < pars.length; i++) {
|
||||
if (pars[i]._n != 'p')
|
||||
@@ -259,16 +282,24 @@ class ConvertHtml extends ConvertBase {
|
||||
|
||||
if (pars[i]._t.indexOf('<') >= 0 || bold || italic) {
|
||||
const t = pars[i]._t;
|
||||
let first = true;
|
||||
|
||||
let a = [];
|
||||
|
||||
const onTextNode = (text) => {
|
||||
let tOpen = (bold ? '<strong>' : '');
|
||||
let tOpen = '';
|
||||
tOpen += (inSubTitle ? '<subtitle>' : '');
|
||||
tOpen += (bold ? '<strong>' : '');
|
||||
tOpen += (italic ? '<emphasis>' : '');
|
||||
let tClose = (italic ? '</emphasis>' : '');
|
||||
let tClose = ''
|
||||
tClose += (italic ? '</emphasis>' : '');
|
||||
tClose += (bold ? '</strong>' : '');
|
||||
tClose += (inSubTitle ? '</subtitle>' : '');
|
||||
|
||||
if (first)
|
||||
text = text.replace(/^\s+/, ''); //trimLeft
|
||||
a.push(`${tOpen}${text}${tClose}`);
|
||||
first = false;
|
||||
}
|
||||
|
||||
const onStartNode = (tag) => {
|
||||
@@ -276,6 +307,8 @@ class ConvertHtml extends ConvertBase {
|
||||
bold = true;
|
||||
if (tag == 'emphasis')
|
||||
italic = true;
|
||||
if (tag == 'subtitle')
|
||||
inSubTitle = true;
|
||||
}
|
||||
|
||||
const onEndNode = (tag) => {
|
||||
@@ -283,6 +316,8 @@ class ConvertHtml extends ConvertBase {
|
||||
bold = false;
|
||||
if (tag == 'emphasis')
|
||||
italic = false;
|
||||
if (tag == 'subtitle')
|
||||
inSubTitle = false;
|
||||
}
|
||||
|
||||
sax.parseSync(t, { onStartNode, onEndNode, onTextNode });
|
||||
|
||||
@@ -16,7 +16,7 @@ class ConvertMobi extends ConvertBase {
|
||||
return false;
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback} = opts;
|
||||
const {inputFiles, callback, abort} = opts;
|
||||
|
||||
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||
const mobiFile = `${outFile}.mobi`;
|
||||
@@ -25,10 +25,10 @@ class ConvertMobi extends ConvertBase {
|
||||
await fs.copy(inputFiles.sourceFile, mobiFile);
|
||||
|
||||
let perc = 0;
|
||||
await this.execConverter(this.calibrePath, [mobiFile, fb2File], () => {
|
||||
perc = (perc < 100 ? perc + 5 : 50);
|
||||
await this.execConverter(this.calibrePath, [mobiFile, fb2File, '-vv'], () => {
|
||||
perc = (perc < 100 ? perc + 1 : 50);
|
||||
callback(perc);
|
||||
});
|
||||
}, abort);
|
||||
|
||||
return await fs.readFile(fb2File);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class ConvertPdf extends ConvertHtml {
|
||||
return false;
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback} = opts;
|
||||
const {inputFiles, callback, abort} = opts;
|
||||
|
||||
const outFile = `${inputFiles.filesDir}/${utils.randomHexString(10)}.xml`;
|
||||
|
||||
@@ -27,7 +27,7 @@ class ConvertPdf extends ConvertHtml {
|
||||
await this.execConverter(this.pdfToHtmlPath, ['-c', '-s', '-xml', inputFiles.sourceFile, outFile], () => {
|
||||
perc = (perc < 80 ? perc + 10 : 40);
|
||||
callback(perc);
|
||||
});
|
||||
}, abort);
|
||||
callback(80);
|
||||
|
||||
const data = await fs.readFile(outFile);
|
||||
|
||||
@@ -16,7 +16,7 @@ class ConvertRtf extends ConvertDocX {
|
||||
return false;
|
||||
await this.checkExternalConverterPresent();
|
||||
|
||||
const {inputFiles, callback} = opts;
|
||||
const {inputFiles, callback, abort} = opts;
|
||||
|
||||
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||
const rtfFile = `${outFile}.rtf`;
|
||||
@@ -24,9 +24,9 @@ class ConvertRtf extends ConvertDocX {
|
||||
const fb2File = `${outFile}.fb2`;
|
||||
|
||||
await fs.copy(inputFiles.sourceFile, rtfFile);
|
||||
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.filesDir, rtfFile]);
|
||||
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.filesDir, rtfFile], null, abort);
|
||||
|
||||
return await super.convert(docxFile, fb2File, callback);
|
||||
return await super.convert(docxFile, fb2File, callback, abort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,8 @@ class ConvertSamlib extends ConvertBase {
|
||||
case 'h1':
|
||||
case 'h2':
|
||||
case 'h3':
|
||||
case 'h4':
|
||||
case 'h5':
|
||||
if (inPara)
|
||||
closeTag('p');
|
||||
openTag('p');
|
||||
@@ -173,6 +175,8 @@ class ConvertSamlib extends ConvertBase {
|
||||
case 'h1':
|
||||
case 'h2':
|
||||
case 'h3':
|
||||
case 'h4':
|
||||
case 'h5':
|
||||
closeTag('p');
|
||||
bold = false;
|
||||
break;
|
||||
|
||||
@@ -12,7 +12,10 @@ const sitesFilter = {
|
||||
converter: 'cutter',
|
||||
begin: `<!-- BEGIN section where work skin applies -->`,
|
||||
end: `<!-- END work skin -->`,
|
||||
}
|
||||
},
|
||||
'flibusta.is': {
|
||||
converter: 'flibusta'
|
||||
},
|
||||
};
|
||||
|
||||
class ConvertSites extends ConvertHtml {
|
||||
@@ -54,11 +57,11 @@ class ConvertSites extends ConvertHtml {
|
||||
if (m)
|
||||
title = m[1];
|
||||
|
||||
return `<title>${title.trim()}</title>`;
|
||||
return title.trim();
|
||||
}
|
||||
|
||||
cutter(text, opts) {
|
||||
const title = this.getTitle(text);
|
||||
const title = `<title>${this.getTitle(text)}</title>`;
|
||||
const l = text.indexOf(opts.begin) + opts.begin.length;
|
||||
const r = text.indexOf(opts.end);
|
||||
if (l < 0 || r < 0 || r <= l)
|
||||
@@ -66,6 +69,42 @@ class ConvertSites extends ConvertHtml {
|
||||
|
||||
return text.substring(l, r) + title;
|
||||
}
|
||||
|
||||
flibusta(text) {
|
||||
let author = '';
|
||||
let m = text.match(/- <a href=".+">([\s\S]*?)<\/a><br\/?>/);
|
||||
if (m)
|
||||
author = m[1];
|
||||
|
||||
let book = this.getTitle(text);
|
||||
book = book.replace(' (fb2) | Флибуста', '');
|
||||
|
||||
const title = `<title>${author}${(author ? ' - ' : '')}${book}</title>`;
|
||||
|
||||
let begin = '<h3 class="book">';
|
||||
if (text.indexOf(begin) <= 0)
|
||||
begin = '<h3 class=book>';
|
||||
|
||||
const end = '<div id="footer">';
|
||||
|
||||
const l = text.indexOf(begin);
|
||||
const r = text.indexOf(end);
|
||||
if (l < 0 || r < 0 || r <= l)
|
||||
return false;
|
||||
|
||||
return text.substring(l, r)
|
||||
.replace(/blockquote class="?book"?/g, 'p')
|
||||
.replace(/<br\/?>\s*<\/h3>/g, '</h3>')
|
||||
.replace(/<h3 class="?book"?>/g, '<br><br><subtitle>')
|
||||
.replace(/<h5 class="?book"?>/g, '<br><br><subtitle>')
|
||||
.replace(/<h3>/g, '<br><br><subtitle>')
|
||||
.replace(/<h5>/g, '<br><br><subtitle>')
|
||||
.replace(/<\/h3>/g, '</subtitle><br>')
|
||||
.replace(/<\/h5>/g, '</subtitle><br>')
|
||||
.replace(/<div class="?stanza"?>/g, '<br>')
|
||||
.replace(/<div>/g, '<br>')
|
||||
+ title;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConvertSites;
|
||||
|
||||
@@ -7,6 +7,7 @@ const convertClassFactory = [
|
||||
require('./ConvertPdf'),
|
||||
require('./ConvertRtf'),
|
||||
require('./ConvertDocX'),
|
||||
require('./ConvertFb3'),
|
||||
require('./ConvertDoc'),
|
||||
require('./ConvertMobi'),
|
||||
require('./ConvertFb2'),
|
||||
@@ -25,11 +26,14 @@ class BookConverter {
|
||||
}
|
||||
}
|
||||
|
||||
async convertToFb2(inputFiles, outputFile, opts, callback) {
|
||||
async convertToFb2(inputFiles, outputFile, opts, callback, abort) {
|
||||
if (abort && abort())
|
||||
throw new Error('abort');
|
||||
|
||||
const selectedFileType = await this.detector.detectFile(inputFiles.selectedFile);
|
||||
const data = await fs.readFile(inputFiles.selectedFile);
|
||||
|
||||
const convertOpts = Object.assign({}, opts, {inputFiles, callback, dataType: selectedFileType});
|
||||
const convertOpts = Object.assign({}, opts, {inputFiles, callback, abort, dataType: selectedFileType});
|
||||
let result = false;
|
||||
for (const convert of this.convertFactory) {
|
||||
result = await convert.run(data, convertOpts);
|
||||
@@ -40,7 +44,7 @@ class BookConverter {
|
||||
}
|
||||
|
||||
if (!result && inputFiles.nesting) {
|
||||
result = await this.convertToFb2(inputFiles.nesting, outputFile, opts, callback);
|
||||
result = await this.convertToFb2(inputFiles.nesting, outputFile, opts, callback, abort);
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
||||
const LimitedQueue = require('../LimitedQueue');
|
||||
const WorkerState = require('../WorkerState');//singleton
|
||||
const FileDownloader = require('../FileDownloader');
|
||||
const FileDecompressor = require('../FileDecompressor');
|
||||
const BookConverter = require('./BookConverter');
|
||||
const RemoteWebDavStorage = require('../RemoteWebDavStorage');
|
||||
|
||||
const utils = require('../utils');
|
||||
const log = new (require('../AppLogger'))().log;//singleton
|
||||
|
||||
const cleanDirPeriod = 60*60*1000;//1 раз в час
|
||||
const queue = new LimitedQueue(5, 100, 5*60*1000);//5 минут ожидание подвижек
|
||||
|
||||
let instance = null;
|
||||
|
||||
//singleton
|
||||
@@ -24,12 +29,19 @@ class ReaderWorker {
|
||||
fs.ensureDirSync(this.config.tempPublicDir);
|
||||
|
||||
this.workerState = new WorkerState();
|
||||
this.down = new FileDownloader();
|
||||
this.decomp = new FileDecompressor();
|
||||
this.down = new FileDownloader(config.maxUploadFileSize);
|
||||
this.decomp = new FileDecompressor(2*config.maxUploadFileSize);
|
||||
this.bookConverter = new BookConverter(this.config);
|
||||
|
||||
this.periodicCleanDir(this.config.tempPublicDir, this.config.maxTempPublicDirSize, 60*60*1000);//1 раз в час
|
||||
this.periodicCleanDir(this.config.uploadDir, this.config.maxUploadPublicDirSize, 60*60*1000);//1 раз в час
|
||||
this.remoteWebDavStorage = false;
|
||||
if (config.remoteWebDavStorage) {
|
||||
this.remoteWebDavStorage = new RemoteWebDavStorage(
|
||||
Object.assign({maxContentLength: config.maxUploadFileSize}, config.remoteWebDavStorage)
|
||||
);
|
||||
}
|
||||
|
||||
this.periodicCleanDir(this.config.tempPublicDir, this.config.maxTempPublicDirSize, cleanDirPeriod);
|
||||
this.periodicCleanDir(this.config.uploadDir, this.config.maxUploadPublicDirSize, cleanDirPeriod);
|
||||
|
||||
instance = this;
|
||||
}
|
||||
@@ -39,22 +51,39 @@ class ReaderWorker {
|
||||
|
||||
async loadBook(opts, wState) {
|
||||
const url = opts.url;
|
||||
let errMes = '';
|
||||
let decompDir = '';
|
||||
let downloadedFilename = '';
|
||||
let isUploaded = false;
|
||||
let convertFilename = '';
|
||||
|
||||
const overLoadMes = 'Слишком большая очередь загрузки. Пожалуйста, попробуйте позже.';
|
||||
const overLoadErr = new Error(overLoadMes);
|
||||
|
||||
let q = null;
|
||||
try {
|
||||
wState.set({state: 'queue', step: 1, totalSteps: 1});
|
||||
try {
|
||||
let qSize = 0;
|
||||
q = await queue.get((place) => {
|
||||
wState.set({place, progress: (qSize ? Math.round((qSize - place)/qSize*100) : 0)});
|
||||
if (!qSize)
|
||||
qSize = place;
|
||||
});
|
||||
} catch (e) {
|
||||
throw overLoadErr;
|
||||
}
|
||||
|
||||
wState.set({state: 'download', step: 1, totalSteps: 3, url});
|
||||
|
||||
const tempFilename = utils.randomHexString(30);
|
||||
const tempFilename2 = utils.randomHexString(30);
|
||||
const decompDirname = utils.randomHexString(30);
|
||||
|
||||
//download or use uploaded
|
||||
if (url.indexOf('file://') != 0) {//download
|
||||
const downdata = await this.down.load(url, (progress) => {
|
||||
wState.set({progress});
|
||||
});
|
||||
}, q.abort);
|
||||
|
||||
downloadedFilename = `${this.config.tempDownloadDir}/${tempFilename}`;
|
||||
await fs.writeFile(downloadedFilename, downdata);
|
||||
@@ -67,6 +96,10 @@ class ReaderWorker {
|
||||
}
|
||||
wState.set({progress: 100});
|
||||
|
||||
if (q.abort())
|
||||
throw overLoadErr;
|
||||
q.resetTimeout();
|
||||
|
||||
//decompress
|
||||
wState.set({state: 'decompress', step: 2, progress: 0});
|
||||
decompDir = `${this.config.tempDownloadDir}/${decompDirname}`;
|
||||
@@ -79,27 +112,49 @@ class ReaderWorker {
|
||||
}
|
||||
wState.set({progress: 100});
|
||||
|
||||
if (q.abort())
|
||||
throw overLoadErr;
|
||||
q.resetTimeout();
|
||||
|
||||
//конвертирование в fb2
|
||||
wState.set({state: 'convert', step: 3, progress: 0});
|
||||
convertFilename = `${this.config.tempDownloadDir}/${tempFilename2}`;
|
||||
await this.bookConverter.convertToFb2(decompFiles, convertFilename, opts, progress => {
|
||||
wState.set({progress});
|
||||
});
|
||||
}, q.abort);
|
||||
|
||||
//сжимаем файл в tmp, если там уже нет с тем же именем-sha256
|
||||
const compFilename = await this.decomp.gzipFileIfNotExists(convertFilename, `${this.config.tempPublicDir}`);
|
||||
const compFilename = await this.decomp.gzipFileIfNotExists(convertFilename, this.config.tempPublicDir);
|
||||
const stat = await fs.stat(compFilename);
|
||||
|
||||
wState.set({progress: 100});
|
||||
|
||||
//finish
|
||||
const finishFilename = path.basename(compFilename);
|
||||
wState.finish({path: `/tmp/${finishFilename}`});
|
||||
wState.finish({path: `/tmp/${finishFilename}`, size: stat.size});
|
||||
|
||||
//лениво сохраним compFilename в удаленном хранилище
|
||||
if (this.remoteWebDavStorage) {
|
||||
(async() => {
|
||||
await utils.sleep(20*1000);
|
||||
try {
|
||||
//log(`remoteWebDavStorage.putFile ${path.basename(compFilename)}`);
|
||||
await this.remoteWebDavStorage.putFile(compFilename);
|
||||
} catch (e) {
|
||||
log(LM_ERR, e.stack);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
log(LM_ERR, e.stack);
|
||||
wState.set({state: 'error', error: (errMes ? errMes : e.message)});
|
||||
if (e.message == 'abort')
|
||||
e.message = overLoadMes;
|
||||
wState.set({state: 'error', error: e.message});
|
||||
} finally {
|
||||
//clean
|
||||
if (q)
|
||||
q.ret();
|
||||
if (decompDir)
|
||||
await fs.remove(decompDir);
|
||||
if (downloadedFilename && !isUploaded)
|
||||
@@ -133,6 +188,41 @@ class ReaderWorker {
|
||||
return `file://${hash}`;
|
||||
}
|
||||
|
||||
restoreCachedFile(filename) {
|
||||
const workerId = this.workerState.generateWorkerId();
|
||||
const wState = this.workerState.getControl(workerId);
|
||||
wState.set({state: 'start'});
|
||||
|
||||
(async() => {
|
||||
try {
|
||||
wState.set({state: 'download', step: 1, totalSteps: 1, path: filename, progress: 0});
|
||||
|
||||
const basename = path.basename(filename);
|
||||
const targetName = `${this.config.tempPublicDir}/${basename}`;
|
||||
|
||||
if (!await fs.pathExists(targetName)) {
|
||||
let found = false;
|
||||
if (this.remoteWebDavStorage) {
|
||||
found = await this.remoteWebDavStorage.getFileSuccess(targetName);
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
throw new Error('404 Файл не найден');
|
||||
}
|
||||
}
|
||||
|
||||
const stat = await fs.stat(targetName);
|
||||
wState.finish({path: `/tmp/${basename}`, size: stat.size, progress: 100});
|
||||
} catch (e) {
|
||||
if (e.message.indexOf('404') < 0)
|
||||
log(LM_ERR, e.stack);
|
||||
wState.set({state: 'error', error: e.message});
|
||||
}
|
||||
})();
|
||||
|
||||
return workerId;
|
||||
}
|
||||
|
||||
async periodicCleanDir(dir, maxSize, timeout) {
|
||||
try {
|
||||
const list = await fs.readdir(dir);
|
||||
@@ -153,7 +243,19 @@ class ReaderWorker {
|
||||
let i = 0;
|
||||
while (i < files.length && size > maxSize) {
|
||||
const file = files[i];
|
||||
await fs.remove(`${dir}/${file.name}`);
|
||||
const oldFile = `${dir}/${file.name}`;
|
||||
|
||||
//отправляем только this.config.tempPublicDir
|
||||
//TODO: убрать в будущем, т.к. уже делается ленивое сохранение compFilename в удаленном хранилище
|
||||
if (this.remoteWebDavStorage && dir === this.config.tempPublicDir) {
|
||||
try {
|
||||
//log(`remoteWebDavStorage.putFile ${path.basename(oldFile)}`);
|
||||
await this.remoteWebDavStorage.putFile(oldFile);
|
||||
} catch (e) {
|
||||
log(LM_ERR, e.stack);
|
||||
}
|
||||
}
|
||||
await fs.remove(oldFile);
|
||||
size -= file.stat.size;
|
||||
i++;
|
||||
}
|
||||
|
||||
107
server/core/RemoteWebDavStorage.js
Normal file
107
server/core/RemoteWebDavStorage.js
Normal file
@@ -0,0 +1,107 @@
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
||||
const { createClient } = require('webdav');
|
||||
|
||||
class RemoteWebDavStorage {
|
||||
constructor(config) {
|
||||
this.config = Object.assign({}, config);
|
||||
this.config.maxContentLength = this.config.maxContentLength || 10*1024*1024;
|
||||
this.wdc = createClient(config.url, this.config);
|
||||
}
|
||||
|
||||
_convertStat(data) {
|
||||
return {
|
||||
isDirectory: function() {
|
||||
return data.type === "directory";
|
||||
},
|
||||
isFile: function() {
|
||||
return data.type === "file";
|
||||
},
|
||||
mtime: (new Date(data.lastmod)).getTime(),
|
||||
name: data.basename,
|
||||
size: data.size || 0
|
||||
};
|
||||
}
|
||||
|
||||
async stat(filename) {
|
||||
const stat = await this.wdc.stat(filename);
|
||||
return this._convertStat(stat);
|
||||
}
|
||||
|
||||
async writeFile(filename, data) {
|
||||
return await this.wdc.putFileContents(filename, data, { maxContentLength: this.config.maxContentLength })
|
||||
}
|
||||
|
||||
async unlink(filename) {
|
||||
return await this.wdc.deleteFile(filename);
|
||||
}
|
||||
|
||||
async readFile(filename) {
|
||||
return await this.wdc.getFileContents(filename, { maxContentLength: this.config.maxContentLength })
|
||||
}
|
||||
|
||||
async mkdir(dirname) {
|
||||
return await this.wdc.createDirectory(dirname);
|
||||
}
|
||||
|
||||
async putFile(filename) {
|
||||
if (!await fs.pathExists(filename)) {
|
||||
throw new Error(`File not found: ${filename}`);
|
||||
}
|
||||
|
||||
const base = path.basename(filename);
|
||||
let remoteFilename = `/${base}`;
|
||||
|
||||
if (base.length > 3) {
|
||||
const remoteDir = `/${base.substr(0, 3)}`;
|
||||
try {
|
||||
await this.mkdir(remoteDir);
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
remoteFilename = `${remoteDir}/${base}`;
|
||||
}
|
||||
|
||||
try {
|
||||
const localStat = await fs.stat(filename);
|
||||
const remoteStat = await this.stat(remoteFilename);
|
||||
if (remoteStat.isFile && localStat.size == remoteStat.size) {
|
||||
return;
|
||||
}
|
||||
await this.unlink(remoteFilename);
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
|
||||
const data = await fs.readFile(filename);
|
||||
await this.writeFile(remoteFilename, data);
|
||||
}
|
||||
|
||||
async getFile(filename) {
|
||||
if (await fs.pathExists(filename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const base = path.basename(filename);
|
||||
let remoteFilename = `/${base}`;
|
||||
if (base.length > 3) {
|
||||
remoteFilename = `/${base.substr(0, 3)}/${base}`;
|
||||
}
|
||||
|
||||
const data = await this.readFile(remoteFilename);
|
||||
await fs.writeFile(filename, data);
|
||||
}
|
||||
|
||||
async getFileSuccess(filename) {
|
||||
try {
|
||||
await this.getFile(filename);
|
||||
return true;
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RemoteWebDavStorage;
|
||||
@@ -52,7 +52,7 @@ class ZipStreamer {
|
||||
})().catch(reject); });
|
||||
}
|
||||
|
||||
unpack(zipFile, outputDir, entryCallback) {
|
||||
unpack(zipFile, outputDir, entryCallback, limitFileSize = 0) {
|
||||
return new Promise((resolve, reject) => {
|
||||
entryCallback = (entryCallback ? entryCallback : () => {});
|
||||
const unzip = new unzipStream({file: zipFile});
|
||||
@@ -67,6 +67,15 @@ class ZipStreamer {
|
||||
});
|
||||
|
||||
unzip.on('ready', () => {
|
||||
if (limitFileSize) {
|
||||
for (const entry of Object.values(unzip.entries())) {
|
||||
if (!entry.isDirectory && entry.size > limitFileSize) {
|
||||
reject('Файл слишком большой');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unzip.extract(null, outputDir, (err) => {
|
||||
if (err) reject(err);
|
||||
unzip.close();
|
||||
|
||||
@@ -37,8 +37,8 @@ async function touchFile(filename) {
|
||||
}
|
||||
|
||||
function spawnProcess(cmd, opts) {
|
||||
let {args, killAfter, onData} = opts;
|
||||
killAfter = (killAfter ? killAfter : 120*1000);
|
||||
let {args, killAfter, onData, abort} = opts;
|
||||
killAfter = (killAfter ? killAfter : 120);//seconds
|
||||
onData = (onData ? onData : () => {});
|
||||
args = (args ? args : []);
|
||||
|
||||
@@ -67,10 +67,18 @@ function spawnProcess(cmd, opts) {
|
||||
reject({status: 'error', error, stdout, stderr});
|
||||
});
|
||||
|
||||
await sleep(killAfter);
|
||||
if (!resolved) {
|
||||
process.kill(proc.pid);
|
||||
reject({status: 'killed', stdout, stderr});
|
||||
while (!resolved) {
|
||||
await sleep(1000);
|
||||
killAfter -= 1;
|
||||
if (killAfter <= 0 || (abort && abort())) {
|
||||
process.kill(proc.pid);
|
||||
if (killAfter <= 0) {
|
||||
reject({status: 'killed', stdout, stderr});
|
||||
} else {
|
||||
reject({status: 'abort', stdout, stderr});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
})().catch(reject); });
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ class SqliteConnectionPool {
|
||||
if (!Number.isInteger(connCount) || connCount <= 0)
|
||||
return;
|
||||
this.connections = [];
|
||||
this.taken = new Set();
|
||||
this.freed = new Set();
|
||||
|
||||
for (let i = 0; i < connCount; i++) {
|
||||
@@ -22,7 +21,6 @@ class SqliteConnectionPool {
|
||||
client.configure('busyTimeout', 10000); //ms
|
||||
|
||||
client.ret = () => {
|
||||
this.taken.delete(i);
|
||||
this.freed.add(i);
|
||||
};
|
||||
|
||||
@@ -52,7 +50,6 @@ class SqliteConnectionPool {
|
||||
}
|
||||
|
||||
this.freed.delete(freeConnIndex);
|
||||
this.taken.add(freeConnIndex);
|
||||
|
||||
return this.connections[freeConnIndex];
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
require('tls').DEFAULT_MIN_VERSION = 'TLSv1';
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const argv = require('minimist')(process.argv.slice(2));
|
||||
const express = require('express');
|
||||
const compression = require('compression');
|
||||
const http = require('http');
|
||||
const WebSocket = require ('ws');
|
||||
|
||||
async function init() {
|
||||
//config
|
||||
@@ -18,7 +21,7 @@ async function init() {
|
||||
const log = appLogger.log;
|
||||
|
||||
//dirs
|
||||
log(`${config.name} v${config.version}`);
|
||||
log(`${config.name} v${config.version}, Node.js ${process.version}`);
|
||||
log('Initializing');
|
||||
|
||||
await fs.ensureDir(config.dataDir);
|
||||
@@ -40,15 +43,18 @@ async function init() {
|
||||
await connManager.init(config);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
async function main() {
|
||||
const log = new (require('./core/AppLogger'))().log;//singleton
|
||||
const config = new (require('./config'))().config;//singleton
|
||||
|
||||
//servers
|
||||
for (let server of config.servers) {
|
||||
if (server.mode !== 'none') {
|
||||
for (let serverCfg of config.servers) {
|
||||
if (serverCfg.mode !== 'none') {
|
||||
const app = express();
|
||||
const serverConfig = Object.assign({}, config, server);
|
||||
const server = http.createServer(app);
|
||||
const wss = new WebSocket.Server({ server, maxPayload: 10*1024*1024 });
|
||||
|
||||
const serverConfig = Object.assign({}, config, serverCfg);
|
||||
|
||||
let devModule = undefined;
|
||||
if (serverConfig.branch == 'development') {
|
||||
@@ -72,7 +78,7 @@ async function main() {
|
||||
}
|
||||
}));
|
||||
|
||||
require('./routes').initRoutes(app, serverConfig);
|
||||
require('./routes').initRoutes(app, wss, serverConfig);
|
||||
|
||||
if (devModule) {
|
||||
devModule.logErrors(app);
|
||||
@@ -83,7 +89,7 @@ async function main() {
|
||||
});
|
||||
}
|
||||
|
||||
app.listen(serverConfig.port, serverConfig.ip, function() {
|
||||
server.listen(serverConfig.port, serverConfig.ip, function() {
|
||||
log(`Server-${serverConfig.serverName} is ready on ${serverConfig.ip}:${serverConfig.port}, mode: ${serverConfig.mode}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ const c = require('./controllers');
|
||||
const utils = require('./core/utils');
|
||||
const multer = require('multer');
|
||||
|
||||
function initRoutes(app, config) {
|
||||
function initRoutes(app, wss, config) {
|
||||
const misc = new c.MiscController(config);
|
||||
const reader = new c.ReaderController(config);
|
||||
const worker = new c.WorkerController(config);
|
||||
new c.WebSocketController(wss, config);
|
||||
|
||||
//access
|
||||
const [aAll, aNormal, aSite, aReader, aOmnireader] = // eslint-disable-line no-unused-vars
|
||||
@@ -28,7 +29,9 @@ function initRoutes(app, config) {
|
||||
['POST', '/api/reader/load-book', reader.loadBook.bind(reader), [aAll], {}],
|
||||
['POST', '/api/reader/storage', reader.storage.bind(reader), [aAll], {}],
|
||||
['POST', '/api/reader/upload-file', [upload.single('file'), reader.uploadFile.bind(reader)], [aAll], {}],
|
||||
['POST', '/api/reader/restore-cached-file', reader.restoreCachedFile.bind(reader), [aAll], {}],
|
||||
['POST', '/api/worker/get-state', worker.getState.bind(worker), [aAll], {}],
|
||||
['POST', '/api/worker/get-state-finish', worker.getStateFinish.bind(worker), [aAll], {}],
|
||||
];
|
||||
|
||||
//to app
|
||||
|
||||
Reference in New Issue
Block a user