Compare commits

..

13 Commits
0.1.3 ... 0.1.4

Author SHA1 Message Date
Book Pauk
824fe68194 Merge branch 'release/0.1.4' 2019-02-13 18:05:16 +07:00
Book Pauk
b056feda59 Версия 0.1.4 2019-02-13 18:04:54 +07:00
Book Pauk
32635dedb0 Добавил сохранение нужных настроек 2019-02-13 18:02:08 +07:00
Book Pauk
835f9374f6 Добавил использование на клиенте настройки maxUploadFileSize 2019-02-13 17:58:44 +07:00
Book Pauk
edece5e17f Вынес ограничения размеров файлов и директорий в настройки 2019-02-13 17:54:41 +07:00
Book Pauk
298317d352 Подправил дефолтный конфиг 2019-02-13 17:45:22 +07:00
Book Pauk
c7637eb941 Добавил сохранение и загрузку конфига 2019-02-13 17:43:13 +07:00
Book Pauk
c8f9e0ac9d Добавил пакет minimist 2019-02-13 17:41:41 +07:00
Book Pauk
3e3f259920 Поправка бага 2019-02-13 16:41:30 +07:00
Book Pauk
c88baf3c2c Улучшение парсинга fb2 2019-02-13 14:56:54 +07:00
Book Pauk
0d27dabd62 Улучшение парсинга fb2 2019-02-13 14:49:51 +07:00
Book Pauk
5c29594b3d Добавил распознавание тега text-author 2019-02-13 14:14:34 +07:00
Book Pauk
1e71d0ae2f Merge tag '0.1.3' into develop
0.1.3
2019-02-13 13:46:07 +07:00
13 changed files with 136 additions and 77 deletions

View File

