Compare commits
136 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75f5a50d20 | ||
|
|
a38ba2fd9a | ||
|
|
d46d153416 | ||
|
|
e7fe77ef6c | ||
|
|
810920beed | ||
|
|
55984769ea | ||
|
|
0e4344995c | ||
|
|
548f18430d | ||
|
|
8982b3eaf0 | ||
|
|
bcd0308641 | ||
|
|
21ec7df1e7 | ||
|
|
35d7e5296f | ||
|
|
ca812f0eb4 | ||
|
|
e0c856ce8e | ||
|
|
820769071d | ||
|
|
4ea9b388f0 | ||
|
|
26340bf061 | ||
|
|
39dc7647bc | ||
|
|
198a2b9d76 | ||
|
|
6e9662b409 | ||
|
|
c5bd31e514 | ||
|
|
ea5cf4e3bd | ||
|
|
c6080fa423 | ||
|
|
f2f22c362d | ||
|
|
55e05d3469 | ||
|
|
87f8567d93 | ||
|
|
1659f69aae | ||
|
|
f310a70e49 | ||
|
|
b4cb08ea62 | ||
|
|
fba7300131 | ||
|
|
c904990eed | ||
|
|
75cb5444b2 | ||
|
|
1210e5bd8a | ||
|
|
70de9e2ab4 | ||
|
|
3f39b55ca0 | ||
|
|
2ba8297594 | ||
|
|
c3724feba0 | ||
|
|
0b9a25aff0 | ||
|
|
96576307c8 | ||
|
|
f51166822b | ||
|
|
fee3231d10 | ||
|
|
52ed97c8de | ||
|
|
52f3938077 | ||
|
|
c00754c4ca | ||
|
|
78602a082b | ||
|
|
c33fc407d2 | ||
|
|
529095e014 | ||
|
|
8a6852c4ae | ||
|
|
ecb372ec70 | ||
|
|
87fc08e3bc | ||
|
|
b7555fe55d | ||
|
|
1669a21add | ||
|
|
7f68b1d68a | ||
|
|
4cacecc13b | ||
|
|
2509b0f742 | ||
|
|
491c2f3406 | ||
|
|
20bb9f925a | ||
|
|
87369a00a2 | ||
|
|
04f0b17d32 | ||
|
|
86f6ba5ba0 | ||
|
|
dff2f0fcb0 | ||
|
|
801bf3aea9 | ||
|
|
a7db617c14 | ||
|
|
ed4313b77b | ||
|
|
d579be5376 | ||
|
|
b7d176c123 | ||
|
|
cc5d5167a3 | ||
|
|
3a8fa12894 | ||
|
|
1b503dba8e | ||
|
|
53663b2867 | ||
|
|
5c03e06648 | ||
|
|
b598a43361 | ||
|
|
d770d499da | ||
|
|
739f06226f | ||
|
|
03e5a87eb3 | ||
|
|
dd5598a695 | ||
|
|
7553b88b89 | ||
|
|
5f4b993154 | ||
|
|
6eae46eaa1 | ||
|
|
e6485ec0a2 | ||
|
|
8df8ba5e0e | ||
|
|
993fe2d142 | ||
|
|
d7c1a83785 | ||
|
|
f582c34a72 | ||
|
|
fd93d3f523 | ||
|
|
634d646622 | ||
|
|
b707f8425e | ||
|
|
bc2a54c4ab | ||
|
|
63dfdaf2c2 | ||
|
|
723af3ea8b | ||
|
|
f1267879af | ||
|
|
784dda03fd | ||
|
|
ea6d61ac6f | ||
|
|
54f0cfec76 | ||
|
|
91d3d4c254 | ||
|
|
ab4d54cc85 | ||
|
|
86aa3511bf | ||
|
|
8d5792d456 | ||
|
|
12e5c32578 | ||
|
|
19aaba2492 | ||
|
|
1d3a661973 | ||
|
|
6a8f08fca8 | ||
|
|
93634b1137 | ||
|
|
cd72de5014 | ||
|
|
5a19af3c7d | ||
|
|
46829a9b08 | ||
|
|
87d418a32a | ||
|
|
d5a9b77334 | ||
|
|
e865070f23 | ||
|
|
294fb35f4d | ||
|
|
1490fc854a | ||
|
|
8b67cd09ad | ||
|
|
48ebff923e | ||
|
|
7a58b5a3ba | ||
|
|
8c1ec1dc93 | ||
|
|
f7297ac573 | ||
|
|
8e7fda9fbf | ||
|
|
ba3d6adac6 | ||
|
|
11a6c06997 | ||
|
|
2d8dc8c04b | ||
|
|
3204946fc8 | ||
|
|
1aaa27e68b | ||
|
|
31d5fc6df3 | ||
|
|
78dc1c87c8 | ||
|
|
88d49852e0 | ||
|
|
526683b7ef | ||
|
|
4ca56db142 | ||
|
|
a556a88ee5 | ||
|
|
90be2a1447 | ||
|
|
e70247e473 | ||
|
|
fba127f7ca | ||
|
|
a5a734a333 | ||
|
|
f8416a4aec | ||
|
|
e0e26df5cb | ||
|
|
af3bac6a09 | ||
|
|
43921953a7 |
11
README.md
11
README.md
@@ -42,6 +42,9 @@ inpx-web
|
|||||||
|
|
||||||
## Использование
|
## Использование
|
||||||
Поместите приложение `inpx-web` в папку с .inpx-файлом и файлами библиотеки и запустите.
|
Поместите приложение `inpx-web` в папку с .inpx-файлом и файлами библиотеки и запустите.
|
||||||
|
Там же, при первом запуске, будет создана рабочая директория `.inpx-web`, в которой хранится
|
||||||
|
конфигурационный файл `config.json`, файлы базы данных, журналы и прочее.
|
||||||
|
|
||||||
По умолчанию сервер будет доступен по адресу http://127.0.0.1:12380
|
По умолчанию сервер будет доступен по адресу http://127.0.0.1:12380
|
||||||
|
|
||||||
<a id="cli" />
|
<a id="cli" />
|
||||||
@@ -78,6 +81,10 @@ Options:
|
|||||||
// включить(true)/выключить(false) журналирование
|
// включить(true)/выключить(false) журналирование
|
||||||
"loggingEnabled": true,
|
"loggingEnabled": true,
|
||||||
|
|
||||||
|
// максимальный размер кеша каждой таблицы в БД, в блоках (требуется примерно 1-10Мб памяти на один блок)
|
||||||
|
// если надо кешировать всю БД, можно поставить значение от 1000 и больше
|
||||||
|
"dbCacheSize": 5,
|
||||||
|
|
||||||
// максимальный размер в байтах директории закешированных файлов в <раб.дир>/public/files
|
// максимальный размер в байтах директории закешированных файлов в <раб.дир>/public/files
|
||||||
// чистка каждый час
|
// чистка каждый час
|
||||||
"maxFilesDirSize": 1073741824,
|
"maxFilesDirSize": 1073741824,
|
||||||
@@ -99,6 +106,10 @@ Options:
|
|||||||
// во столько же раз увеличивается время создания
|
// во столько же раз увеличивается время создания
|
||||||
"lowMemoryMode": false,
|
"lowMemoryMode": false,
|
||||||
|
|
||||||
|
// включить(true)/выключить(false) полную оптимизацию поисковой БД
|
||||||
|
// ускоряет работу поиска, но увеличивает размер БД в 2-3 раза при импорте INPX
|
||||||
|
"fullOptimization": false,
|
||||||
|
|
||||||
// включить(true)/выключить(false) режим "Удаленная библиотека" (сервер)
|
// включить(true)/выключить(false) режим "Удаленная библиотека" (сервер)
|
||||||
"allowRemoteLib": false,
|
"allowRemoteLib": false,
|
||||||
|
|
||||||
|
|||||||
@@ -35,24 +35,22 @@ import vueComponent from '../vueComponent.js';
|
|||||||
import wsc from './webSocketConnection';
|
import wsc from './webSocketConnection';
|
||||||
import * as utils from '../../share/utils';
|
import * as utils from '../../share/utils';
|
||||||
import * as cryptoUtils from '../../share/cryptoUtils';
|
import * as cryptoUtils from '../../share/cryptoUtils';
|
||||||
import LockQueue from '../../share/LockQueue';
|
import LockQueue from '../../../server/core/LockQueue';
|
||||||
import packageJson from '../../../package.json';
|
import packageJson from '../../../package.json';
|
||||||
|
|
||||||
const rotor = '|/-\\';
|
const rotor = '|/-\\';
|
||||||
const stepBound = [
|
const stepBound = [
|
||||||
0,
|
0,
|
||||||
0,// jobStep = 1
|
0,// jobStep = 1
|
||||||
18,// jobStep = 2
|
40,// jobStep = 2
|
||||||
20,// jobStep = 3
|
50,// jobStep = 3
|
||||||
60,// jobStep = 4
|
54,// jobStep = 4
|
||||||
72,// jobStep = 5
|
58,// jobStep = 5
|
||||||
72,// jobStep = 6
|
69,// jobStep = 6
|
||||||
74,// jobStep = 7
|
69,// jobStep = 7
|
||||||
75,// jobStep = 8
|
70,// jobStep = 8
|
||||||
79,// jobStep = 9
|
95,// jobStep = 9
|
||||||
79,// jobStep = 10
|
100,// jobStep = 10
|
||||||
80,// jobStep = 11
|
|
||||||
100,// jobStep = 12
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const componentOptions = {
|
const componentOptions = {
|
||||||
@@ -185,80 +183,60 @@ class Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async request(params, timeoutSecs = 10) {
|
async request(params, timeoutSecs = 10) {
|
||||||
|
let errCount = 0;
|
||||||
while (1) {// eslint-disable-line
|
while (1) {// eslint-disable-line
|
||||||
if (this.accessToken)
|
try {
|
||||||
params.accessToken = this.accessToken;
|
if (this.accessToken)
|
||||||
|
params.accessToken = this.accessToken;
|
||||||
|
|
||||||
const response = await wsc.message(await wsc.send(params), timeoutSecs);
|
const response = await wsc.message(await wsc.send(params), timeoutSecs);
|
||||||
|
|
||||||
if (response && response.error == 'need_access_token') {
|
if (response && response.error == 'need_access_token') {
|
||||||
await this.showPasswordDialog();
|
await this.showPasswordDialog();
|
||||||
} else if (response && response.error == 'server_busy') {
|
} else if (response && response.error == 'server_busy') {
|
||||||
await this.showBusyDialog();
|
await this.showBusyDialog();
|
||||||
} else {
|
} else {
|
||||||
return response;
|
if (response.error) {
|
||||||
|
throw new Error(response.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
errCount = 0;
|
||||||
|
} catch(e) {
|
||||||
|
errCount++;
|
||||||
|
if (e.message !== 'WebSocket не отвечает' || errCount > 10) {
|
||||||
|
errCount = 0;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
await utils.sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async search(query) {
|
async search(from, query) {
|
||||||
const response = await this.request({action: 'search', query});
|
return await this.request({action: 'search', from, query}, 30);
|
||||||
|
|
||||||
if (response.error) {
|
|
||||||
throw new Error(response.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBookList(authorId) {
|
async getAuthorBookList(authorId) {
|
||||||
const response = await this.request({action: 'get-book-list', authorId});
|
return await this.request({action: 'get-author-book-list', authorId});
|
||||||
|
|
||||||
if (response.error) {
|
|
||||||
throw new Error(response.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSeriesBookList(series) {
|
async getSeriesBookList(series) {
|
||||||
const response = await this.request({action: 'get-series-book-list', series});
|
return await this.request({action: 'get-series-book-list', series});
|
||||||
|
|
||||||
if (response.error) {
|
|
||||||
throw new Error(response.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGenreTree() {
|
async getGenreTree() {
|
||||||
const response = await this.request({action: 'get-genre-tree'});
|
return await this.request({action: 'get-genre-tree'});
|
||||||
|
|
||||||
if (response.error) {
|
|
||||||
throw new Error(response.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBookLink(params) {
|
async getBookLink(params) {
|
||||||
const response = await this.request(Object.assign({action: 'get-book-link'}, params), 120);
|
return await this.request(Object.assign({action: 'get-book-link'}, params), 120);
|
||||||
|
|
||||||
if (response.error) {
|
|
||||||
throw new Error(response.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getConfig() {
|
async getConfig() {
|
||||||
const response = await this.request({action: 'get-config'});
|
return await this.request({action: 'get-config'});
|
||||||
|
|
||||||
if (response.error) {
|
|
||||||
throw new Error(response.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ body, html, #app {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
font: normal 12px GameDefault;
|
font: normal 13px Web Default;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dborder {
|
.dborder {
|
||||||
@@ -142,9 +142,13 @@ body, html, #app {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'GameDefault';
|
font-family: 'Web Default';
|
||||||
src: url('fonts/web-default.woff') format('woff'),
|
src: url('fonts/web-default.ttf') format('truetype');
|
||||||
url('fonts/web-default.ttf') format('truetype');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Verdana';
|
||||||
|
font-weight: bold;
|
||||||
|
src: url('fonts/web-default-bold.ttf') format('truetype');
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
447
client/components/Search/AuthorList/AuthorList.vue
Normal file
447
client/components/Search/AuthorList/AuthorList.vue
Normal file
@@ -0,0 +1,447 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<a ref="download" style="display: none;"></a>
|
||||||
|
|
||||||
|
<LoadingMessage :message="loadingMessage" z-index="2" />
|
||||||
|
<LoadingMessage :message="loadingMessage2" z-index="1" />
|
||||||
|
|
||||||
|
<!-- Формирование списка ------------------------------------------------------------------------>
|
||||||
|
<div v-for="item in tableData" :key="item.key" class="column" :class="{'odd-item': item.num % 2}" style="font-size: 120%">
|
||||||
|
<div class="row items-center q-ml-md q-mr-xs no-wrap">
|
||||||
|
<div class="row items-center clickable2 q-py-xs no-wrap" @click="expandAuthor(item)">
|
||||||
|
<div style="min-width: 30px">
|
||||||
|
<div v-if="!isExpandedAuthor(item)">
|
||||||
|
<q-icon name="la la-plus-square" size="28px" />
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<q-icon name="la la-minus-square" size="28px" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="clickable2 q-ml-xs q-py-sm text-green-10 text-bold" @click="selectAuthor(item.author)">
|
||||||
|
{{ item.name }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="q-ml-sm text-bold" style="color: #555">
|
||||||
|
{{ getBookCount(item) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="item.bookLoading" class="book-row row items-center">
|
||||||
|
<q-icon class="la la-spinner icon-rotate text-blue-8" size="28px" />
|
||||||
|
<div class="q-ml-xs">
|
||||||
|
Обработка...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isExpandedAuthor(item) && item.books">
|
||||||
|
<div v-for="book in item.books" :key="book.key" class="book-row column">
|
||||||
|
<!-- серия книг -->
|
||||||
|
<div v-if="book.type == 'series'" class="column">
|
||||||
|
<div class="row items-center q-mr-xs no-wrap text-grey-9">
|
||||||
|
<div class="row items-center clickable2 q-py-xs no-wrap" @click="expandSeries(book)">
|
||||||
|
<div style="min-width: 30px">
|
||||||
|
<div v-if="!isExpandedSeries(book)">
|
||||||
|
<q-icon name="la la-plus-square" size="28px" />
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<q-icon name="la la-minus-square" size="28px" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="clickable2 q-ml-xs q-py-sm text-bold" @click="selectSeries(book.series)">
|
||||||
|
Серия: {{ book.series }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isExpandedSeries(book) && book.seriesBooks">
|
||||||
|
<div v-if="book.showAllBooks" class="book-row column">
|
||||||
|
<BookView
|
||||||
|
v-for="seriesBook in book.allBooks" :key="seriesBook.id"
|
||||||
|
:book="seriesBook"
|
||||||
|
mode="series"
|
||||||
|
:genre-map="genreMap" :show-read-link="showReadLink"
|
||||||
|
:title-color="isFoundSeriesBook(book, seriesBook) ? 'text-blue-10' : 'text-red'"
|
||||||
|
@book-event="bookEvent"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div v-else class="book-row column">
|
||||||
|
<BookView
|
||||||
|
v-for="seriesBook in book.seriesBooks" :key="seriesBook.key"
|
||||||
|
:book="seriesBook" mode="author" :genre-map="genreMap" :show-read-link="showReadLink" @book-event="bookEvent"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="book.allBooksLoaded && book.allBooksLoaded.length != book.seriesBooks.length"
|
||||||
|
class="row items-center q-my-sm"
|
||||||
|
style="margin-left: 100px"
|
||||||
|
>
|
||||||
|
<div v-if="book.showAllBooks && book.showMoreAll" class="row items-center q-mr-md">
|
||||||
|
<i class="las la-ellipsis-h text-red" style="font-size: 40px"></i>
|
||||||
|
<q-btn class="q-ml-md" color="red" style="width: 200px" dense rounded no-caps @click="showMoreAll(book)">
|
||||||
|
Показать еще (~{{ showMoreCount }})
|
||||||
|
</q-btn>
|
||||||
|
<q-btn class="q-ml-sm" color="red" style="width: 200px" dense rounded no-caps @click="showMoreAll(book, true)">
|
||||||
|
Показать все ({{ (book.allBooksLoaded && book.allBooksLoaded.length) || '?' }})
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="book.showAllBooks" class="row items-center clickable2 text-blue-10" @click="book.showAllBooks = false">
|
||||||
|
<q-icon class="la la-long-arrow-alt-up" size="28px" />
|
||||||
|
Только найденные книги
|
||||||
|
</div>
|
||||||
|
<div v-else class="row items-center clickable2 text-red" @click="book.showAllBooks = true">
|
||||||
|
<q-icon class="la la-long-arrow-alt-down" size="28px" />
|
||||||
|
Все книги серии
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- книга без серии -->
|
||||||
|
<BookView v-else :book="book" mode="author" :genre-map="genreMap" :show-read-link="showReadLink" @book-event="bookEvent" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--div v-if="isExpandedAuthor(item) && item.books && !item.books.length" class="book-row row items-center">
|
||||||
|
<q-icon class="la la-meh q-mr-xs" size="24px" />
|
||||||
|
По каждому из заданных критериев у этого автора были найдены разные книги, но нет полного совпадения
|
||||||
|
</div-->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isExpandedAuthor(item) && item.showMore" class="row items-center book-row q-mb-sm">
|
||||||
|
<i class="las la-ellipsis-h text-blue-10" style="font-size: 40px"></i>
|
||||||
|
<q-btn class="q-ml-md" color="primary" style="width: 200px" dense rounded no-caps @click="showMore(item)">
|
||||||
|
Показать еще (~{{ showMoreCount }})
|
||||||
|
</q-btn>
|
||||||
|
<q-btn class="q-ml-sm" color="primary" style="width: 200px" dense rounded no-caps @click="showMore(item, true)">
|
||||||
|
Показать все ({{ (item.booksLoaded && item.booksLoaded.length) || '?' }})
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- Формирование списка конец ------------------------------------------------------------------>
|
||||||
|
|
||||||
|
<div v-if="!refreshing && !tableData.length" class="row items-center q-ml-md" style="font-size: 120%">
|
||||||
|
<q-icon class="la la-meh q-mr-xs" size="28px" />
|
||||||
|
Поиск не дал результатов
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
import vueComponent from '../../vueComponent.js';
|
||||||
|
import { reactive } from 'vue';
|
||||||
|
|
||||||
|
import BaseList from '../BaseList';
|
||||||
|
|
||||||
|
import authorBooksStorage from '../authorBooksStorage';
|
||||||
|
|
||||||
|
import * as utils from '../../../share/utils';
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
class AuthorList extends BaseList {
|
||||||
|
cachedAuthors = {};
|
||||||
|
|
||||||
|
showHiddenHelp() {
|
||||||
|
this.$root.stdDialog.alert(`
|
||||||
|
Книги скрытых авторов помечены как удаленные. Для того, чтобы их увидеть, необходимо установить опцию "Показывать удаленные" в настройках.
|
||||||
|
`, 'Пояснение', {iconName: 'la la-info-circle'});
|
||||||
|
}
|
||||||
|
|
||||||
|
get foundCountMessage() {
|
||||||
|
return `${this.list.totalFound} автор${utils.wordEnding(this.list.totalFound)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
isFoundSeriesBook(seriesItem, seriesBook) {
|
||||||
|
if (!seriesItem.booksSet) {
|
||||||
|
seriesItem.booksSet = new Set(seriesItem.seriesBooks.map(b => b.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return seriesItem.booksSet.has(seriesBook.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
getBookCount(item) {
|
||||||
|
let result = '';
|
||||||
|
if (!this.showCounts || item.count === undefined)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if (item.booksLoaded) {
|
||||||
|
let count = 0;
|
||||||
|
for (const book of item.booksLoaded) {
|
||||||
|
if (book.type == 'series')
|
||||||
|
count += book.seriesBooks.length;
|
||||||
|
else
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = `${count}/${item.count}`;
|
||||||
|
} else
|
||||||
|
result = `#/${item.count}`;
|
||||||
|
|
||||||
|
return `(${result})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async expandAuthor(item) {
|
||||||
|
this.$emit('listEvent', {action: 'ignoreScroll'});
|
||||||
|
|
||||||
|
const expanded = _.cloneDeep(this.expandedAuthor);
|
||||||
|
const key = item.author;
|
||||||
|
|
||||||
|
if (!this.isExpandedAuthor(item)) {
|
||||||
|
expanded.push(key);
|
||||||
|
|
||||||
|
await this.getAuthorBooks(item);
|
||||||
|
|
||||||
|
if (expanded.length > 10) {
|
||||||
|
expanded.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setSetting('expandedAuthor', expanded);
|
||||||
|
} else {
|
||||||
|
const i = expanded.indexOf(key);
|
||||||
|
if (i >= 0) {
|
||||||
|
expanded.splice(i, 1);
|
||||||
|
this.setSetting('expandedAuthor', expanded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAuthorBooks(item) {
|
||||||
|
if (item.books) {
|
||||||
|
if (item.count > this.maxItemCount) {
|
||||||
|
item.bookLoading = true;
|
||||||
|
await utils.sleep(1);//для перерисовки списка
|
||||||
|
item.bookLoading = false;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.getBooksFlag)
|
||||||
|
this.getBooksFlag = 0;
|
||||||
|
|
||||||
|
this.getBooksFlag++;
|
||||||
|
if (item.count > this.maxItemCount)
|
||||||
|
item.bookLoading = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (this.getBooksFlag == 1) {
|
||||||
|
(async() => {
|
||||||
|
await utils.sleep(500);
|
||||||
|
if (this.getBooksFlag > 0)
|
||||||
|
this.loadingMessage2 = 'Загрузка списка книг...';
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
const booksToFilter = await this.loadAuthorBooks(item.key);
|
||||||
|
const filtered = this.filterBooks(booksToFilter);
|
||||||
|
|
||||||
|
const prepareBook = (book) => {
|
||||||
|
return Object.assign(
|
||||||
|
{
|
||||||
|
key: book.id,
|
||||||
|
type: 'book',
|
||||||
|
},
|
||||||
|
book
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
//объединение по сериям
|
||||||
|
const books = [];
|
||||||
|
const seriesIndex = {};
|
||||||
|
for (const book of filtered) {
|
||||||
|
if (book.series) {
|
||||||
|
let index = seriesIndex[book.series];
|
||||||
|
if (index === undefined) {
|
||||||
|
index = books.length;
|
||||||
|
books.push(reactive({
|
||||||
|
key: book.series,
|
||||||
|
type: 'series',
|
||||||
|
series: book.series,
|
||||||
|
allBooksLoaded: false,
|
||||||
|
allBooks: false,
|
||||||
|
showAllBooks: false,
|
||||||
|
showMoreAll: false,
|
||||||
|
|
||||||
|
seriesBooks: [],
|
||||||
|
}));
|
||||||
|
|
||||||
|
seriesIndex[book.series] = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
books[index].seriesBooks.push(prepareBook(book));
|
||||||
|
} else {
|
||||||
|
books.push(prepareBook(book));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//сортировка
|
||||||
|
books.sort((a, b) => {
|
||||||
|
if (a.type == 'series') {
|
||||||
|
return (b.type == 'series' ? a.key.localeCompare(b.key) : -1);
|
||||||
|
} else {
|
||||||
|
return (b.type == 'book' ? a.title.localeCompare(b.title) : 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//сортировка внутри серий
|
||||||
|
for (const book of books) {
|
||||||
|
if (book.type == 'series') {
|
||||||
|
this.sortSeriesBooks(book.seriesBooks);
|
||||||
|
|
||||||
|
//асинхронно подгрузим все книги серии, если она раскрыта
|
||||||
|
if (this.isExpandedSeries(book)) {
|
||||||
|
this.getSeriesBooks(book);//no await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (books.length == 1 && books[0].type == 'series' && !this.isExpandedSeries(books[0])) {
|
||||||
|
this.expandSeries(books[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
item.booksLoaded = books;
|
||||||
|
this.showMore(item);
|
||||||
|
|
||||||
|
await this.$nextTick();
|
||||||
|
} finally {
|
||||||
|
item.bookLoading = false;
|
||||||
|
this.getBooksFlag--;
|
||||||
|
if (this.getBooksFlag == 0)
|
||||||
|
this.loadingMessage2 = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateTableData() {
|
||||||
|
let result = [];
|
||||||
|
|
||||||
|
const expandedSet = new Set(this.expandedAuthor);
|
||||||
|
const authors = this.searchResult.found;
|
||||||
|
if (!authors)
|
||||||
|
return;
|
||||||
|
|
||||||
|
let num = 0;
|
||||||
|
for (const rec of authors) {
|
||||||
|
this.cachedAuthors[rec.author] = rec;
|
||||||
|
|
||||||
|
const count = (this.showDeleted ? rec.bookCount + rec.bookDelCount : rec.bookCount);
|
||||||
|
|
||||||
|
const item = reactive({
|
||||||
|
key: rec.id,
|
||||||
|
num,
|
||||||
|
author: rec.author,
|
||||||
|
name: rec.author.replace(/,/g, ', '),
|
||||||
|
count,
|
||||||
|
booksLoaded: false,
|
||||||
|
books: false,
|
||||||
|
bookLoading: false,
|
||||||
|
showMore: false,
|
||||||
|
});
|
||||||
|
num++;
|
||||||
|
|
||||||
|
if (expandedSet.has(item.author)) {
|
||||||
|
if (authors.length > 1 || item.count > this.maxItemCount)
|
||||||
|
this.getAuthorBooks(item);//no await
|
||||||
|
else
|
||||||
|
await this.getAuthorBooks(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.length == 1 && !this.isExpandedAuthor(result[0])) {
|
||||||
|
this.expandAuthor(result[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tableData = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async refresh() {
|
||||||
|
//параметры запроса
|
||||||
|
const newQuery = this.getQuery();
|
||||||
|
if (_.isEqual(newQuery, this.prevQuery))
|
||||||
|
return;
|
||||||
|
this.prevQuery = newQuery;
|
||||||
|
|
||||||
|
//оптимизация, вместо запроса к серверу, берем из кеша
|
||||||
|
if (this.abCacheEnabled && this.search.author && this.search.author[0] == '=') {
|
||||||
|
const authorSearch = this.search.author.substring(1);
|
||||||
|
const author = this.cachedAuthors[authorSearch];
|
||||||
|
|
||||||
|
if (author) {
|
||||||
|
const key = `author-${author.id}-${this.list.inpxHash}`;
|
||||||
|
let data = await authorBooksStorage.getData(key);
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
this.list.queryFound = 1;
|
||||||
|
this.list.totalFound = 1;
|
||||||
|
this.searchResult = {found: [author]};
|
||||||
|
await this.updateTableData();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.queryExecute = newQuery;
|
||||||
|
|
||||||
|
if (this.refreshing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.refreshing = true;
|
||||||
|
|
||||||
|
(async() => {
|
||||||
|
await utils.sleep(500);
|
||||||
|
if (this.refreshing)
|
||||||
|
this.loadingMessage = 'Поиск авторов...';
|
||||||
|
})();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (this.queryExecute) {
|
||||||
|
const query = this.queryExecute;
|
||||||
|
this.queryExecute = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await this.api.search('author', query);
|
||||||
|
|
||||||
|
this.list.queryFound = response.found.length;
|
||||||
|
this.list.totalFound = response.totalFound;
|
||||||
|
this.list.inpxHash = response.inpxHash;
|
||||||
|
|
||||||
|
this.searchResult = response;
|
||||||
|
|
||||||
|
await utils.sleep(1);
|
||||||
|
if (!this.queryExecute) {
|
||||||
|
await this.updateTableData();
|
||||||
|
this.scrollToTop();
|
||||||
|
this.highlightPageScroller(query);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.$root.stdDialog.alert(e.message, 'Ошибка');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.refreshing = false;
|
||||||
|
this.loadingMessage = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default vueComponent(AuthorList);
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.clickable2 {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.odd-item {
|
||||||
|
background-color: #e8e8e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-row {
|
||||||
|
margin-left: 50px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
522
client/components/Search/BaseList.js
Normal file
522
client/components/Search/BaseList.js
Normal file
@@ -0,0 +1,522 @@
|
|||||||
|
import moment from 'moment';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
import authorBooksStorage from './authorBooksStorage';
|
||||||
|
|
||||||
|
import BookView from './BookView/BookView.vue';
|
||||||
|
import LoadingMessage from './LoadingMessage/LoadingMessage.vue';
|
||||||
|
import * as utils from '../../share/utils';
|
||||||
|
|
||||||
|
const showMoreCount = 100;//значение для "Показать еще"
|
||||||
|
const maxItemCount = 500;//выше этого значения показываем "Загрузка"
|
||||||
|
|
||||||
|
const componentOptions = {
|
||||||
|
components: {
|
||||||
|
BookView,
|
||||||
|
LoadingMessage,
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
settings() {
|
||||||
|
this.loadSettings();
|
||||||
|
},
|
||||||
|
search: {
|
||||||
|
handler(newValue) {
|
||||||
|
this.limit = newValue.limit;
|
||||||
|
|
||||||
|
if (this.pageCount > 1)
|
||||||
|
this.prevPage = this.search.page;
|
||||||
|
|
||||||
|
this.refresh();
|
||||||
|
},
|
||||||
|
deep: true,
|
||||||
|
},
|
||||||
|
showDeleted() {
|
||||||
|
this.refresh();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default class BaseList {
|
||||||
|
_options = componentOptions;
|
||||||
|
_props = {
|
||||||
|
list: Object,
|
||||||
|
search: Object,
|
||||||
|
genreMap: Object,
|
||||||
|
};
|
||||||
|
|
||||||
|
loadingMessage = '';
|
||||||
|
loadingMessage2 = '';
|
||||||
|
|
||||||
|
//settings
|
||||||
|
expandedAuthor = [];
|
||||||
|
expandedSeries = [];
|
||||||
|
|
||||||
|
showCounts = true;
|
||||||
|
showRates = true;
|
||||||
|
showGenres = true;
|
||||||
|
showDeleted = false;
|
||||||
|
abCacheEnabled = true;
|
||||||
|
|
||||||
|
//stuff
|
||||||
|
refreshing = false;
|
||||||
|
|
||||||
|
showMoreCount = showMoreCount;
|
||||||
|
maxItemCount = maxItemCount;
|
||||||
|
|
||||||
|
searchResult = {};
|
||||||
|
tableData = [];
|
||||||
|
|
||||||
|
created() {
|
||||||
|
this.commit = this.$store.commit;
|
||||||
|
this.api = this.$root.api;
|
||||||
|
|
||||||
|
this.loadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.refresh();//no await
|
||||||
|
}
|
||||||
|
|
||||||
|
loadSettings() {
|
||||||
|
const settings = this.settings;
|
||||||
|
|
||||||
|
this.expandedAuthor = _.cloneDeep(settings.expandedAuthor);
|
||||||
|
this.expandedSeries = _.cloneDeep(settings.expandedSeries);
|
||||||
|
this.showCounts = settings.showCounts;
|
||||||
|
this.showRates = settings.showRates;
|
||||||
|
this.showGenres = settings.showGenres;
|
||||||
|
this.showDeleted = settings.showDeleted;
|
||||||
|
this.abCacheEnabled = settings.abCacheEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
get config() {
|
||||||
|
return this.$store.state.config;
|
||||||
|
}
|
||||||
|
|
||||||
|
get settings() {
|
||||||
|
return this.$store.state.settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
get showReadLink() {
|
||||||
|
return this.config.bookReadLink != '' || this.list.liberamaReady;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollToTop() {
|
||||||
|
this.$emit('listEvent', {action: 'scrollToTop'});
|
||||||
|
}
|
||||||
|
|
||||||
|
selectAuthor(author) {
|
||||||
|
this.search.author = `=${author}`;
|
||||||
|
this.scrollToTop();
|
||||||
|
}
|
||||||
|
|
||||||
|
selectSeries(series) {
|
||||||
|
this.search.series = `=${series}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectTitle(title) {
|
||||||
|
this.search.title = `=${title}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async download(book, action) {
|
||||||
|
if (this.downloadFlag)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.downloadFlag = true;
|
||||||
|
(async() => {
|
||||||
|
await utils.sleep(200);
|
||||||
|
if (this.downloadFlag)
|
||||||
|
this.loadingMessage2 = 'Подготовка файла...';
|
||||||
|
})();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const makeValidFilenameOrEmpty = (s) => {
|
||||||
|
try {
|
||||||
|
return utils.makeValidFilename(s);
|
||||||
|
} catch(e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//имя файла
|
||||||
|
let downFileName = 'default-name';
|
||||||
|
const author = book.author.split(',');
|
||||||
|
const at = [author[0], book.title];
|
||||||
|
downFileName = makeValidFilenameOrEmpty(at.filter(r => r).join(' - '))
|
||||||
|
|| makeValidFilenameOrEmpty(at[0])
|
||||||
|
|| makeValidFilenameOrEmpty(at[1])
|
||||||
|
|| downFileName;
|
||||||
|
downFileName = downFileName.substring(0, 100);
|
||||||
|
|
||||||
|
const ext = `.${book.ext}`;
|
||||||
|
if (downFileName.substring(downFileName.length - ext.length) != ext)
|
||||||
|
downFileName += ext;
|
||||||
|
|
||||||
|
const bookPath = `${book.folder}/${book.file}${ext}`;
|
||||||
|
//подготовка
|
||||||
|
const response = await this.api.getBookLink({bookPath, downFileName});
|
||||||
|
|
||||||
|
const link = response.link;
|
||||||
|
const href = `${window.location.origin}${link}`;
|
||||||
|
|
||||||
|
if (action == 'download') {
|
||||||
|
//скачивание
|
||||||
|
const d = this.$refs.download;
|
||||||
|
d.href = href;
|
||||||
|
d.download = downFileName;
|
||||||
|
|
||||||
|
d.click();
|
||||||
|
} else if (action == 'copyLink') {
|
||||||
|
//копирование ссылки
|
||||||
|
if (await utils.copyTextToClipboard(href))
|
||||||
|
this.$root.notify.success('Ссылка успешно скопирована');
|
||||||
|
else
|
||||||
|
this.$root.stdDialog.alert(
|
||||||
|
`Копирование ссылки не удалось. Пожалуйста, попробуйте еще раз.
|
||||||
|
<br><br>
|
||||||
|
<b>Пояснение</b>: вероятно, браузер запретил копирование, т.к. прошло<br>
|
||||||
|
слишком много времени с момента нажатия на кнопку (инициация<br>
|
||||||
|
пользовательского события). Сейчас ссылка уже закеширована,<br>
|
||||||
|
поэтому повторная попытка должна быть успешной.`, 'Ошибка');
|
||||||
|
} else if (action == 'readBook') {
|
||||||
|
//читать
|
||||||
|
if (this.list.liberamaReady) {
|
||||||
|
this.$emit('listEvent', {action: 'submitUrl', data: href});
|
||||||
|
} else {
|
||||||
|
const url = this.config.bookReadLink.replace('${DOWNLOAD_LINK}', href);
|
||||||
|
window.open(url, '_blank');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
this.$root.stdDialog.alert(e.message, 'Ошибка');
|
||||||
|
} finally {
|
||||||
|
this.downloadFlag = false;
|
||||||
|
this.loadingMessage2 = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bookEvent(event) {
|
||||||
|
switch (event.action) {
|
||||||
|
case 'authorClick':
|
||||||
|
this.selectAuthor(event.book.author);
|
||||||
|
break;
|
||||||
|
case 'seriesClick':
|
||||||
|
this.selectSeries(event.book.series);
|
||||||
|
break;
|
||||||
|
case 'titleClick':
|
||||||
|
this.selectTitle(event.book.title);
|
||||||
|
break;
|
||||||
|
case 'download':
|
||||||
|
case 'copyLink':
|
||||||
|
case 'readBook':
|
||||||
|
this.download(event.book, event.action);//no await
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isExpandedAuthor(item) {
|
||||||
|
return this.expandedAuthor.indexOf(item.author) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
isExpandedSeries(seriesItem) {
|
||||||
|
return this.expandedSeries.indexOf(seriesItem.key) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSetting(name, newValue) {
|
||||||
|
this.commit('setSettings', {[name]: _.cloneDeep(newValue)});
|
||||||
|
}
|
||||||
|
|
||||||
|
highlightPageScroller(query) {
|
||||||
|
this.$emit('listEvent', {action: 'highlightPageScroller', query});
|
||||||
|
}
|
||||||
|
|
||||||
|
async expandSeries(seriesItem) {
|
||||||
|
this.$emit('listEvent', {action: 'ignoreScroll'});
|
||||||
|
|
||||||
|
const expandedSeries = _.cloneDeep(this.expandedSeries);
|
||||||
|
const key = seriesItem.key;
|
||||||
|
|
||||||
|
if (!this.isExpandedSeries(seriesItem)) {
|
||||||
|
expandedSeries.push(key);
|
||||||
|
|
||||||
|
if (expandedSeries.length > 100) {
|
||||||
|
expandedSeries.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getSeriesBooks(seriesItem); //no await
|
||||||
|
|
||||||
|
this.setSetting('expandedSeries', expandedSeries);
|
||||||
|
} else {
|
||||||
|
const i = expandedSeries.indexOf(key);
|
||||||
|
if (i >= 0) {
|
||||||
|
expandedSeries.splice(i, 1);
|
||||||
|
this.setSetting('expandedSeries', expandedSeries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadAuthorBooks(authorId) {
|
||||||
|
try {
|
||||||
|
let result;
|
||||||
|
|
||||||
|
if (this.abCacheEnabled) {
|
||||||
|
const key = `author-${authorId}-${this.list.inpxHash}`;
|
||||||
|
const data = await authorBooksStorage.getData(key);
|
||||||
|
if (data) {
|
||||||
|
result = JSON.parse(data);
|
||||||
|
} else {
|
||||||
|
result = await this.api.getAuthorBookList(authorId);
|
||||||
|
await authorBooksStorage.setData(key, JSON.stringify(result));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = await this.api.getAuthorBookList(authorId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (result.books ? JSON.parse(result.books) : []);
|
||||||
|
} catch (e) {
|
||||||
|
this.$root.stdDialog.alert(e.message, 'Ошибка');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadSeriesBooks(series) {
|
||||||
|
try {
|
||||||
|
let result;
|
||||||
|
|
||||||
|
if (this.abCacheEnabled) {
|
||||||
|
const key = `series-${series}-${this.list.inpxHash}`;
|
||||||
|
const data = await authorBooksStorage.getData(key);
|
||||||
|
if (data) {
|
||||||
|
result = JSON.parse(data);
|
||||||
|
} else {
|
||||||
|
result = await this.api.getSeriesBookList(series);
|
||||||
|
await authorBooksStorage.setData(key, JSON.stringify(result));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = await this.api.getSeriesBookList(series);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (result.books ? JSON.parse(result.books) : []);
|
||||||
|
} catch (e) {
|
||||||
|
this.$root.stdDialog.alert(e.message, 'Ошибка');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSeriesBooks(seriesItem) {
|
||||||
|
//блокируем повторный вызов
|
||||||
|
if (seriesItem.seriesBookLoading)
|
||||||
|
return;
|
||||||
|
seriesItem.seriesBookLoading = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
seriesItem.allBooksLoaded = await this.loadSeriesBooks(seriesItem.series);
|
||||||
|
|
||||||
|
if (seriesItem.allBooksLoaded) {
|
||||||
|
seriesItem.allBooksLoaded = seriesItem.allBooksLoaded.filter(book => (this.showDeleted || !book.del));
|
||||||
|
this.sortSeriesBooks(seriesItem.allBooksLoaded);
|
||||||
|
this.showMoreAll(seriesItem);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
seriesItem.seriesBookLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filterBooks(books) {
|
||||||
|
const s = this.search;
|
||||||
|
|
||||||
|
const emptyFieldValue = '?';
|
||||||
|
const maxUtf8Char = String.fromCodePoint(0xFFFFF);
|
||||||
|
const ruAlphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';
|
||||||
|
const enAlphabet = 'abcdefghijklmnopqrstuvwxyz';
|
||||||
|
const enru = new Set((ruAlphabet + enAlphabet).split(''));
|
||||||
|
|
||||||
|
const splitAuthor = (author) => {
|
||||||
|
if (!author) {
|
||||||
|
author = emptyFieldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = author.split(',');
|
||||||
|
if (result.length > 1)
|
||||||
|
result.push(author);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const filterBySearch = (bookValue, searchValue) => {
|
||||||
|
if (!searchValue)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!bookValue)
|
||||||
|
bookValue = emptyFieldValue;
|
||||||
|
|
||||||
|
bookValue = bookValue.toLowerCase();
|
||||||
|
searchValue = searchValue.toLowerCase();
|
||||||
|
|
||||||
|
//особая обработка префиксов
|
||||||
|
if (searchValue[0] == '=') {
|
||||||
|
|
||||||
|
searchValue = searchValue.substring(1);
|
||||||
|
return bookValue.localeCompare(searchValue) == 0;
|
||||||
|
} else if (searchValue[0] == '*') {
|
||||||
|
|
||||||
|
searchValue = searchValue.substring(1);
|
||||||
|
return bookValue !== emptyFieldValue && bookValue.indexOf(searchValue) >= 0;
|
||||||
|
} else if (searchValue[0] == '#') {
|
||||||
|
|
||||||
|
searchValue = searchValue.substring(1);
|
||||||
|
return !bookValue || (bookValue !== emptyFieldValue && !enru.has(bookValue[0]) && bookValue.indexOf(searchValue) >= 0);
|
||||||
|
} else {
|
||||||
|
//where = `@dirtyIndexLR('value', ${db.esc(a)}, ${db.esc(a + maxUtf8Char)})`;
|
||||||
|
return bookValue.localeCompare(searchValue) >= 0 && bookValue.localeCompare(searchValue + maxUtf8Char) <= 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return books.filter((book) => {
|
||||||
|
//author
|
||||||
|
let authorFound = false;
|
||||||
|
const authors = splitAuthor(book.author);
|
||||||
|
for (const a of authors) {
|
||||||
|
if (filterBySearch(a, s.author)) {
|
||||||
|
authorFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//genre
|
||||||
|
let genreFound = !s.genre;
|
||||||
|
if (!genreFound) {
|
||||||
|
const searchGenres = new Set(s.genre.split(','));
|
||||||
|
const bookGenres = book.genre.split(',');
|
||||||
|
|
||||||
|
for (let g of bookGenres) {
|
||||||
|
if (!g)
|
||||||
|
g = emptyFieldValue;
|
||||||
|
|
||||||
|
if (searchGenres.has(g)) {
|
||||||
|
genreFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//lang
|
||||||
|
let langFound = !s.lang;
|
||||||
|
if (!langFound) {
|
||||||
|
const searchLang = new Set(s.lang.split(','));
|
||||||
|
langFound = searchLang.has(book.lang || emptyFieldValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
//date
|
||||||
|
let dateFound = !s.date;
|
||||||
|
if (!dateFound) {
|
||||||
|
const date = this.queryDate(s.date).split(',');
|
||||||
|
let [from = '0000-00-00', to = '9999-99-99'] = date;
|
||||||
|
|
||||||
|
dateFound = (book.date >= from && book.date <= to);
|
||||||
|
}
|
||||||
|
|
||||||
|
//librate
|
||||||
|
let librateFound = !s.librate;
|
||||||
|
if (!librateFound) {
|
||||||
|
const searchLibrate = new Set(s.librate.split(',').map(n => parseInt(n, 10)).filter(n => !isNaN(n)));
|
||||||
|
librateFound = searchLibrate.has(book.librate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (this.showDeleted || !book.del)
|
||||||
|
&& authorFound
|
||||||
|
&& filterBySearch(book.series, s.series)
|
||||||
|
&& filterBySearch(book.title, s.title)
|
||||||
|
&& genreFound
|
||||||
|
&& langFound
|
||||||
|
&& dateFound
|
||||||
|
&& librateFound
|
||||||
|
;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
showMore(item, all = false) {
|
||||||
|
if (item.booksLoaded) {
|
||||||
|
const currentLen = (item.books ? item.books.length : 0);
|
||||||
|
let books;
|
||||||
|
if (all || currentLen + this.showMoreCount*1.5 > item.booksLoaded.length) {
|
||||||
|
books = item.booksLoaded;
|
||||||
|
} else {
|
||||||
|
books = item.booksLoaded.slice(0, currentLen + this.showMoreCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
item.showMore = (books.length < item.booksLoaded.length);
|
||||||
|
item.books = books;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showMoreAll(seriesItem, all = false) {
|
||||||
|
if (seriesItem.allBooksLoaded) {
|
||||||
|
const currentLen = (seriesItem.allBooks ? seriesItem.allBooks.length : 0);
|
||||||
|
let books;
|
||||||
|
if (all || currentLen + this.showMoreCount*1.5 > seriesItem.allBooksLoaded.length) {
|
||||||
|
books = seriesItem.allBooksLoaded;
|
||||||
|
} else {
|
||||||
|
books = seriesItem.allBooksLoaded.slice(0, currentLen + this.showMoreCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
seriesItem.showMoreAll = (books.length < seriesItem.allBooksLoaded.length);
|
||||||
|
seriesItem.allBooks = books;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sortSeriesBooks(seriesBooks) {
|
||||||
|
seriesBooks.sort((a, b) => {
|
||||||
|
const dserno = (a.serno || Number.MAX_VALUE) - (b.serno || Number.MAX_VALUE);
|
||||||
|
const dtitle = a.title.localeCompare(b.title);
|
||||||
|
const dext = a.ext.localeCompare(b.ext);
|
||||||
|
return (dserno ? dserno : (dtitle ? dtitle : dext));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
queryDate(date) {
|
||||||
|
if (!utils.isManualDate(date)) {//!manual
|
||||||
|
/*
|
||||||
|
{label: 'сегодня', value: 'today'},
|
||||||
|
{label: 'за 3 дня', value: '3days'},
|
||||||
|
{label: 'за неделю', value: 'week'},
|
||||||
|
{label: 'за 2 недели', value: '2weeks'},
|
||||||
|
{label: 'за месяц', value: 'month'},
|
||||||
|
{label: 'за 2 месяца', value: '2months'},
|
||||||
|
{label: 'за 3 месяца', value: '3months'},
|
||||||
|
{label: 'указать даты', value: 'manual'},
|
||||||
|
*/
|
||||||
|
const sqlFormat = 'YYYY-MM-DD';
|
||||||
|
switch (date) {
|
||||||
|
case 'today': date = utils.dateFormat(moment(), sqlFormat); break;
|
||||||
|
case '3days': date = utils.dateFormat(moment().subtract(3, 'days'), sqlFormat); break;
|
||||||
|
case 'week': date = utils.dateFormat(moment().subtract(1, 'weeks'), sqlFormat); break;
|
||||||
|
case '2weeks': date = utils.dateFormat(moment().subtract(2, 'weeks'), sqlFormat); break;
|
||||||
|
case 'month': date = utils.dateFormat(moment().subtract(1, 'months'), sqlFormat); break;
|
||||||
|
case '2months': date = utils.dateFormat(moment().subtract(2, 'months'), sqlFormat); break;
|
||||||
|
case '3months': date = utils.dateFormat(moment().subtract(3, 'months'), sqlFormat); break;
|
||||||
|
default:
|
||||||
|
date = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
getQuery() {
|
||||||
|
let newQuery = _.cloneDeep(this.search);
|
||||||
|
newQuery = newQuery.setDefaults(newQuery);
|
||||||
|
delete newQuery.setDefaults;
|
||||||
|
|
||||||
|
//дата
|
||||||
|
if (newQuery.date) {
|
||||||
|
newQuery.date = this.queryDate(newQuery.date);
|
||||||
|
}
|
||||||
|
|
||||||
|
//offset
|
||||||
|
newQuery.offset = (newQuery.page - 1)*newQuery.limit;
|
||||||
|
|
||||||
|
//del
|
||||||
|
if (!this.showDeleted)
|
||||||
|
newQuery.del = 0;
|
||||||
|
|
||||||
|
return newQuery;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="row items-center q-my-sm">
|
<div class="row items-center q-my-sm no-wrap">
|
||||||
<div class="row items-center no-wrap">
|
<div class="row items-center">
|
||||||
<div v-if="showRate || showDeleted">
|
<div v-if="showRates || showDeleted">
|
||||||
<div v-if="showRate && !book.del">
|
<div v-if="showRates && !book.del">
|
||||||
<div v-if="book.librate">
|
<div v-if="book.librate">
|
||||||
<q-knob
|
<q-knob
|
||||||
:model-value="book.librate"
|
:model-value="book.librate"
|
||||||
@@ -31,30 +31,72 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="q-ml-sm clickable2" @click="selectTitle">
|
<!--div v-if="!titleList" class="q-ml-sm row items-center">
|
||||||
{{ book.serno ? `${book.serno}. ` : '' }}
|
{{ book.serno ? `${book.serno}. ` : '' }}
|
||||||
<span :class="titleColor">{{ bookTitle }}</span>
|
<div v-if="showAuthor && book.author">
|
||||||
|
<span class="clickable2 text-green-10" @click="selectAuthor">{{ bookAuthor }}</span>
|
||||||
|
-
|
||||||
|
<span class="clickable2" :class="titleColor" @click="selectTitle">{{ book.title }}</span>
|
||||||
|
</div>
|
||||||
|
<span v-else class="clickable2" :class="titleColor" @click="selectTitle">{{ book.title }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else class="q-ml-sm row items-center">
|
||||||
|
<span class="clickable2" :class="titleColor" @click="selectTitle">{{ book.title }}</span>
|
||||||
|
|
||||||
|
<div v-if="book.author || bookSeries" class="row">
|
||||||
|
-
|
||||||
|
<div v-if="book.author">
|
||||||
|
<span class="clickable2 text-green-10" @click="selectAuthor">{{ bookAuthor }}</span>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div v-if="bookSeries">
|
||||||
|
<span class="clickable2" @click="selectSeries">{{ bookSeries }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div-->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="q-ml-sm">
|
<div class="q-ml-sm column">
|
||||||
{{ bookSize }}, {{ book.ext }}
|
<div v-if="(mode == 'series' || mode == 'title') && bookAuthor" class="row items-center clickable2 text-green-10">
|
||||||
</div>
|
{{ bookAuthor }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="q-ml-sm clickable" @click="download">
|
<div class="row items-center">
|
||||||
(скачать)
|
<div v-if="book.serno" class="q-mr-xs">
|
||||||
</div>
|
{{ book.serno }}.
|
||||||
|
</div>
|
||||||
|
<div class="clickable2" :class="titleColor" @click="selectTitle">
|
||||||
|
{{ book.title }}
|
||||||
|
</div>
|
||||||
|
<div v-if="mode == 'title' && bookSeries" class="q-ml-xs clickable2" @click="selectSeries">
|
||||||
|
{{ bookSeries }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="q-ml-sm clickable" @click="copyLink">
|
|
||||||
<q-icon name="la la-copy" size="20px" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="showReadLink" class="q-ml-sm clickable" @click="readBook">
|
<div class="q-ml-sm">
|
||||||
(читать)
|
{{ bookSize }}, {{ book.ext }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="showGenres && book.genre" class="q-ml-sm">
|
<div class="q-ml-sm clickable" @click="download">
|
||||||
{{ bookGenre }}
|
(скачать)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="q-ml-sm clickable" @click="copyLink">
|
||||||
|
<q-icon name="la la-copy" size="20px" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="showReadLink" class="q-ml-sm clickable" @click="readBook">
|
||||||
|
(читать)
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="showGenres && book.genre" class="q-ml-sm">
|
||||||
|
{{ bookGenre }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="showDates && book.date" class="q-ml-sm">
|
||||||
|
{{ bookDate }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-show="false">
|
<div v-show="false">
|
||||||
@@ -67,6 +109,8 @@
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
import vueComponent from '../../vueComponent.js';
|
import vueComponent from '../../vueComponent.js';
|
||||||
|
|
||||||
|
import * as utils from '../../../share/utils';
|
||||||
|
|
||||||
const componentOptions = {
|
const componentOptions = {
|
||||||
components: {
|
components: {
|
||||||
},
|
},
|
||||||
@@ -80,15 +124,16 @@ class BookView {
|
|||||||
_options = componentOptions;
|
_options = componentOptions;
|
||||||
_props = {
|
_props = {
|
||||||
book: Object,
|
book: Object,
|
||||||
genreTree: Array,
|
mode: String,
|
||||||
showAuthor: Boolean,
|
genreMap: Object,
|
||||||
showReadLink: Boolean,
|
showReadLink: Boolean,
|
||||||
titleColor: { type: String, default: 'text-blue-10'},
|
titleColor: { type: String, default: 'text-blue-10'},
|
||||||
};
|
};
|
||||||
|
|
||||||
showRate = true;
|
showRates = true;
|
||||||
showGenres = true;
|
showGenres = true;
|
||||||
showDeleted = false;
|
showDeleted = false;
|
||||||
|
showDates = false;
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.loadSettings();
|
this.loadSettings();
|
||||||
@@ -97,8 +142,9 @@ class BookView {
|
|||||||
loadSettings() {
|
loadSettings() {
|
||||||
const settings = this.settings;
|
const settings = this.settings;
|
||||||
|
|
||||||
this.showRate = settings.showRate;
|
this.showRates = settings.showRates;
|
||||||
this.showGenres = settings.showGenres;
|
this.showGenres = settings.showGenres;
|
||||||
|
this.showDates = settings.showDates;
|
||||||
this.showDeleted = settings.showDeleted;
|
this.showDeleted = settings.showDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,15 +152,21 @@ class BookView {
|
|||||||
return this.$store.state.settings;
|
return this.$store.state.settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
get bookTitle() {
|
get bookAuthor() {
|
||||||
if (this.showAuthor && this.book.author) {
|
if (this.book.author) {
|
||||||
let a = this.book.author.split(',');
|
let a = this.book.author.split(',');
|
||||||
const author = a.slice(0, 2).join(', ') + (a.length > 2 ? ' и др.' : '');
|
return a.slice(0, 3).join(', ') + (a.length > 3 ? ' и др.' : '');
|
||||||
|
|
||||||
return `${author} - ${this.book.title}`;
|
|
||||||
} else {
|
|
||||||
return this.book.title;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
get bookSeries() {
|
||||||
|
if (this.book.series) {
|
||||||
|
return `(Серия: ${this.book.series})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
get bookSize() {
|
get bookSize() {
|
||||||
@@ -137,17 +189,32 @@ class BookView {
|
|||||||
|
|
||||||
get bookGenre() {
|
get bookGenre() {
|
||||||
let result = [];
|
let result = [];
|
||||||
const genre = new Set(this.book.genre.split(','));
|
const genre = this.book.genre.split(',');
|
||||||
|
|
||||||
for (const section of this.genreTree) {
|
for (const g of genre) {
|
||||||
for (const g of section.value)
|
const name = this.genreMap.get(g);
|
||||||
if (genre.has(g.value))
|
if (name)
|
||||||
result.push(g.name);
|
result.push(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return `(${result.join(' / ')})`;
|
return `(${result.join(' / ')})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get bookDate() {
|
||||||
|
if (!this.book.date)
|
||||||
|
return '';
|
||||||
|
|
||||||
|
return utils.sqlDateFormat(this.book.date);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectAuthor() {
|
||||||
|
this.$emit('bookEvent', {action: 'authorClick', book: this.book});
|
||||||
|
}
|
||||||
|
|
||||||
|
selectSeries() {
|
||||||
|
this.$emit('bookEvent', {action: 'seriesClick', book: this.book});
|
||||||
|
}
|
||||||
|
|
||||||
selectTitle() {
|
selectTitle() {
|
||||||
this.$emit('bookEvent', {action: 'titleClick', book: this.book});
|
this.$emit('bookEvent', {action: 'titleClick', book: this.book});
|
||||||
}
|
}
|
||||||
|
|||||||
33
client/components/Search/LoadingMessage/LoadingMessage.vue
Normal file
33
client/components/Search/LoadingMessage/LoadingMessage.vue
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<template>
|
||||||
|
<div v-show="message" class="fit row justify-center items-center" :style="`position: fixed; top: 0; left: 0; background-color: rgba(0, 0, 0, 0.2); z-index: ${zIndex}`">
|
||||||
|
<div class="bg-white row justify-center items-center q-px-lg" style="min-width: 180px; height: 50px; border-radius: 10px; box-shadow: 2px 2px 10px #333333">
|
||||||
|
<q-icon class="la la-spinner icon-rotate text-blue-8" size="28px" />
|
||||||
|
<div class="q-ml-sm">
|
||||||
|
{{ message }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
import vueComponent from '../../vueComponent.js';
|
||||||
|
|
||||||
|
const componentOptions = {
|
||||||
|
components: {
|
||||||
|
},
|
||||||
|
};
|
||||||
|
class LoadingMessage {
|
||||||
|
_options = componentOptions;
|
||||||
|
_props = {
|
||||||
|
message: String,
|
||||||
|
zIndex: {type: String, dafault: '100'},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default vueComponent(LoadingMessage);
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
</style>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<div class="q-mr-xs">
|
<div class="q-mr-xs">
|
||||||
Страница
|
Страница
|
||||||
</div>
|
</div>
|
||||||
<div class="bg-white">
|
<div class="trans" :class="{'bg-green-4': highlight, 'bg-white': !highlight}">
|
||||||
<NumInput
|
<NumInput
|
||||||
v-model="page" :min="1" :max="pageCount" mask="#######"
|
v-model="page" :min="1" :max="pageCount" mask="#######"
|
||||||
style="width: 220px" minus-icon="la la-chevron-circle-left" plus-icon="la la-chevron-circle-right" :disable="disable" mm-buttons
|
style="width: 220px" minus-icon="la la-chevron-circle-left" plus-icon="la la-chevron-circle-right" :disable="disable" mm-buttons
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
import vueComponent from '../../vueComponent.js';
|
import vueComponent from '../../vueComponent.js';
|
||||||
|
|
||||||
import NumInput from '../../share/NumInput.vue';
|
import NumInput from '../../share/NumInput.vue';
|
||||||
|
import * as utils from '../../../share/utils';
|
||||||
|
|
||||||
const componentOptions = {
|
const componentOptions = {
|
||||||
components: {
|
components: {
|
||||||
@@ -43,10 +44,23 @@ class PageScroller {
|
|||||||
};
|
};
|
||||||
|
|
||||||
page = 1;
|
page = 1;
|
||||||
|
highlight = false;
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async highlightScroller() {
|
||||||
|
if (this.inTrans)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.inTrans = true;
|
||||||
|
await utils.sleep(300);
|
||||||
|
this.highlight = true;
|
||||||
|
await utils.sleep(300);
|
||||||
|
this.highlight = false;
|
||||||
|
await utils.sleep(300);
|
||||||
|
this.inTrans = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default vueComponent(PageScroller);
|
export default vueComponent(PageScroller);
|
||||||
@@ -54,4 +68,8 @@ export default vueComponent(PageScroller);
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.trans {
|
||||||
|
border-radius: 5px;
|
||||||
|
transition: background-color 0.3s linear;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
File diff suppressed because it is too large
Load Diff
139
client/components/Search/SelectDateDialog/SelectDateDialog.vue
Normal file
139
client/components/Search/SelectDateDialog/SelectDateDialog.vue
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
<template>
|
||||||
|
<Dialog ref="dialog" v-model="dialogVisible">
|
||||||
|
<template #header>
|
||||||
|
<div class="row items-center">
|
||||||
|
<div style="font-size: 130%">
|
||||||
|
Выбрать даты
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div ref="box" class="column q-mt-xs overflow-auto no-wrap" style="width: 240px; padding: 0px 10px 10px 10px;">
|
||||||
|
<div class="row items-center">
|
||||||
|
<div class="row justify-end q-mr-sm" style="width: 15px">
|
||||||
|
С:
|
||||||
|
</div>
|
||||||
|
<q-btn icon="la la-calendar" color="secondary" :label="labelFrom" dense no-caps style="width: 150px;">
|
||||||
|
<q-popup-proxy cover transition-show="scale" transition-hide="scale">
|
||||||
|
<q-date v-model="from" mask="YYYY-MM-DD">
|
||||||
|
<div class="row items-center justify-end q-gutter-sm">
|
||||||
|
<q-btn v-close-popup label="Отмена" color="primary" flat />
|
||||||
|
<q-btn v-close-popup label="OK" color="primary" flat @click="save" />
|
||||||
|
</div>
|
||||||
|
</q-date>
|
||||||
|
</q-popup-proxy>
|
||||||
|
</q-btn>
|
||||||
|
<q-icon name="la la-times-circle" class="q-ml-sm text-grey-6 clickable2" size="28px" @click="from = ''; save();" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="q-my-sm" />
|
||||||
|
<div class="row items-center">
|
||||||
|
<div class="row justify-end q-mr-sm" style="width: 15px">
|
||||||
|
По:
|
||||||
|
</div>
|
||||||
|
<q-btn icon="la la-calendar" color="secondary" :label="labelTo" dense no-caps style="width: 150px;">
|
||||||
|
<q-popup-proxy cover transition-show="scale" transition-hide="scale">
|
||||||
|
<q-date v-model="to" mask="YYYY-MM-DD">
|
||||||
|
<div class="row items-center justify-end q-gutter-sm">
|
||||||
|
<q-btn v-close-popup label="Отмена" color="primary" flat />
|
||||||
|
<q-btn v-close-popup label="OK" color="primary" flat @click="save" />
|
||||||
|
</div>
|
||||||
|
</q-date>
|
||||||
|
</q-popup-proxy>
|
||||||
|
</q-btn>
|
||||||
|
<q-icon name="la la-times-circle" class="q-ml-sm text-grey-6 clickable2" size="28px" @click="to = ''; save();" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick">
|
||||||
|
OK
|
||||||
|
</q-btn>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
import vueComponent from '../../vueComponent.js';
|
||||||
|
|
||||||
|
import Dialog from '../../share/Dialog.vue';
|
||||||
|
import * as utils from '../../../share/utils';
|
||||||
|
|
||||||
|
const componentOptions = {
|
||||||
|
components: {
|
||||||
|
Dialog
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
modelValue(newValue) {
|
||||||
|
this.dialogVisible = newValue;
|
||||||
|
},
|
||||||
|
dialogVisible(newValue) {
|
||||||
|
this.$emit('update:modelValue', newValue);
|
||||||
|
},
|
||||||
|
date() {
|
||||||
|
this.updateFromTo();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
class SelectDateDialog {
|
||||||
|
_options = componentOptions;
|
||||||
|
_props = {
|
||||||
|
modelValue: Boolean,
|
||||||
|
date: String,
|
||||||
|
};
|
||||||
|
|
||||||
|
dialogVisible = false;
|
||||||
|
|
||||||
|
from = '';
|
||||||
|
to = '';
|
||||||
|
|
||||||
|
created() {
|
||||||
|
}
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.updateFromTo();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFromTo() {
|
||||||
|
this.from = this.splitDate.from;
|
||||||
|
this.to = this.splitDate.to;
|
||||||
|
}
|
||||||
|
|
||||||
|
get splitDate() {
|
||||||
|
if (!utils.isManualDate(this.date))
|
||||||
|
return {from: '', to: ''};
|
||||||
|
|
||||||
|
const [from = '', to = ''] = (this.date || '').split(',');
|
||||||
|
return {from, to};
|
||||||
|
}
|
||||||
|
|
||||||
|
get labelFrom() {
|
||||||
|
return (this.splitDate.from ? utils.sqlDateFormat(this.splitDate.from) : 'Не указано');
|
||||||
|
}
|
||||||
|
|
||||||
|
get labelTo() {
|
||||||
|
return (this.splitDate.to ? utils.sqlDateFormat(this.splitDate.to) : 'Не указано');
|
||||||
|
}
|
||||||
|
|
||||||
|
save() {
|
||||||
|
let d = this.from;
|
||||||
|
if (this.to)
|
||||||
|
d += `,${this.to}`;
|
||||||
|
this.$emit('update:date', d);
|
||||||
|
}
|
||||||
|
|
||||||
|
okClick() {
|
||||||
|
this.dialogVisible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default vueComponent(SelectDateDialog);
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.clickable2 {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<template #header>
|
<template #header>
|
||||||
<div class="row items-center">
|
<div class="row items-center">
|
||||||
<div style="font-size: 130%">
|
<div style="font-size: 130%">
|
||||||
Выбрать язык
|
Выбрать языки
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
<template>
|
||||||
|
<Dialog ref="dialog" v-model="dialogVisible">
|
||||||
|
<template #header>
|
||||||
|
<div class="row items-center">
|
||||||
|
<div style="font-size: 130%">
|
||||||
|
Выбрать оценки
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div ref="box" class="column q-mt-xs overflow-auto no-wrap" style="width: 200px; padding: 0px 10px 10px 10px;">
|
||||||
|
<q-option-group
|
||||||
|
v-model="ticked"
|
||||||
|
:options="options"
|
||||||
|
type="checkbox"
|
||||||
|
>
|
||||||
|
</q-option-group>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick">
|
||||||
|
OK
|
||||||
|
</q-btn>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
import vueComponent from '../../vueComponent.js';
|
||||||
|
|
||||||
|
import Dialog from '../../share/Dialog.vue';
|
||||||
|
|
||||||
|
const componentOptions = {
|
||||||
|
components: {
|
||||||
|
Dialog
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
modelValue(newValue) {
|
||||||
|
this.dialogVisible = newValue;
|
||||||
|
},
|
||||||
|
dialogVisible(newValue) {
|
||||||
|
this.$emit('update:modelValue', newValue);
|
||||||
|
},
|
||||||
|
librate() {
|
||||||
|
this.updateTicked();
|
||||||
|
},
|
||||||
|
ticked() {
|
||||||
|
this.updateLibrate();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
class SelectLibRateDialog {
|
||||||
|
_options = componentOptions;
|
||||||
|
_props = {
|
||||||
|
modelValue: Boolean,
|
||||||
|
librate: String,
|
||||||
|
};
|
||||||
|
|
||||||
|
dialogVisible = false;
|
||||||
|
|
||||||
|
ticked = [];
|
||||||
|
tickAll = false;
|
||||||
|
|
||||||
|
created() {
|
||||||
|
this.commit = this.$store.commit;
|
||||||
|
}
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.updateTicked();
|
||||||
|
}
|
||||||
|
|
||||||
|
get options() {
|
||||||
|
return [
|
||||||
|
{label: 'Без оценки', value: '0'},
|
||||||
|
{label: '1', value: '1'},
|
||||||
|
{label: '2', value: '2'},
|
||||||
|
{label: '3', value: '3'},
|
||||||
|
{label: '4', value: '4'},
|
||||||
|
{label: '5', value: '5'},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTicked() {
|
||||||
|
this.ticked = this.librate.split(',').filter(s => s);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateLibrate() {
|
||||||
|
this.ticked.sort((a, b) => a.localeCompare(b))
|
||||||
|
this.$emit('update:librate', this.ticked.join(','));
|
||||||
|
}
|
||||||
|
|
||||||
|
okClick() {
|
||||||
|
this.dialogVisible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default vueComponent(SelectLibRateDialog);
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
</style>
|
||||||
292
client/components/Search/SeriesList/SeriesList.vue
Normal file
292
client/components/Search/SeriesList/SeriesList.vue
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<a ref="download" style="display: none;"></a>
|
||||||
|
|
||||||
|
<LoadingMessage :message="loadingMessage" z-index="2" />
|
||||||
|
<LoadingMessage :message="loadingMessage2" z-index="1" />
|
||||||
|
|
||||||
|
<!-- Формирование списка ------------------------------------------------------------------------>
|
||||||
|
<div v-for="item in tableData" :key="item.key" class="column" :class="{'odd-item': item.num % 2}" style="font-size: 120%">
|
||||||
|
<div class="row items-center q-ml-md q-mr-xs no-wrap">
|
||||||
|
<div class="row items-center clickable2 q-py-xs no-wrap" @click="expandSeries(item)">
|
||||||
|
<div style="min-width: 30px">
|
||||||
|
<div v-if="!isExpandedSeries(item)">
|
||||||
|
<q-icon name="la la-plus-square" size="28px" />
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<q-icon name="la la-minus-square" size="28px" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="clickable2 q-ml-xs q-py-sm text-bold" @click="selectSeries(item.series)">
|
||||||
|
Серия: {{ item.series }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="q-ml-sm text-bold" style="color: #555">
|
||||||
|
{{ getBookCount(item) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="item.bookLoading" class="book-row row items-center">
|
||||||
|
<q-icon class="la la-spinner icon-rotate text-blue-8" size="28px" />
|
||||||
|
<div class="q-ml-xs">
|
||||||
|
Обработка...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isExpandedSeries(item) && item.books">
|
||||||
|
<div v-if="item.showAllBooks" class="book-row column">
|
||||||
|
<BookView
|
||||||
|
v-for="seriesBook in item.allBooks" :key="seriesBook.id"
|
||||||
|
:book="seriesBook"
|
||||||
|
mode="series"
|
||||||
|
:genre-map="genreMap" :show-read-link="showReadLink"
|
||||||
|
:title-color="isFoundSeriesBook(item, seriesBook) ? 'text-blue-10' : 'text-red'"
|
||||||
|
@book-event="bookEvent"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div v-else class="book-row column">
|
||||||
|
<BookView
|
||||||
|
v-for="seriesBook in item.books" :key="seriesBook.key"
|
||||||
|
:book="seriesBook" mode="series" :genre-map="genreMap" :show-read-link="showReadLink" @book-event="bookEvent"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--div v-if="!item.showAllBooks && isExpandedSeries(item) && item.books && !item.books.length" class="book-row row items-center">
|
||||||
|
<q-icon class="la la-meh q-mr-xs" size="24px" />
|
||||||
|
Возможно у этой серии были найдены книги, помеченные как удаленные, но подходящие по критериям
|
||||||
|
</div-->
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="item.allBooksLoaded && item.allBooksLoaded.length != item.booksLoaded.length"
|
||||||
|
class="row items-center q-my-sm"
|
||||||
|
style="margin-left: 100px"
|
||||||
|
>
|
||||||
|
<div v-if="item.showAllBooks && item.showMoreAll" class="row items-center q-mr-md">
|
||||||
|
<i class="las la-ellipsis-h text-red" style="font-size: 40px"></i>
|
||||||
|
<q-btn class="q-ml-md" color="red" style="width: 200px" dense rounded no-caps @click="showMoreAll(item)">
|
||||||
|
Показать еще (~{{ showMoreCount }})
|
||||||
|
</q-btn>
|
||||||
|
<q-btn class="q-ml-sm" color="red" style="width: 200px" dense rounded no-caps @click="showMoreAll(item, true)">
|
||||||
|
Показать все ({{ (item.allBooksLoaded && item.allBooksLoaded.length) || '?' }})
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="item.showAllBooks" class="row items-center clickable2 text-blue-10" @click="item.showAllBooks = false">
|
||||||
|
<q-icon class="la la-long-arrow-alt-up" size="28px" />
|
||||||
|
Только найденные книги
|
||||||
|
</div>
|
||||||
|
<div v-else class="row items-center clickable2 text-red" @click="item.showAllBooks = true">
|
||||||
|
<q-icon class="la la-long-arrow-alt-down" size="28px" />
|
||||||
|
Все книги серии
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="isExpandedSeries(item) && item.showMore" class="row items-center book-row q-mb-sm">
|
||||||
|
<i class="las la-ellipsis-h text-blue-10" style="font-size: 40px"></i>
|
||||||
|
<q-btn class="q-ml-md" color="primary" style="width: 200px" dense rounded no-caps @click="showMore(item)">
|
||||||
|
Показать еще (~{{ showMoreCount }})
|
||||||
|
</q-btn>
|
||||||
|
<q-btn class="q-ml-sm" color="primary" style="width: 200px" dense rounded no-caps @click="showMore(item, true)">
|
||||||
|
Показать все ({{ (item.booksLoaded && item.booksLoaded.length) || '?' }})
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- Формирование списка конец ------------------------------------------------------------------>
|
||||||
|
|
||||||
|
<div v-if="!refreshing && !tableData.length" class="row items-center q-ml-md" style="font-size: 120%">
|
||||||
|
<q-icon class="la la-meh q-mr-xs" size="28px" />
|
||||||
|
Поиск не дал результатов
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
import vueComponent from '../../vueComponent.js';
|
||||||
|
import { reactive } from 'vue';
|
||||||
|
|
||||||
|
import BaseList from '../BaseList';
|
||||||
|
|
||||||
|
import * as utils from '../../../share/utils';
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
class SeriesList extends BaseList {
|
||||||
|
get foundCountMessage() {
|
||||||
|
return `${this.list.totalFound} сери${utils.wordEnding(this.list.totalFound, 1)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
isFoundSeriesBook(seriesItem, seriesBook) {
|
||||||
|
if (!seriesItem.booksSet) {
|
||||||
|
seriesItem.booksSet = new Set(seriesItem.books.map(b => b.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return seriesItem.booksSet.has(seriesBook.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
getBookCount(item) {
|
||||||
|
let result = '';
|
||||||
|
if (!this.showCounts || item.count === undefined)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if (item.booksLoaded) {
|
||||||
|
result = `${item.booksLoaded.length}/${item.count}`;
|
||||||
|
} else
|
||||||
|
result = `#/${item.count}`;
|
||||||
|
|
||||||
|
return `(${result})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSeriesBooks(seriesItem) {
|
||||||
|
if (seriesItem.count > this.maxItemCount) {
|
||||||
|
seriesItem.bookLoading = true;
|
||||||
|
await this.$nextTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await super.getSeriesBooks(seriesItem);
|
||||||
|
|
||||||
|
if (seriesItem.allBooksLoaded) {
|
||||||
|
const prepareBook = (book) => {
|
||||||
|
return Object.assign(
|
||||||
|
{
|
||||||
|
key: book.id,
|
||||||
|
type: 'book',
|
||||||
|
},
|
||||||
|
book
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const filtered = this.filterBooks(seriesItem.allBooksLoaded);
|
||||||
|
|
||||||
|
const books = [];
|
||||||
|
for (const book of filtered) {
|
||||||
|
books.push(prepareBook(book));
|
||||||
|
}
|
||||||
|
|
||||||
|
seriesItem.booksLoaded = books;
|
||||||
|
this.showMore(seriesItem);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
seriesItem.bookLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateTableData() {
|
||||||
|
let result = [];
|
||||||
|
|
||||||
|
const expandedSet = new Set(this.expandedSeries);
|
||||||
|
const series = this.searchResult.found;
|
||||||
|
if (!series)
|
||||||
|
return;
|
||||||
|
|
||||||
|
let num = 0;
|
||||||
|
for (const rec of series) {
|
||||||
|
const count = (this.showDeleted ? rec.bookCount + rec.bookDelCount : rec.bookCount);
|
||||||
|
|
||||||
|
const item = reactive({
|
||||||
|
key: rec.series,
|
||||||
|
series: rec.series,
|
||||||
|
num,
|
||||||
|
count,
|
||||||
|
bookLoading: false,
|
||||||
|
|
||||||
|
allBooksLoaded: false,
|
||||||
|
allBooks: false,
|
||||||
|
showAllBooks: false,
|
||||||
|
showMoreAll: false,
|
||||||
|
|
||||||
|
booksLoaded: false,
|
||||||
|
books: false,
|
||||||
|
showMore: false,
|
||||||
|
});
|
||||||
|
num++;
|
||||||
|
|
||||||
|
if (expandedSet.has(item.series)) {
|
||||||
|
if (series.length > 1 || item.count > this.maxItemCount)
|
||||||
|
this.getSeriesBooks(item);//no await
|
||||||
|
else
|
||||||
|
await this.getSeriesBooks(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.length == 1 && !this.isExpandedSeries(result[0])) {
|
||||||
|
this.expandSeries(result[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tableData = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async refresh() {
|
||||||
|
//параметры запроса
|
||||||
|
const newQuery = this.getQuery();
|
||||||
|
if (_.isEqual(newQuery, this.prevQuery))
|
||||||
|
return;
|
||||||
|
this.prevQuery = newQuery;
|
||||||
|
|
||||||
|
this.queryExecute = newQuery;
|
||||||
|
|
||||||
|
if (this.refreshing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.refreshing = true;
|
||||||
|
|
||||||
|
(async() => {
|
||||||
|
await utils.sleep(500);
|
||||||
|
if (this.refreshing)
|
||||||
|
this.loadingMessage = 'Поиск серий...';
|
||||||
|
})();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (this.queryExecute) {
|
||||||
|
const query = this.queryExecute;
|
||||||
|
this.queryExecute = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await this.api.search('series', query);
|
||||||
|
|
||||||
|
this.list.queryFound = response.found.length;
|
||||||
|
this.list.totalFound = response.totalFound;
|
||||||
|
this.list.inpxHash = response.inpxHash;
|
||||||
|
|
||||||
|
this.searchResult = response;
|
||||||
|
|
||||||
|
await utils.sleep(1);
|
||||||
|
if (!this.queryExecute) {
|
||||||
|
await this.updateTableData();
|
||||||
|
this.scrollToTop();
|
||||||
|
this.highlightPageScroller(query);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.$root.stdDialog.alert(e.message, 'Ошибка');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.refreshing = false;
|
||||||
|
this.loadingMessage = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default vueComponent(SeriesList);
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.clickable2 {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.odd-item {
|
||||||
|
background-color: #e8e8e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-row {
|
||||||
|
margin-left: 50px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
149
client/components/Search/TitleList/TitleList.vue
Normal file
149
client/components/Search/TitleList/TitleList.vue
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<a ref="download" style="display: none;"></a>
|
||||||
|
|
||||||
|
<LoadingMessage :message="loadingMessage" z-index="2" />
|
||||||
|
<LoadingMessage :message="loadingMessage2" z-index="1" />
|
||||||
|
|
||||||
|
<!-- Формирование списка ------------------------------------------------------------------------>
|
||||||
|
<div v-for="item in tableData" :key="item.key" class="column" :class="{'odd-item': item.num % 2}" style="font-size: 120%">
|
||||||
|
<BookView
|
||||||
|
class="q-ml-md"
|
||||||
|
:book="item.book" mode="title" :genre-map="genreMap" :show-read-link="showReadLink" @book-event="bookEvent"
|
||||||
|
/>
|
||||||
|
<BookView
|
||||||
|
v-for="book in item.books" :key="book.id"
|
||||||
|
class="q-ml-md"
|
||||||
|
:book="book"
|
||||||
|
mode="title"
|
||||||
|
:genre-map="genreMap" :show-read-link="showReadLink"
|
||||||
|
@book-event="bookEvent"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<!-- Формирование списка конец ------------------------------------------------------------------>
|
||||||
|
|
||||||
|
<div v-if="!refreshing && !tableData.length" class="row items-center q-ml-md" style="font-size: 120%">
|
||||||
|
<q-icon class="la la-meh q-mr-xs" size="28px" />
|
||||||
|
Поиск не дал результатов
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
import vueComponent from '../../vueComponent.js';
|
||||||
|
import { reactive } from 'vue';
|
||||||
|
|
||||||
|
import BaseList from '../BaseList';
|
||||||
|
|
||||||
|
import * as utils from '../../../share/utils';
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
class TitleList extends BaseList {
|
||||||
|
get foundCountMessage() {
|
||||||
|
return `${this.list.totalFound} уникальн${utils.wordEnding(this.list.totalFound, 6)} назван${utils.wordEnding(this.list.totalFound, 3)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateTableData() {
|
||||||
|
let result = [];
|
||||||
|
|
||||||
|
const title = this.searchResult.found;
|
||||||
|
if (!title)
|
||||||
|
return;
|
||||||
|
|
||||||
|
let num = 0;
|
||||||
|
for (const rec of title) {
|
||||||
|
const item = reactive({
|
||||||
|
key: rec.id,
|
||||||
|
title: rec.title,
|
||||||
|
num,
|
||||||
|
|
||||||
|
book: false,
|
||||||
|
books: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (rec.books) {
|
||||||
|
const filtered = this.filterBooks(rec.books);
|
||||||
|
|
||||||
|
for (let i = 0; i < filtered.length; i++) {
|
||||||
|
if (i === 0)
|
||||||
|
item.book = filtered[i];
|
||||||
|
else
|
||||||
|
item.books.push(filtered[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filtered.length) {
|
||||||
|
num++;
|
||||||
|
result.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tableData = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async refresh() {
|
||||||
|
//параметры запроса
|
||||||
|
const newQuery = this.getQuery();
|
||||||
|
if (_.isEqual(newQuery, this.prevQuery))
|
||||||
|
return;
|
||||||
|
this.prevQuery = newQuery;
|
||||||
|
|
||||||
|
this.queryExecute = newQuery;
|
||||||
|
|
||||||
|
if (this.refreshing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.refreshing = true;
|
||||||
|
|
||||||
|
(async() => {
|
||||||
|
await utils.sleep(500);
|
||||||
|
if (this.refreshing)
|
||||||
|
this.loadingMessage = 'Поиск книг...';
|
||||||
|
})();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (this.queryExecute) {
|
||||||
|
const query = this.queryExecute;
|
||||||
|
this.queryExecute = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await this.api.search('title', query);
|
||||||
|
|
||||||
|
this.list.queryFound = response.found.length;
|
||||||
|
this.list.totalFound = response.totalFound;
|
||||||
|
this.list.inpxHash = response.inpxHash;
|
||||||
|
|
||||||
|
this.searchResult = response;
|
||||||
|
|
||||||
|
await utils.sleep(1);
|
||||||
|
if (!this.queryExecute) {
|
||||||
|
await this.updateTableData();
|
||||||
|
this.scrollToTop();
|
||||||
|
this.highlightPageScroller(query);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.$root.stdDialog.alert(e.message, 'Ошибка');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.refreshing = false;
|
||||||
|
this.loadingMessage = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default vueComponent(TitleList);
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.clickable2 {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.odd-item {
|
||||||
|
background-color: #e8e8e8;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
94
client/components/fonts/OFL.txt
Normal file
94
client/components/fonts/OFL.txt
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
Copyright (c) 2010, ParaType Ltd. (http://www.paratype.com/public),
|
||||||
|
with Reserved Font Names "PT Sans" and "ParaType".
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||||
|
This license is copied below, and is also available with a FAQ at:
|
||||||
|
http://scripts.sil.org/OFL
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||||
|
development of collaborative font projects, to support the font creation
|
||||||
|
efforts of academic and linguistic communities, and to provide a free and
|
||||||
|
open framework in which fonts may be shared and improved in partnership
|
||||||
|
with others.
|
||||||
|
|
||||||
|
The OFL allows the licensed fonts to be used, studied, modified and
|
||||||
|
redistributed freely as long as they are not sold by themselves. The
|
||||||
|
fonts, including any derivative works, can be bundled, embedded,
|
||||||
|
redistributed and/or sold with any software provided that any reserved
|
||||||
|
names are not used by derivative works. The fonts and derivatives,
|
||||||
|
however, cannot be released under any other type of license. The
|
||||||
|
requirement for fonts to remain under this license does not apply
|
||||||
|
to any document created using the fonts or their derivatives.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright
|
||||||
|
Holder(s) under this license and clearly marked as such. This may
|
||||||
|
include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Reserved Font Name" refers to any names specified as such after the
|
||||||
|
copyright statement(s).
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components as
|
||||||
|
distributed by the Copyright Holder(s).
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||||
|
or substituting -- in part or in whole -- any of the components of the
|
||||||
|
Original Version, by changing formats or by porting the Font Software to a
|
||||||
|
new environment.
|
||||||
|
|
||||||
|
"Author" refers to any designer, engineer, programmer, technical
|
||||||
|
writer or other person who contributed to the Font Software.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||||
|
redistribute, and sell modified and unmodified copies of the Font
|
||||||
|
Software, subject to the following conditions:
|
||||||
|
|
||||||
|
1) Neither the Font Software nor any of its individual components,
|
||||||
|
in Original or Modified Versions, may be sold by itself.
|
||||||
|
|
||||||
|
2) Original or Modified Versions of the Font Software may be bundled,
|
||||||
|
redistributed and/or sold with any software, provided that each copy
|
||||||
|
contains the above copyright notice and this license. These can be
|
||||||
|
included either as stand-alone text files, human-readable headers or
|
||||||
|
in the appropriate machine-readable metadata fields within text or
|
||||||
|
binary files as long as those fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
3) No Modified Version of the Font Software may use the Reserved Font
|
||||||
|
Name(s) unless explicit written permission is granted by the corresponding
|
||||||
|
Copyright Holder. This restriction only applies to the primary font name as
|
||||||
|
presented to the users.
|
||||||
|
|
||||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||||
|
Software shall not be used to promote, endorse or advertise any
|
||||||
|
Modified Version, except to acknowledge the contribution(s) of the
|
||||||
|
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
5) The Font Software, modified or unmodified, in part or in whole,
|
||||||
|
must be distributed entirely under this license, and must not be
|
||||||
|
distributed under any other license. The requirement for fonts to
|
||||||
|
remain under this license does not apply to any document created
|
||||||
|
using the Font Software.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This license becomes null and void if any of the above conditions are
|
||||||
|
not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||||
|
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||||
BIN
client/components/fonts/web-default-bold.ttf
Normal file
BIN
client/components/fonts/web-default-bold.ttf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,6 +4,7 @@
|
|||||||
<i :class="icon" :style="`font-size: ${iconSize}px; margin-top: ${imt}px`" />
|
<i :class="icon" :style="`font-size: ${iconSize}px; margin-top: ${imt}px`" />
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
|
<slot name="tooltip"></slot>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export default function(componentClass) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (prop === '_props') {
|
} else if (prop === '_props') {
|
||||||
comp['props'] = obj[prop];
|
comp.props = obj[prop];
|
||||||
}
|
}
|
||||||
} else {//usual prop
|
} else {//usual prop
|
||||||
data[prop] = obj[prop];
|
data[prop] = obj[prop];
|
||||||
@@ -26,23 +26,32 @@ export default function(componentClass) {
|
|||||||
comp.data = () => _.cloneDeep(data);
|
comp.data = () => _.cloneDeep(data);
|
||||||
|
|
||||||
//methods
|
//methods
|
||||||
const classProto = Object.getPrototypeOf(obj);
|
|
||||||
const classMethods = Object.getOwnPropertyNames(classProto);
|
|
||||||
const methods = {};
|
const methods = {};
|
||||||
const computed = {};
|
const computed = {};
|
||||||
for (const method of classMethods) {
|
|
||||||
const desc = Object.getOwnPropertyDescriptor(classProto, method);
|
let classProto = Object.getPrototypeOf(obj);
|
||||||
if (desc.get) {//has getter, computed
|
while (classProto) {
|
||||||
computed[method] = {get: desc.get};
|
const classMethods = Object.getOwnPropertyNames(classProto);
|
||||||
if (desc.set)
|
for (const method of classMethods) {
|
||||||
computed[method].set = desc.set;
|
const desc = Object.getOwnPropertyDescriptor(classProto, method);
|
||||||
} else if ( ['beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'activated',//life cycle hooks
|
if (desc.get) {//has getter, computed
|
||||||
'deactivated', 'beforeUnmount', 'unmounted', 'errorCaptured', 'renderTracked', 'renderTriggered',//life cycle hooks
|
if (!computed[method]) {
|
||||||
'setup'].includes(method) ) {
|
computed[method] = {get: desc.get};
|
||||||
comp[method] = obj[method];
|
if (desc.set)
|
||||||
} else if (method !== 'constructor') {//usual
|
computed[method].set = desc.set;
|
||||||
methods[method] = obj[method];
|
}
|
||||||
|
} else if ( ['beforeCreate', 'created', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'activated',
|
||||||
|
'deactivated', 'beforeUnmount', 'unmounted', 'errorCaptured', 'renderTracked', 'renderTriggered',
|
||||||
|
'setup'].includes(method) ) {//life cycle hooks
|
||||||
|
if (!comp[method])
|
||||||
|
comp[method] = obj[method];
|
||||||
|
} else if (method !== 'constructor') {//usual
|
||||||
|
if (!methods[method])
|
||||||
|
methods[method] = obj[method];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
classProto = Object.getPrototypeOf(classProto);
|
||||||
}
|
}
|
||||||
comp.methods = methods;
|
comp.methods = methods;
|
||||||
comp.computed = computed;
|
comp.computed = computed;
|
||||||
|
|||||||
@@ -14,21 +14,22 @@ import {QLinearProgress} from 'quasar/src/components/linear-progress';
|
|||||||
import {QInput} from 'quasar/src/components/input';
|
import {QInput} from 'quasar/src/components/input';
|
||||||
import {QBtn} from 'quasar/src/components/btn';
|
import {QBtn} from 'quasar/src/components/btn';
|
||||||
//import {QBtnGroup} from 'quasar/src/components/btn-group';
|
//import {QBtnGroup} from 'quasar/src/components/btn-group';
|
||||||
//import {QBtnToggle} from 'quasar/src/components/btn-toggle';
|
import {QBtnToggle} from 'quasar/src/components/btn-toggle';
|
||||||
import {QIcon} from 'quasar/src/components/icon';
|
import {QIcon} from 'quasar/src/components/icon';
|
||||||
//import {QSlider} from 'quasar/src/components/slider';
|
//import {QSlider} from 'quasar/src/components/slider';
|
||||||
//import {QTabs, QTab} from 'quasar/src/components/tabs';
|
//import {QTabs, QTab} from 'quasar/src/components/tabs';
|
||||||
//import {QTabPanels, QTabPanel} from 'quasar/src/components/tab-panels';
|
//import {QTabPanels, QTabPanel} from 'quasar/src/components/tab-panels';
|
||||||
//import {QSeparator} from 'quasar/src/components/separator';
|
//import {QSeparator} from 'quasar/src/components/separator';
|
||||||
//import {QList} from 'quasar/src/components/item';
|
//import {QList} from 'quasar/src/components/item';
|
||||||
//import {QItem, QItemSection, QItemLabel} from 'quasar/src/components/item';
|
import {QItem, QItemSection, QItemLabel} from 'quasar/src/components/item';
|
||||||
import {QTooltip} from 'quasar/src/components/tooltip';
|
import {QTooltip} from 'quasar/src/components/tooltip';
|
||||||
//import {QSpinner} from 'quasar/src/components/spinner';
|
//import {QSpinner} from 'quasar/src/components/spinner';
|
||||||
//import {QTable, QTh, QTr, QTd} from 'quasar/src/components/table';
|
//import {QTable, QTh, QTr, QTd} from 'quasar/src/components/table';
|
||||||
import {QCheckbox} from 'quasar/src/components/checkbox';
|
import {QCheckbox} from 'quasar/src/components/checkbox';
|
||||||
import {QSelect} from 'quasar/src/components/select';
|
import {QSelect} from 'quasar/src/components/select';
|
||||||
//import {QColor} from 'quasar/src/components/color';
|
//import {QColor} from 'quasar/src/components/color';
|
||||||
//import {QPopupProxy} from 'quasar/src/components/popup-proxy';
|
import {QPopupProxy} from 'quasar/src/components/popup-proxy';
|
||||||
|
import {QDate} from 'quasar/src/components/date';
|
||||||
import {QDialog} from 'quasar/src/components/dialog';
|
import {QDialog} from 'quasar/src/components/dialog';
|
||||||
//import {QChip} from 'quasar/src/components/chip';
|
//import {QChip} from 'quasar/src/components/chip';
|
||||||
import {QTree} from 'quasar/src/components/tree';
|
import {QTree} from 'quasar/src/components/tree';
|
||||||
@@ -48,21 +49,22 @@ const components = {
|
|||||||
QInput,
|
QInput,
|
||||||
QBtn,
|
QBtn,
|
||||||
//QBtnGroup,
|
//QBtnGroup,
|
||||||
//QBtnToggle,
|
QBtnToggle,
|
||||||
QIcon,
|
QIcon,
|
||||||
//QSlider,
|
//QSlider,
|
||||||
//QTabs, QTab,
|
//QTabs, QTab,
|
||||||
//QTabPanels, QTabPanel,
|
//QTabPanels, QTabPanel,
|
||||||
//QSeparator,
|
//QSeparator,
|
||||||
//QList,
|
//QList,
|
||||||
//QItem, QItemSection, QItemLabel,
|
QItem, QItemSection, QItemLabel,
|
||||||
QTooltip,
|
QTooltip,
|
||||||
//QSpinner,
|
//QSpinner,
|
||||||
//QTable, QTh, QTr, QTd,
|
//QTable, QTh, QTr, QTd,
|
||||||
QCheckbox,
|
QCheckbox,
|
||||||
QSelect,
|
QSelect,
|
||||||
//QColor,
|
//QColor,
|
||||||
//QPopupProxy,
|
QPopupProxy,
|
||||||
|
QDate,
|
||||||
QDialog,
|
QDialog,
|
||||||
//QChip,
|
//QChip,
|
||||||
QTree,
|
QTree,
|
||||||
@@ -91,12 +93,13 @@ const plugins = {
|
|||||||
//import '@quasar/extras/fontawesome-v5/fontawesome-v5.css';
|
//import '@quasar/extras/fontawesome-v5/fontawesome-v5.css';
|
||||||
//import fontawesomeV5 from 'quasar/icon-set/fontawesome-v5.js'
|
//import fontawesomeV5 from 'quasar/icon-set/fontawesome-v5.js'
|
||||||
|
|
||||||
|
import lang from 'quasar/lang/ru';
|
||||||
import '@quasar/extras/line-awesome/line-awesome.css';
|
import '@quasar/extras/line-awesome/line-awesome.css';
|
||||||
import lineAwesome from 'quasar/icon-set/line-awesome.js'
|
import lineAwesome from 'quasar/icon-set/line-awesome.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
quasar: Quasar,
|
quasar: Quasar,
|
||||||
options: { config, components, directives, plugins },
|
options: { config, components, directives, plugins, lang },
|
||||||
init: () => {
|
init: () => {
|
||||||
Quasar.iconSet.set(lineAwesome);
|
Quasar.iconSet.set(lineAwesome);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ const Search = () => import('./components/Search/Search.vue');
|
|||||||
|
|
||||||
const myRoutes = [
|
const myRoutes = [
|
||||||
['/', Search],
|
['/', Search],
|
||||||
|
['/author', Search],
|
||||||
|
['/series', Search],
|
||||||
|
['/title', Search],
|
||||||
['/:pathMatch(.*)*', null, null, '/'],
|
['/:pathMatch(.*)*', null, null, '/'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import moment from 'moment';
|
||||||
import {Buffer} from 'safe-buffer';
|
import {Buffer} from 'safe-buffer';
|
||||||
//import _ from 'lodash';
|
//import _ from 'lodash';
|
||||||
|
|
||||||
@@ -38,7 +39,11 @@ export function wordEnding(num, type = 0) {
|
|||||||
['ов', '', 'а', 'а', 'а', 'ов', 'ов', 'ов', 'ов', 'ов'],
|
['ов', '', 'а', 'а', 'а', 'ов', 'ов', 'ов', 'ов', 'ов'],
|
||||||
['й', 'я', 'и', 'и', 'и', 'й', 'й', 'й', 'й', 'й'],
|
['й', 'я', 'и', 'и', 'и', 'й', 'й', 'й', 'й', 'й'],
|
||||||
['о', '', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о'],
|
['о', '', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о'],
|
||||||
['ий', 'ие', 'ия', 'ия', 'ия', 'ий', 'ий', 'ий', 'ий', 'ий']
|
['ий', 'ие', 'ия', 'ия', 'ия', 'ий', 'ий', 'ий', 'ий', 'ий'],
|
||||||
|
['о', 'а', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о'],
|
||||||
|
['ок', 'ка', 'ки', 'ки', 'ки', 'ок', 'ок', 'ок', 'ок', 'ок'],
|
||||||
|
['ых', 'ое', 'ых', 'ых', 'ых', 'ых', 'ых', 'ых', 'ых', 'ых'],
|
||||||
|
['о', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о'],
|
||||||
];
|
];
|
||||||
const deci = num % 100;
|
const deci = num % 100;
|
||||||
if (deci > 10 && deci < 20) {
|
if (deci > 10 && deci < 20) {
|
||||||
@@ -94,3 +99,48 @@ export function makeValidFilename(filename, repl = '_') {
|
|||||||
else
|
else
|
||||||
throw new Error('Invalid filename');
|
throw new Error('Invalid filename');
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
export function formatDate(d, format = 'normal') {
|
||||||
|
switch (format) {
|
||||||
|
case 'normal':
|
||||||
|
return `${d.getDate().toString().padStart(2, '0')}.${(d.getMonth() + 1).toString().padStart(2, '0')}.${d.getFullYear()} ` +
|
||||||
|
`${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}`;
|
||||||
|
case 'coDate':
|
||||||
|
return `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')}`;
|
||||||
|
case 'coMonth':
|
||||||
|
return `${(d.getMonth() + 1).toString().padStart(2, '0')}`;
|
||||||
|
case 'noDate':
|
||||||
|
return `${d.getDate().toString().padStart(2, '0')}.${(d.getMonth() + 1).toString().padStart(2, '0')}.${d.getFullYear()}`;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error('formatDate: unknown date format');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseDate(sqlDate) {
|
||||||
|
const d = sqlDate.split('-');
|
||||||
|
const result = new Date();
|
||||||
|
result.setDate(parseInt(d[2], 10));
|
||||||
|
result.setMonth(parseInt(d[1], 10) - 1);
|
||||||
|
result.setYear(parseInt(d[0], 10));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function isDigit(c) {
|
||||||
|
return !isNaN(parseInt(c, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function dateFormat(date, format = 'DD.MM.YYYY') {
|
||||||
|
return moment(date).format(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sqlDateFormat(date, format = 'DD.MM.YYYY') {
|
||||||
|
return moment(date, 'YYYY-MM-DD').format(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isManualDate(date) {
|
||||||
|
return date && (date[0] == ',' || (isDigit(date[0]) && isDigit(date[1])));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ const state = {
|
|||||||
config: {},
|
config: {},
|
||||||
settings: {
|
settings: {
|
||||||
accessToken: '',
|
accessToken: '',
|
||||||
|
extendedParams: false,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
expanded: [],
|
expandedAuthor: [],
|
||||||
expandedSeries: [],
|
expandedSeries: [],
|
||||||
showCounts: true,
|
showCounts: true,
|
||||||
showRate: true,
|
showRates: true,
|
||||||
showGenres: true,
|
showGenres: true,
|
||||||
|
showDates: false,
|
||||||
showDeleted: false,
|
showDeleted: false,
|
||||||
abCacheEnabled: true,
|
abCacheEnabled: true,
|
||||||
langDefault: '',
|
langDefault: '',
|
||||||
|
|||||||
147
package-lock.json
generated
147
package-lock.json
generated
@@ -1,24 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "inpx-web",
|
"name": "inpx-web",
|
||||||
"version": "1.0.6",
|
"version": "1.1.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "inpx-web",
|
"name": "inpx-web",
|
||||||
"version": "1.0.6",
|
"version": "1.1.0",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "CC0-1.0",
|
"license": "CC0-1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@quasar/extras": "^1.15.0",
|
"@quasar/extras": "^1.15.0",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"compression": "^1.7.4",
|
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"jembadb": "^4.2.0",
|
"jembadb": "^5.0.2",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"minimist": "^1.2.6",
|
"minimist": "^1.2.6",
|
||||||
|
"moment": "^2.29.4",
|
||||||
"node-stream-zip": "^1.15.0",
|
"node-stream-zip": "^1.15.0",
|
||||||
"quasar": "^2.7.5",
|
"quasar": "^2.7.5",
|
||||||
"safe-buffer": "^5.2.1",
|
"safe-buffer": "^5.2.1",
|
||||||
@@ -2736,14 +2736,6 @@
|
|||||||
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/bytes": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/call-bind": {
|
"node_modules/call-bind": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
||||||
@@ -2954,52 +2946,6 @@
|
|||||||
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==",
|
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/compressible": {
|
|
||||||
"version": "2.0.18",
|
|
||||||
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
|
|
||||||
"integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
|
|
||||||
"dependencies": {
|
|
||||||
"mime-db": ">= 1.43.0 < 2"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/compression": {
|
|
||||||
"version": "1.7.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz",
|
|
||||||
"integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"accepts": "~1.3.5",
|
|
||||||
"bytes": "3.0.0",
|
|
||||||
"compressible": "~2.0.16",
|
|
||||||
"debug": "2.6.9",
|
|
||||||
"on-headers": "~1.0.2",
|
|
||||||
"safe-buffer": "5.1.2",
|
|
||||||
"vary": "~1.1.2"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/compression/node_modules/debug": {
|
|
||||||
"version": "2.6.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
|
||||||
"dependencies": {
|
|
||||||
"ms": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/compression/node_modules/ms": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
|
||||||
},
|
|
||||||
"node_modules/compression/node_modules/safe-buffer": {
|
|
||||||
"version": "5.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
|
||||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
|
||||||
},
|
|
||||||
"node_modules/concat-map": {
|
"node_modules/concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
@@ -5077,9 +5023,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/jembadb": {
|
"node_modules/jembadb": {
|
||||||
"version": "4.2.0",
|
"version": "5.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-5.0.2.tgz",
|
||||||
"integrity": "sha512-wnqUwaZSWU99hJYHPBhXJVRYHA1aQVjpt5fDHMuXaz7VWZqK9DhLgNDIKD9z8czICz56ECTR2xlVBpDgBnuQVA==",
|
"integrity": "sha512-0309Qo4wSkyf154xTokxNl0DuBP5f2Q2MzWGUNX1JmMzlRypFsPY/9VDYV/htkxhT53f2prlQ2NUguQjG2lCRA==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.16.0"
|
"node": ">=16.16.0"
|
||||||
}
|
}
|
||||||
@@ -5555,6 +5501,14 @@
|
|||||||
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
|
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/moment": {
|
||||||
|
"version": "2.29.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
||||||
|
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
@@ -5811,14 +5765,6 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/on-headers": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
|
||||||
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/once": {
|
"node_modules/once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
@@ -10832,11 +10778,6 @@
|
|||||||
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"bytes": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw=="
|
|
||||||
},
|
|
||||||
"call-bind": {
|
"call-bind": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
||||||
@@ -11006,48 +10947,6 @@
|
|||||||
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==",
|
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"compressible": {
|
|
||||||
"version": "2.0.18",
|
|
||||||
"resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz",
|
|
||||||
"integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==",
|
|
||||||
"requires": {
|
|
||||||
"mime-db": ">= 1.43.0 < 2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compression": {
|
|
||||||
"version": "1.7.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz",
|
|
||||||
"integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==",
|
|
||||||
"requires": {
|
|
||||||
"accepts": "~1.3.5",
|
|
||||||
"bytes": "3.0.0",
|
|
||||||
"compressible": "~2.0.16",
|
|
||||||
"debug": "2.6.9",
|
|
||||||
"on-headers": "~1.0.2",
|
|
||||||
"safe-buffer": "5.1.2",
|
|
||||||
"vary": "~1.1.2"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"debug": {
|
|
||||||
"version": "2.6.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
|
||||||
"requires": {
|
|
||||||
"ms": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ms": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
|
||||||
},
|
|
||||||
"safe-buffer": {
|
|
||||||
"version": "5.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
|
||||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
@@ -12578,9 +12477,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"jembadb": {
|
"jembadb": {
|
||||||
"version": "4.2.0",
|
"version": "5.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-5.0.2.tgz",
|
||||||
"integrity": "sha512-wnqUwaZSWU99hJYHPBhXJVRYHA1aQVjpt5fDHMuXaz7VWZqK9DhLgNDIKD9z8czICz56ECTR2xlVBpDgBnuQVA=="
|
"integrity": "sha512-0309Qo4wSkyf154xTokxNl0DuBP5f2Q2MzWGUNX1JmMzlRypFsPY/9VDYV/htkxhT53f2prlQ2NUguQjG2lCRA=="
|
||||||
},
|
},
|
||||||
"jest-worker": {
|
"jest-worker": {
|
||||||
"version": "27.5.1",
|
"version": "27.5.1",
|
||||||
@@ -12938,6 +12837,11 @@
|
|||||||
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
|
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"moment": {
|
||||||
|
"version": "2.29.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
||||||
|
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w=="
|
||||||
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||||
@@ -13118,11 +13022,6 @@
|
|||||||
"ee-first": "1.1.1"
|
"ee-first": "1.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"on-headers": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
|
||||||
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA=="
|
|
||||||
},
|
|
||||||
"once": {
|
"once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "inpx-web",
|
"name": "inpx-web",
|
||||||
"version": "1.0.6",
|
"version": "1.1.0",
|
||||||
"author": "Book Pauk <bookpauk@gmail.com>",
|
"author": "Book Pauk <bookpauk@gmail.com>",
|
||||||
"license": "CC0-1.0",
|
"license": "CC0-1.0",
|
||||||
"repository": "bookpauk/inpx-web",
|
"repository": "bookpauk/inpx-web",
|
||||||
@@ -51,13 +51,13 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@quasar/extras": "^1.15.0",
|
"@quasar/extras": "^1.15.0",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"compression": "^1.7.4",
|
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"jembadb": "^4.2.0",
|
"jembadb": "^5.0.2",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"minimist": "^1.2.6",
|
"minimist": "^1.2.6",
|
||||||
|
"moment": "^2.29.4",
|
||||||
"node-stream-zip": "^1.15.0",
|
"node-stream-zip": "^1.15.0",
|
||||||
"quasar": "^2.7.5",
|
"quasar": "^2.7.5",
|
||||||
"safe-buffer": "^5.2.1",
|
"safe-buffer": "^5.2.1",
|
||||||
|
|||||||
@@ -14,14 +14,20 @@ module.exports = {
|
|||||||
bookReadLink: '',
|
bookReadLink: '',
|
||||||
loggingEnabled: true,
|
loggingEnabled: true,
|
||||||
|
|
||||||
|
//поправить в случае, если были критические изменения в DbCreator
|
||||||
|
//иначе будет рассинхронизация между сервером и клиентом на уровне БД
|
||||||
|
dbVersion: '5',
|
||||||
|
dbCacheSize: 5,
|
||||||
|
|
||||||
maxPayloadSize: 500,//in MB
|
maxPayloadSize: 500,//in MB
|
||||||
maxFilesDirSize: 1024*1024*1024,//1Gb
|
maxFilesDirSize: 1024*1024*1024,//1Gb
|
||||||
queryCacheEnabled: true,
|
queryCacheEnabled: true,
|
||||||
cacheCleanInterval: 60,//minutes
|
cacheCleanInterval: 60,//minutes
|
||||||
inpxCheckInterval: 60,//minutes
|
inpxCheckInterval: 60,//minutes
|
||||||
lowMemoryMode: false,
|
lowMemoryMode: false,
|
||||||
|
fullOptimization: false,
|
||||||
|
|
||||||
webConfigParams: ['name', 'version', 'branch', 'bookReadLink'],
|
webConfigParams: ['name', 'version', 'branch', 'bookReadLink', 'dbVersion'],
|
||||||
|
|
||||||
allowRemoteLib: false,
|
allowRemoteLib: false,
|
||||||
remoteLib: false,
|
remoteLib: false,
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ const propsToSave = [
|
|||||||
'accessPassword',
|
'accessPassword',
|
||||||
'bookReadLink',
|
'bookReadLink',
|
||||||
'loggingEnabled',
|
'loggingEnabled',
|
||||||
|
'dbCacheSize',
|
||||||
'maxFilesDirSize',
|
'maxFilesDirSize',
|
||||||
'queryCacheEnabled',
|
'queryCacheEnabled',
|
||||||
'cacheCleanInterval',
|
'cacheCleanInterval',
|
||||||
'inpxCheckInterval',
|
'inpxCheckInterval',
|
||||||
'lowMemoryMode',
|
'lowMemoryMode',
|
||||||
|
'fullOptimization',
|
||||||
'allowRemoteLib',
|
'allowRemoteLib',
|
||||||
'remoteLib',
|
'remoteLib',
|
||||||
'server',
|
'server',
|
||||||
@@ -82,15 +84,28 @@ class ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
if (!this.inited)
|
try {
|
||||||
throw new Error('not inited');
|
if (!this.inited)
|
||||||
if (!await fs.pathExists(this.userConfigFile)) {
|
throw new Error('not inited');
|
||||||
await this.save();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await fs.readFile(this.userConfigFile, 'utf8');
|
if (await fs.pathExists(this.userConfigFile)) {
|
||||||
this.config = JSON.parse(data);
|
const data = JSON.parse(await fs.readFile(this.userConfigFile, 'utf8'));
|
||||||
|
const config = _.pick(data, propsToSave);
|
||||||
|
|
||||||
|
this.config = config;
|
||||||
|
|
||||||
|
//сохраним конфиг, если не все атрибуты присутствуют в файле конфига
|
||||||
|
for (const prop of propsToSave)
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(config, prop)) {
|
||||||
|
await this.save();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await this.save();
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
throw new Error(`Error while loading "${this.userConfigFile}": ${e.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ class WebSocketController {
|
|||||||
await this.getWorkerState(req, ws); break;
|
await this.getWorkerState(req, ws); break;
|
||||||
case 'search':
|
case 'search':
|
||||||
await this.search(req, ws); break;
|
await this.search(req, ws); break;
|
||||||
case 'get-book-list':
|
case 'get-author-book-list':
|
||||||
await this.getBookList(req, ws); break;
|
await this.getAuthorBookList(req, ws); break;
|
||||||
case 'get-series-book-list':
|
case 'get-series-book-list':
|
||||||
await this.getSeriesBookList(req, ws); break;
|
await this.getSeriesBookList(req, ws); break;
|
||||||
case 'get-genre-tree':
|
case 'get-genre-tree':
|
||||||
@@ -107,7 +107,7 @@ class WebSocketController {
|
|||||||
ws.send(message);
|
ws.send(message);
|
||||||
|
|
||||||
if (this.isDevelopment) {
|
if (this.isDevelopment) {
|
||||||
log(`WebSocket-OUT: ${message.substr(0, 4000)}`);
|
log(`WebSocket-OUT: ${message.substr(0, 200)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -136,25 +136,21 @@ class WebSocketController {
|
|||||||
async search(req, ws) {
|
async search(req, ws) {
|
||||||
if (!req.query)
|
if (!req.query)
|
||||||
throw new Error(`query is empty`);
|
throw new Error(`query is empty`);
|
||||||
|
if (!req.from)
|
||||||
|
throw new Error(`from is empty`);
|
||||||
|
|
||||||
const result = await this.webWorker.search(req.query);
|
const result = await this.webWorker.search(req.from, req.query);
|
||||||
|
|
||||||
this.send(result, req, ws);
|
this.send(result, req, ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBookList(req, ws) {
|
async getAuthorBookList(req, ws) {
|
||||||
if (!utils.hasProp(req, 'authorId'))
|
const result = await this.webWorker.getAuthorBookList(req.authorId);
|
||||||
throw new Error(`authorId is empty`);
|
|
||||||
|
|
||||||
const result = await this.webWorker.getBookList(req.authorId);
|
|
||||||
|
|
||||||
this.send(result, req, ws);
|
this.send(result, req, ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSeriesBookList(req, ws) {
|
async getSeriesBookList(req, ws) {
|
||||||
if (!utils.hasProp(req, 'series'))
|
|
||||||
throw new Error(`series is empty`);
|
|
||||||
|
|
||||||
const result = await this.webWorker.getSeriesBookList(req.series);
|
const result = await this.webWorker.getSeriesBookList(req.series);
|
||||||
|
|
||||||
this.send(result, req, ws);
|
this.send(result, req, ws);
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ class AppLogger {
|
|||||||
{log: 'FileLog', fileName: this.errLogFileName, exclude: [LM_OK, LM_INFO, LM_TOTAL]},
|
{log: 'FileLog', fileName: this.errLogFileName, exclude: [LM_OK, LM_INFO, LM_TOTAL]},
|
||||||
{log: 'FileLog', fileName: this.fatalLogFileName, exclude: [LM_OK, LM_INFO, LM_WARN, LM_ERR, LM_TOTAL]},//LM_FATAL only
|
{log: 'FileLog', fileName: this.fatalLogFileName, exclude: [LM_OK, LM_INFO, LM_WARN, LM_ERR, LM_TOTAL]},//LM_FATAL only
|
||||||
];
|
];
|
||||||
|
} else {
|
||||||
|
loggerParams = [
|
||||||
|
{log: 'ConsoleLog'},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
this._logger = new Logger(loggerParams);
|
this._logger = new Logger(loggerParams);
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ class DbCreator {
|
|||||||
let genreArr = [];
|
let genreArr = [];
|
||||||
let langMap = new Map();//языки
|
let langMap = new Map();//языки
|
||||||
let langArr = [];
|
let langArr = [];
|
||||||
|
let delMap = new Map();//удаленные
|
||||||
|
let delArr = [];
|
||||||
|
let dateMap = new Map();//дата поступления
|
||||||
|
let dateArr = [];
|
||||||
|
let librateMap = new Map();//оценка
|
||||||
|
let librateArr = [];
|
||||||
|
|
||||||
//stats
|
//stats
|
||||||
let authorCount = 0;
|
let authorCount = 0;
|
||||||
@@ -132,6 +138,84 @@ class DbCreator {
|
|||||||
callback({progress: (readState.current || 0)/totalFiles});
|
callback({progress: (readState.current || 0)/totalFiles});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parseField = (fieldValue, fieldMap, fieldArr, bookId, rec, fillBookIds = true) => {
|
||||||
|
let value = fieldValue;
|
||||||
|
|
||||||
|
if (typeof(fieldValue) == 'string') {
|
||||||
|
if (!fieldValue)
|
||||||
|
fieldValue = emptyFieldValue;
|
||||||
|
|
||||||
|
value = fieldValue.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
let fieldRec;
|
||||||
|
if (fieldMap.has(value)) {
|
||||||
|
const fieldId = fieldMap.get(value);
|
||||||
|
fieldRec = fieldArr[fieldId];
|
||||||
|
} else {
|
||||||
|
fieldRec = {id: fieldArr.length, value, bookIds: new Set()};
|
||||||
|
if (rec !== undefined) {
|
||||||
|
fieldRec.name = fieldValue;
|
||||||
|
fieldRec.bookCount = 0;
|
||||||
|
fieldRec.bookDelCount = 0;
|
||||||
|
}
|
||||||
|
fieldArr.push(fieldRec);
|
||||||
|
fieldMap.set(value, fieldRec.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldValue !== emptyFieldValue || fillBookIds)
|
||||||
|
fieldRec.bookIds.add(bookId);
|
||||||
|
|
||||||
|
if (rec !== undefined) {
|
||||||
|
if (!rec.del)
|
||||||
|
fieldRec.bookCount++;
|
||||||
|
else
|
||||||
|
fieldRec.bookDelCount++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const parseBookRec = (rec) => {
|
||||||
|
//авторы
|
||||||
|
const author = splitAuthor(rec.author);
|
||||||
|
|
||||||
|
for (let i = 0; i < author.length; i++) {
|
||||||
|
const a = author[i];
|
||||||
|
|
||||||
|
//статистика
|
||||||
|
if (!authorMap.has(a.toLowerCase()) && (author.length == 1 || i < author.length - 1)) //без соавторов
|
||||||
|
authorCount++;
|
||||||
|
|
||||||
|
parseField(a, authorMap, authorArr, rec.id, rec);
|
||||||
|
}
|
||||||
|
|
||||||
|
//серии
|
||||||
|
parseField(rec.series, seriesMap, seriesArr, rec.id, rec, false);
|
||||||
|
|
||||||
|
//названия
|
||||||
|
parseField(rec.title, titleMap, titleArr, rec.id, rec);
|
||||||
|
|
||||||
|
//жанры
|
||||||
|
let genre = rec.genre || emptyFieldValue;
|
||||||
|
genre = rec.genre.split(',');
|
||||||
|
|
||||||
|
for (let g of genre) {
|
||||||
|
parseField(g, genreMap, genreArr, rec.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//языки
|
||||||
|
parseField(rec.lang, langMap, langArr, rec.id);
|
||||||
|
|
||||||
|
//удаленные
|
||||||
|
parseField(rec.del, delMap, delArr, rec.id);
|
||||||
|
|
||||||
|
//дата поступления
|
||||||
|
parseField(rec.date, dateMap, dateArr, rec.id);
|
||||||
|
|
||||||
|
//оценка
|
||||||
|
parseField(rec.librate, librateMap, librateArr, rec.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
//основная процедура парсинга
|
||||||
let id = 0;
|
let id = 0;
|
||||||
const parsedCallback = async(chunk) => {
|
const parsedCallback = async(chunk) => {
|
||||||
let filtered = false;
|
let filtered = false;
|
||||||
@@ -153,40 +237,7 @@ class DbCreator {
|
|||||||
bookDelCount++;
|
bookDelCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//авторы
|
parseBookRec(rec);
|
||||||
const author = splitAuthor(rec.author);
|
|
||||||
|
|
||||||
for (let i = 0; i < author.length; i++) {
|
|
||||||
const a = author[i];
|
|
||||||
const value = a.toLowerCase();
|
|
||||||
|
|
||||||
let authorRec;
|
|
||||||
if (authorMap.has(value)) {
|
|
||||||
const authorTmpId = authorMap.get(value);
|
|
||||||
authorRec = authorArr[authorTmpId];
|
|
||||||
} else {
|
|
||||||
authorRec = {tmpId: authorArr.length, author: a, value, bookCount: 0, bookDelCount: 0, bookId: []};
|
|
||||||
authorArr.push(authorRec);
|
|
||||||
authorMap.set(value, authorRec.tmpId);
|
|
||||||
|
|
||||||
if (author.length == 1 || i < author.length - 1) //без соавторов
|
|
||||||
authorCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//это нужно для того, чтобы имя автора начиналось с заглавной
|
|
||||||
if (a[0].toUpperCase() === a[0])
|
|
||||||
authorRec.author = a;
|
|
||||||
|
|
||||||
//счетчики
|
|
||||||
if (!rec.del) {
|
|
||||||
authorRec.bookCount++;
|
|
||||||
} else {
|
|
||||||
authorRec.bookDelCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ссылки на книги
|
|
||||||
authorRec.bookId.push(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let saveChunk = [];
|
let saveChunk = [];
|
||||||
@@ -205,248 +256,66 @@ class DbCreator {
|
|||||||
utils.freeMemory();
|
utils.freeMemory();
|
||||||
};
|
};
|
||||||
|
|
||||||
//парсинг 1
|
//парсинг
|
||||||
const parser = new InpxParser();
|
const parser = new InpxParser();
|
||||||
await parser.parse(config.inpxFile, readFileCallback, parsedCallback);
|
await parser.parse(config.inpxFile, readFileCallback, parsedCallback);
|
||||||
|
|
||||||
utils.freeMemory();
|
|
||||||
|
|
||||||
//отсортируем авторов и выдадим им правильные id
|
|
||||||
//порядок id соответствует ASC-сортировке по author.toLowerCase
|
|
||||||
callback({job: 'author sort', jobMessage: 'Сортировка авторов', jobStep: 2, progress: 0});
|
|
||||||
await utils.sleep(100);
|
|
||||||
authorArr.sort((a, b) => a.value.localeCompare(b.value));
|
|
||||||
|
|
||||||
id = 0;
|
|
||||||
authorMap = new Map();
|
|
||||||
for (const authorRec of authorArr) {
|
|
||||||
authorRec.id = ++id;
|
|
||||||
authorMap.set(authorRec.author, id);
|
|
||||||
delete authorRec.tmpId;
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.freeMemory();
|
|
||||||
|
|
||||||
//подготовка к сохранению author_book
|
|
||||||
const saveBookChunk = async(authorChunk, callback) => {
|
|
||||||
callback(0);
|
|
||||||
|
|
||||||
const ids = [];
|
|
||||||
for (const a of authorChunk) {
|
|
||||||
for (const id of a.bookId) {
|
|
||||||
ids.push(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ids.sort();// обязательно, иначе будет тормозить - особенности JembaDb
|
|
||||||
|
|
||||||
callback(0.1);
|
|
||||||
const rows = await db.select({table: 'book', where: `@@id(${db.esc(ids)})`});
|
|
||||||
callback(0.6);
|
|
||||||
await utils.sleep(100);
|
|
||||||
|
|
||||||
const bookArr = new Map();
|
|
||||||
for (const row of rows)
|
|
||||||
bookArr.set(row.id, row);
|
|
||||||
|
|
||||||
const abRows = [];
|
|
||||||
for (const a of authorChunk) {
|
|
||||||
const aBooks = [];
|
|
||||||
for (const id of a.bookId) {
|
|
||||||
const rec = bookArr.get(id);
|
|
||||||
aBooks.push(rec);
|
|
||||||
}
|
|
||||||
|
|
||||||
abRows.push({id: a.id, author: a.author, books: JSON.stringify(aBooks)});
|
|
||||||
|
|
||||||
delete a.bookId;//в дальнейшем не понадобится, authorArr сохраняем без него
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(0.7);
|
|
||||||
await db.insert({
|
|
||||||
table: 'author_book',
|
|
||||||
rows: abRows,
|
|
||||||
});
|
|
||||||
callback(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
callback({job: 'book sort', jobMessage: 'Сортировка книг', jobStep: 3, progress: 0});
|
|
||||||
|
|
||||||
//сохранение author_book
|
|
||||||
await db.create({
|
|
||||||
table: 'author_book',
|
|
||||||
});
|
|
||||||
|
|
||||||
let idsLen = 0;
|
|
||||||
let aChunk = [];
|
|
||||||
let prevI = 0;
|
|
||||||
for (let i = 0; i < authorArr.length; i++) {// eslint-disable-line
|
|
||||||
const author = authorArr[i];
|
|
||||||
|
|
||||||
aChunk.push(author);
|
|
||||||
idsLen += author.bookId.length;
|
|
||||||
|
|
||||||
if (idsLen > 50000) {//константа выяснена эмпирическим путем "память/скорость"
|
|
||||||
await saveBookChunk(aChunk, (p) => {
|
|
||||||
callback({progress: (prevI + (i - prevI)*p)/authorArr.length});
|
|
||||||
});
|
|
||||||
|
|
||||||
prevI = i;
|
|
||||||
idsLen = 0;
|
|
||||||
aChunk = [];
|
|
||||||
await utils.sleep(100);
|
|
||||||
utils.freeMemory();
|
|
||||||
await db.freeMemory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (aChunk.length) {
|
|
||||||
await saveBookChunk(aChunk, () => {});
|
|
||||||
aChunk = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback({progress: 1});
|
|
||||||
|
|
||||||
//чистка памяти, ибо жрет как не в себя
|
|
||||||
await db.close({table: 'book'});
|
|
||||||
await db.freeMemory();
|
|
||||||
utils.freeMemory();
|
|
||||||
|
|
||||||
//парсинг 2, подготовка
|
|
||||||
const parseField = (fieldValue, fieldMap, fieldArr, authorIds, bookId) => {
|
|
||||||
let addBookId = bookId;
|
|
||||||
if (!fieldValue) {
|
|
||||||
fieldValue = emptyFieldValue;
|
|
||||||
addBookId = 0;//!!!
|
|
||||||
}
|
|
||||||
|
|
||||||
const value = fieldValue.toLowerCase();
|
|
||||||
|
|
||||||
let fieldRec;
|
|
||||||
if (fieldMap.has(value)) {
|
|
||||||
const fieldId = fieldMap.get(value);
|
|
||||||
fieldRec = fieldArr[fieldId];
|
|
||||||
} else {
|
|
||||||
fieldRec = {id: fieldArr.length, value, authorId: new Set()};
|
|
||||||
if (bookId)
|
|
||||||
fieldRec.bookId = new Set();
|
|
||||||
fieldArr.push(fieldRec);
|
|
||||||
fieldMap.set(value, fieldRec.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const id of authorIds) {
|
|
||||||
fieldRec.authorId.add(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addBookId)
|
|
||||||
fieldRec.bookId.add(addBookId);
|
|
||||||
};
|
|
||||||
|
|
||||||
const parseBookRec = (rec) => {
|
|
||||||
//авторы
|
|
||||||
const author = splitAuthor(rec.author);
|
|
||||||
|
|
||||||
const authorIds = [];
|
|
||||||
for (const a of author) {
|
|
||||||
const authorId = authorMap.get(a);
|
|
||||||
if (!authorId) //подстраховка
|
|
||||||
continue;
|
|
||||||
authorIds.push(authorId);
|
|
||||||
}
|
|
||||||
|
|
||||||
//серии
|
|
||||||
parseField(rec.series, seriesMap, seriesArr, authorIds, rec.id);
|
|
||||||
|
|
||||||
//названия
|
|
||||||
parseField(rec.title, titleMap, titleArr, authorIds);
|
|
||||||
|
|
||||||
//жанры
|
|
||||||
let genre = rec.genre || emptyFieldValue;
|
|
||||||
genre = rec.genre.split(',');
|
|
||||||
|
|
||||||
for (let g of genre) {
|
|
||||||
if (!g)
|
|
||||||
g = emptyFieldValue;
|
|
||||||
|
|
||||||
let genreRec;
|
|
||||||
if (genreMap.has(g)) {
|
|
||||||
const genreId = genreMap.get(g);
|
|
||||||
genreRec = genreArr[genreId];
|
|
||||||
} else {
|
|
||||||
genreRec = {id: genreArr.length, value: g, authorId: new Set()};
|
|
||||||
genreArr.push(genreRec);
|
|
||||||
genreMap.set(g, genreRec.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const id of authorIds) {
|
|
||||||
genreRec.authorId.add(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//языки
|
|
||||||
parseField(rec.lang, langMap, langArr, authorIds);
|
|
||||||
};
|
|
||||||
|
|
||||||
callback({job: 'search tables create', jobMessage: 'Создание поисковых таблиц', jobStep: 4, progress: 0});
|
|
||||||
|
|
||||||
//парсинг 2, теперь можно создавать остальные поисковые таблицы
|
|
||||||
let proc = 0;
|
|
||||||
while (1) {// eslint-disable-line
|
|
||||||
const rows = await db.select({
|
|
||||||
table: 'author_book',
|
|
||||||
where: `
|
|
||||||
let iter = @getItem('parse_book');
|
|
||||||
if (!iter) {
|
|
||||||
iter = @all();
|
|
||||||
@setItem('parse_book', iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
const ids = new Set();
|
|
||||||
let id = iter.next();
|
|
||||||
while (!id.done) {
|
|
||||||
ids.add(id.value);
|
|
||||||
if (ids.size >= 10000)
|
|
||||||
break;
|
|
||||||
id = iter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ids;
|
|
||||||
`
|
|
||||||
});
|
|
||||||
|
|
||||||
if (rows.length) {
|
|
||||||
for (const row of rows) {
|
|
||||||
const books = JSON.parse(row.books);
|
|
||||||
for (const rec of books)
|
|
||||||
parseBookRec(rec);
|
|
||||||
}
|
|
||||||
|
|
||||||
proc += rows.length;
|
|
||||||
callback({progress: proc/authorArr.length});
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
|
|
||||||
await utils.sleep(100);
|
|
||||||
if (config.lowMemoryMode) {
|
|
||||||
utils.freeMemory();
|
|
||||||
await db.freeMemory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//чистка памяти, ибо жрет как не в себя
|
//чистка памяти, ибо жрет как не в себя
|
||||||
authorMap = null;
|
authorMap = null;
|
||||||
seriesMap = null;
|
seriesMap = null;
|
||||||
titleMap = null;
|
titleMap = null;
|
||||||
genreMap = null;
|
genreMap = null;
|
||||||
|
langMap = null;
|
||||||
|
delMap = null;
|
||||||
|
dateMap = null;
|
||||||
|
librateMap = null;
|
||||||
|
|
||||||
|
await db.close({table: 'book'});
|
||||||
|
await db.freeMemory();
|
||||||
utils.freeMemory();
|
utils.freeMemory();
|
||||||
|
|
||||||
//config
|
//отсортируем таблицы выдадим им правильные id
|
||||||
callback({job: 'config save', jobMessage: 'Сохранение конфигурации', jobStep: 5, progress: 0});
|
//порядок id соответствует ASC-сортировке по value
|
||||||
await db.create({
|
callback({job: 'sort', jobMessage: 'Сортировка', jobStep: 2, progress: 0});
|
||||||
table: 'config'
|
await utils.sleep(100);
|
||||||
});
|
//сортировка авторов
|
||||||
|
authorArr.sort((a, b) => a.value.localeCompare(b.value));
|
||||||
|
callback({progress: 0.2});
|
||||||
|
await utils.sleep(100);
|
||||||
|
|
||||||
|
id = 0;
|
||||||
|
for (const authorRec of authorArr) {
|
||||||
|
authorRec.id = ++id;
|
||||||
|
}
|
||||||
|
callback({progress: 0.3});
|
||||||
|
await utils.sleep(100);
|
||||||
|
|
||||||
|
//сортировка серий
|
||||||
|
seriesArr.sort((a, b) => a.value.localeCompare(b.value));
|
||||||
|
callback({progress: 0.5});
|
||||||
|
await utils.sleep(100);
|
||||||
|
|
||||||
|
id = 0;
|
||||||
|
for (const seriesRec of seriesArr) {
|
||||||
|
seriesRec.id = ++id;
|
||||||
|
}
|
||||||
|
callback({progress: 0.6});
|
||||||
|
await utils.sleep(100);
|
||||||
|
|
||||||
|
//сортировка названий
|
||||||
|
titleArr.sort((a, b) => a.value.localeCompare(b.value));
|
||||||
|
callback({progress: 0.8});
|
||||||
|
await utils.sleep(100);
|
||||||
|
id = 0;
|
||||||
|
for (const titleRec of titleArr) {
|
||||||
|
titleRec.id = ++id;
|
||||||
|
}
|
||||||
|
|
||||||
|
//stats
|
||||||
const stats = {
|
const stats = {
|
||||||
|
filesCount: 0,//вычислим позднее
|
||||||
|
filesCountAll: 0,//вычислим позднее
|
||||||
|
filesDelCount: 0,//вычислим позднее
|
||||||
recsLoaded,
|
recsLoaded,
|
||||||
authorCount,
|
authorCount,
|
||||||
authorCountAll: authorArr.length,
|
authorCountAll: authorArr.length,
|
||||||
@@ -461,45 +330,33 @@ class DbCreator {
|
|||||||
};
|
};
|
||||||
//console.log(stats);
|
//console.log(stats);
|
||||||
|
|
||||||
const inpxHashCreator = new InpxHashCreator(config);
|
|
||||||
|
|
||||||
await db.insert({table: 'config', rows: [
|
|
||||||
{id: 'inpxInfo', value: (inpxFilter && inpxFilter.info ? inpxFilter.info : parser.info)},
|
|
||||||
{id: 'stats', value: stats},
|
|
||||||
{id: 'inpxHash', value: await inpxHashCreator.getHash()},
|
|
||||||
]});
|
|
||||||
|
|
||||||
//сохраним поисковые таблицы
|
//сохраним поисковые таблицы
|
||||||
const chunkSize = 10000;
|
const chunkSize = 10000;
|
||||||
|
|
||||||
const saveTable = async(table, arr, nullArr, authorIdToArray = false, bookIdToArray = false) => {
|
const saveTable = async(table, arr, nullArr, indexType = 'string') => {
|
||||||
|
|
||||||
arr.sort((a, b) => a.value.localeCompare(b.value));
|
if (indexType == 'string')
|
||||||
|
arr.sort((a, b) => a.value.localeCompare(b.value));
|
||||||
|
else
|
||||||
|
arr.sort((a, b) => a.value - b.value);
|
||||||
|
|
||||||
await db.create({
|
await db.create({
|
||||||
table,
|
table,
|
||||||
index: {field: 'value', unique: true, depth: 1000000},
|
index: {field: 'value', unique: true, type: indexType, depth: 1000000},
|
||||||
});
|
});
|
||||||
|
|
||||||
//вставка в БД по кусочкам, экономим память
|
//вставка в БД по кусочкам, экономим память
|
||||||
for (let i = 0; i < arr.length; i += chunkSize) {
|
for (let i = 0; i < arr.length; i += chunkSize) {
|
||||||
const chunk = arr.slice(i, i + chunkSize);
|
const chunk = arr.slice(i, i + chunkSize);
|
||||||
|
|
||||||
if (authorIdToArray) {
|
for (const rec of chunk)
|
||||||
for (const rec of chunk)
|
rec.bookIds = Array.from(rec.bookIds);
|
||||||
rec.authorId = Array.from(rec.authorId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bookIdToArray) {
|
|
||||||
for (const rec of chunk)
|
|
||||||
rec.bookId = Array.from(rec.bookId);
|
|
||||||
}
|
|
||||||
|
|
||||||
await db.insert({table, rows: chunk});
|
await db.insert({table, rows: chunk});
|
||||||
|
|
||||||
if (i % 5 == 0) {
|
if (i % 5 == 0) {
|
||||||
await db.freeMemory();
|
await db.freeMemory();
|
||||||
await utils.sleep(100);
|
await utils.sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback({progress: i/arr.length});
|
callback({progress: i/arr.length});
|
||||||
@@ -512,24 +369,33 @@ class DbCreator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//author
|
//author
|
||||||
callback({job: 'author save', jobMessage: 'Сохранение индекса авторов', jobStep: 6, progress: 0});
|
callback({job: 'author save', jobMessage: 'Сохранение индекса авторов', jobStep: 3, progress: 0});
|
||||||
await saveTable('author', authorArr, () => {authorArr = null});
|
await saveTable('author', authorArr, () => {authorArr = null});
|
||||||
|
|
||||||
//series
|
//series
|
||||||
callback({job: 'series save', jobMessage: 'Сохранение индекса серий', jobStep: 7, progress: 0});
|
callback({job: 'series save', jobMessage: 'Сохранение индекса серий', jobStep: 4, progress: 0});
|
||||||
await saveTable('series_temporary', seriesArr, () => {seriesArr = null}, true, true);
|
await saveTable('series', seriesArr, () => {seriesArr = null});
|
||||||
|
|
||||||
//title
|
//title
|
||||||
callback({job: 'title save', jobMessage: 'Сохранение индекса названий', jobStep: 8, progress: 0});
|
callback({job: 'title save', jobMessage: 'Сохранение индекса названий', jobStep: 5, progress: 0});
|
||||||
await saveTable('title', titleArr, () => {titleArr = null}, true);
|
await saveTable('title', titleArr, () => {titleArr = null});
|
||||||
|
|
||||||
//genre
|
//genre
|
||||||
callback({job: 'genre save', jobMessage: 'Сохранение индекса жанров', jobStep: 9, progress: 0});
|
callback({job: 'genre save', jobMessage: 'Сохранение индекса жанров', jobStep: 6, progress: 0});
|
||||||
await saveTable('genre', genreArr, () => {genreArr = null}, true);
|
await saveTable('genre', genreArr, () => {genreArr = null});
|
||||||
|
|
||||||
|
callback({job: 'others save', jobMessage: 'Сохранение остальных индексов', jobStep: 7, progress: 0});
|
||||||
//lang
|
//lang
|
||||||
callback({job: 'lang save', jobMessage: 'Сохранение индекса языков', jobStep: 10, progress: 0});
|
await saveTable('lang', langArr, () => {langArr = null});
|
||||||
await saveTable('lang', langArr, () => {langArr = null}, true);
|
|
||||||
|
//del
|
||||||
|
await saveTable('del', delArr, () => {delArr = null}, 'number');
|
||||||
|
|
||||||
|
//date
|
||||||
|
await saveTable('date', dateArr, () => {dateArr = null});
|
||||||
|
|
||||||
|
//librate
|
||||||
|
await saveTable('librate', librateArr, () => {librateArr = null}, 'number');
|
||||||
|
|
||||||
//кэш-таблицы запросов
|
//кэш-таблицы запросов
|
||||||
await db.create({table: 'query_cache'});
|
await db.create({table: 'query_cache'});
|
||||||
@@ -539,92 +405,226 @@ class DbCreator {
|
|||||||
await db.create({table: 'file_hash'});
|
await db.create({table: 'file_hash'});
|
||||||
|
|
||||||
//-- завершающие шаги --------------------------------
|
//-- завершающие шаги --------------------------------
|
||||||
//оптимизация series, превращаем массив bookId в books
|
|
||||||
callback({job: 'series optimization', jobMessage: 'Оптимизация', jobStep: 11, progress: 0});
|
|
||||||
|
|
||||||
await db.open({
|
await db.open({
|
||||||
table: 'book',
|
table: 'book',
|
||||||
cacheSize: (config.lowMemoryMode ? 5 : 500),
|
cacheSize: (config.lowMemoryMode ? 5 : 500),
|
||||||
});
|
});
|
||||||
await db.open({table: 'series_temporary'});
|
|
||||||
await db.create({
|
callback({job: 'optimization', jobMessage: 'Оптимизация', jobStep: 8, progress: 0});
|
||||||
table: 'series',
|
await this.optimizeTable('author', db, (p) => {
|
||||||
index: {field: 'value', unique: true, depth: 1000000},
|
if (p.progress)
|
||||||
|
p.progress = 0.3*p.progress;
|
||||||
|
callback(p);
|
||||||
|
});
|
||||||
|
await this.optimizeTable('series', db, (p) => {
|
||||||
|
if (p.progress)
|
||||||
|
p.progress = 0.3 + 0.2*p.progress;
|
||||||
|
callback(p);
|
||||||
|
});
|
||||||
|
await this.optimizeTable('title', db, (p) => {
|
||||||
|
if (p.progress)
|
||||||
|
p.progress = 0.5 + 0.5*p.progress;
|
||||||
|
callback(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
const count = await db.select({table: 'series_temporary', count: true});
|
callback({job: 'stats count', jobMessage: 'Подсчет статистики', jobStep: 9, progress: 0});
|
||||||
const seriesCount = (count.length ? count[0].count : 0);
|
await this.countStats(db, callback, stats);
|
||||||
|
|
||||||
const saveSeriesChunk = async(seriesChunk) => {
|
//чистка памяти, ибо жрет как не в себя
|
||||||
|
await db.close({table: 'book'});
|
||||||
|
await db.freeMemory();
|
||||||
|
utils.freeMemory();
|
||||||
|
|
||||||
|
//config сохраняем в самом конце, нет конфига - с базой что-то не так
|
||||||
|
const inpxHashCreator = new InpxHashCreator(config);
|
||||||
|
|
||||||
|
await db.create({
|
||||||
|
table: 'config'
|
||||||
|
});
|
||||||
|
|
||||||
|
await db.insert({table: 'config', rows: [
|
||||||
|
{id: 'inpxInfo', value: (inpxFilter && inpxFilter.info ? inpxFilter.info : parser.info)},
|
||||||
|
{id: 'stats', value: stats},
|
||||||
|
{id: 'inpxHash', value: await inpxHashCreator.getHash()},
|
||||||
|
]});
|
||||||
|
|
||||||
|
callback({job: 'done', jobMessage: ''});
|
||||||
|
}
|
||||||
|
|
||||||
|
async optimizeTable(from, db, callback) {
|
||||||
|
const config = this.config;
|
||||||
|
|
||||||
|
const to = `${from}_book`;
|
||||||
|
const toId = `${from}_id`;
|
||||||
|
|
||||||
|
await db.open({table: from});
|
||||||
|
await db.create({table: to});
|
||||||
|
|
||||||
|
let bookId2RecId = new Map();
|
||||||
|
|
||||||
|
const saveChunk = async(chunk) => {
|
||||||
const ids = [];
|
const ids = [];
|
||||||
for (const s of seriesChunk) {
|
for (const rec of chunk) {
|
||||||
for (const id of s.bookId) {
|
for (const id of rec.bookIds) {
|
||||||
|
let b2r = bookId2RecId.get(id);
|
||||||
|
if (!b2r) {
|
||||||
|
b2r = [];
|
||||||
|
bookId2RecId.set(id, b2r);
|
||||||
|
}
|
||||||
|
b2r.push(rec.id);
|
||||||
|
|
||||||
ids.push(id);
|
ids.push(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ids.sort();// обязательно, иначе будет тормозить - особенности JembaDb
|
if (config.fullOptimization) {
|
||||||
|
ids.sort((a, b) => a - b);// обязательно, иначе будет тормозить - особенности JembaDb
|
||||||
|
|
||||||
const rows = await db.select({table: 'book', where: `@@id(${db.esc(ids)})`});
|
const rows = await db.select({table: 'book', where: `@@id(${db.esc(ids)})`});
|
||||||
|
|
||||||
const bookArr = new Map();
|
const bookArr = new Map();
|
||||||
for (const row of rows)
|
for (const row of rows)
|
||||||
bookArr.set(row.id, row);
|
bookArr.set(row.id, row);
|
||||||
|
|
||||||
for (const s of seriesChunk) {
|
for (const rec of chunk) {
|
||||||
const sBooks = [];
|
rec.books = [];
|
||||||
for (const id of s.bookId) {
|
|
||||||
const rec = bookArr.get(id);
|
for (const id of rec.bookIds) {
|
||||||
sBooks.push(rec);
|
const book = bookArr.get(id);
|
||||||
|
if (book) {//на всякий случай
|
||||||
|
rec.books.push(book);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete rec.name;
|
||||||
|
delete rec.value;
|
||||||
|
delete rec.bookIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
s.books = JSON.stringify(sBooks);
|
await db.insert({
|
||||||
delete s.bookId;
|
table: to,
|
||||||
|
rows: chunk,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.insert({
|
|
||||||
table: 'series',
|
|
||||||
rows: seriesChunk,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const rows = await db.select({table: 'series_temporary'});
|
const rows = await db.select({table: from, count: true});
|
||||||
|
const fromLength = rows[0].count;
|
||||||
|
|
||||||
idsLen = 0;
|
let processed = 0;
|
||||||
aChunk = [];
|
while (1) {// eslint-disable-line
|
||||||
proc = 0;
|
const chunk = await db.select({
|
||||||
for (const row of rows) {// eslint-disable-line
|
table: from,
|
||||||
aChunk.push(row);
|
where: `
|
||||||
idsLen += row.bookId.length;
|
let iter = @getItem('optimize');
|
||||||
proc++;
|
if (!iter) {
|
||||||
|
iter = @all();
|
||||||
|
@setItem('optimize', iter);
|
||||||
|
}
|
||||||
|
|
||||||
if (idsLen > 20000) {//константа выяснена эмпирическим путем "память/скорость"
|
const ids = new Set();
|
||||||
await saveSeriesChunk(aChunk);
|
let bookIdsLen = 0;
|
||||||
|
let id = iter.next();
|
||||||
|
while (!id.done) {
|
||||||
|
ids.add(id.value);
|
||||||
|
|
||||||
idsLen = 0;
|
const row = @row(id.value);
|
||||||
aChunk = [];
|
bookIdsLen += row.bookIds.length;
|
||||||
|
if (bookIdsLen >= 50000)
|
||||||
|
break;
|
||||||
|
|
||||||
callback({progress: proc/seriesCount});
|
id = iter.next();
|
||||||
|
}
|
||||||
|
|
||||||
await utils.sleep(100);
|
return ids;
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
|
if (chunk.length) {
|
||||||
|
await saveChunk(chunk);
|
||||||
|
|
||||||
|
processed += chunk.length;
|
||||||
|
callback({progress: 0.5*processed/fromLength});
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (this.config.lowMemoryMode) {
|
||||||
|
await utils.sleep(10);
|
||||||
utils.freeMemory();
|
utils.freeMemory();
|
||||||
await db.freeMemory();
|
await db.freeMemory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (aChunk.length) {
|
|
||||||
await saveSeriesChunk(aChunk);
|
await db.close({table: to});
|
||||||
aChunk = null;
|
await db.close({table: from});
|
||||||
|
|
||||||
|
await db.create({table: toId});
|
||||||
|
|
||||||
|
const chunkSize = 50000;
|
||||||
|
let idRows = [];
|
||||||
|
let proc = 0;
|
||||||
|
for (const [id, value] of bookId2RecId) {
|
||||||
|
idRows.push({id, value});
|
||||||
|
if (idRows.length >= chunkSize) {
|
||||||
|
await db.insert({table: toId, rows: idRows});
|
||||||
|
idRows = [];
|
||||||
|
|
||||||
|
proc += chunkSize;
|
||||||
|
callback({progress: 0.5 + 0.5*proc/bookId2RecId.size});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (idRows.length)
|
||||||
|
await db.insert({table: toId, rows: idRows});
|
||||||
|
await db.close({table: toId});
|
||||||
|
|
||||||
|
bookId2RecId = null;
|
||||||
|
utils.freeMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
async countStats(db, callback, stats) {
|
||||||
|
//статистика по количеству файлов
|
||||||
|
|
||||||
|
//эмуляция прогресса
|
||||||
|
let countDone = false;
|
||||||
|
(async() => {
|
||||||
|
let i = 0;
|
||||||
|
while (!countDone) {
|
||||||
|
callback({progress: i/100});
|
||||||
|
i = (i < 100 ? i + 5 : 100);
|
||||||
|
await utils.sleep(1000);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
//подчсет
|
||||||
|
const countRes = await db.select({table: 'book', rawResult: true, where: `
|
||||||
|
const files = new Set();
|
||||||
|
const filesDel = new Set();
|
||||||
|
|
||||||
|
for (const id of @all()) {
|
||||||
|
const r = @row(id);
|
||||||
|
const file = ${"`${r.folder}/${r.file}.${r.ext}`"};
|
||||||
|
if (!r.del) {
|
||||||
|
files.add(file);
|
||||||
|
} else {
|
||||||
|
filesDel.add(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of filesDel)
|
||||||
|
if (files.has(file))
|
||||||
|
filesDel.delete(file);
|
||||||
|
|
||||||
|
return {filesCount: files.size, filesDelCount: filesDel.size};
|
||||||
|
`});
|
||||||
|
|
||||||
|
if (countRes.length) {
|
||||||
|
const res = countRes[0].rawResult;
|
||||||
|
stats.filesCount = res.filesCount;
|
||||||
|
stats.filesCountAll = res.filesCount + res.filesDelCount;
|
||||||
|
stats.filesDelCount = res.filesDelCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
//чистка памяти, ибо жрет как не в себя
|
countDone = true;
|
||||||
await db.drop({table: 'book'});//таблица больше не понадобится
|
|
||||||
await db.drop({table: 'series_temporary'});//таблица больше не понадобится
|
|
||||||
|
|
||||||
await db.close({table: 'series'});
|
|
||||||
await db.freeMemory();
|
|
||||||
utils.freeMemory();
|
|
||||||
|
|
||||||
callback({job: 'done', jobMessage: ''});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
//const _ = require('lodash');
|
//const _ = require('lodash');
|
||||||
|
const LockQueue = require('./LockQueue');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
|
const maxMemCacheSize = 100;
|
||||||
|
const maxLimit = 1000;
|
||||||
|
|
||||||
|
const emptyFieldValue = '?';
|
||||||
const maxUtf8Char = String.fromCodePoint(0xFFFFF);
|
const maxUtf8Char = String.fromCodePoint(0xFFFFF);
|
||||||
const ruAlphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';
|
const ruAlphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';
|
||||||
const enAlphabet = 'abcdefghijklmnopqrstuvwxyz';
|
const enAlphabet = 'abcdefghijklmnopqrstuvwxyz';
|
||||||
@@ -12,11 +16,20 @@ class DbSearcher {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
|
|
||||||
|
this.lock = new LockQueue();
|
||||||
this.searchFlag = 0;
|
this.searchFlag = 0;
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
this.closed = false;
|
this.closed = false;
|
||||||
|
|
||||||
|
this.memCache = new Map();
|
||||||
|
this.bookIdMap = {};
|
||||||
|
|
||||||
this.periodicCleanCache();//no await
|
this.periodicCleanCache();//no await
|
||||||
|
this.fillBookIdMapAll();//no await
|
||||||
|
}
|
||||||
|
|
||||||
|
queryKey(q) {
|
||||||
|
return JSON.stringify([q.author, q.series, q.title, q.genre, q.lang, q.del, q.date, q.librate]);
|
||||||
}
|
}
|
||||||
|
|
||||||
getWhere(a) {
|
getWhere(a) {
|
||||||
@@ -28,75 +41,72 @@ class DbSearcher {
|
|||||||
//особая обработка префиксов
|
//особая обработка префиксов
|
||||||
if (a[0] == '=') {
|
if (a[0] == '=') {
|
||||||
a = a.substring(1);
|
a = a.substring(1);
|
||||||
where = `@@dirtyIndexLR('value', ${db.esc(a)}, ${db.esc(a)})`;
|
where = `@dirtyIndexLR('value', ${db.esc(a)}, ${db.esc(a)})`;
|
||||||
} else if (a[0] == '*') {
|
} else if (a[0] == '*') {
|
||||||
a = a.substring(1);
|
a = a.substring(1);
|
||||||
where = `@@indexIter('value', (v) => (v.indexOf(${db.esc(a)}) >= 0) )`;
|
where = `@indexIter('value', (v) => (v !== ${db.esc(emptyFieldValue)} && v.indexOf(${db.esc(a)}) >= 0) )`;
|
||||||
} else if (a[0] == '#') {
|
} else if (a[0] == '#') {
|
||||||
a = a.substring(1);
|
a = a.substring(1);
|
||||||
where = `@@indexIter('value', (v) => {
|
where = `@indexIter('value', (v) => {
|
||||||
const enru = new Set(${db.esc(enruArr)});
|
const enru = new Set(${db.esc(enruArr)});
|
||||||
return !v || (!enru.has(v[0].toLowerCase()) && v.indexOf(${db.esc(a)}) >= 0);
|
return !v || (v !== ${db.esc(emptyFieldValue)} && !enru.has(v[0]) && v.indexOf(${db.esc(a)}) >= 0);
|
||||||
});`;
|
})`;
|
||||||
} else {
|
} else {
|
||||||
where = `@@dirtyIndexLR('value', ${db.esc(a)}, ${db.esc(a + maxUtf8Char)})`;
|
where = `@dirtyIndexLR('value', ${db.esc(a)}, ${db.esc(a + maxUtf8Char)})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return where;
|
return where;
|
||||||
}
|
}
|
||||||
|
|
||||||
async selectAuthorIds(query) {
|
async selectBookIds(query) {
|
||||||
const db = this.db;
|
const db = this.db;
|
||||||
|
|
||||||
let authorIds = new Set();
|
const idsArr = [];
|
||||||
|
|
||||||
//сначала выберем все id авторов по фильтру
|
const tableBookIds = async(table, where) => {
|
||||||
//порядок id соответсвует ASC-сортировке по author
|
const rows = await db.select({
|
||||||
if (query.author && query.author !== '*') {
|
table,
|
||||||
const where = this.getWhere(query.author);
|
rawResult: true,
|
||||||
|
where: `
|
||||||
|
const ids = ${where};
|
||||||
|
|
||||||
const authorRows = await db.select({
|
const result = new Set();
|
||||||
table: 'author',
|
for (const id of ids) {
|
||||||
dirtyIdsOnly: true,
|
const row = @unsafeRow(id);
|
||||||
where
|
for (const bookId of row.bookIds)
|
||||||
|
result.add(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(result);
|
||||||
|
`
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const row of authorRows)
|
return rows[0].rawResult;
|
||||||
authorIds.add(row.id);
|
};
|
||||||
} else {//все авторы
|
|
||||||
if (!db.searchCache.authorIdsAll) {
|
|
||||||
const authorRows = await db.select({
|
|
||||||
table: 'author',
|
|
||||||
dirtyIdsOnly: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
db.searchCache.authorIdsAll = [];
|
//авторы
|
||||||
for (const row of authorRows) {
|
if (query.author && query.author !== '*') {
|
||||||
authorIds.add(row.id);
|
const key = `book-ids-author-${query.author}`;
|
||||||
db.searchCache.authorIdsAll.push(row.id);
|
let ids = await this.getCached(key);
|
||||||
}
|
|
||||||
} else {//оптимизация
|
if (ids === null) {
|
||||||
authorIds = new Set(db.searchCache.authorIdsAll);
|
ids = await tableBookIds('author', this.getWhere(query.author));
|
||||||
|
|
||||||
|
await this.putCached(key, ids);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const idsArr = [];
|
idsArr.push(ids);
|
||||||
idsArr.push(authorIds);
|
}
|
||||||
|
|
||||||
//серии
|
//серии
|
||||||
if (query.series && query.series !== '*') {
|
if (query.series && query.series !== '*') {
|
||||||
const where = this.getWhere(query.series);
|
const key = `book-ids-series-${query.series}`;
|
||||||
|
let ids = await this.getCached(key);
|
||||||
|
|
||||||
const seriesRows = await db.select({
|
if (ids === null) {
|
||||||
table: 'series',
|
ids = await tableBookIds('series', this.getWhere(query.series));
|
||||||
map: `(r) => ({authorId: r.authorId})`,
|
|
||||||
where
|
|
||||||
});
|
|
||||||
|
|
||||||
const ids = new Set();
|
await this.putCached(key, ids);
|
||||||
for (const row of seriesRows) {
|
|
||||||
for (const id of row.authorId)
|
|
||||||
ids.add(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
idsArr.push(ids);
|
idsArr.push(ids);
|
||||||
@@ -104,45 +114,49 @@ class DbSearcher {
|
|||||||
|
|
||||||
//названия
|
//названия
|
||||||
if (query.title && query.title !== '*') {
|
if (query.title && query.title !== '*') {
|
||||||
const where = this.getWhere(query.title);
|
const key = `book-ids-title-${query.title}`;
|
||||||
|
let ids = await this.getCached(key);
|
||||||
|
|
||||||
let titleRows = await db.select({
|
if (ids === null) {
|
||||||
table: 'title',
|
ids = await tableBookIds('title', this.getWhere(query.title));
|
||||||
map: `(r) => ({authorId: r.authorId})`,
|
|
||||||
where
|
|
||||||
});
|
|
||||||
|
|
||||||
const ids = new Set();
|
await this.putCached(key, ids);
|
||||||
for (const row of titleRows) {
|
|
||||||
for (const id of row.authorId)
|
|
||||||
ids.add(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
idsArr.push(ids);
|
idsArr.push(ids);
|
||||||
|
|
||||||
//чистки памяти при тяжелых запросах
|
|
||||||
if (query.title[0] == '*') {
|
|
||||||
titleRows = null;
|
|
||||||
utils.freeMemory();
|
|
||||||
await db.freeMemory();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//жанры
|
//жанры
|
||||||
if (query.genre) {
|
if (query.genre) {
|
||||||
const genres = query.genre.split(',');
|
const key = `book-ids-genre-${query.genre}`;
|
||||||
|
let ids = await this.getCached(key);
|
||||||
|
|
||||||
const ids = new Set();
|
if (ids === null) {
|
||||||
for (const g of genres) {
|
|
||||||
const genreRows = await db.select({
|
const genreRows = await db.select({
|
||||||
table: 'genre',
|
table: 'genre',
|
||||||
map: `(r) => ({authorId: r.authorId})`,
|
rawResult: true,
|
||||||
where: `@@indexLR('value', ${db.esc(g)}, ${db.esc(g)})`,
|
where: `
|
||||||
|
const genres = ${db.esc(query.genre.split(','))};
|
||||||
|
|
||||||
|
const ids = new Set();
|
||||||
|
for (const g of genres) {
|
||||||
|
for (const id of @indexLR('value', g, g))
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = new Set();
|
||||||
|
for (const id of ids) {
|
||||||
|
const row = @unsafeRow(id);
|
||||||
|
for (const bookId of row.bookIds)
|
||||||
|
result.add(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(result);
|
||||||
|
`
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const row of genreRows) {
|
ids = genreRows[0].rawResult;
|
||||||
for (const id of row.authorId)
|
await this.putCached(key, ids);
|
||||||
ids.add(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
idsArr.push(ids);
|
idsArr.push(ids);
|
||||||
@@ -150,143 +164,401 @@ class DbSearcher {
|
|||||||
|
|
||||||
//языки
|
//языки
|
||||||
if (query.lang) {
|
if (query.lang) {
|
||||||
const langs = query.lang.split(',');
|
const key = `book-ids-lang-${query.lang}`;
|
||||||
|
let ids = await this.getCached(key);
|
||||||
|
|
||||||
const ids = new Set();
|
if (ids === null) {
|
||||||
for (const l of langs) {
|
|
||||||
const langRows = await db.select({
|
const langRows = await db.select({
|
||||||
table: 'lang',
|
table: 'lang',
|
||||||
map: `(r) => ({authorId: r.authorId})`,
|
rawResult: true,
|
||||||
where: `@@indexLR('value', ${db.esc(l)}, ${db.esc(l)})`,
|
where: `
|
||||||
|
const langs = ${db.esc(query.lang.split(','))};
|
||||||
|
|
||||||
|
const ids = new Set();
|
||||||
|
for (const l of langs) {
|
||||||
|
for (const id of @indexLR('value', l, l))
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = new Set();
|
||||||
|
for (const id of ids) {
|
||||||
|
const row = @unsafeRow(id);
|
||||||
|
for (const bookId of row.bookIds)
|
||||||
|
result.add(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(result);
|
||||||
|
`
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const row of langRows) {
|
ids = langRows[0].rawResult;
|
||||||
for (const id of row.authorId)
|
await this.putCached(key, ids);
|
||||||
ids.add(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
idsArr.push(ids);
|
idsArr.push(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idsArr.length > 1)
|
//удаленные
|
||||||
authorIds = utils.intersectSet(idsArr);
|
if (query.del !== undefined) {
|
||||||
|
const key = `book-ids-del-${query.del}`;
|
||||||
|
let ids = await this.getCached(key);
|
||||||
|
|
||||||
//сортировка
|
if (ids === null) {
|
||||||
authorIds = Array.from(authorIds);
|
ids = await tableBookIds('del', `@indexLR('value', ${db.esc(query.del)}, ${db.esc(query.del)})`);
|
||||||
|
|
||||||
authorIds.sort((a, b) => a - b);
|
|
||||||
|
|
||||||
return authorIds;
|
await this.putCached(key, ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
idsArr.push(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
//дата поступления
|
||||||
|
if (query.date) {
|
||||||
|
const key = `book-ids-date-${query.date}`;
|
||||||
|
let ids = await this.getCached(key);
|
||||||
|
|
||||||
|
if (ids === null) {
|
||||||
|
let [from = '', to = ''] = query.date.split(',');
|
||||||
|
ids = await tableBookIds('date', `@indexLR('value', ${db.esc(from)} || undefined, ${db.esc(to)} || undefined)`);
|
||||||
|
|
||||||
|
await this.putCached(key, ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
idsArr.push(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
//оценка
|
||||||
|
if (query.librate) {
|
||||||
|
const key = `book-ids-librate-${query.librate}`;
|
||||||
|
let ids = await this.getCached(key);
|
||||||
|
|
||||||
|
if (ids === null) {
|
||||||
|
const dateRows = await db.select({
|
||||||
|
table: 'librate',
|
||||||
|
rawResult: true,
|
||||||
|
where: `
|
||||||
|
const rates = ${db.esc(query.librate.split(',').map(n => parseInt(n, 10)).filter(n => !isNaN(n)))};
|
||||||
|
|
||||||
|
const ids = new Set();
|
||||||
|
for (const rate of rates) {
|
||||||
|
for (const id of @indexLR('value', rate, rate))
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = new Set();
|
||||||
|
for (const id of ids) {
|
||||||
|
const row = @unsafeRow(id);
|
||||||
|
for (const bookId of row.bookIds)
|
||||||
|
result.add(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(result);
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
|
ids = dateRows[0].rawResult;
|
||||||
|
await this.putCached(key, ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
idsArr.push(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idsArr.length > 1) {
|
||||||
|
//ищем пересечение множеств
|
||||||
|
let proc = 0;
|
||||||
|
let nextProc = 0;
|
||||||
|
let inter = new Set(idsArr[0]);
|
||||||
|
for (let i = 1; i < idsArr.length; i++) {
|
||||||
|
const newInter = new Set();
|
||||||
|
|
||||||
|
for (const id of idsArr[i]) {
|
||||||
|
if (inter.has(id))
|
||||||
|
newInter.add(id);
|
||||||
|
|
||||||
|
//прерываемся иногда, чтобы не блокировать Event Loop
|
||||||
|
proc++;
|
||||||
|
if (proc >= nextProc) {
|
||||||
|
nextProc += 10000;
|
||||||
|
await utils.processLoop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inter = newInter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(inter);
|
||||||
|
} else if (idsArr.length == 1) {
|
||||||
|
return idsArr[0];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAuthorIds(query) {
|
async fillBookIdMap(from) {
|
||||||
const db = this.db;
|
if (this.bookIdMap[from])
|
||||||
|
return this.bookIdMap[from];
|
||||||
|
|
||||||
if (!db.searchCache)
|
await this.lock.get();
|
||||||
db.searchCache = {};
|
try {
|
||||||
|
const db = this.db;
|
||||||
|
const map = new Map();
|
||||||
|
const table = `${from}_id`;
|
||||||
|
|
||||||
let result;
|
await db.open({table});
|
||||||
|
let rows = await db.select({table});
|
||||||
|
await db.close({table});
|
||||||
|
|
||||||
//сначала попробуем найти в кеше
|
for (const row of rows) {
|
||||||
const q = query;
|
if (!row.value.length)
|
||||||
const keyArr = [q.author, q.series, q.title, q.genre, q.lang];
|
continue;
|
||||||
const keyStr = `query-${keyArr.join('')}`;
|
|
||||||
|
|
||||||
if (!keyStr) {//пустой запрос
|
|
||||||
if (db.searchCache.authorIdsAll)
|
|
||||||
result = db.searchCache.authorIdsAll;
|
|
||||||
else
|
|
||||||
result = await this.selectAuthorIds(query);
|
|
||||||
|
|
||||||
} else {//непустой запрос
|
if (row.value.length > 1)
|
||||||
if (this.config.queryCacheEnabled) {
|
map.set(row.id, row.value);
|
||||||
const key = JSON.stringify(keyArr);
|
else
|
||||||
const rows = await db.select({table: 'query_cache', where: `@@id(${db.esc(key)})`});
|
map.set(row.id, row.value[0]);
|
||||||
|
|
||||||
if (rows.length) {//нашли в кеше
|
|
||||||
await db.insert({
|
|
||||||
table: 'query_time',
|
|
||||||
replace: true,
|
|
||||||
rows: [{id: key, time: Date.now()}],
|
|
||||||
});
|
|
||||||
|
|
||||||
result = rows[0].value;
|
|
||||||
} else {//не нашли в кеше, ищем в поисковых таблицах
|
|
||||||
result = await this.selectAuthorIds(query);
|
|
||||||
|
|
||||||
await db.insert({
|
|
||||||
table: 'query_cache',
|
|
||||||
replace: true,
|
|
||||||
rows: [{id: key, value: result}],
|
|
||||||
});
|
|
||||||
await db.insert({
|
|
||||||
table: 'query_time',
|
|
||||||
replace: true,
|
|
||||||
rows: [{id: key, time: Date.now()}],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result = await this.selectAuthorIds(query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.bookIdMap[from] = map;
|
||||||
|
|
||||||
|
rows = null;
|
||||||
|
await db.freeMemory();
|
||||||
|
utils.freeMemory();
|
||||||
|
|
||||||
|
return this.bookIdMap[from];
|
||||||
|
} finally {
|
||||||
|
this.lock.ret();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fillBookIdMapAll() {
|
||||||
|
await this.fillBookIdMap('author');
|
||||||
|
await this.fillBookIdMap('series');
|
||||||
|
await this.fillBookIdMap('title');
|
||||||
|
}
|
||||||
|
|
||||||
|
async filterTableIds(tableIds, from, query) {
|
||||||
|
let result = tableIds;
|
||||||
|
|
||||||
|
//т.к. авторы у книги идут списком, то дополнительно фильтруем
|
||||||
|
if (from == 'author' && query.author && query.author !== '*') {
|
||||||
|
const key = `filter-ids-author-${query.author}`;
|
||||||
|
let authorIds = await this.getCached(key);
|
||||||
|
|
||||||
|
if (authorIds === null) {
|
||||||
|
const rows = await this.db.select({
|
||||||
|
table: 'author',
|
||||||
|
rawResult: true,
|
||||||
|
where: `return Array.from(${this.getWhere(query.author)})`
|
||||||
|
});
|
||||||
|
|
||||||
|
authorIds = rows[0].rawResult;
|
||||||
|
|
||||||
|
await this.putCached(key, authorIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
//пересечение tableIds и authorIds
|
||||||
|
result = [];
|
||||||
|
const authorIdsSet = new Set(authorIds);
|
||||||
|
for (const id of tableIds)
|
||||||
|
if (authorIdsSet.has(id))
|
||||||
|
result.push(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async search(query) {
|
async selectTableIds(from, query) {
|
||||||
|
const db = this.db;
|
||||||
|
const queryKey = this.queryKey(query);
|
||||||
|
const tableKey = `${from}-table-ids-${queryKey}`;
|
||||||
|
let tableIds = await this.getCached(tableKey);
|
||||||
|
|
||||||
|
if (tableIds === null) {
|
||||||
|
const bookKey = `book-ids-${queryKey}`;
|
||||||
|
let bookIds = await this.getCached(bookKey);
|
||||||
|
|
||||||
|
if (bookIds === null) {
|
||||||
|
bookIds = await this.selectBookIds(query);
|
||||||
|
await this.putCached(bookKey, bookIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bookIds) {
|
||||||
|
const tableIdsSet = new Set();
|
||||||
|
const bookIdMap = await this.fillBookIdMap(from);
|
||||||
|
let proc = 0;
|
||||||
|
let nextProc = 0;
|
||||||
|
for (const bookId of bookIds) {
|
||||||
|
const tableIdValue = bookIdMap.get(bookId);
|
||||||
|
if (!tableIdValue)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (Array.isArray(tableIdValue)) {
|
||||||
|
for (const tableId of tableIdValue) {
|
||||||
|
tableIdsSet.add(tableId);
|
||||||
|
proc++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tableIdsSet.add(tableIdValue);
|
||||||
|
proc++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//прерываемся иногда, чтобы не блокировать Event Loop
|
||||||
|
if (proc >= nextProc) {
|
||||||
|
nextProc += 10000;
|
||||||
|
await utils.processLoop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tableIds = Array.from(tableIdsSet);
|
||||||
|
} else {
|
||||||
|
const rows = await db.select({
|
||||||
|
table: from,
|
||||||
|
rawResult: true,
|
||||||
|
where: `return Array.from(@all())`
|
||||||
|
});
|
||||||
|
|
||||||
|
tableIds = rows[0].rawResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
tableIds = await this.filterTableIds(tableIds, from, query);
|
||||||
|
|
||||||
|
tableIds.sort((a, b) => a - b);
|
||||||
|
|
||||||
|
await this.putCached(tableKey, tableIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tableIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
async restoreBooks(from, ids) {
|
||||||
|
const db = this.db;
|
||||||
|
const bookTable = `${from}_book`;
|
||||||
|
|
||||||
|
const rows = await db.select({
|
||||||
|
table: bookTable,
|
||||||
|
where: `@@id(${db.esc(ids)})`
|
||||||
|
});
|
||||||
|
|
||||||
|
if (rows.length == ids.length)
|
||||||
|
return rows;
|
||||||
|
|
||||||
|
//далее восстановим книги из book в <from>_book
|
||||||
|
const idsSet = new Set(rows.map(r => r.id));
|
||||||
|
|
||||||
|
//недостающие
|
||||||
|
const tableIds = [];
|
||||||
|
for (const id of ids) {
|
||||||
|
if (!idsSet.has(id))
|
||||||
|
tableIds.push(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tableRows = await db.select({
|
||||||
|
table: from,
|
||||||
|
where: `@@id(${db.esc(tableIds)})`
|
||||||
|
});
|
||||||
|
|
||||||
|
//список недостающих bookId
|
||||||
|
const bookIds = [];
|
||||||
|
for (const row of tableRows) {
|
||||||
|
for (const bookId of row.bookIds)
|
||||||
|
bookIds.push(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
//выбираем книги
|
||||||
|
const books = await db.select({
|
||||||
|
table: 'book',
|
||||||
|
where: `@@id(${db.esc(bookIds)})`
|
||||||
|
});
|
||||||
|
|
||||||
|
const booksMap = new Map();
|
||||||
|
for (const book of books)
|
||||||
|
booksMap.set(book.id, book);
|
||||||
|
|
||||||
|
//распределяем
|
||||||
|
for (const row of tableRows) {
|
||||||
|
const books = [];
|
||||||
|
for (const bookId of row.bookIds) {
|
||||||
|
const book = booksMap.get(bookId);
|
||||||
|
if (book)
|
||||||
|
books.push(book);
|
||||||
|
}
|
||||||
|
|
||||||
|
rows.push({id: row.id, name: row.name, books});
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.insert({table: bookTable, ignore: true, rows});
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
async search(from, query) {
|
||||||
if (this.closed)
|
if (this.closed)
|
||||||
throw new Error('DbSearcher closed');
|
throw new Error('DbSearcher closed');
|
||||||
|
|
||||||
|
if (!['author', 'series', 'title'].includes(from))
|
||||||
|
throw new Error(`Unknown value for param 'from'`);
|
||||||
|
|
||||||
this.searchFlag++;
|
this.searchFlag++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const db = this.db;
|
const db = this.db;
|
||||||
|
|
||||||
const authorIds = await this.getAuthorIds(query);
|
const ids = await this.selectTableIds(from, query);
|
||||||
|
|
||||||
const totalFound = authorIds.length;
|
const totalFound = ids.length;
|
||||||
let limit = (query.limit ? query.limit : 100);
|
let limit = (query.limit ? query.limit : 100);
|
||||||
limit = (limit > 1000 ? 1000 : limit);
|
limit = (limit > maxLimit ? maxLimit : limit);
|
||||||
const offset = (query.offset ? query.offset : 0);
|
const offset = (query.offset ? query.offset : 0);
|
||||||
|
|
||||||
//выборка найденных авторов
|
//выборка найденных значений
|
||||||
let result = await db.select({
|
const found = await db.select({
|
||||||
table: 'author',
|
table: from,
|
||||||
map: `(r) => ({id: r.id, author: r.author, bookCount: r.bookCount, bookDelCount: r.bookDelCount})`,
|
map: `(r) => ({id: r.id, ${from}: r.name, bookCount: r.bookCount, bookDelCount: r.bookDelCount})`,
|
||||||
where: `@@id(${db.esc(authorIds.slice(offset, offset + limit))})`
|
where: `@@id(${db.esc(ids.slice(offset, offset + limit))})`
|
||||||
});
|
});
|
||||||
|
|
||||||
return {result, totalFound};
|
//для title восстановим books
|
||||||
|
if (from == 'title') {
|
||||||
|
const bookIds = found.map(r => r.id);
|
||||||
|
const rows = await this.restoreBooks(from, bookIds);
|
||||||
|
const rowsMap = new Map();
|
||||||
|
for (const row of rows)
|
||||||
|
rowsMap.set(row.id, row);
|
||||||
|
|
||||||
|
for (const f of found) {
|
||||||
|
const b = rowsMap.get(f.id);
|
||||||
|
if (b)
|
||||||
|
f.books = b.books;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {found, totalFound};
|
||||||
} finally {
|
} finally {
|
||||||
this.searchFlag--;
|
this.searchFlag--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBookList(authorId) {
|
async getAuthorBookList(authorId) {
|
||||||
if (this.closed)
|
if (this.closed)
|
||||||
throw new Error('DbSearcher closed');
|
throw new Error('DbSearcher closed');
|
||||||
|
|
||||||
|
if (!authorId)
|
||||||
|
return {author: '', books: ''};
|
||||||
|
|
||||||
this.searchFlag++;
|
this.searchFlag++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const db = this.db;
|
//выборка книг автора по authorId
|
||||||
|
const rows = await this.restoreBooks('author', [authorId])
|
||||||
//выборка автора по authorId
|
|
||||||
const rows = await db.select({
|
|
||||||
table: 'author_book',
|
|
||||||
where: `@@id(${db.esc(authorId)})`
|
|
||||||
});
|
|
||||||
|
|
||||||
let author = '';
|
let author = '';
|
||||||
let books = '';
|
let books = '';
|
||||||
|
|
||||||
if (rows.length) {
|
if (rows.length) {
|
||||||
author = rows[0].author;
|
author = rows[0].name;
|
||||||
books = rows[0].books;
|
books = rows[0].books;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {author, books};
|
return {author, books: (books && books.length ? JSON.stringify(books) : '')};
|
||||||
} finally {
|
} finally {
|
||||||
this.searchFlag--;
|
this.searchFlag--;
|
||||||
}
|
}
|
||||||
@@ -296,24 +568,116 @@ class DbSearcher {
|
|||||||
if (this.closed)
|
if (this.closed)
|
||||||
throw new Error('DbSearcher closed');
|
throw new Error('DbSearcher closed');
|
||||||
|
|
||||||
|
if (!series)
|
||||||
|
return {books: ''};
|
||||||
|
|
||||||
this.searchFlag++;
|
this.searchFlag++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const db = this.db;
|
const db = this.db;
|
||||||
|
|
||||||
series = series.toLowerCase();
|
series = series.toLowerCase();
|
||||||
|
|
||||||
//выборка серии по названию серии
|
//выборка серии по названию серии
|
||||||
const rows = await db.select({
|
let rows = await db.select({
|
||||||
table: 'series',
|
table: 'series',
|
||||||
where: `@@dirtyIndexLR('value', ${db.esc(series)}, ${db.esc(series)})`
|
rawResult: true,
|
||||||
|
where: `return Array.from(@dirtyIndexLR('value', ${db.esc(series)}, ${db.esc(series)}))`
|
||||||
});
|
});
|
||||||
|
|
||||||
return {books: (rows.length ? rows[0].books : '')};
|
let books;
|
||||||
|
if (rows.length && rows[0].rawResult.length) {
|
||||||
|
//выборка книг серии
|
||||||
|
const bookRows = await this.restoreBooks('series', [rows[0].rawResult[0]])
|
||||||
|
|
||||||
|
if (bookRows.length)
|
||||||
|
books = bookRows[0].books;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {books: (books && books.length ? JSON.stringify(books) : '')};
|
||||||
} finally {
|
} finally {
|
||||||
this.searchFlag--;
|
this.searchFlag--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getCached(key) {
|
||||||
|
if (!this.config.queryCacheEnabled)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
let result = null;
|
||||||
|
|
||||||
|
const db = this.db;
|
||||||
|
const memCache = this.memCache;
|
||||||
|
|
||||||
|
if (memCache.has(key)) {//есть в недавних
|
||||||
|
result = memCache.get(key);
|
||||||
|
|
||||||
|
//изменим порядок ключей, для последующей правильной чистки старых
|
||||||
|
memCache.delete(key);
|
||||||
|
memCache.set(key, result);
|
||||||
|
} else {//смотрим в таблице
|
||||||
|
const rows = await db.select({table: 'query_cache', where: `@@id(${db.esc(key)})`});
|
||||||
|
|
||||||
|
if (rows.length) {//нашли в кеше
|
||||||
|
await db.insert({
|
||||||
|
table: 'query_time',
|
||||||
|
replace: true,
|
||||||
|
rows: [{id: key, time: Date.now()}],
|
||||||
|
});
|
||||||
|
|
||||||
|
result = rows[0].value;
|
||||||
|
memCache.set(key, result);
|
||||||
|
|
||||||
|
if (memCache.size > maxMemCacheSize) {
|
||||||
|
//удаляем самый старый ключ-значение
|
||||||
|
for (const k of memCache.keys()) {
|
||||||
|
memCache.delete(k);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async putCached(key, value) {
|
||||||
|
if (!this.config.queryCacheEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const db = this.db;
|
||||||
|
|
||||||
|
const memCache = this.memCache;
|
||||||
|
memCache.set(key, value);
|
||||||
|
|
||||||
|
if (memCache.size > maxMemCacheSize) {
|
||||||
|
//удаляем самый старый ключ-значение
|
||||||
|
for (const k of memCache.keys()) {
|
||||||
|
memCache.delete(k);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//кладем в таблицу асинхронно
|
||||||
|
(async() => {
|
||||||
|
try {
|
||||||
|
await db.insert({
|
||||||
|
table: 'query_cache',
|
||||||
|
replace: true,
|
||||||
|
rows: [{id: key, value}],
|
||||||
|
});
|
||||||
|
|
||||||
|
await db.insert({
|
||||||
|
table: 'query_time',
|
||||||
|
replace: true,
|
||||||
|
rows: [{id: key, time: Date.now()}],
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
console.error(`putCached: ${e.message}`);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
async periodicCleanCache() {
|
async periodicCleanCache() {
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
const cleanInterval = this.config.cacheCleanInterval*60*1000;
|
const cleanInterval = this.config.cacheCleanInterval*60*1000;
|
||||||
@@ -356,6 +720,8 @@ class DbSearcher {
|
|||||||
await utils.sleep(50);
|
await utils.sleep(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.searchCache = null;
|
||||||
|
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
clearTimeout(this.timer);
|
clearTimeout(this.timer);
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
|
|||||||
144
server/core/HeavyCalc.js
Normal file
144
server/core/HeavyCalc.js
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
const { Worker } = require('worker_threads');
|
||||||
|
|
||||||
|
class CalcThread {
|
||||||
|
constructor() {
|
||||||
|
this.worker = null;
|
||||||
|
this.listeners = new Map();
|
||||||
|
this.requestId = 0;
|
||||||
|
|
||||||
|
this.runWorker();
|
||||||
|
}
|
||||||
|
|
||||||
|
terminate() {
|
||||||
|
if (this.worker) {
|
||||||
|
this.worker.terminate();
|
||||||
|
|
||||||
|
for (const listener of this.listeners.values()) {
|
||||||
|
listener({error: 'Worker terminated'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.worker = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
runWorker() {
|
||||||
|
const workerProc = () => {
|
||||||
|
const { parentPort } = require('worker_threads');
|
||||||
|
|
||||||
|
const sleep = (ms) => {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
};
|
||||||
|
|
||||||
|
if (parentPort) {
|
||||||
|
parentPort.on('message', async(mes) => {
|
||||||
|
let result = {};
|
||||||
|
try {
|
||||||
|
const fn = new Function(`'use strict'; return ${mes.fn}`)();
|
||||||
|
result.result = await fn(mes.args, sleep);
|
||||||
|
} catch (e) {
|
||||||
|
result = {error: e.message};
|
||||||
|
}
|
||||||
|
|
||||||
|
result.requestId = mes.requestId;
|
||||||
|
parentPort.postMessage(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const worker = new Worker(`const wp = ${workerProc.toString()}; wp();`, {eval: true});
|
||||||
|
|
||||||
|
worker.on('message', (mes) => {
|
||||||
|
const listener = this.listeners.get(mes.requestId);
|
||||||
|
if (listener) {
|
||||||
|
this.listeners.delete(mes.requestId);
|
||||||
|
listener(mes);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
worker.on('error', (err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
worker.on('exit', () => {
|
||||||
|
this.terminate();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.worker = worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
//async
|
||||||
|
run(args, fn) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.requestId++;
|
||||||
|
|
||||||
|
this.listeners.set(this.requestId, (mes) => {
|
||||||
|
if (mes.error)
|
||||||
|
reject(new Error(mes.error));
|
||||||
|
else
|
||||||
|
resolve(mes.result);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.worker) {
|
||||||
|
this.worker.postMessage({requestId: this.requestId, args, fn: fn.toString()});
|
||||||
|
} else {
|
||||||
|
reject(new Error('Worker does not exist'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//singleton
|
||||||
|
let instance = null;
|
||||||
|
|
||||||
|
class HeavyCalc {
|
||||||
|
constructor(opts = {}) {
|
||||||
|
const singleton = opts.singleton || false;
|
||||||
|
|
||||||
|
if (singleton && instance)
|
||||||
|
return instance;
|
||||||
|
|
||||||
|
this.threads = opts.threads || 1;
|
||||||
|
this.terminated = false;
|
||||||
|
|
||||||
|
this.workers = [];
|
||||||
|
this.load = [];
|
||||||
|
for (let i = 0; i < this.threads; i++) {
|
||||||
|
const worker = new CalcThread();
|
||||||
|
this.workers.push(worker);
|
||||||
|
this.load.push(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (singleton) {
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(args, fn) {
|
||||||
|
if (this.terminated || !this.workers.length)
|
||||||
|
throw new Error('All workers terminated');
|
||||||
|
|
||||||
|
//находим поток с минимальной нагрузкой
|
||||||
|
let found = 0;
|
||||||
|
for (let i = 1; i < this.load.length; i++) {
|
||||||
|
if (this.load[i] < this.load[found])
|
||||||
|
found = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.load[found]++;
|
||||||
|
return await this.workers[found].run(args, fn);
|
||||||
|
} finally {
|
||||||
|
this.load[found]--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
terminate() {
|
||||||
|
for (let i = 0; i < this.workers.length; i++) {
|
||||||
|
this.workers[i].terminate();
|
||||||
|
}
|
||||||
|
this.workers = [];
|
||||||
|
this.load = [];
|
||||||
|
this.terminated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = HeavyCalc;
|
||||||
@@ -2,10 +2,6 @@ const fs = require('fs-extra');
|
|||||||
|
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
//поправить в случае, если были критические изменения в DbCreator
|
|
||||||
//иначе будет рассинхронизация между сервером и клиентом на уровне БД
|
|
||||||
const dbCreatorVersion = '2';
|
|
||||||
|
|
||||||
class InpxHashCreator {
|
class InpxHashCreator {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
@@ -18,7 +14,7 @@ class InpxHashCreator {
|
|||||||
if (await fs.pathExists(config.inpxFilterFile))
|
if (await fs.pathExists(config.inpxFilterFile))
|
||||||
inpxFilterHash = await utils.getFileHash(config.inpxFilterFile, 'sha256', 'hex');
|
inpxFilterHash = await utils.getFileHash(config.inpxFilterFile, 'sha256', 'hex');
|
||||||
|
|
||||||
const joinedHash = dbCreatorVersion + inpxFilterHash +
|
const joinedHash = this.config.dbVersion + inpxFilterHash +
|
||||||
await utils.getFileHash(config.inpxFile, 'sha256', 'hex');
|
await utils.getFileHash(config.inpxFile, 'sha256', 'hex');
|
||||||
|
|
||||||
return utils.getBufHash(joinedHash, 'sha256', 'hex');
|
return utils.getBufHash(joinedHash, 'sha256', 'hex');
|
||||||
|
|||||||
@@ -50,4 +50,4 @@ class LockQueue {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LockQueue;
|
module.exports = LockQueue;
|
||||||
@@ -5,7 +5,7 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
const ZipReader = require('./ZipReader');
|
const ZipReader = require('./ZipReader');
|
||||||
const WorkerState = require('./WorkerState');//singleton
|
const WorkerState = require('./WorkerState');//singleton
|
||||||
const { JembaDbThread } = require('jembadb');
|
const { JembaDb, JembaDbThread } = require('jembadb');
|
||||||
const DbCreator = require('./DbCreator');
|
const DbCreator = require('./DbCreator');
|
||||||
const DbSearcher = require('./DbSearcher');
|
const DbSearcher = require('./DbSearcher');
|
||||||
const InpxHashCreator = require('./InpxHashCreator');
|
const InpxHashCreator = require('./InpxHashCreator');
|
||||||
@@ -58,8 +58,8 @@ class WebWorker {
|
|||||||
|
|
||||||
const dirConfig = [
|
const dirConfig = [
|
||||||
{
|
{
|
||||||
dir: `${this.config.publicDir}/files`,
|
dir: config.filesDir,
|
||||||
maxSize: this.config.maxFilesDirSize,
|
maxSize: config.maxFilesDirSize,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ class WebWorker {
|
|||||||
softLock: true,
|
softLock: true,
|
||||||
|
|
||||||
tableDefaults: {
|
tableDefaults: {
|
||||||
cacheSize: 5,
|
cacheSize: config.dbCacheSize,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ class WebWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadOrCreateDb(recreate = false) {
|
async loadOrCreateDb(recreate = false, iteration = 0) {
|
||||||
this.setMyState(ssDbLoading);
|
this.setMyState(ssDbLoading);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -141,18 +141,35 @@ class WebWorker {
|
|||||||
|
|
||||||
this.inpxFileHash = await this.inpxHashCreator.getInpxFileHash();
|
this.inpxFileHash = await this.inpxHashCreator.getInpxFileHash();
|
||||||
|
|
||||||
//пересоздаем БД из INPX если нужно
|
//проверим полный InxpHash (включая фильтр и версию БД)
|
||||||
|
//для этого заглянем в конфиг внутри БД, если он есть
|
||||||
|
if (!(config.recreateDb || recreate) && await fs.pathExists(dbPath)) {
|
||||||
|
const newInpxHash = await this.inpxHashCreator.getHash();
|
||||||
|
|
||||||
|
const tmpDb = new JembaDb();
|
||||||
|
await tmpDb.lock({dbPath, softLock: true});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await tmpDb.open({table: 'config'});
|
||||||
|
const rows = await tmpDb.select({table: 'config', where: `@@id('inpxHash')`});
|
||||||
|
|
||||||
|
if (!rows.length || newInpxHash !== rows[0].value)
|
||||||
|
throw new Error('inpx file: changes found on start, recreating DB');
|
||||||
|
} catch (e) {
|
||||||
|
log(LM_WARN, e.message);
|
||||||
|
recreate = true;
|
||||||
|
} finally {
|
||||||
|
await tmpDb.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//удалим БД если нужно
|
||||||
if (config.recreateDb || recreate)
|
if (config.recreateDb || recreate)
|
||||||
await fs.remove(dbPath);
|
await fs.remove(dbPath);
|
||||||
|
|
||||||
|
//пересоздаем БД из INPX если нужно
|
||||||
if (!await fs.pathExists(dbPath)) {
|
if (!await fs.pathExists(dbPath)) {
|
||||||
try {
|
await this.createDb(dbPath);
|
||||||
await this.createDb(dbPath);
|
|
||||||
} catch (e) {
|
|
||||||
//при ошибке создания БД удалим ее, чтобы не работать с поломанной базой при следующем запуске
|
|
||||||
await fs.remove(dbPath);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
utils.freeMemory();
|
utils.freeMemory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,35 +177,49 @@ class WebWorker {
|
|||||||
this.setMyState(ssDbLoading);
|
this.setMyState(ssDbLoading);
|
||||||
log('Searcher DB loading');
|
log('Searcher DB loading');
|
||||||
|
|
||||||
const db = new JembaDbThread();
|
const db = new JembaDbThread();//в отдельном потоке
|
||||||
await db.lock({
|
await db.lock({
|
||||||
dbPath,
|
dbPath,
|
||||||
softLock: true,
|
softLock: true,
|
||||||
|
|
||||||
tableDefaults: {
|
tableDefaults: {
|
||||||
cacheSize: 5,
|
cacheSize: config.dbCacheSize,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
//открываем все таблицы
|
try {
|
||||||
await db.openAll();
|
//открываем таблицы
|
||||||
//переоткроем таблицу 'author' с бОльшим размером кеша блоков, для ускорения выборки
|
await db.openAll({exclude: ['author_id', 'series_id', 'title_id', 'book']});
|
||||||
await db.close({table: 'author'});
|
|
||||||
await db.open({table: 'author', cacheSize: 100});
|
|
||||||
|
|
||||||
|
const bookCacheSize = 500;
|
||||||
|
await db.open({
|
||||||
|
table: 'book',
|
||||||
|
cacheSize: (config.lowMemoryMode || config.dbCacheSize > bookCacheSize ? config.dbCacheSize : bookCacheSize)
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
log(LM_ERR, `Database error: ${e.message}`);
|
||||||
|
if (iteration < 1) {
|
||||||
|
log('Recreating DB');
|
||||||
|
await this.loadOrCreateDb(true, iteration + 1);
|
||||||
|
} else
|
||||||
|
throw e;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//поисковый движок
|
||||||
this.dbSearcher = new DbSearcher(config, db);
|
this.dbSearcher = new DbSearcher(config, db);
|
||||||
|
|
||||||
|
//stuff
|
||||||
db.wwCache = {};
|
db.wwCache = {};
|
||||||
this.db = db;
|
this.db = db;
|
||||||
|
|
||||||
log('Searcher DB ready');
|
this.setMyState(ssNormal);
|
||||||
|
|
||||||
|
log('Searcher DB ready');
|
||||||
this.logServerStats();
|
this.logServerStats();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(LM_FATAL, e.message);
|
log(LM_FATAL, e.message);
|
||||||
ayncExit.exit(1);
|
ayncExit.exit(1);
|
||||||
} finally {
|
|
||||||
this.setMyState(ssNormal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,29 +254,27 @@ class WebWorker {
|
|||||||
return db.wwCache.config;
|
return db.wwCache.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
async search(query) {
|
async search(from, query) {
|
||||||
this.checkMyState();
|
this.checkMyState();
|
||||||
|
|
||||||
|
const result = await this.dbSearcher.search(from, query);
|
||||||
|
|
||||||
const config = await this.dbConfig();
|
const config = await this.dbConfig();
|
||||||
const result = await this.dbSearcher.search(query);
|
result.inpxHash = (config.inpxHash ? config.inpxHash : '');
|
||||||
|
|
||||||
return {
|
return result;
|
||||||
author: result.result,
|
|
||||||
totalFound: result.totalFound,
|
|
||||||
inpxHash: (config.inpxHash ? config.inpxHash : ''),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBookList(authorId) {
|
async getAuthorBookList(authorId) {
|
||||||
this.checkMyState();
|
this.checkMyState();
|
||||||
|
|
||||||
return await this.dbSearcher.getBookList(authorId);
|
return await this.dbSearcher.getAuthorBookList(authorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSeriesBookList(seriesId) {
|
async getSeriesBookList(series) {
|
||||||
this.checkMyState();
|
this.checkMyState();
|
||||||
|
|
||||||
return await this.dbSearcher.getSeriesBookList(seriesId);
|
return await this.dbSearcher.getSeriesBookList(series);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGenreTree() {
|
async getGenreTree() {
|
||||||
@@ -336,20 +365,25 @@ class WebWorker {
|
|||||||
hash = await this.remoteLib.downloadBook(bookPath, downFileName);
|
hash = await this.remoteLib.downloadBook(bookPath, downFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const link = `/files/${hash}`;
|
const link = `${this.config.filesPathStatic}/${hash}`;
|
||||||
const publicPath = `${this.config.publicDir}${link}`;
|
const bookFile = `${this.config.filesDir}/${hash}`;
|
||||||
|
const bookFileDesc = `${bookFile}.json`;
|
||||||
|
|
||||||
if (!await fs.pathExists(publicPath)) {
|
if (!await fs.pathExists(bookFile) || !await fs.pathExists(bookFileDesc)) {
|
||||||
await fs.ensureDir(path.dirname(publicPath));
|
await fs.ensureDir(path.dirname(bookFile));
|
||||||
|
|
||||||
const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
|
const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
|
||||||
await utils.gzipFile(extractedFile, tmpFile, 4);
|
await utils.gzipFile(extractedFile, tmpFile, 4);
|
||||||
await fs.remove(extractedFile);
|
await fs.remove(extractedFile);
|
||||||
await fs.move(tmpFile, publicPath, {overwrite: true});
|
await fs.move(tmpFile, bookFile, {overwrite: true});
|
||||||
|
|
||||||
|
await fs.writeFile(bookFileDesc, JSON.stringify({bookPath, downFileName}));
|
||||||
} else {
|
} else {
|
||||||
if (extractedFile)
|
if (extractedFile)
|
||||||
await fs.remove(extractedFile);
|
await fs.remove(extractedFile);
|
||||||
await utils.touchFile(publicPath);
|
|
||||||
|
await utils.touchFile(bookFile);
|
||||||
|
await utils.touchFile(bookFileDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.insert({
|
await db.insert({
|
||||||
@@ -377,11 +411,10 @@ class WebWorker {
|
|||||||
const rows = await db.select({table: 'file_hash', where: `@@id(${db.esc(bookPath)})`});
|
const rows = await db.select({table: 'file_hash', where: `@@id(${db.esc(bookPath)})`});
|
||||||
if (rows.length) {//хеш найден по bookPath
|
if (rows.length) {//хеш найден по bookPath
|
||||||
const hash = rows[0].hash;
|
const hash = rows[0].hash;
|
||||||
link = `/files/${hash}`;
|
const bookFileDesc = `${this.config.filesDir}/${hash}.json`;
|
||||||
const publicPath = `${this.config.publicDir}${link}`;
|
|
||||||
|
|
||||||
if (!await fs.pathExists(publicPath)) {
|
if (await fs.pathExists(bookFileDesc)) {
|
||||||
link = '';
|
link = `${this.config.filesPathStatic}/${hash}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,6 +434,7 @@ class WebWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
async restoreBookFile(publicPath) {
|
async restoreBookFile(publicPath) {
|
||||||
this.checkMyState();
|
this.checkMyState();
|
||||||
|
|
||||||
@@ -440,6 +474,7 @@ class WebWorker {
|
|||||||
throw new Error('404 Файл не найден');
|
throw new Error('404 Файл не найден');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
async getInpxFile(params) {
|
async getInpxFile(params) {
|
||||||
let data = null;
|
let data = null;
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ function sleep(ms) {
|
|||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processLoop() {
|
||||||
|
return new Promise(resolve => setImmediate(resolve));
|
||||||
|
}
|
||||||
|
|
||||||
function versionText(config) {
|
function versionText(config) {
|
||||||
return `${config.name} v${config.version}, Node.js ${process.version}`;
|
return `${config.name} v${config.version}, Node.js ${process.version}`;
|
||||||
}
|
}
|
||||||
@@ -114,6 +118,7 @@ function toUnixPath(dir) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sleep,
|
sleep,
|
||||||
|
processLoop,
|
||||||
versionText,
|
versionText,
|
||||||
findFiles,
|
findFiles,
|
||||||
touchFile,
|
touchFile,
|
||||||
|
|||||||
@@ -13,15 +13,6 @@ module.exports = async(config) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//сохраним files
|
|
||||||
const filesDir = `${config.publicDir}/files`;
|
|
||||||
let tmpFilesDir = '';
|
|
||||||
if (await fs.pathExists(filesDir)) {
|
|
||||||
tmpFilesDir = `${config.dataDir}/files`;
|
|
||||||
if (!await fs.pathExists(tmpFilesDir))
|
|
||||||
await fs.move(filesDir, tmpFilesDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.remove(config.publicDir);
|
await fs.remove(config.publicDir);
|
||||||
|
|
||||||
//извлекаем новый webApp
|
//извлекаем новый webApp
|
||||||
@@ -35,10 +26,6 @@ module.exports = async(config) => {
|
|||||||
await zipReader.close();
|
await zipReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
//восстановим files
|
|
||||||
if (tmpFilesDir)
|
|
||||||
await fs.move(tmpFilesDir, filesDir);
|
|
||||||
|
|
||||||
await fs.writeFile(verFile, config.version);
|
await fs.writeFile(verFile, config.version);
|
||||||
await fs.remove(zipFile);
|
await fs.remove(zipFile);
|
||||||
};
|
};
|
||||||
@@ -2,7 +2,6 @@ const fs = require('fs-extra');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const compression = require('compression');
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const WebSocket = require ('ws');
|
const WebSocket = require ('ws');
|
||||||
|
|
||||||
@@ -50,9 +49,14 @@ async function init() {
|
|||||||
config.tempDir = `${config.dataDir}/tmp`;
|
config.tempDir = `${config.dataDir}/tmp`;
|
||||||
config.logDir = `${config.dataDir}/log`;
|
config.logDir = `${config.dataDir}/log`;
|
||||||
config.publicDir = `${config.dataDir}/public`;
|
config.publicDir = `${config.dataDir}/public`;
|
||||||
|
config.publicFilesDir = `${config.dataDir}/public-files`;
|
||||||
|
config.filesPathStatic = `/book`;
|
||||||
|
config.filesDir = `${config.publicFilesDir}${config.filesPathStatic}`;
|
||||||
|
|
||||||
configManager.config = config;
|
configManager.config = config;
|
||||||
|
|
||||||
await fs.ensureDir(config.dataDir);
|
await fs.ensureDir(config.dataDir);
|
||||||
|
await fs.ensureDir(config.filesDir);
|
||||||
await fs.ensureDir(config.tempDir);
|
await fs.ensureDir(config.tempDir);
|
||||||
await fs.emptyDir(config.tempDir);
|
await fs.emptyDir(config.tempDir);
|
||||||
|
|
||||||
@@ -114,7 +118,7 @@ async function init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
config.inpxFile = `${config.tempDir}/${utils.randomHexString(20)}`;
|
config.inpxFile = `${config.dataDir}/remote.inpx`;
|
||||||
const RemoteLib = require('./core/RemoteLib');//singleton
|
const RemoteLib = require('./core/RemoteLib');//singleton
|
||||||
const remoteLib = new RemoteLib(config);
|
const remoteLib = new RemoteLib(config);
|
||||||
await remoteLib.downloadInpxFile();
|
await remoteLib.downloadInpxFile();
|
||||||
@@ -147,8 +151,6 @@ async function main() {
|
|||||||
devModule.webpackDevMiddleware(app);
|
devModule.webpackDevMiddleware(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(compression({ level: 1 }));
|
|
||||||
//app.use(express.json({limit: `${config.maxPayloadSize}mb`}));
|
|
||||||
if (devModule)
|
if (devModule)
|
||||||
devModule.logQueries(app);
|
devModule.logQueries(app);
|
||||||
|
|
||||||
@@ -173,29 +175,42 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initStatic(app, config) {
|
function initStatic(app, config) {
|
||||||
const WebWorker = require('./core/WebWorker');//singleton
|
/*
|
||||||
const webWorker = new WebWorker(config);
|
publicFilesDir = `${config.dataDir}/public-files`;
|
||||||
|
filesPathStatic = `/book`;
|
||||||
|
filesDir = `${config.publicFilesDir}${config.filesPathStatic}`;
|
||||||
|
*/
|
||||||
|
const filesPath = `${config.filesPathStatic}/`;
|
||||||
//загрузка или восстановление файлов в /files, при необходимости
|
//загрузка или восстановление файлов в /files, при необходимости
|
||||||
app.use(async(req, res, next) => {
|
app.use(async(req, res, next) => {
|
||||||
if ((req.method !== 'GET' && req.method !== 'HEAD') ||
|
if ((req.method !== 'GET' && req.method !== 'HEAD') ||
|
||||||
!(req.path.indexOf('/files/') === 0)
|
!(req.path.indexOf(filesPath) === 0)
|
||||||
) {
|
) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const publicPath = `${config.publicDir}${req.path}`;
|
if (path.extname(req.path) == '.json')
|
||||||
|
return next();
|
||||||
|
|
||||||
|
const bookFile = `${config.publicFilesDir}${req.path}`;
|
||||||
|
const bookFileDesc = `${bookFile}.json`;
|
||||||
|
|
||||||
let downFileName = '';
|
let downFileName = '';
|
||||||
//восстановим
|
//восстановим из json-файла описания
|
||||||
try {
|
try {
|
||||||
if (!await fs.pathExists(publicPath)) {
|
if (await fs.pathExists(bookFile) && await fs.pathExists(bookFileDesc)) {
|
||||||
downFileName = await webWorker.restoreBookFile(publicPath);
|
await utils.touchFile(bookFile);
|
||||||
|
await utils.touchFile(bookFileDesc);
|
||||||
|
|
||||||
|
let desc = await fs.readFile(bookFileDesc, 'utf8');
|
||||||
|
desc = JSON.parse(desc);
|
||||||
|
downFileName = desc.downFileName;
|
||||||
} else {
|
} else {
|
||||||
downFileName = await webWorker.getDownFileName(publicPath);
|
await fs.remove(bookFile);
|
||||||
|
await fs.remove(bookFileDesc);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
//quiet
|
log(LM_ERR, e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downFileName)
|
if (downFileName)
|
||||||
@@ -205,20 +220,16 @@ function initStatic(app, config) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//заголовки при отдаче
|
//заголовки при отдаче
|
||||||
const filesDir = utils.toUnixPath(`${config.publicDir}/files`);
|
app.use(config.filesPathStatic, express.static(config.filesDir, {
|
||||||
app.use(express.static(config.publicDir, {
|
setHeaders: (res) => {
|
||||||
setHeaders: (res, filePath) => {
|
if (res.downFileName) {
|
||||||
//res.set('Cache-Control', 'no-cache');
|
|
||||||
//res.set('Expires', '-1');
|
|
||||||
|
|
||||||
if (utils.toUnixPath(path.dirname(filePath)) == filesDir) {
|
|
||||||
res.set('Content-Encoding', 'gzip');
|
res.set('Content-Encoding', 'gzip');
|
||||||
|
res.set('Content-Disposition', `inline; filename*=UTF-8''${encodeURIComponent(res.downFileName)}`);
|
||||||
if (res.downFileName)
|
|
||||||
res.set('Content-Disposition', `inline; filename*=UTF-8''${encodeURIComponent(res.downFileName)}`);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
app.use(express.static(config.publicDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
(async() => {
|
(async() => {
|
||||||
@@ -226,10 +237,11 @@ function initStatic(app, config) {
|
|||||||
await init();
|
await init();
|
||||||
await main();
|
await main();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
const mes = (branch == 'development' ? e.stack : e.message);
|
||||||
if (log)
|
if (log)
|
||||||
log(LM_FATAL, (branch == 'development' ? e.stack : e.message));
|
log(LM_FATAL, mes);
|
||||||
else
|
else
|
||||||
console.error(branch == 'development' ? e.stack : e.message);
|
console.error(mes);
|
||||||
|
|
||||||
ayncExit.exit(1);
|
ayncExit.exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user