Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc35a5aa97 | ||
|
|
d52d9d7f20 | ||
|
|
a3b83f93c3 | ||
|
|
2efdc6b0aa | ||
|
|
1e7d81b181 | ||
|
|
bbf7b43aa3 | ||
|
|
5aefa9e558 | ||
|
|
605aba7a05 | ||
|
|
5a43cd0e46 | ||
|
|
307b9adfa3 | ||
|
|
85a23578e7 | ||
|
|
db0b3c8c62 | ||
|
|
e820c82c56 | ||
|
|
ac29dbebba | ||
|
|
84843fb6bd | ||
|
|
74ece78175 | ||
|
|
b2fcf8d043 | ||
|
|
9ce33715d2 | ||
|
|
76fc64c1b7 | ||
|
|
b0edc3561e |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,3 +1,15 @@
|
|||||||
|
1.5.6 / 2024-03-25
|
||||||
|
|
||||||
|
- Добавлен вывод version.info в статистику по коллекции (#27)
|
||||||
|
- Убрано (по умолчанию) ежеминутное журналирование статистики сервера. В конфиг добавлен параметр logServerStats (#26)
|
||||||
|
- В конфиг добавлен параметр logQueries для журналирования запросов и времени их выполнения
|
||||||
|
- Добавлена расшифровка имен жанров в информации о книге(#24)
|
||||||
|
|
||||||
|
1.5.5 / 2023-04-25
|
||||||
|
|
||||||
|
- Улучшение работы с inpx: теперь понимает zip-архивы, вложенные в каталоги (библиотека Траума)
|
||||||
|
- Улучшение работы с zip-файлами: теперь понимает кодировку cp866 в именах файлов
|
||||||
|
|
||||||
1.5.4 / 2023-04-12
|
1.5.4 / 2023-04-12
|
||||||
|
|
||||||
- Добавлена возможность поиска по типу файла
|
- Добавлена возможность поиска по типу файла
|
||||||
|
|||||||
@@ -111,6 +111,12 @@ Options:
|
|||||||
// включить(true)/выключить(false) журналирование
|
// включить(true)/выключить(false) журналирование
|
||||||
"loggingEnabled": true,
|
"loggingEnabled": true,
|
||||||
|
|
||||||
|
// включить/выключить ежеминутный вывод в лог memUsage и loadAvg
|
||||||
|
"logServerStats": false,
|
||||||
|
|
||||||
|
// включить/выключить вывод в лог запросов и времени их выполнения
|
||||||
|
"logQueries": false,
|
||||||
|
|
||||||
// максимальный размер кеша каждой таблицы в БД, в блоках (требуется примерно 1-10Мб памяти на один блок)
|
// максимальный размер кеша каждой таблицы в БД, в блоках (требуется примерно 1-10Мб памяти на один блок)
|
||||||
// если надо кешировать всю БД, можно поставить значение от 1000 и больше
|
// если надо кешировать всю БД, можно поставить значение от 1000 и больше
|
||||||
"dbCacheSize": 5,
|
"dbCacheSize": 5,
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ class BookInfoDialog {
|
|||||||
_props = {
|
_props = {
|
||||||
modelValue: Boolean,
|
modelValue: Boolean,
|
||||||
bookInfo: Object,
|
bookInfo: Object,
|
||||||
|
genreMap: Object,
|
||||||
};
|
};
|
||||||
|
|
||||||
dialogVisible = false;
|
dialogVisible = false;
|
||||||
@@ -169,6 +170,19 @@ class BookInfoDialog {
|
|||||||
return `${size.toFixed(1)} ${unit}`;
|
return `${size.toFixed(1)} ${unit}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convertGenres(genreArr) {
|
||||||
|
let result = [];
|
||||||
|
if (genreArr) {
|
||||||
|
for (const genre of genreArr) {
|
||||||
|
const g = genre.trim();
|
||||||
|
const name = this.genreMap.get(g);
|
||||||
|
result.push(name ? name : g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.join(', ');
|
||||||
|
}
|
||||||
|
|
||||||
get inpx() {
|
get inpx() {
|
||||||
const mapping = [
|
const mapping = [
|
||||||
{name: 'fileInfo', label: 'Информация о файле', value: [
|
{name: 'fileInfo', label: 'Информация о файле', value: [
|
||||||
@@ -211,6 +225,9 @@ class BookInfoDialog {
|
|||||||
if (nodePath == 'titleInfo/author')
|
if (nodePath == 'titleInfo/author')
|
||||||
return value.split(',').join(', ');
|
return value.split(',').join(', ');
|
||||||
|
|
||||||
|
if (nodePath == 'titleInfo/genre')
|
||||||
|
return this.convertGenres(value.split(','));
|
||||||
|
|
||||||
if (nodePath == 'titleInfo/librate' && !value)
|
if (nodePath == 'titleInfo/librate' && !value)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -279,11 +296,16 @@ class BookInfoDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const self = this;
|
||||||
this.fb2 = parser.bookInfoList(infoObj, {
|
this.fb2 = parser.bookInfoList(infoObj, {
|
||||||
valueToString(value, nodePath, origVTS) {//eslint-disable-line no-unused-vars
|
valueToString(value, nodePath, origVTS) {//eslint-disable-line no-unused-vars
|
||||||
if (nodePath == 'documentInfo/historyHtml' && value)
|
if (nodePath == 'documentInfo/historyHtml' && value)
|
||||||
return value.replace(/<p>/g, `<p class="p-history">`);
|
return value.replace(/<p>/g, `<p class="p-history">`);
|
||||||
|
|
||||||
|
if ((nodePath == 'titleInfo/genre' || nodePath == 'srcTitleInfo/genre') && value) {
|
||||||
|
return self.convertGenres(value);
|
||||||
|
}
|
||||||
|
|
||||||
return origVTS(value, nodePath);
|
return origVTS(value, nodePath);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -347,7 +347,7 @@
|
|||||||
<SelectLibRateDialog v-model="selectLibRateDialogVisible" v-model:librate="search.librate" />
|
<SelectLibRateDialog v-model="selectLibRateDialogVisible" v-model:librate="search.librate" />
|
||||||
<SelectDateDialog v-model="selectDateDialogVisible" v-model:date="search.date" />
|
<SelectDateDialog v-model="selectDateDialogVisible" v-model:date="search.date" />
|
||||||
<SelectExtDialog v-model="selectExtDialogVisible" v-model:ext="search.ext" :ext-list="extList" />
|
<SelectExtDialog v-model="selectExtDialogVisible" v-model:ext="search.ext" :ext-list="extList" />
|
||||||
<BookInfoDialog v-model="bookInfoDialogVisible" :book-info="bookInfo" />
|
<BookInfoDialog v-model="bookInfoDialogVisible" :book-info="bookInfo" :genre-map="genreMap" />
|
||||||
<SelectExtSearchDialog v-model="selectExtSearchDialogVisible" v-model:ext-search="extSearch" />
|
<SelectExtSearchDialog v-model="selectExtSearchDialogVisible" v-model:ext-search="extSearch" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -931,6 +931,10 @@ class Search {
|
|||||||
<b>collection.info:</b>
|
<b>collection.info:</b>
|
||||||
<pre>${inpxInfo.collection}</pre>
|
<pre>${inpxInfo.collection}</pre>
|
||||||
</div>
|
</div>
|
||||||
|
<div><hr/>
|
||||||
|
<b>version.info:</b>
|
||||||
|
<pre>${inpxInfo.version}</pre>
|
||||||
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
this.$root.stdDialog.alert(info, 'Статистика по коллекции', {iconName: 'la la-info-circle'});
|
this.$root.stdDialog.alert(info, 'Статистика по коллекции', {iconName: 'la la-info-circle'});
|
||||||
|
|||||||
7543
package-lock.json
generated
7543
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
58
package.json
58
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "inpx-web",
|
"name": "inpx-web",
|
||||||
"version": "1.5.4",
|
"version": "1.5.6",
|
||||||
"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",
|
||||||
@@ -25,38 +25,38 @@
|
|||||||
"assets": "dist/public.json"
|
"assets": "dist/public.json"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.20.5",
|
"@babel/core": "^7.24.3",
|
||||||
"@babel/eslint-parser": "^7.19.1",
|
"@babel/eslint-parser": "^7.24.1",
|
||||||
"@babel/eslint-plugin": "^7.19.1",
|
"@babel/eslint-plugin": "^7.23.5",
|
||||||
"@babel/plugin-proposal-decorators": "^7.20.5",
|
"@babel/plugin-proposal-decorators": "^7.24.1",
|
||||||
"@babel/preset-env": "^7.20.2",
|
"@babel/preset-env": "^7.24.3",
|
||||||
"@vue/compiler-sfc": "^3.2.22",
|
"@vue/compiler-sfc": "^3.2.22",
|
||||||
"babel-loader": "^9.1.0",
|
"babel-loader": "^9.1.3",
|
||||||
"copy-webpack-plugin": "^11.0.0",
|
"copy-webpack-plugin": "^11.0.0",
|
||||||
"css-loader": "^6.7.2",
|
"css-loader": "^6.10.0",
|
||||||
"css-minimizer-webpack-plugin": "^4.2.2",
|
"css-minimizer-webpack-plugin": "^4.2.2",
|
||||||
"eslint": "^8.28.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-vue": "^9.8.0",
|
"eslint-plugin-vue": "^9.23.0",
|
||||||
"html-webpack-plugin": "^5.5.0",
|
"html-webpack-plugin": "^5.6.0",
|
||||||
"mini-css-extract-plugin": "^2.7.1",
|
"mini-css-extract-plugin": "^2.8.1",
|
||||||
"pkg": "^5.8.0",
|
"pkg": "^5.8.1",
|
||||||
"showdown": "^2.1.0",
|
"showdown": "^2.1.0",
|
||||||
"terser-webpack-plugin": "^5.3.6",
|
"terser-webpack-plugin": "^5.3.10",
|
||||||
"vue-eslint-parser": "^9.1.0",
|
"vue-eslint-parser": "^9.4.2",
|
||||||
"vue-loader": "^17.0.1",
|
"vue-loader": "^17.4.2",
|
||||||
"vue-style-loader": "^4.1.3",
|
"vue-style-loader": "^4.1.3",
|
||||||
"webpack": "^5.75.0",
|
"webpack": "^5.91.0",
|
||||||
"webpack-cli": "^5.0.0",
|
"webpack-cli": "^5.1.4",
|
||||||
"webpack-dev-middleware": "^6.0.1",
|
"webpack-dev-middleware": "^6.1.2",
|
||||||
"webpack-hot-middleware": "^2.25.3",
|
"webpack-hot-middleware": "^2.26.1",
|
||||||
"webpack-merge": "^5.8.0"
|
"webpack-merge": "^5.10.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@quasar/extras": "^1.15.6",
|
"@quasar/extras": "^1.16.9",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"chardet": "^1.5.0",
|
"chardet": "^1.6.0",
|
||||||
"dayjs": "^1.11.6",
|
"dayjs": "^1.11.10",
|
||||||
"express": "^4.18.2",
|
"express": "^4.19.1",
|
||||||
"express-basic-auth": "^1.2.1",
|
"express-basic-auth": "^1.2.1",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"he": "^1.2.0",
|
"he": "^1.2.0",
|
||||||
@@ -64,15 +64,15 @@
|
|||||||
"jembadb": "^5.1.7",
|
"jembadb": "^5.1.7",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"minimist": "^1.2.7",
|
"minimist": "^1.2.8",
|
||||||
"node-stream-zip": "^1.15.0",
|
"node-stream-zip": "^1.15.0",
|
||||||
"quasar": "^2.10.2",
|
"quasar": "^2.15.1",
|
||||||
"safe-buffer": "^5.2.1",
|
"safe-buffer": "^5.2.1",
|
||||||
"vue": "^3.2.37",
|
"vue": "^3.2.37",
|
||||||
"vue-router": "^4.1.6",
|
"vue-router": "^4.3.0",
|
||||||
"vuex": "^4.1.0",
|
"vuex": "^4.1.0",
|
||||||
"vuex-persist": "^3.1.3",
|
"vuex-persist": "^3.1.3",
|
||||||
"ws": "^8.11.0",
|
"ws": "^8.16.0",
|
||||||
"yazl": "^2.5.1"
|
"yazl": "^2.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ module.exports = {
|
|||||||
extendedSearch: true,
|
extendedSearch: true,
|
||||||
bookReadLink: '',
|
bookReadLink: '',
|
||||||
loggingEnabled: true,
|
loggingEnabled: true,
|
||||||
|
logServerStats: false,
|
||||||
|
logQueries: false,
|
||||||
|
|
||||||
//поправить в случае, если были критические изменения в DbCreator или InpxParser
|
//поправить в случае, если были критические изменения в DbCreator или InpxParser
|
||||||
//иначе будет рассинхронизация по кешу между сервером и клиентом на уровне БД
|
//иначе будет рассинхронизация по кешу между сервером и клиентом на уровне БД
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ const propsToSave = [
|
|||||||
'extendedSearch',
|
'extendedSearch',
|
||||||
'bookReadLink',
|
'bookReadLink',
|
||||||
'loggingEnabled',
|
'loggingEnabled',
|
||||||
|
'logServerStats',
|
||||||
|
'logQueries',
|
||||||
'dbCacheSize',
|
'dbCacheSize',
|
||||||
'maxFilesDirSize',
|
'maxFilesDirSize',
|
||||||
'queryCacheEnabled',
|
'queryCacheEnabled',
|
||||||
|
|||||||
@@ -56,11 +56,12 @@ class WebSocketController {
|
|||||||
async onMessage(ws, message) {
|
async onMessage(ws, message) {
|
||||||
let req = {};
|
let req = {};
|
||||||
try {
|
try {
|
||||||
if (this.isDevelopment) {
|
if (this.isDevelopment || this.config.logQueries) {
|
||||||
log(`WebSocket-IN: ${message.substr(0, 4000)}`);
|
log(`WebSocket-IN: ${utils.cutString(message)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
req = JSON.parse(message);
|
req = JSON.parse(message);
|
||||||
|
req.__startTime = Date.now();
|
||||||
|
|
||||||
ws.lastActivity = Date.now();
|
ws.lastActivity = Date.now();
|
||||||
|
|
||||||
@@ -123,8 +124,9 @@ class WebSocketController {
|
|||||||
const message = JSON.stringify(r);
|
const message = JSON.stringify(r);
|
||||||
ws.send(message);
|
ws.send(message);
|
||||||
|
|
||||||
if (this.isDevelopment) {
|
if (this.isDevelopment || this.config.logQueries) {
|
||||||
log(`WebSocket-OUT: ${message.substr(0, 200)}`);
|
log(`WebSocket-OUT: ${utils.cutString(message)}`);
|
||||||
|
log(`${Date.now() - req.__startTime}ms`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const os = require('os');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const iconv = require('iconv-lite');
|
||||||
|
|
||||||
const ZipReader = require('./ZipReader');
|
const ZipReader = require('./ZipReader');
|
||||||
const WorkerState = require('./WorkerState');//singleton
|
const WorkerState = require('./WorkerState');//singleton
|
||||||
@@ -313,7 +314,7 @@ class WebWorker {
|
|||||||
|
|
||||||
let result;
|
let result;
|
||||||
const db = this.db;
|
const db = this.db;
|
||||||
if (!db.wwCache.genres) {
|
if (!db.wwCache.genreTree) {
|
||||||
const genres = _.cloneDeep(genreTree);
|
const genres = _.cloneDeep(genreTree);
|
||||||
const last = genres[genres.length - 1];
|
const last = genres[genres.length - 1];
|
||||||
|
|
||||||
@@ -361,22 +362,43 @@ class WebWorker {
|
|||||||
inpxHash: (config.inpxHash ? config.inpxHash : ''),
|
inpxHash: (config.inpxHash ? config.inpxHash : ''),
|
||||||
};
|
};
|
||||||
|
|
||||||
db.wwCache.genres = result;
|
db.wwCache.genreTree = result;
|
||||||
} else {
|
} else {
|
||||||
result = db.wwCache.genres;
|
result = db.wwCache.genreTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async extractBook(bookPath) {
|
async getGenreMap() {
|
||||||
|
this.checkMyState();
|
||||||
|
|
||||||
|
let result;
|
||||||
|
const db = this.db;
|
||||||
|
if (!db.wwCache.genreMap) {
|
||||||
|
const genreTree = await this.getGenreTree();
|
||||||
|
|
||||||
|
result = new Map();
|
||||||
|
for (const section of genreTree.genreTree) {
|
||||||
|
for (const g of section.value)
|
||||||
|
result.set(g.value, g.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.wwCache.genreMap = result;
|
||||||
|
} else {
|
||||||
|
result = db.wwCache.genreMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
async extractBook(libFolder, libFile) {
|
||||||
const outFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
|
const outFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
|
||||||
|
|
||||||
bookPath = bookPath.replace(/\\/g, '/').replace(/\/\//g, '/');
|
libFolder = libFolder.replace(/\\/g, '/').replace(/\/\//g, '/');
|
||||||
|
|
||||||
const i = bookPath.indexOf('/');
|
const folder = `${this.config.libDir}/${libFolder}`;
|
||||||
const folder = `${this.config.libDir}/${(i >= 0 ? bookPath.substring(0, i) : bookPath )}`;
|
const file = libFile;
|
||||||
const file = (i >= 0 ? bookPath.substring(i + 1) : '' );
|
|
||||||
|
|
||||||
const fullPath = `${folder}/${file}`;
|
const fullPath = `${folder}/${file}`;
|
||||||
|
|
||||||
@@ -390,6 +412,11 @@ class WebWorker {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await zipReader.extractToFile(file, outFile);
|
await zipReader.extractToFile(file, outFile);
|
||||||
|
|
||||||
|
if (!await fs.pathExists(outFile)) {//не удалось найти в архиве, попробуем имя файла в кодировке cp866
|
||||||
|
await zipReader.extractToFile(iconv.encode(file, 'cp866').toString(), outFile);
|
||||||
|
}
|
||||||
|
|
||||||
return outFile;
|
return outFile;
|
||||||
} finally {
|
} finally {
|
||||||
await zipReader.close();
|
await zipReader.close();
|
||||||
@@ -397,14 +424,14 @@ class WebWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async restoreBook(bookUid, bookPath, downFileName) {
|
async restoreBook(bookUid, libFolder, libFile, downFileName) {
|
||||||
const db = this.db;
|
const db = this.db;
|
||||||
|
|
||||||
let extractedFile = '';
|
let extractedFile = '';
|
||||||
let hash = '';
|
let hash = '';
|
||||||
|
|
||||||
if (!this.remoteLib) {
|
if (!this.remoteLib) {
|
||||||
extractedFile = await this.extractBook(bookPath);
|
extractedFile = await this.extractBook(libFolder, libFile);
|
||||||
hash = await utils.getFileHash(extractedFile, 'sha256', 'hex');
|
hash = await utils.getFileHash(extractedFile, 'sha256', 'hex');
|
||||||
} else {
|
} else {
|
||||||
hash = await this.remoteLib.downloadBook(bookUid);
|
hash = await this.remoteLib.downloadBook(bookUid);
|
||||||
@@ -424,7 +451,7 @@ class WebWorker {
|
|||||||
await utils.touchFile(bookFile);
|
await utils.touchFile(bookFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
await fs.writeFile(bookFileDesc, JSON.stringify({bookPath, downFileName}));
|
await fs.writeFile(bookFileDesc, JSON.stringify({libFolder, libFile, downFileName}));
|
||||||
} else {
|
} else {
|
||||||
if (extractedFile)
|
if (extractedFile)
|
||||||
await fs.remove(extractedFile);
|
await fs.remove(extractedFile);
|
||||||
@@ -437,8 +464,7 @@ class WebWorker {
|
|||||||
table: 'file_hash',
|
table: 'file_hash',
|
||||||
replace: true,
|
replace: true,
|
||||||
rows: [
|
rows: [
|
||||||
{id: bookPath, hash},
|
{id: bookUid, hash},
|
||||||
{id: hash, bookPath, downFileName}
|
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -452,7 +478,7 @@ class WebWorker {
|
|||||||
const db = this.db;
|
const db = this.db;
|
||||||
let link = '';
|
let link = '';
|
||||||
|
|
||||||
//найдем downFileName и bookPath
|
//найдем downFileName, libFolder, libFile
|
||||||
let rows = await db.select({table: 'book', where: `@@hash('_uid', ${db.esc(bookUid)})`});
|
let rows = await db.select({table: 'book', where: `@@hash('_uid', ${db.esc(bookUid)})`});
|
||||||
if (!rows.length)
|
if (!rows.length)
|
||||||
throw new Error('404 Файл не найден');
|
throw new Error('404 Файл не найден');
|
||||||
@@ -479,11 +505,12 @@ class WebWorker {
|
|||||||
if (downFileName.substring(downFileName.length - ext.length) != ext)
|
if (downFileName.substring(downFileName.length - ext.length) != ext)
|
||||||
downFileName += ext;
|
downFileName += ext;
|
||||||
|
|
||||||
const bookPath = `${book.folder}/${book.file}${ext}`;
|
const libFolder = book.folder;
|
||||||
|
const libFile = `${book.file}${ext}`;
|
||||||
|
|
||||||
//найдем хеш
|
//найдем хеш
|
||||||
rows = await db.select({table: 'file_hash', where: `@@id(${db.esc(bookPath)})`});
|
rows = await db.select({table: 'file_hash', where: `@@id(${db.esc(bookUid)})`});
|
||||||
if (rows.length) {//хеш найден по bookPath
|
if (rows.length) {//хеш найден по bookUid
|
||||||
const hash = rows[0].hash;
|
const hash = rows[0].hash;
|
||||||
const bookFile = `${this.config.bookDir}/${hash}`;
|
const bookFile = `${this.config.bookDir}/${hash}`;
|
||||||
const bookFileDesc = `${bookFile}.d.json`;
|
const bookFileDesc = `${bookFile}.d.json`;
|
||||||
@@ -494,13 +521,13 @@ class WebWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!link) {
|
if (!link) {
|
||||||
link = await this.restoreBook(bookUid, bookPath, downFileName)
|
link = await this.restoreBook(bookUid, libFolder, libFile, downFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!link)
|
if (!link)
|
||||||
throw new Error('404 Файл не найден');
|
throw new Error('404 Файл не найден');
|
||||||
|
|
||||||
return {link, bookPath, downFileName};
|
return {link, libFolder, libFile, downFileName};
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
log(LM_ERR, `getBookLink error: ${e.message}`);
|
log(LM_ERR, `getBookLink error: ${e.message}`);
|
||||||
if (e.message.indexOf('ENOENT') >= 0)
|
if (e.message.indexOf('ENOENT') >= 0)
|
||||||
@@ -599,16 +626,16 @@ class WebWorker {
|
|||||||
let loadAvg = os.loadavg();
|
let loadAvg = os.loadavg();
|
||||||
loadAvg = loadAvg.map(v => v.toFixed(2));
|
loadAvg = loadAvg.map(v => v.toFixed(2));
|
||||||
|
|
||||||
log(`Server info [ memUsage: ${memUsage.toFixed(2)}MB, loadAvg: (${loadAvg.join(', ')}) ]`);
|
log(`Server stats [ memUsage: ${memUsage.toFixed(2)}MB, loadAvg: (${loadAvg.join(', ')}) ]`);
|
||||||
|
|
||||||
if (this.config.server.ready)
|
|
||||||
log(`Server accessible at http://127.0.0.1:${this.config.server.port} (listening on ${this.config.server.host}:${this.config.server.port})`);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(LM_ERR, e.message);
|
log(LM_ERR, e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async periodicLogServerStats() {
|
async periodicLogServerStats() {
|
||||||
|
if (!this.config.logServerStats)
|
||||||
|
return;
|
||||||
|
|
||||||
while (1) {// eslint-disable-line
|
while (1) {// eslint-disable-line
|
||||||
this.logServerStats();
|
this.logServerStats();
|
||||||
await utils.sleep(60*1000);
|
await utils.sleep(60*1000);
|
||||||
|
|||||||
@@ -24,6 +24,19 @@ class BookPage extends BasePage {
|
|||||||
return `${size.toFixed(1)} ${unit}`;
|
return `${size.toFixed(1)} ${unit}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convertGenres(genreArr) {
|
||||||
|
let result = [];
|
||||||
|
if (genreArr) {
|
||||||
|
for (const genre of genreArr) {
|
||||||
|
const g = genre.trim();
|
||||||
|
const name = this.genreMap.get(g);
|
||||||
|
result.push(name ? name : g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.join(', ');
|
||||||
|
}
|
||||||
|
|
||||||
inpxInfo(bookRec) {
|
inpxInfo(bookRec) {
|
||||||
const mapping = [
|
const mapping = [
|
||||||
{name: 'fileInfo', label: 'Информация о файле', value: [
|
{name: 'fileInfo', label: 'Информация о файле', value: [
|
||||||
@@ -66,6 +79,9 @@ class BookPage extends BasePage {
|
|||||||
if (nodePath == 'titleInfo/author')
|
if (nodePath == 'titleInfo/author')
|
||||||
return value.split(',').join(', ');
|
return value.split(',').join(', ');
|
||||||
|
|
||||||
|
if (nodePath == 'titleInfo/genre')
|
||||||
|
return this.convertGenres(value.split(','));
|
||||||
|
|
||||||
if (nodePath == 'titleInfo/librate' && !value)
|
if (nodePath == 'titleInfo/librate' && !value)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -118,6 +134,7 @@ class BookPage extends BasePage {
|
|||||||
async body(req) {
|
async body(req) {
|
||||||
const result = {};
|
const result = {};
|
||||||
|
|
||||||
|
this.genreMap = await this.webWorker.getGenreMap();
|
||||||
result.link = this.baseLinks(req, true);
|
result.link = this.baseLinks(req, true);
|
||||||
|
|
||||||
const bookUid = req.query.uid;
|
const bookUid = req.query.uid;
|
||||||
@@ -183,7 +200,17 @@ class BookPage extends BasePage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ann = infoObj.titleInfo.annotationHtml || '';
|
ann = infoObj.titleInfo.annotationHtml || '';
|
||||||
const infoList = parser.bookInfoList(infoObj);
|
const self = this;
|
||||||
|
const infoList = parser.bookInfoList(infoObj, {
|
||||||
|
valueToString(value, nodePath, origVTS) {//eslint-disable-line no-unused-vars
|
||||||
|
if ((nodePath == 'titleInfo/genre' || nodePath == 'srcTitleInfo/genre') && value) {
|
||||||
|
return self.convertGenres(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return origVTS(value, nodePath);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
info += this.htmlInfo('Fb2 инфо', infoList);
|
info += this.htmlInfo('Fb2 инфо', infoList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,12 @@ module.exports = function(app, config) {
|
|||||||
if (config.opds.password) {
|
if (config.opds.password) {
|
||||||
if (!config.opds.user)
|
if (!config.opds.user)
|
||||||
throw new Error('User must not be empty if password set');
|
throw new Error('User must not be empty if password set');
|
||||||
|
/*
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
console.log(req.headers);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
*/
|
||||||
app.use(opdsPaths, basicAuth({
|
app.use(opdsPaths, basicAuth({
|
||||||
users: {[config.opds.user]: config.opds.password},
|
users: {[config.opds.user]: config.opds.password},
|
||||||
challenge: true,
|
challenge: true,
|
||||||
|
|||||||
@@ -196,6 +196,20 @@ function wordEnding(num, type = 0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cutString(data, len = 500) {
|
||||||
|
try {
|
||||||
|
if (!data)
|
||||||
|
return '';
|
||||||
|
|
||||||
|
if (typeof(data) !== 'string')
|
||||||
|
data = JSON.stringify(data);
|
||||||
|
|
||||||
|
return `${data.substring(0, len)}${data.length > len ? ' ...' : ''}`;
|
||||||
|
} catch (e) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sleep,
|
sleep,
|
||||||
processLoop,
|
processLoop,
|
||||||
@@ -216,4 +230,5 @@ module.exports = {
|
|||||||
makeValidFileName,
|
makeValidFileName,
|
||||||
makeValidFileNameOrEmpty,
|
makeValidFileNameOrEmpty,
|
||||||
wordEnding,
|
wordEnding,
|
||||||
|
cutString,
|
||||||
};
|
};
|
||||||
@@ -137,6 +137,18 @@ async function init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logQueries(app) {
|
||||||
|
app.use(function(req, res, next) {
|
||||||
|
const start = Date.now();
|
||||||
|
log(`${req.method} ${req.originalUrl} ${utils.cutString(req.body)}`);
|
||||||
|
//log(`${JSON.stringify(req.headers, null, 2)}`)
|
||||||
|
res.once('finish', () => {
|
||||||
|
log(`${Date.now() - start}ms`);
|
||||||
|
});
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const log = new (require('./core/AppLogger'))().log;//singleton
|
const log = new (require('./core/AppLogger'))().log;//singleton
|
||||||
|
|
||||||
@@ -168,6 +180,10 @@ async function main() {
|
|||||||
const { WebSocketController } = require('./controllers');
|
const { WebSocketController } = require('./controllers');
|
||||||
new WebSocketController(wss, webAccess, config);
|
new WebSocketController(wss, webAccess, config);
|
||||||
|
|
||||||
|
if (config.logQueries) {
|
||||||
|
logQueries(app);
|
||||||
|
}
|
||||||
|
|
||||||
if (devModule) {
|
if (devModule) {
|
||||||
devModule.logErrors(app);
|
devModule.logErrors(app);
|
||||||
} else {
|
} else {
|
||||||
@@ -179,7 +195,7 @@ async function main() {
|
|||||||
|
|
||||||
server.listen(config.server.port, config.server.host, () => {
|
server.listen(config.server.port, config.server.host, () => {
|
||||||
config.server.ready = true;
|
config.server.ready = true;
|
||||||
log(`Server ready`);
|
log(`Server accessible at http://127.0.0.1:${config.server.port} (listening on ${config.server.host}:${config.server.port})`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user