@@ -6,7 +6,7 @@ const api = axios.create({
class Misc { class Misc {
async loadConfig() { async loadConfig() {
const response = await api.post('/config', {params: ['name', 'version', 'mode']}); const response = await api.post('/config', {params: ['name', 'version', 'mode', 'maxUploadFileSize']});
return response.data; return response.data;
} }
} }

View File

@@ -1,7 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import {sleep} from '../share/utils'; import {sleep} from '../share/utils';
const maxFileUploadSize = 50*1024*1024;
const api = axios.create({ const api = axios.create({
baseURL: '/api/reader' baseURL: '/api/reader'
}); });
@@ -75,9 +74,11 @@ class Reader {
return await axios.get(url, options); return await axios.get(url, options);
} }
async uploadFile(file, callback) { async uploadFile(file, maxUploadFileSize, callback) {
if (file.size > maxFileUploadSize) if (!maxUploadFileSize)
throw new Error(`Размер файла превышает ${maxFileUploadSize} байт`); maxUploadFileSize = 10*1024*1024;
if (file.size > maxUploadFileSize)
throw new Error(`Размер файла превышает ${maxUploadFileSize} байт`);
let formData = new FormData(); let formData = new FormData();
formData.append('file', file); formData.append('file', file);

View File

@@ -168,6 +168,7 @@ class Reader extends Vue {
this.commit = this.$store.commit; this.commit = this.$store.commit;
this.dispatch = this.$store.dispatch; this.dispatch = this.$store.dispatch;
this.reader = this.$store.state.reader; this.reader = this.$store.state.reader;
this.config = this.$store.state.config;
this.$root.addKeyHook(this.keyHook); this.$root.addKeyHook(this.keyHook);
@@ -179,7 +180,7 @@ class Reader extends Vue {
this.debouncedSetRecentBook = _.debounce(async(newValue) => { this.debouncedSetRecentBook = _.debounce(async(newValue) => {
const recent = this.mostRecentBook(); const recent = this.mostRecentBook();
if (recent && recent.bookPos != newValue) { if (recent && (recent.bookPos != newValue || recent.bookPosSeen !== this.bookPosSeen)) {
await bookManager.setRecentBook(Object.assign({}, recent, {bookPos: newValue, bookPosSeen: this.bookPosSeen})); await bookManager.setRecentBook(Object.assign({}, recent, {bookPos: newValue, bookPosSeen: this.bookPosSeen}));
if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue)) if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue))
@@ -713,7 +714,7 @@ class Reader extends Vue {
progress.show(); progress.show();
progress.setState({state: 'upload'}); progress.setState({state: 'upload'});
const url = await readerApi.uploadFile(opts.file, (state) => { const url = await readerApi.uploadFile(opts.file, this.config.maxUploadFileSize, (state) => {
progress.setState(state); progress.setState(state);
}); });

View File

@@ -45,10 +45,13 @@ const minLayoutWidth = 100;
export default @Component({ export default @Component({
watch: { watch: {
bookPos: function(newValue) { bookPos: function() {
this.$emit('book-pos-changed', {bookPos: newValue, bookPosSeen: this.bookPosSeen}); this.$emit('book-pos-changed', {bookPos: this.bookPos, bookPosSeen: this.bookPosSeen});
this.draw(); this.draw();
}, },
bookPosSeen: function() {
this.$emit('book-pos-changed', {bookPos: this.bookPos, bookPosSeen: this.bookPosSeen});
},
settings: function() { settings: function() {
this.debouncedLoadSettings(); this.debouncedLoadSettings();
}, },
@@ -69,6 +72,7 @@ class TextPage extends Vue {
lastBook = null; lastBook = null;
bookPos = 0; bookPos = 0;
bookPosSeen = null;
fontStyle = null; fontStyle = null;
fontSize = null; fontSize = null;

View File

@@ -63,7 +63,8 @@ export default class BookParser {
const growParagraph = (text, len) => { const growParagraph = (text, len) => {
if (paraIndex < 0) { if (paraIndex < 0) {
newParagraph(text, len); newParagraph(' ', 1);
growParagraph(text, len);
return; return;
} }
@@ -96,55 +97,63 @@ export default class BookParser {
tag = elemName; tag = elemName;
path += '/' + elemName; path += '/' + elemName;
if ((tag == 'p' || tag == 'empty-line' || tag == 'v') && path.indexOf('/fictionbook/body/section') == 0) { if (path.indexOf('/fictionbook/body') == 0) {
newParagraph(' ', 1); if (tag == 'title') {
} newParagraph(' ', 1);
bold = true;
center = true;
}
if (tag == 'emphasis' || tag == 'strong') { if (tag == 'emphasis' || tag == 'strong') {
growParagraph(`<${tag}>`, 0); growParagraph(`<${tag}>`, 0);
} }
if (tag == 'title') { if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) {
newParagraph(' ', 1); newParagraph(' ', 1);
bold = true; }
center = true;
}
if (tag == 'subtitle') { if (tag == 'subtitle') {
newParagraph(' ', 1); newParagraph(' ', 1);
bold = true; bold = true;
} }
if (tag == 'epigraph') { if (tag == 'epigraph') {
italic = true; italic = true;
} }
if (tag == 'stanza') { if (tag == 'poem') {
newParagraph(' ', 1); newParagraph(' ', 1);
}
if (tag == 'text-author') {
newParagraph(' <s> <s> <s> ', 4);
}
} }
}; };
const onEndNode = (elemName) => {// eslint-disable-line no-unused-vars const onEndNode = (elemName) => {// eslint-disable-line no-unused-vars
if (tag == elemName) { if (tag == elemName) {
if (tag == 'emphasis' || tag == 'strong') { if (path.indexOf('/fictionbook/body') == 0) {
growParagraph(`</${tag}>`, 0); if (tag == 'title') {
} bold = false;
center = false;
}
if (tag == 'title') { if (tag == 'emphasis' || tag == 'strong') {
bold = false; growParagraph(`</${tag}>`, 0);
center = false; }
}
if (tag == 'subtitle') { if (tag == 'subtitle') {
bold = false; bold = false;
} }
if (tag == 'epigraph') { if (tag == 'epigraph') {
italic = false; italic = false;
} }
if (tag == 'stanza') { if (tag == 'stanza') {
newParagraph(' ', 1); newParagraph(' ', 1);
}
} }
path = path.substr(0, path.length - tag.length - 1); path = path.substr(0, path.length - tag.length - 1);
@@ -206,12 +215,12 @@ export default class BookParser {
let tOpen = (center ? '<center>' : ''); let tOpen = (center ? '<center>' : '');
tOpen += (bold ? '<strong>' : ''); tOpen += (bold ? '<strong>' : '');
tOpen += (italic ? '<emphasis>' : ''); tOpen += (italic ? '<emphasis>' : '');
let tClose = (center ? '</center>' : ''); let tClose = (italic ? '</emphasis>' : '');
tClose += (bold ? '</strong>' : ''); tClose += (bold ? '</strong>' : '');
tClose += (italic ? '</emphasis>' : ''); tClose += (center ? '</center>' : '');
if (path.indexOf('/fictionbook/body/title') == 0) { if (path.indexOf('/fictionbook/body/title') == 0) {
newParagraph(`${tOpen}${text}${tClose}`, text.length, true); growParagraph(`${tOpen}${text}${tClose}`, text.length, true);
} }
if (path.indexOf('/fictionbook/body/section') == 0) { if (path.indexOf('/fictionbook/body/section') == 0) {

15
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "Liberama", "name": "Liberama",
"version": "0.1.0", "version": "0.1.3",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@@ -6501,9 +6501,9 @@
} }
}, },
"minimist": { "minimist": {
"version": "0.0.8", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
@@ -6567,6 +6567,13 @@
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
},
"dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
}
} }
}, },
"move-concurrently": { "move-concurrently": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "Liberama", "name": "Liberama",
"version": "0.1.3", "version": "0.1.4",
"engines": { "engines": {
"node": ">=10.0.0" "node": ">=10.0.0"
}, },
@@ -70,6 +70,7 @@
"iconv-lite": "^0.4.24", "iconv-lite": "^0.4.24",
"localforage": "^1.7.3", "localforage": "^1.7.3",
"lodash": "^4.17.11", "lodash": "^4.17.11",
"minimist": "^1.2.0",
"multer": "^1.4.1", "multer": "^1.4.1",
"path-browserify": "^1.0.0", "path-browserify": "^1.0.0",
"sql-template-strings": "^2.2.2", "sql-template-strings": "^2.2.2",

View File

@@ -17,6 +17,10 @@ module.exports = {
dbFileName: 'db.sqlite', dbFileName: 'db.sqlite',
loggingEnabled: true, loggingEnabled: true,
maxUploadFileSize: 50*1024*1024,//50Мб
maxTempPublicDirSize: 512*1024*1024,//512Мб
maxUploadPublicDirSize: 200*1024*1024,//100Мб
servers: [ servers: [
{ {
serverName: '1', serverName: '1',
@@ -24,12 +28,6 @@ module.exports = {
ip: '0.0.0.0', ip: '0.0.0.0',
port: '33080', port: '33080',
}, },
{
serverName: '2',
mode: 'omnireader',
ip: '0.0.0.0',
port: '33081',
},
], ],
}; };

View File

@@ -0,0 +1,36 @@
const fs = require('fs-extra');
const _ = require('lodash');
const propsToSave = [
'maxUploadFileSize',
'maxTempPublicDirSize',
'maxUploadPublicDirSize',
'servers',
];
async function load(config, configFilename) {
if (!configFilename) {
configFilename = `${config.dataDir}/config.json`;
if (!await fs.pathExists(configFilename)) {
save(config);
return;
}
}
const data = await fs.readFile(configFilename, 'utf8');
Object.assign(config, JSON.parse(data));
}
async function save(config) {
const configFilename = `${config.dataDir}/config.json`;
const dataToSave = _.pick(config, propsToSave);
await fs.writeFile(configFilename, JSON.stringify(dataToSave, null, 4));
}
module.exports = {
load,
save
};

View File

@@ -19,12 +19,6 @@ module.exports = Object.assign({}, base, {
ip: '0.0.0.0', ip: '0.0.0.0',
port: '44080', port: '44080',
}, },
{
serverName: '2',
mode: 'omnireader',
ip: '0.0.0.0',
port: '44081',
},
], ],
} }

View File

@@ -8,8 +8,6 @@ const FileDecompressor = require('./FileDecompressor');
const BookConverter = require('./BookConverter'); const BookConverter = require('./BookConverter');
const utils = require('./utils'); const utils = require('./utils');
const maxTempPublicDirSize = 512*1024*1024;//512Мб
const maxUploadDirSize = 200*1024*1024;//100Мб
let singleCleanExecute = false; let singleCleanExecute = false;
class ReaderWorker { class ReaderWorker {
@@ -27,8 +25,8 @@ class ReaderWorker {
this.bookConverter = new BookConverter(); this.bookConverter = new BookConverter();
if (!singleCleanExecute) { if (!singleCleanExecute) {
this.periodicCleanDir(this.config.tempPublicDir, maxTempPublicDirSize, 60*60*1000);//1 раз в час this.periodicCleanDir(this.config.tempPublicDir, this.config.maxTempPublicDirSize, 60*60*1000);//1 раз в час
this.periodicCleanDir(this.config.uploadDir, maxUploadDirSize, 60*60*1000);//1 раз в час this.periodicCleanDir(this.config.uploadDir, this.config.maxUploadPublicDirSize, 60*60*1000);//1 раз в час
singleCleanExecute = true; singleCleanExecute = true;
} }
} }

View File

@@ -1,9 +1,11 @@
const config = require('./config'); const config = require('./config');
const {initLogger, getLog} = require('./core/getLogger'); const {initLogger, getLog} = require('./core/getLogger');
initLogger(config); initLogger(config);
const log = getLog(); const log = getLog();
const configSaver = require('./config/configSaver');
const argv = require('minimist')(process.argv.slice(2));
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
const express = require('express'); const express = require('express');
@@ -23,15 +25,17 @@ async function init() {
await fs.remove(appDir); await fs.remove(appDir);
await fs.move(appNewDir, appDir); await fs.move(appNewDir, appDir);
} }
//загружаем конфиг из файла
await configSaver.load(config, argv.config);
} }
async function main() { async function main() {
const connPool = new SqliteConnectionPool(20, config);
log('Initializing'); log('Initializing');
await init(); await init();
log('Opening database'); log('Opening database');
const connPool = new SqliteConnectionPool(20, config);
await connPool.init(); await connPool.init();
//servers //servers
@@ -42,7 +46,7 @@ async function main() {
let devModule = undefined; let devModule = undefined;
if (serverConfig.branch == 'development') { if (serverConfig.branch == 'development') {
const devFileName = './dev.js'; //ignored by pkg -50Mb executable size const devFileName = './dev.js'; //require ignored by pkg -50Mb executable size
devModule = require(devFileName); devModule = require(devFileName);
devModule.webpackDevMiddleware(app); devModule.webpackDevMiddleware(app);
} }
@@ -80,4 +84,12 @@ async function main() {
} }
} }
main();
(async() => {
try {
await main();
} catch (e) {
console.error(e.message);
process.exit(1);
}
})();

View File

@@ -2,8 +2,6 @@ const c = require('./controllers');
const utils = require('./core/utils'); const utils = require('./core/utils');
const multer = require('multer'); const multer = require('multer');
const maxUploadSize = 50*1024*1024;
function initRoutes(app, connPool, config) { function initRoutes(app, connPool, config) {
const misc = new c.MiscController(connPool, config); const misc = new c.MiscController(connPool, config);
const reader = new c.ReaderController(connPool, config); const reader = new c.ReaderController(connPool, config);
@@ -22,7 +20,7 @@ function initRoutes(app, connPool, config) {
cb(null, utils.randomHexString(30)); cb(null, utils.randomHexString(30));
} }
}); });
const upload = multer({ storage, limits: {fileSize: maxUploadSize} }); const upload = multer({ storage, limits: {fileSize: config.maxUploadFileSize} });
//routes //routes
const routes = [ const routes = [