Compare commits
177 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0341cc1630 | ||
|
|
d307d233f0 | ||
|
|
5931b9625b | ||
|
|
fb837f5b97 | ||
|
|
8cfe95b3cf | ||
|
|
5fd73ac1e1 | ||
|
|
b51a574038 | ||
|
|
51b39f0775 | ||
|
|
17c4f96c94 | ||
|
|
89bf907613 | ||
|
|
641d0e45fd | ||
|
|
b3e579d8b7 | ||
|
|
fcb61c89d5 | ||
|
|
3483d78c2c | ||
|
|
36b14d0b3a | ||
|
|
2f8b68ec62 | ||
|
|
cb65cac333 | ||
|
|
d12ffc3d0d | ||
|
|
921744167e | ||
|
|
ebd96c4759 | ||
|
|
dd9876fc43 | ||
|
|
e0de614f30 | ||
|
|
30260883fb | ||
|
|
91c331e5f3 | ||
|
|
db803bcd23 | ||
|
|
cd482ea890 | ||
|
|
a2497c939a | ||
|
|
2e5249d30b | ||
|
|
b1d60c19d5 | ||
|
|
d28a82b33a | ||
|
|
787821f64b | ||
|
|
612b15fecc | ||
|
|
d88d5a1352 | ||
|
|
8584ddd00e | ||
|
|
4f572b5a10 | ||
|
|
90a0882c59 | ||
|
|
759344bb34 | ||
|
|
c9b65a3c43 | ||
|
|
b06e600946 | ||
|
|
2777751e54 | ||
|
|
b4493b2e8d | ||
|
|
55d5f6524d | ||
|
|
c7d376adf2 | ||
|
|
56bf69a770 | ||
|
|
22f9287d8b | ||
|
|
ca47d9272c | ||
|
|
0d61f5523a | ||
|
|
863ea9089a | ||
|
|
ad2af95ebd | ||
|
|
d65092c203 | ||
|
|
7982698880 | ||
|
|
afbdff8a88 | ||
|
|
cec07208ac | ||
|
|
c1b82d0fd2 | ||
|
|
c69e9d4b69 | ||
|
|
cc66c7f5ce | ||
|
|
7d3a689577 | ||
|
|
7b5915cdf7 | ||
|
|
5cc99366ef | ||
|
|
73289543e7 | ||
|
|
716b8b5b9a | ||
|
|
c4f6c9383c | ||
|
|
7d77d478c1 | ||
|
|
572c0d0717 | ||
|
|
b786b7b2d6 | ||
|
|
3253858c7f | ||
|
|
a5fe61078d | ||
|
|
528adae3d0 | ||
|
|
d3ff0edbff | ||
|
|
61cfee222f | ||
|
|
a96eb50784 | ||
|
|
8219e19c1b | ||
|
|
3d56a6915f | ||
|
|
4d6502f5e2 | ||
|
|
f0f245884f | ||
|
|
815f9178bf | ||
|
|
2df88f4280 | ||
|
|
156a1b4aa8 | ||
|
|
962eda7860 | ||
|
|
954ce9e85c | ||
|
|
ff27ddd442 | ||
|
|
f9cc2ad70a | ||
|
|
4bcd45a795 | ||
|
|
9e7ccd6e20 | ||
|
|
631c5930e9 | ||
|
|
0ddb182642 | ||
|
|
de2f0e74c8 | ||
|
|
ad4ee6ccc9 | ||
|
|
1670df02db | ||
|
|
0268e647cd | ||
|
|
4b9315c13c | ||
|
|
14a9948dd2 | ||
|
|
060ec98b0c | ||
|
|
9c1efe381e | ||
|
|
6a1b052d16 | ||
|
|
d6151d541e | ||
|
|
3e90277e1e | ||
|
|
641cbdfe85 | ||
|
|
c36e9b36d8 | ||
|
|
ecc3acce93 | ||
|
|
33a2ca55f0 | ||
|
|
9d0bbec4b3 | ||
|
|
4de0b3cffd | ||
|
|
06221a474b | ||
|
|
e99a42b7af | ||
|
|
37822e8409 | ||
|
|
2e477e6c99 | ||
|
|
360ee98d8d | ||
|
|
69afd7720a | ||
|
|
a75590c493 | ||
|
|
2acb65f6b3 | ||
|
|
1e1a58b58c | ||
|
|
aeadb5aeb8 | ||
|
|
3e2f01d56d | ||
|
|
cad97e639a | ||
|
|
e2632f1802 | ||
|
|
9aa0bb2bde | ||
|
|
f015d5f7ed | ||
|
|
74f8f7f9a4 | ||
|
|
2598538de9 | ||
|
|
a78a00df2b | ||
|
|
92f6beb64e | ||
|
|
3920b71613 | ||
|
|
d661150665 | ||
|
|
ab29c80dab | ||
|
|
e5384e27e5 | ||
|
|
06cdc6eb63 | ||
|
|
da284c793e | ||
|
|
c2cef91eb3 | ||
|
|
19da1aff45 | ||
|
|
5f2206e766 | ||
|
|
e272308823 | ||
|
|
8491c40890 | ||
|
|
dfa7013cbd | ||
|
|
1a7ceb333d | ||
|
|
d3a30b87f4 | ||
|
|
dd61c04d63 | ||
|
|
5496e874c4 | ||
|
|
56d13288ff | ||
|
|
618111ab05 | ||
|
|
55d02495a3 | ||
|
|
83fc586e03 | ||
|
|
ae3dc9b22c | ||
|
|
12e0f9459b | ||
|
|
fd1dd54b99 | ||
|
|
32cbb2a82c | ||
|
|
048b7c08ca | ||
|
|
d98251e34a | ||
|
|
1eea4e8fc1 | ||
|
|
da330bc615 | ||
|
|
1134250954 | ||
|
|
d8fddd4128 | ||
|
|
42656cd690 | ||
|
|
746f9517d9 | ||
|
|
2a373de5f5 | ||
|
|
b507f00929 | ||
|
|
aea8a254bf | ||
|
|
4247665ba4 | ||
|
|
d59d0a6a42 | ||
|
|
8d40ed0bda | ||
|
|
67bc893e22 | ||
|
|
0f5d3b34a5 | ||
|
|
39b577e935 | ||
|
|
91380d2aed | ||
|
|
f995c24264 | ||
|
|
c7db0ec643 | ||
|
|
f9e000034f | ||
|
|
8ddd2d6290 | ||
|
|
f6c8666f06 | ||
|
|
1bf173fcae | ||
|
|
696866f065 | ||
|
|
c82283c7f0 | ||
|
|
0e62f25557 | ||
|
|
e2c51f44bf | ||
|
|
d4768392a6 | ||
|
|
580744819d | ||
|
|
959794de10 |
@@ -5,8 +5,7 @@ const stream = require('stream');
|
|||||||
const pipeline = util.promisify(stream.pipeline);
|
const pipeline = util.promisify(stream.pipeline);
|
||||||
|
|
||||||
const got = require('got');
|
const got = require('got');
|
||||||
const decompress = require('decompress');
|
const FileDecompressor = require('../server/core/FileDecompressor');
|
||||||
const decompressTargz = require('decompress-targz');
|
|
||||||
|
|
||||||
const distDir = path.resolve(__dirname, '../dist');
|
const distDir = path.resolve(__dirname, '../dist');
|
||||||
const publicDir = `${distDir}/tmp/public`;
|
const publicDir = `${distDir}/tmp/public`;
|
||||||
@@ -15,6 +14,8 @@ const outDir = `${distDir}/linux`;
|
|||||||
const tempDownloadDir = `${distDir}/tmp/download`;
|
const tempDownloadDir = `${distDir}/tmp/download`;
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
const decomp = new FileDecompressor();
|
||||||
|
|
||||||
await fs.emptyDir(outDir);
|
await fs.emptyDir(outDir);
|
||||||
// перемещаем public на место
|
// перемещаем public на место
|
||||||
if (await fs.pathExists(publicDir))
|
if (await fs.pathExists(publicDir))
|
||||||
@@ -32,11 +33,7 @@ async function main() {
|
|||||||
console.log(`done downloading ${sqliteRemoteUrl}`);
|
console.log(`done downloading ${sqliteRemoteUrl}`);
|
||||||
|
|
||||||
//распаковываем
|
//распаковываем
|
||||||
await decompress(`${tempDownloadDir}/sqlite.tar.gz`, `${tempDownloadDir}`, {
|
console.log(await decomp.unpackTarZZ(`${tempDownloadDir}/sqlite.tar.gz`, tempDownloadDir));
|
||||||
plugins: [
|
|
||||||
decompressTargz()
|
|
||||||
]
|
|
||||||
});
|
|
||||||
console.log('files decompressed');
|
console.log('files decompressed');
|
||||||
}
|
}
|
||||||
// копируем в дистрибутив
|
// копируем в дистрибутив
|
||||||
@@ -53,11 +50,7 @@ async function main() {
|
|||||||
console.log(`done downloading ${ipfsRemoteUrl}`);
|
console.log(`done downloading ${ipfsRemoteUrl}`);
|
||||||
|
|
||||||
//распаковываем
|
//распаковываем
|
||||||
await decompress(`${tempDownloadDir}/ipfs.tar.gz`, `${tempDownloadDir}`, {
|
console.log(await decomp.unpackTarZZ(`${tempDownloadDir}/ipfs.tar.gz`, tempDownloadDir));
|
||||||
plugins: [
|
|
||||||
decompressTargz()
|
|
||||||
]
|
|
||||||
});
|
|
||||||
console.log('files decompressed');
|
console.log('files decompressed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
build/win.js
13
build/win.js
@@ -5,8 +5,7 @@ const stream = require('stream');
|
|||||||
const pipeline = util.promisify(stream.pipeline);
|
const pipeline = util.promisify(stream.pipeline);
|
||||||
|
|
||||||
const got = require('got');
|
const got = require('got');
|
||||||
const decompress = require('decompress');
|
const FileDecompressor = require('../server/core/FileDecompressor');
|
||||||
const decompressTargz = require('decompress-targz');
|
|
||||||
|
|
||||||
const distDir = path.resolve(__dirname, '../dist');
|
const distDir = path.resolve(__dirname, '../dist');
|
||||||
const publicDir = `${distDir}/tmp/public`;
|
const publicDir = `${distDir}/tmp/public`;
|
||||||
@@ -15,6 +14,8 @@ const outDir = `${distDir}/win`;
|
|||||||
const tempDownloadDir = `${distDir}/tmp/download`;
|
const tempDownloadDir = `${distDir}/tmp/download`;
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
const decomp = new FileDecompressor();
|
||||||
|
|
||||||
await fs.emptyDir(outDir);
|
await fs.emptyDir(outDir);
|
||||||
// перемещаем public на место
|
// перемещаем public на место
|
||||||
if (await fs.pathExists(publicDir))
|
if (await fs.pathExists(publicDir))
|
||||||
@@ -32,11 +33,7 @@ async function main() {
|
|||||||
console.log(`done downloading ${sqliteRemoteUrl}`);
|
console.log(`done downloading ${sqliteRemoteUrl}`);
|
||||||
|
|
||||||
//распаковываем
|
//распаковываем
|
||||||
await decompress(`${tempDownloadDir}/sqlite.tar.gz`, `${tempDownloadDir}`, {
|
console.log(await decomp.unpackTarZZ(`${tempDownloadDir}/sqlite.tar.gz`, tempDownloadDir));
|
||||||
plugins: [
|
|
||||||
decompressTargz()
|
|
||||||
]
|
|
||||||
});
|
|
||||||
console.log('files decompressed');
|
console.log('files decompressed');
|
||||||
}
|
}
|
||||||
// копируем в дистрибутив
|
// копируем в дистрибутив
|
||||||
@@ -53,7 +50,7 @@ async function main() {
|
|||||||
console.log(`done downloading ${ipfsRemoteUrl}`);
|
console.log(`done downloading ${ipfsRemoteUrl}`);
|
||||||
|
|
||||||
//распаковываем
|
//распаковываем
|
||||||
await decompress(`${tempDownloadDir}/ipfs.zip`, `${tempDownloadDir}`);
|
console.log(await decomp.unpack(`${tempDownloadDir}/ipfs.zip`, tempDownloadDir));
|
||||||
console.log('files decompressed');
|
console.log('files decompressed');
|
||||||
}
|
}
|
||||||
// копируем в дистрибутив
|
// копируем в дистрибутив
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ const api = axios.create({
|
|||||||
|
|
||||||
class Misc {
|
class Misc {
|
||||||
async loadConfig() {
|
async loadConfig() {
|
||||||
const response = await api.post('/config', {params: ['name', 'version', 'mode', 'maxUploadFileSize', 'branch']});
|
const response = await api.post('/config', {params: [
|
||||||
|
'name', 'version', 'mode', 'maxUploadFileSize', 'useExternalBookConverter', 'branch',
|
||||||
|
]});
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const workerApi = axios.create({
|
|||||||
|
|
||||||
class Reader {
|
class Reader {
|
||||||
async loadBook(url, callback) {
|
async loadBook(url, callback) {
|
||||||
const refreshPause = 200;
|
const refreshPause = 300;
|
||||||
if (!callback) callback = () => {};
|
if (!callback) callback = () => {};
|
||||||
|
|
||||||
let response = await api.post('/load-book', {type: 'url', url});
|
let response = await api.post('/load-book', {type: 'url', url});
|
||||||
@@ -44,13 +44,14 @@ class Reader {
|
|||||||
await sleep(refreshPause);
|
await sleep(refreshPause);
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
if (i > 30*1000/refreshPause) {//30 сек ждем телодвижений воркера
|
if (i > 120*1000/refreshPause) {//2 мин ждем телодвижений воркера
|
||||||
throw new Error('Слишком долгое время ожидания');
|
throw new Error('Слишком долгое время ожидания');
|
||||||
}
|
}
|
||||||
//проверка воркера
|
//проверка воркера
|
||||||
const prevProgress = response.data.progress;
|
const prevProgress = response.data.progress;
|
||||||
|
const prevState = response.data.state;
|
||||||
response = await workerApi.post('/get-state', {workerId});
|
response = await workerApi.post('/get-state', {workerId});
|
||||||
i = (prevProgress != response.data.progress ? 1 : i);
|
i = (prevProgress != response.data.progress || prevState != response.data.state ? 1 : i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<p>В качестве URL можно задавать html-страничку с книгой, либо прямую ссылку
|
<p>В качестве URL можно задавать html-страничку с книгой, либо прямую ссылку
|
||||||
на файл из онлайн-библиотеки (например, скопировав адрес ссылки или кнопки "скачать fb2").</p>
|
на файл из онлайн-библиотеки (например, скопировав адрес ссылки или кнопки "скачать fb2").</p>
|
||||||
<p>Поддерживаемые форматы: <strong>html, txt, fb2, fb2.zip</strong></p>
|
<p>Поддерживаемые форматы: <b>fb2, fb2.zip, html, txt</b> и другие</p>
|
||||||
|
|
||||||
<div v-html="automationHtml"></div>
|
<div v-html="automationHtml"></div>
|
||||||
<p>Связаться с разработчиком: <a href="mailto:bookpauk@gmail.com">bookpauk@gmail.com</a></p>
|
<p>Связаться с разработчиком: <a href="mailto:bookpauk@gmail.com">bookpauk@gmail.com</a></p>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li><b>F1, H</b> - открыть справку</li>
|
<li><b>F1, H</b> - открыть справку</li>
|
||||||
<li><b>Escape</b> - показать/скрыть страницу загрузки</li>
|
<li><b>Escape</b> - показать/скрыть страницу загрузки</li>
|
||||||
<li><b>Tab</b> - показать/скрыть панель управления</li>
|
<li><b>Tab, Q</b> - показать/скрыть панель управления</li>
|
||||||
<li><b>PageUp, Left, Shift+Space, Backspace</b> - страницу назад</li>
|
<li><b>PageUp, Left, Shift+Space, Backspace</b> - страницу назад</li>
|
||||||
<li><b>PageDown, Right, Space</b> - страницу вперед</li>
|
<li><b>PageDown, Right, Space</b> - страницу вперед</li>
|
||||||
<li><b>Home</b> - в начало книги</li>
|
<li><b>Home</b> - в начало книги</li>
|
||||||
|
|||||||
@@ -15,8 +15,14 @@
|
|||||||
border
|
border
|
||||||
:default-sort = "{prop: 'touchDateTime', order: 'descending'}"
|
:default-sort = "{prop: 'touchDateTime', order: 'descending'}"
|
||||||
:header-cell-style = "headerCellStyle"
|
:header-cell-style = "headerCellStyle"
|
||||||
|
:row-key = "rowKey"
|
||||||
>
|
>
|
||||||
|
|
||||||
|
<el-table-column
|
||||||
|
type="index"
|
||||||
|
width="35px"
|
||||||
|
>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
prop="touchDateTime"
|
prop="touchDateTime"
|
||||||
min-width="90px"
|
min-width="90px"
|
||||||
@@ -43,6 +49,7 @@
|
|||||||
placeholder="Найти"/-->
|
placeholder="Найти"/-->
|
||||||
<div class="el-input el-input--mini">
|
<div class="el-input el-input--mini">
|
||||||
<input class="el-input__inner"
|
<input class="el-input__inner"
|
||||||
|
ref="input"
|
||||||
placeholder="Найти"
|
placeholder="Найти"
|
||||||
style="margin: 0; padding: 0; vertical-align: bottom; margin-top: 20px; padding: 0 10px 0 10px"
|
style="margin: 0; padding: 0; vertical-align: bottom; margin-top: 20px; padding: 0 10px 0 10px"
|
||||||
:value="search" @input="search = $event.target.value"
|
:value="search" @input="search = $event.target.value"
|
||||||
@@ -118,9 +125,16 @@ class HistoryPage extends Vue {
|
|||||||
created() {
|
created() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mounted() {
|
init() {
|
||||||
this.updateTableData();
|
this.updateTableData();
|
||||||
this.mostRecentBook = bookManager.mostRecentBook();
|
this.mostRecentBook = bookManager.mostRecentBook();
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.$refs.input.focus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
rowKey(row) {
|
||||||
|
return row.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTableData() {
|
updateTableData() {
|
||||||
@@ -172,13 +186,15 @@ class HistoryPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const search = this.search;
|
const search = this.search;
|
||||||
this.tableData = result.filter(item => {
|
result = result.filter(item => {
|
||||||
return !search ||
|
return !search ||
|
||||||
item.touchTime.includes(search) ||
|
item.touchTime.includes(search) ||
|
||||||
item.touchDate.includes(search) ||
|
item.touchDate.includes(search) ||
|
||||||
item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
|
item.desc.title.toLowerCase().includes(search.toLowerCase()) ||
|
||||||
item.desc.author.toLowerCase().includes(search.toLowerCase())
|
item.desc.author.toLowerCase().includes(search.toLowerCase())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.tableData = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
headerCellStyle(cell) {
|
headerCellStyle(cell) {
|
||||||
@@ -210,7 +226,8 @@ class HistoryPage extends Vue {
|
|||||||
this.updateTableData();
|
this.updateTableData();
|
||||||
|
|
||||||
const newRecent = bookManager.mostRecentBook();
|
const newRecent = bookManager.mostRecentBook();
|
||||||
if (this.mostRecentBook != newRecent)
|
|
||||||
|
if (!(this.mostRecentBook && newRecent && this.mostRecentBook.key == newRecent.key))
|
||||||
this.$emit('load-book', newRecent);
|
this.$emit('load-book', newRecent);
|
||||||
|
|
||||||
this.mostRecentBook = newRecent;
|
this.mostRecentBook = newRecent;
|
||||||
|
|||||||
@@ -2,9 +2,12 @@
|
|||||||
<div ref="main" class="main">
|
<div ref="main" class="main">
|
||||||
<div class="part">
|
<div class="part">
|
||||||
<span class="greeting bold-font">{{ title }}</span>
|
<span class="greeting bold-font">{{ title }}</span>
|
||||||
|
<div class="space"></div>
|
||||||
<span class="greeting">Добро пожаловать!</span>
|
<span class="greeting">Добро пожаловать!</span>
|
||||||
<span class="greeting">Поддерживаются форматы: fb2, fb2.zip, html, txt</span>
|
<span class="greeting">Поддерживаются форматы: <b>fb2, html, txt</b> и сжатие: <b>zip, bz2, gz</b></span>
|
||||||
|
<span v-if="isExternalConverter" class="greeting">...а также форматы: <b>rtf, doc, docx, pdf, epub, mobi</b></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="part center">
|
<div class="part center">
|
||||||
<el-input ref="input" placeholder="URL книги" v-model="bookUrl">
|
<el-input ref="input" placeholder="URL книги" v-model="bookUrl">
|
||||||
<el-button slot="append" icon="el-icon-check" @click="submitUrl"></el-button>
|
<el-button slot="append" icon="el-icon-check" @click="submitUrl"></el-button>
|
||||||
@@ -15,8 +18,9 @@
|
|||||||
Загрузить файл с диска
|
Загрузить файл с диска
|
||||||
</el-button>
|
</el-button>
|
||||||
<div class="space"></div>
|
<div class="space"></div>
|
||||||
<span v-if="config.mode == 'omnireader'" class="bottom-span clickable" @click="openComments">Комментарии</span>
|
<span v-if="mode == 'omnireader'" class="bottom-span clickable" @click="openComments">Комментарии</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="part bottom">
|
<div class="part bottom">
|
||||||
<span class="bottom-span clickable" @click="openHelp">Справка</span>
|
<span class="bottom-span clickable" @click="openHelp">Справка</span>
|
||||||
<span class="bottom-span clickable" @click="openDonate">Помочь проекту</span>
|
<span class="bottom-span clickable" @click="openDonate">Помочь проекту</span>
|
||||||
@@ -38,7 +42,6 @@ class LoaderPage extends Vue {
|
|||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
this.config = this.$store.state.config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
@@ -50,14 +53,22 @@ class LoaderPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get title() {
|
get title() {
|
||||||
if (this.config.mode == 'omnireader')
|
if (this.$store.state.config.mode == 'omnireader')
|
||||||
return 'Omni Reader - браузерная онлайн-читалка.';
|
return 'Omni Reader - браузерная онлайн-читалка.';
|
||||||
return 'Универсальная читалка книг и ресурсов интернета.';
|
return 'Универсальная читалка книг и ресурсов интернета.';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get mode() {
|
||||||
|
return this.$store.state.config.mode;
|
||||||
|
}
|
||||||
|
|
||||||
get version() {
|
get version() {
|
||||||
return `v${this.config.version}`;
|
return `v${this.$store.state.config.version}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isExternalConverter() {
|
||||||
|
return this.$store.state.config.useExternalBookConverter;
|
||||||
}
|
}
|
||||||
|
|
||||||
submitUrl() {
|
submitUrl() {
|
||||||
@@ -103,6 +114,13 @@ class LoaderPage extends Vue {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.type == 'keydown' && (document.activeElement !== input && event.code == 'KeyQ')) {
|
||||||
|
this.$emit('tool-bar-toggle');
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -112,6 +130,7 @@ class LoaderPage extends Vue {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
min-height: 340px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.part {
|
.part {
|
||||||
@@ -123,8 +142,8 @@ class LoaderPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.greeting {
|
.greeting {
|
||||||
font-size: 130%;
|
font-size: 120%;
|
||||||
line-height: 170%;
|
line-height: 160%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bold-font {
|
.bold-font {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
@stop-text-search="stopTextSearch">
|
@stop-text-search="stopTextSearch">
|
||||||
</SearchPage>
|
</SearchPage>
|
||||||
<CopyTextPage v-if="copyTextActive" ref="copyTextPage" @copy-text-toggle="copyTextToggle"></CopyTextPage>
|
<CopyTextPage v-if="copyTextActive" ref="copyTextPage" @copy-text-toggle="copyTextToggle"></CopyTextPage>
|
||||||
<HistoryPage v-if="historyActive" ref="historyPage" @load-book="loadBook" @history-toggle="historyToggle"></HistoryPage>
|
<HistoryPage v-show="historyActive" ref="historyPage" @load-book="loadBook" @history-toggle="historyToggle"></HistoryPage>
|
||||||
<SettingsPage v-if="settingsActive" ref="settingsPage" @settings-toggle="settingsToggle"></SettingsPage>
|
<SettingsPage v-if="settingsActive" ref="settingsPage" @settings-toggle="settingsToggle"></SettingsPage>
|
||||||
<HelpPage v-if="helpActive" ref="helpPage" @help-toggle="helpToggle"></HelpPage>
|
<HelpPage v-if="helpActive" ref="helpPage" @help-toggle="helpToggle"></HelpPage>
|
||||||
<ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage>
|
<ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage>
|
||||||
@@ -340,8 +340,8 @@ class Reader extends Vue {
|
|||||||
this.setPositionActive = true;
|
this.setPositionActive = true;
|
||||||
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.setPositionPage.sliderMax = this.mostRecentBook().textLength - 1;
|
const recent = this.mostRecentBook();
|
||||||
this.$refs.setPositionPage.sliderValue = this.mostRecentBook().bookPos;
|
this.$refs.setPositionPage.init(recent.bookPos, recent.textLength - 1);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setPositionActive = false;
|
this.setPositionActive = false;
|
||||||
@@ -415,6 +415,7 @@ class Reader extends Vue {
|
|||||||
this.historyActive = !this.historyActive;
|
this.historyActive = !this.historyActive;
|
||||||
if (this.historyActive) {
|
if (this.historyActive) {
|
||||||
this.closeAllTextPages();
|
this.closeAllTextPages();
|
||||||
|
this.$refs.historyPage.init();
|
||||||
this.historyActive = true;
|
this.historyActive = true;
|
||||||
} else {
|
} else {
|
||||||
this.historyActive = false;
|
this.historyActive = false;
|
||||||
@@ -655,7 +656,7 @@ class Reader extends Vue {
|
|||||||
|
|
||||||
// если есть в локальном кэше
|
// если есть в локальном кэше
|
||||||
if (bookParsed) {
|
if (bookParsed) {
|
||||||
await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen, bookPosPercent}, bookManager.metaOnly(bookParsed)));
|
await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen, bookPosPercent}, bookParsed));
|
||||||
this.mostRecentBook();
|
this.mostRecentBook();
|
||||||
this.addAction(bookPos);
|
this.addAction(bookPos);
|
||||||
this.loaderActive = false;
|
this.loaderActive = false;
|
||||||
@@ -698,7 +699,7 @@ class Reader extends Vue {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// добавляем в историю
|
// добавляем в историю
|
||||||
await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen, bookPosPercent}, bookManager.metaOnly(addedBook)));
|
await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen, bookPosPercent}, addedBook));
|
||||||
this.mostRecentBook();
|
this.mostRecentBook();
|
||||||
this.addAction(bookPos);
|
this.addAction(bookPos);
|
||||||
this.updateRoute(true);
|
this.updateRoute(true);
|
||||||
@@ -831,6 +832,8 @@ class Reader extends Vue {
|
|||||||
break;
|
break;
|
||||||
case 'KeyX':
|
case 'KeyX':
|
||||||
this.historyToggle();
|
this.historyToggle();
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
case 'KeyS':
|
case 'KeyS':
|
||||||
this.settingsToggle();
|
this.settingsToggle();
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Component from 'vue-class-component';
|
import Component from 'vue-class-component';
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
import Window from '../../share/Window.vue';
|
import Window from '../../share/Window.vue';
|
||||||
|
|
||||||
@@ -28,7 +27,8 @@ export default @Component({
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
sliderValue: function(newValue) {
|
sliderValue: function(newValue) {
|
||||||
this.$emit('book-pos-changed', {bookPos: newValue});
|
if (this.initialized)
|
||||||
|
this.$emit('book-pos-changed', {bookPos: newValue});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -39,6 +39,13 @@ class SetPositionPage extends Vue {
|
|||||||
created() {
|
created() {
|
||||||
this.commit = this.$store.commit;
|
this.commit = this.$store.commit;
|
||||||
this.reader = this.$store.state.reader;
|
this.reader = this.$store.state.reader;
|
||||||
|
this.initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
init(sliderValue, sliderMax) {
|
||||||
|
this.sliderMax = sliderMax;
|
||||||
|
this.sliderValue = sliderValue;
|
||||||
|
this.initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
formatTooltip(val) {
|
formatTooltip(val) {
|
||||||
|
|||||||
@@ -185,15 +185,49 @@
|
|||||||
<el-checkbox v-model="wordWrap">Перенос по слогам</el-checkbox>
|
<el-checkbox v-model="wordWrap">Перенос по слогам</el-checkbox>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Обработка">
|
<el-form-item label="Обработка">
|
||||||
<el-checkbox v-model="cutEmptyParagraphs" @change="needReload">Убирать пустые параграфы</el-checkbox>
|
<el-checkbox v-model="cutEmptyParagraphs">Убирать пустые строки</el-checkbox>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="">
|
<el-form-item label="">
|
||||||
<el-col :span="12">
|
<el-col :span="12">
|
||||||
Добавлять пустые
|
Добавлять пустые
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-input-number v-model="addEmptyParagraphs" :min="0" :max="2" @change="needReload"></el-input-number>
|
<el-input-number v-model="addEmptyParagraphs" :min="0" :max="2"></el-input-number>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="Изображения">
|
||||||
|
<el-col :span="11">
|
||||||
|
<el-checkbox v-model="showImages">Показывать</el-checkbox>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :span="1">
|
||||||
|
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="11">
|
||||||
|
<el-tooltip :open-delay="500" effect="light" placement="top">
|
||||||
|
<template slot="content">
|
||||||
|
Выносить все изображения в центр экрана
|
||||||
|
</template>
|
||||||
|
<el-checkbox v-model="showInlineImagesInCenter" @change="needReload" :disabled="!showImages">Инлайн в центр</el-checkbox>
|
||||||
|
</el-tooltip>
|
||||||
|
</el-col>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="">
|
||||||
|
<el-checkbox v-model="imageFitWidth" :disabled="!showImages">Ширина не более размера экрана</el-checkbox>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="">
|
||||||
|
<el-col :span="12">
|
||||||
|
Высота не более
|
||||||
|
</el-col>
|
||||||
|
<el-tooltip :open-delay="500" effect="light" placement="top">
|
||||||
|
<template slot="content">
|
||||||
|
Определяет высоту изображения количеством строк.<br>
|
||||||
|
В случае превышения высоты, изображение будет<br>
|
||||||
|
уменьшено с сохранением пропорций так, чтобы<br>
|
||||||
|
помещаться в указанное количество строк.
|
||||||
|
</template>
|
||||||
|
<el-input-number v-model="imageHeightLines" :min="1" :max="100" :disabled="!showImages"></el-input-number>
|
||||||
|
</el-tooltip>
|
||||||
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
|
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
|
||||||
@@ -217,7 +251,7 @@
|
|||||||
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
|
<el-form :model="form" size="mini" label-width="120px" @submit.native.prevent>
|
||||||
<div class="partHeader">Анимация</div>
|
<div class="partHeader">Анимация</div>
|
||||||
|
|
||||||
<el-form-item label="Вид">
|
<el-form-item label="Тип">
|
||||||
<el-col :span="11">
|
<el-col :span="11">
|
||||||
<el-select v-model="pageChangeAnimation">
|
<el-select v-model="pageChangeAnimation">
|
||||||
<el-option label="Нет" value=""></el-option>
|
<el-option label="Нет" value=""></el-option>
|
||||||
@@ -408,11 +442,12 @@ class SettingsPage extends Vue {
|
|||||||
'#000000',
|
'#000000',
|
||||||
'#202020',
|
'#202020',
|
||||||
'#ebe2c9',
|
'#ebe2c9',
|
||||||
|
'#cfdc99',
|
||||||
|
'#478355',
|
||||||
|
'#a6caf0',
|
||||||
'#909080',
|
'#909080',
|
||||||
'#808080',
|
'#808080',
|
||||||
'#c8c8c8',
|
'#c8c8c8',
|
||||||
'#478355',
|
|
||||||
'#a6caf0',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,17 +23,18 @@ export default class DrawHelper {
|
|||||||
if (!this.lastBook || this.pageLineCount < 1 || !this.book || !lines || !this.parsed.textLength)
|
if (!this.lastBook || this.pageLineCount < 1 || !this.book || !lines || !this.parsed.textLength)
|
||||||
return '';
|
return '';
|
||||||
|
|
||||||
const spaceWidth = this.measureText(' ', {});
|
const font = this.fontByStyle({});
|
||||||
|
const justify = (this.textAlignJustify ? 'text-align: justify; text-align-last: justify;' : '');
|
||||||
|
|
||||||
let out = `<div class="layout" style="width: ${this.realWidth}px; height: ${this.realHeight}px;` +
|
let out = `<div style="width: ${this.w}px; height: ${this.h + (isScrolling ? this.lineHeight : 0)}px;` +
|
||||||
` color: ${this.textColor}">`;
|
` position: absolute; top: ${this.fontSize*this.textShift}px; color: ${this.textColor}; font: ${font}; ${justify}` +
|
||||||
|
` line-height: ${this.lineHeight}px; white-space: nowrap;">`;
|
||||||
|
|
||||||
|
let imageDrawn = new Set();
|
||||||
let len = lines.length;
|
let len = lines.length;
|
||||||
const lineCount = this.pageLineCount + (isScrolling ? 1 : 0);
|
const lineCount = this.pageLineCount + (isScrolling ? 1 : 0);
|
||||||
len = (len > lineCount ? lineCount : len);
|
len = (len > lineCount ? lineCount : len);
|
||||||
|
|
||||||
let y = this.fontSize*this.textShift;
|
|
||||||
|
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
const line = lines[i];
|
const line = lines[i];
|
||||||
/* line:
|
/* line:
|
||||||
@@ -43,81 +44,110 @@ export default class DrawHelper {
|
|||||||
first: Boolean,
|
first: Boolean,
|
||||||
last: Boolean,
|
last: Boolean,
|
||||||
parts: array of {
|
parts: array of {
|
||||||
style: {bold: Boolean, italic: Boolean, center: Boolean}
|
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
||||||
|
image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number},
|
||||||
text: String,
|
text: String,
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
let sel = new Set();
|
||||||
|
//поиск
|
||||||
|
if (i == 0 && this.searching) {
|
||||||
|
let pureText = '';
|
||||||
|
for (const part of line.parts) {
|
||||||
|
pureText += part.text;
|
||||||
|
}
|
||||||
|
|
||||||
let indent = line.first ? this.p : 0;
|
pureText = pureText.toLowerCase();
|
||||||
|
let j = 0;
|
||||||
|
while (1) {// eslint-disable-line no-constant-condition
|
||||||
|
j = pureText.indexOf(this.needle, j);
|
||||||
|
if (j >= 0) {
|
||||||
|
for (let k = 0; k < this.needle.length; k++) {
|
||||||
|
sel.add(j + k);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let lineText = '';
|
let lineText = '';
|
||||||
let center = false;
|
let center = false;
|
||||||
let centerStyle = {};
|
let space = 0;
|
||||||
|
let j = 0;
|
||||||
|
//формируем строку
|
||||||
for (const part of line.parts) {
|
for (const part of line.parts) {
|
||||||
lineText += part.text;
|
let tOpen = (part.style.bold ? '<b>' : '');
|
||||||
|
tOpen += (part.style.italic ? '<i>' : '');
|
||||||
|
let tClose = (part.style.italic ? '</i>' : '');
|
||||||
|
tClose += (part.style.bold ? '</b>' : '');
|
||||||
|
|
||||||
|
let text = '';
|
||||||
|
if (i == 0 && this.searching) {
|
||||||
|
for (let k = 0; k < part.text.length; k++) {
|
||||||
|
text += (sel.has(j) ? `<ins>${part.text[k]}</ins>` : part.text[k]);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
text = part.text;
|
||||||
|
|
||||||
|
if (text && text.trim() == '')
|
||||||
|
text = `<span style="white-space: pre">${text}</span>`;
|
||||||
|
|
||||||
|
lineText += `${tOpen}${text}${tClose}`;
|
||||||
|
|
||||||
center = center || part.style.center;
|
center = center || part.style.center;
|
||||||
if (part.style.center)
|
space = (part.style.space > space ? part.style.space : space);
|
||||||
centerStyle = part.style;
|
|
||||||
}
|
|
||||||
|
|
||||||
let filled = false;
|
//избражения
|
||||||
// если выравнивание по ширине включено
|
//image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number, w: Number, h: Number},
|
||||||
if (this.textAlignJustify && !line.last && !center) {
|
const img = part.image;
|
||||||
const words = lineText.split(' ');
|
if (img && img.id && !img.inline && !imageDrawn.has(img.paraIndex)) {
|
||||||
|
const bin = this.parsed.binary[img.id];
|
||||||
|
if (bin) {
|
||||||
|
let resize = '';
|
||||||
|
if (bin.h > img.h) {
|
||||||
|
resize = `height: ${img.h}px`;
|
||||||
|
}
|
||||||
|
|
||||||
if (words.length > 1) {
|
const left = (this.w - img.w)/2;
|
||||||
const spaceCount = words.length - 1;
|
const top = ((img.lineCount*this.lineHeight - img.h)/2) + (i - img.imageLine)*this.lineHeight;
|
||||||
|
if (img.local) {
|
||||||
const space = (this.w - line.width + spaceWidth*spaceCount)/spaceCount;
|
lineText += `<img src="data:${bin.type};base64,${bin.data}" style="position: absolute; left: ${left}px; top: ${top}px; ${resize}"/>`;
|
||||||
|
} else {
|
||||||
let x = indent;
|
lineText += `<img src="${img.id}" style="position: absolute; left: ${left}px; top: ${top}px; ${resize}"/>`;
|
||||||
for (const part of line.parts) {
|
|
||||||
const font = this.fontByStyle(part.style);
|
|
||||||
let partWords = part.text.split(' ');
|
|
||||||
|
|
||||||
for (let j = 0; j < partWords.length; j++) {
|
|
||||||
let f = font;
|
|
||||||
let style = part.style;
|
|
||||||
let word = partWords[j];
|
|
||||||
if (i == 0 && this.searching && word.toLowerCase().indexOf(this.needle) >= 0) {
|
|
||||||
style = Object.assign({}, part.style, {bold: true});
|
|
||||||
f = this.fontByStyle(style);
|
|
||||||
}
|
|
||||||
out += this.fillText(word, x, y, f);
|
|
||||||
x += this.measureText(word, style) + (j < partWords.length - 1 ? space : 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
filled = true;
|
imageDrawn.add(img.paraIndex);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// просто выводим текст
|
if (img && img.id && img.inline) {
|
||||||
if (!filled) {
|
if (img.local) {
|
||||||
let x = indent;
|
const bin = this.parsed.binary[img.id];
|
||||||
x = (center ? (this.w - this.measureText(lineText, centerStyle))/2 : x);
|
if (bin) {
|
||||||
for (const part of line.parts) {
|
let resize = '';
|
||||||
let font = this.fontByStyle(part.style);
|
if (bin.h > this.fontSize) {
|
||||||
|
resize = `height: ${this.fontSize - 3}px`;
|
||||||
if (i == 0 && this.searching) {//для поиска, разбивка по словам
|
|
||||||
let partWords = part.text.split(' ');
|
|
||||||
for (let j = 0; j < partWords.length; j++) {
|
|
||||||
let f = font;
|
|
||||||
let style = part.style;
|
|
||||||
let word = partWords[j];
|
|
||||||
if (word.toLowerCase().indexOf(this.needle) >= 0) {
|
|
||||||
style = Object.assign({}, part.style, {bold: true});
|
|
||||||
f = this.fontByStyle(style);
|
|
||||||
}
|
}
|
||||||
out += this.fillText(word, x, y, f);
|
lineText += `<img src="data:${bin.type};base64,${bin.data}" style="${resize}"/>`;
|
||||||
x += this.measureText(word, style) + (j < partWords.length - 1 ? spaceWidth : 0);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out += this.fillText(part.text, x, y, font);
|
//
|
||||||
x += this.measureText(part.text, part.style);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y += this.lineHeight;
|
|
||||||
|
const centerStyle = (center ? `text-align: center; text-align-last: center; width: ${this.w}px` : '')
|
||||||
|
if ((line.first || space) && !center) {
|
||||||
|
let p = (line.first ? this.p : 0);
|
||||||
|
p = (space ? p + this.p*space : p);
|
||||||
|
lineText = `<span style="display: inline-block; margin-left: ${p}px"></span>${lineText}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.last || center)
|
||||||
|
lineText = `<span style="display: inline-block; ${centerStyle}">${lineText}</span>`;
|
||||||
|
|
||||||
|
out += (i > 0 ? '<br>' : '') + lineText;
|
||||||
}
|
}
|
||||||
|
|
||||||
out += '</div>';
|
out += '</div>';
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="main" class="main">
|
<div ref="main" class="main">
|
||||||
<div class="layout back">
|
<div class="layout back" @wheel.prevent.stop="onMouseWheel">
|
||||||
<div v-html="background"></div>
|
<div v-html="background"></div>
|
||||||
<!-- img -->
|
<!-- img -->
|
||||||
</div>
|
</div>
|
||||||
<div ref="scrollBox1" class="layout" style="overflow: hidden" @wheel.prevent.stop="onMouseWheel">
|
<div ref="scrollBox1" class="layout over-hidden" @wheel.prevent.stop="onMouseWheel">
|
||||||
<div ref="scrollingPage1" class="layout" @transitionend="onPage1TransitionEnd" @animationend="onPage1AnimationEnd">
|
<div ref="scrollingPage1" class="layout over-hidden" @transitionend="onPage1TransitionEnd" @animationend="onPage1AnimationEnd">
|
||||||
<div v-html="page1"></div>
|
<div v-html="page1"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div ref="scrollBox2" class="layout" style="overflow: hidden" @wheel.prevent.stop="onMouseWheel">
|
<div ref="scrollBox2" class="layout over-hidden" @wheel.prevent.stop="onMouseWheel">
|
||||||
<div ref="scrollingPage2" class="layout" @transitionend="onPage2TransitionEnd" @animationend="onPage2AnimationEnd">
|
<div ref="scrollingPage2" class="layout over-hidden" @transitionend="onPage2TransitionEnd" @animationend="onPage2AnimationEnd">
|
||||||
<div v-html="page2"></div>
|
<div v-html="page2"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -157,9 +157,11 @@ class TextPage extends Vue {
|
|||||||
this.$refs.layoutEvents.style.height = this.realHeight + 'px';
|
this.$refs.layoutEvents.style.height = this.realHeight + 'px';
|
||||||
|
|
||||||
this.w = this.realWidth - 2*this.indentLR;
|
this.w = this.realWidth - 2*this.indentLR;
|
||||||
this.h = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0) - 2*this.indentTB;
|
this.scrollHeight = this.realHeight - (this.showStatusBar ? this.statusBarHeight : 0);
|
||||||
|
this.h = this.scrollHeight - 2*this.indentTB;
|
||||||
this.lineHeight = this.fontSize + this.lineInterval;
|
this.lineHeight = this.fontSize + this.lineInterval;
|
||||||
this.pageLineCount = 1 + Math.floor((this.h - this.fontSize)/this.lineHeight);
|
this.pageLineCount = 1 + Math.floor((this.h - this.lineHeight + this.lineInterval/2)/this.lineHeight);
|
||||||
|
this.pageSpace = this.scrollHeight - this.pageLineCount*this.lineHeight;
|
||||||
|
|
||||||
this.$refs.scrollingPage1.style.width = this.w + 'px';
|
this.$refs.scrollingPage1.style.width = this.w + 'px';
|
||||||
this.$refs.scrollingPage2.style.width = this.w + 'px';
|
this.$refs.scrollingPage2.style.width = this.w + 'px';
|
||||||
@@ -193,6 +195,7 @@ class TextPage extends Vue {
|
|||||||
this.drawHelper.indentLR = this.indentLR;
|
this.drawHelper.indentLR = this.indentLR;
|
||||||
this.drawHelper.textAlignJustify = this.textAlignJustify;
|
this.drawHelper.textAlignJustify = this.textAlignJustify;
|
||||||
this.drawHelper.lineHeight = this.lineHeight;
|
this.drawHelper.lineHeight = this.lineHeight;
|
||||||
|
this.drawHelper.pageSpace = this.pageSpace;
|
||||||
this.drawHelper.context = this.context;
|
this.drawHelper.context = this.context;
|
||||||
|
|
||||||
//сообщение "Загрузка шрифтов..."
|
//сообщение "Загрузка шрифтов..."
|
||||||
@@ -209,11 +212,19 @@ class TextPage extends Vue {
|
|||||||
this.parsed.p = this.p;
|
this.parsed.p = this.p;
|
||||||
this.parsed.w = this.w;// px, ширина текста
|
this.parsed.w = this.w;// px, ширина текста
|
||||||
this.parsed.font = this.font;
|
this.parsed.font = this.font;
|
||||||
|
this.parsed.fontSize = this.fontSize;
|
||||||
this.parsed.wordWrap = this.wordWrap;
|
this.parsed.wordWrap = this.wordWrap;
|
||||||
|
this.parsed.cutEmptyParagraphs = this.cutEmptyParagraphs;
|
||||||
|
this.parsed.addEmptyParagraphs = this.addEmptyParagraphs;
|
||||||
let t = '';
|
let t = '';
|
||||||
while (this.drawHelper.measureText(t, {}) < this.w) t += 'Щ';
|
while (this.drawHelper.measureText(t, {}) < this.w) t += 'Щ';
|
||||||
this.parsed.maxWordLength = t.length - 1;
|
this.parsed.maxWordLength = t.length - 1;
|
||||||
this.parsed.measureText = this.drawHelper.measureText.bind(this.drawHelper);
|
this.parsed.measureText = this.drawHelper.measureText.bind(this.drawHelper);
|
||||||
|
this.parsed.lineHeight = this.lineHeight;
|
||||||
|
this.parsed.showImages = this.showImages;
|
||||||
|
this.parsed.showInlineImagesInCenter = this.showInlineImagesInCenter;
|
||||||
|
this.parsed.imageHeightLines = this.imageHeightLines;
|
||||||
|
this.parsed.imageFitWidth = this.imageFitWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
//statusBar
|
//statusBar
|
||||||
@@ -224,20 +235,26 @@ class TextPage extends Vue {
|
|||||||
this.statusBarClickable = this.drawHelper.statusBarClickable(this.statusBarTop, this.statusBarHeight);
|
this.statusBarClickable = this.drawHelper.statusBarClickable(this.statusBarTop, this.statusBarHeight);
|
||||||
|
|
||||||
//scrolling page
|
//scrolling page
|
||||||
const pageDelta = this.h - (this.pageLineCount*this.lineHeight - this.lineInterval);
|
let y = this.pageSpace/2;
|
||||||
let y = this.indentTB + pageDelta/2;
|
|
||||||
if (this.showStatusBar)
|
if (this.showStatusBar)
|
||||||
y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
y += this.statusBarHeight*(this.statusBarTop ? 1 : 0);
|
||||||
const page1 = this.$refs.scrollBox1;
|
let page1 = this.$refs.scrollBox1;
|
||||||
const page2 = this.$refs.scrollBox2;
|
let page2 = this.$refs.scrollBox2;
|
||||||
page1.style.width = this.w + 'px';
|
page1.style.width = this.w + this.indentLR + 'px';
|
||||||
page2.style.width = this.w + 'px';
|
page2.style.width = this.w + this.indentLR + 'px';
|
||||||
page1.style.height = (this.h - pageDelta) + 'px';
|
page1.style.height = this.scrollHeight - (this.pageSpace > 0 ? this.pageSpace : 0) + 'px';
|
||||||
page2.style.height = (this.h - pageDelta) + 'px';
|
page2.style.height = this.scrollHeight - (this.pageSpace > 0 ? this.pageSpace : 0) + 'px';
|
||||||
page1.style.top = y + 'px';
|
page1.style.top = y + 'px';
|
||||||
page2.style.top = y + 'px';
|
page2.style.top = y + 'px';
|
||||||
page1.style.left = this.indentLR + 'px';
|
page1.style.left = this.indentLR + 'px';
|
||||||
page2.style.left = this.indentLR + 'px';
|
page2.style.left = this.indentLR + 'px';
|
||||||
|
|
||||||
|
page1 = this.$refs.scrollingPage1;
|
||||||
|
page2 = this.$refs.scrollingPage2;
|
||||||
|
page1.style.width = this.w + this.indentLR + 'px';
|
||||||
|
page2.style.width = this.w + this.indentLR + 'px';
|
||||||
|
page1.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||||
|
page2.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkLoadedFonts() {
|
async checkLoadedFonts() {
|
||||||
@@ -436,15 +453,7 @@ class TextPage extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startSearch(needle) {
|
startSearch(needle) {
|
||||||
this.drawHelper.needle = '';
|
this.drawHelper.needle = needle;
|
||||||
const words = needle.split(' ');
|
|
||||||
for (const word of words) {
|
|
||||||
if (word != '') {
|
|
||||||
this.drawHelper.needle = word;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.drawHelper.searching = true;
|
this.drawHelper.searching = true;
|
||||||
this.draw();
|
this.draw();
|
||||||
}
|
}
|
||||||
@@ -633,8 +642,14 @@ class TextPage extends Vue {
|
|||||||
duration, this.pageChangeDirectionDown, transition1Finish);
|
duration, this.pageChangeDirectionDown, transition1Finish);
|
||||||
break;
|
break;
|
||||||
case 'downShift':
|
case 'downShift':
|
||||||
|
page1.style.height = this.scrollHeight + 'px';
|
||||||
|
page2.style.height = this.scrollHeight + 'px';
|
||||||
|
|
||||||
await this.drawHelper.doPageAnimationDownShift(page1, page2,
|
await this.drawHelper.doPageAnimationDownShift(page1, page2,
|
||||||
duration, this.pageChangeDirectionDown, transition1Finish);
|
duration, this.pageChangeDirectionDown, transition1Finish);
|
||||||
|
|
||||||
|
page1.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||||
|
page2.style.height = this.scrollHeight + this.lineHeight + 'px';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -936,6 +951,7 @@ class TextPage extends Vue {
|
|||||||
this.$emit('full-screen-toogle');
|
this.$emit('full-screen-toogle');
|
||||||
break;
|
break;
|
||||||
case 'Tab':
|
case 'Tab':
|
||||||
|
case 'KeyQ':
|
||||||
this.doToolBarToggle();
|
this.doToolBarToggle();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@@ -1097,6 +1113,10 @@ class TextPage extends Vue {
|
|||||||
z-index: 10;
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.over-hidden {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.back {
|
.back {
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,14 @@ import he from 'he';
|
|||||||
import sax from '../../../../server/core/BookConverter/sax';
|
import sax from '../../../../server/core/BookConverter/sax';
|
||||||
import {sleep} from '../../../share/utils';
|
import {sleep} from '../../../share/utils';
|
||||||
|
|
||||||
|
const maxImageLineCount = 100;
|
||||||
|
|
||||||
export default class BookParser {
|
export default class BookParser {
|
||||||
constructor(settings) {
|
constructor(settings) {
|
||||||
|
if (settings) {
|
||||||
|
this.showInlineImagesInCenter = settings.showInlineImagesInCenter;
|
||||||
|
}
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
this.p = 30;// px, отступ параграфа
|
this.p = 30;// px, отступ параграфа
|
||||||
this.w = 300;// px, ширина страницы
|
this.w = 300;// px, ширина страницы
|
||||||
@@ -13,12 +19,6 @@ export default class BookParser {
|
|||||||
this.measureText = (text, style) => {// eslint-disable-line no-unused-vars
|
this.measureText = (text, style) => {// eslint-disable-line no-unused-vars
|
||||||
return text.length*20;
|
return text.length*20;
|
||||||
};
|
};
|
||||||
|
|
||||||
//настройки
|
|
||||||
if (settings) {
|
|
||||||
this.cutEmptyParagraphs = settings.cutEmptyParagraphs;
|
|
||||||
this.addEmptyParagraphs = settings.addEmptyParagraphs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async parse(data, callback) {
|
async parse(data, callback) {
|
||||||
@@ -43,6 +43,16 @@ export default class BookParser {
|
|||||||
let center = false;
|
let center = false;
|
||||||
let bold = false;
|
let bold = false;
|
||||||
let italic = false;
|
let italic = false;
|
||||||
|
let space = 0;
|
||||||
|
let inPara = false;
|
||||||
|
let isFirstBody = true;
|
||||||
|
let isFirstSection = true;
|
||||||
|
let isFirstTitlePara = false;
|
||||||
|
|
||||||
|
this.binary = {};
|
||||||
|
let binaryId = '';
|
||||||
|
let binaryType = '';
|
||||||
|
let dimPromises = [];
|
||||||
|
|
||||||
let paraIndex = -1;
|
let paraIndex = -1;
|
||||||
let paraOffset = 0;
|
let paraOffset = 0;
|
||||||
@@ -51,23 +61,70 @@ export default class BookParser {
|
|||||||
index: Number,
|
index: Number,
|
||||||
offset: Number, //сумма всех length до этого параграфа
|
offset: Number, //сумма всех length до этого параграфа
|
||||||
length: Number, //длина text без тегов
|
length: Number, //длина text без тегов
|
||||||
text: String //текст параграфа (или title или epigraph и т.д) с вложенными тегами
|
text: String, //текст параграфа с вложенными тегами
|
||||||
|
cut: Boolean, //параграф - кандидат на сокрытие (cutEmptyParagraphs)
|
||||||
|
addIndex: Number, //индекс добавляемого пустого параграфа (addEmptyParagraphs)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
const newParagraph = (text, len, noCut) => {
|
const getImageDimensions = (binaryId, binaryType, data) => {
|
||||||
//схлопывание пустых параграфов
|
return new Promise (async(resolve, reject) => {
|
||||||
if (!noCut && this.cutEmptyParagraphs && paraIndex >= 0 && len == 1 && text[0] == ' ') {
|
const i = new Image();
|
||||||
let p = para[paraIndex];
|
let resolved = false;
|
||||||
if (p.length == 1 && p.text[0] == ' ')
|
i.onload = () => {
|
||||||
return;
|
resolved = true;
|
||||||
}
|
this.binary[binaryId] = {
|
||||||
|
w: i.width,
|
||||||
|
h: i.height,
|
||||||
|
type: binaryType,
|
||||||
|
data
|
||||||
|
};
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
i.onerror = (e) => {
|
||||||
|
reject(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
i.src = `data:${binaryType};base64,${data}`;
|
||||||
|
await sleep(30*1000);
|
||||||
|
if (!resolved)
|
||||||
|
reject('Не удалось получить размер изображения');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const getExternalImageDimensions = (src) => {
|
||||||
|
return new Promise (async(resolve, reject) => {
|
||||||
|
const i = new Image();
|
||||||
|
let resolved = false;
|
||||||
|
i.onload = () => {
|
||||||
|
resolved = true;
|
||||||
|
this.binary[src] = {
|
||||||
|
w: i.width,
|
||||||
|
h: i.height,
|
||||||
|
};
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
i.onerror = (e) => {
|
||||||
|
reject(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
i.src = src;
|
||||||
|
await sleep(30*1000);
|
||||||
|
if (!resolved)
|
||||||
|
reject('Не удалось получить размер изображения');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const newParagraph = (text, len, addIndex) => {
|
||||||
paraIndex++;
|
paraIndex++;
|
||||||
let p = {
|
let p = {
|
||||||
index: paraIndex,
|
index: paraIndex,
|
||||||
offset: paraOffset,
|
offset: paraOffset,
|
||||||
length: len,
|
length: len,
|
||||||
text: text,
|
text: text,
|
||||||
|
cut: (!addIndex && (len == 1 && text[0] == ' ')),
|
||||||
|
addIndex: (addIndex ? addIndex : 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
para[paraIndex] = p;
|
para[paraIndex] = p;
|
||||||
@@ -82,66 +139,110 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let p = para[paraIndex];
|
let p = para[paraIndex];
|
||||||
if (p) {
|
//добавление пустых (addEmptyParagraphs) параграфов
|
||||||
//добавление пустых параграфов
|
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
|
||||||
if (this.addEmptyParagraphs && p.length == 1 && p.text[0] == ' ' && len > 0) {
|
paraIndex--;
|
||||||
let i = this.addEmptyParagraphs;
|
paraOffset -= p.length;
|
||||||
while (i > 0) {
|
for (let i = 0; i < 2; i++) {
|
||||||
newParagraph(' ', 1, true);
|
newParagraph(' ', 1, i + 1);
|
||||||
i--;
|
|
||||||
}
|
|
||||||
p = para[paraIndex];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
paraOffset -= p.length;
|
paraIndex++;
|
||||||
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
|
p.index = paraIndex;
|
||||||
p.length = 0;
|
p.offset = paraOffset;
|
||||||
p.text = p.text.substr(1);
|
para[paraIndex] = p;
|
||||||
}
|
paraOffset += p.length;
|
||||||
p.length += len;
|
|
||||||
p.text += text;
|
|
||||||
} else {
|
|
||||||
p = {
|
|
||||||
index: paraIndex,
|
|
||||||
offset: paraOffset,
|
|
||||||
length: len,
|
|
||||||
text: text
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paraOffset -= p.length;
|
||||||
|
//параграф оказался непустой
|
||||||
|
if (p.length == 1 && p.text[0] == ' ' && len > 0) {
|
||||||
|
p.length = 0;
|
||||||
|
p.text = p.text.substr(1);
|
||||||
|
p.cut = (len == 1 && text[0] == ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
p.length += len;
|
||||||
|
p.text += text;
|
||||||
|
|
||||||
para[paraIndex] = p;
|
para[paraIndex] = p;
|
||||||
paraOffset += p.length;
|
paraOffset += p.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
const onStartNode = (elemName) => {// eslint-disable-line no-unused-vars
|
const onStartNode = (elemName, tail) => {// eslint-disable-line no-unused-vars
|
||||||
if (elemName == '?xml')
|
if (elemName == '?xml')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tag = elemName;
|
tag = elemName;
|
||||||
path += '/' + elemName;
|
path += '/' + elemName;
|
||||||
|
|
||||||
|
if (tag == 'binary') {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
binaryType = (attrs['content-type'] && attrs['content-type'].value ? attrs['content-type'].value : '');
|
||||||
|
if (binaryType == 'image/jpeg' || binaryType == 'image/png')
|
||||||
|
binaryId = (attrs.id.value ? attrs.id.value : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'image') {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.href && attrs.href.value) {
|
||||||
|
const href = attrs.href.value;
|
||||||
|
if (href[0] == '#') {//local
|
||||||
|
if (inPara && !this.showInlineImagesInCenter && !center)
|
||||||
|
growParagraph(`<image-inline href="${href}"></image-inline>`, 0);
|
||||||
|
else
|
||||||
|
newParagraph(`<image href="${href}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
||||||
|
if (inPara && this.showInlineImagesInCenter)
|
||||||
|
newParagraph(' ', 1);
|
||||||
|
} else {//external
|
||||||
|
dimPromises.push(getExternalImageDimensions(href));
|
||||||
|
newParagraph(`<image href="${href}">${' '.repeat(maxImageLineCount)}</image>`, maxImageLineCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (path.indexOf('/fictionbook/body') == 0) {
|
if (path.indexOf('/fictionbook/body') == 0) {
|
||||||
|
if (tag == 'body') {
|
||||||
|
if (!isFirstBody)
|
||||||
|
newParagraph(' ', 1);
|
||||||
|
isFirstBody = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (tag == 'title') {
|
if (tag == 'title') {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
|
isFirstTitlePara = true;
|
||||||
bold = true;
|
bold = true;
|
||||||
center = true;
|
center = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag == 'section') {
|
||||||
|
if (!isFirstSection)
|
||||||
|
newParagraph(' ', 1);
|
||||||
|
isFirstSection = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (tag == 'emphasis' || tag == 'strong') {
|
if (tag == 'emphasis' || tag == 'strong') {
|
||||||
growParagraph(`<${tag}>`, 0);
|
growParagraph(`<${tag}>`, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) {
|
if ((tag == 'p' || tag == 'empty-line' || tag == 'v')) {
|
||||||
newParagraph(' ', 1);
|
if (!(tag == 'p' && isFirstTitlePara))
|
||||||
|
newParagraph(' ', 1);
|
||||||
|
if (tag == 'p') {
|
||||||
|
inPara = true;
|
||||||
|
isFirstTitlePara = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'subtitle') {
|
if (tag == 'subtitle') {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
|
isFirstTitlePara = true;
|
||||||
bold = true;
|
bold = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'epigraph') {
|
if (tag == 'epigraph') {
|
||||||
italic = true;
|
italic = true;
|
||||||
|
space += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'poem') {
|
if (tag == 'poem') {
|
||||||
@@ -149,15 +250,21 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'text-author') {
|
if (tag == 'text-author') {
|
||||||
newParagraph(' <s> <s> <s> ', 4);
|
newParagraph(' ', 1);
|
||||||
|
space += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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 == 'binary') {
|
||||||
|
binaryId = '';
|
||||||
|
}
|
||||||
|
|
||||||
if (path.indexOf('/fictionbook/body') == 0) {
|
if (path.indexOf('/fictionbook/body') == 0) {
|
||||||
if (tag == 'title') {
|
if (tag == 'title') {
|
||||||
|
isFirstTitlePara = false;
|
||||||
bold = false;
|
bold = false;
|
||||||
center = false;
|
center = false;
|
||||||
}
|
}
|
||||||
@@ -166,17 +273,27 @@ export default class BookParser {
|
|||||||
growParagraph(`</${tag}>`, 0);
|
growParagraph(`</${tag}>`, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag == 'p') {
|
||||||
|
inPara = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (tag == 'subtitle') {
|
if (tag == 'subtitle') {
|
||||||
|
isFirstTitlePara = false;
|
||||||
bold = false;
|
bold = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'epigraph') {
|
if (tag == 'epigraph') {
|
||||||
italic = false;
|
italic = false;
|
||||||
|
space -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag == 'stanza') {
|
if (tag == 'stanza') {
|
||||||
newParagraph(' ', 1);
|
newParagraph(' ', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag == 'text-author') {
|
||||||
|
space -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
path = path.substr(0, path.length - tag.length - 1);
|
path = path.substr(0, path.length - tag.length - 1);
|
||||||
@@ -194,13 +311,13 @@ export default class BookParser {
|
|||||||
text = text.replace(/>/g, '>');
|
text = text.replace(/>/g, '>');
|
||||||
text = text.replace(/</g, '<');
|
text = text.replace(/</g, '<');
|
||||||
|
|
||||||
if (text != ' ' && text.trim() == '')
|
if (text && text.trim() == '')
|
||||||
text = text.trim();
|
text = (text.indexOf(' ') >= 0 ? ' ' : '');
|
||||||
|
|
||||||
if (text == '')
|
if (!text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
text = text.replace(/[\t\n\r]/g, ' ');
|
text = text.replace(/[\t\n\r\xa0]/g, ' ');
|
||||||
|
|
||||||
switch (path) {
|
switch (path) {
|
||||||
case '/fictionbook/description/title-info/author/first-name':
|
case '/fictionbook/description/title-info/author/first-name':
|
||||||
@@ -238,7 +355,9 @@ 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 = (italic ? '</emphasis>' : '');
|
tOpen += (space ? `<space w="${space}">` : '');
|
||||||
|
let tClose = (space ? '</space>' : '');
|
||||||
|
tClose += (italic ? '</emphasis>' : '');
|
||||||
tClose += (bold ? '</strong>' : '');
|
tClose += (bold ? '</strong>' : '');
|
||||||
tClose += (center ? '</center>' : '');
|
tClose += (center ? '</center>' : '');
|
||||||
|
|
||||||
@@ -247,13 +366,11 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (path.indexOf('/fictionbook/body/section') == 0) {
|
if (path.indexOf('/fictionbook/body/section') == 0) {
|
||||||
switch (tag) {
|
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
||||||
case 'p':
|
}
|
||||||
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
|
||||||
break;
|
if (binaryId) {
|
||||||
default:
|
dimPromises.push(getImageDimensions(binaryId, binaryType, text));
|
||||||
growParagraph(`${tOpen}${text}${tClose}`, text.length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -266,6 +383,14 @@ export default class BookParser {
|
|||||||
onStartNode, onEndNode, onTextNode, onProgress
|
onStartNode, onEndNode, onTextNode, onProgress
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (dimPromises.length) {
|
||||||
|
try {
|
||||||
|
await Promise.all(dimPromises);
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.fb2 = fb2;
|
this.fb2 = fb2;
|
||||||
this.para = para;
|
this.para = para;
|
||||||
|
|
||||||
@@ -301,19 +426,22 @@ export default class BookParser {
|
|||||||
|
|
||||||
splitToStyle(s) {
|
splitToStyle(s) {
|
||||||
let result = [];/*array of {
|
let result = [];/*array of {
|
||||||
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
style: {bold: Boolean, italic: Boolean, center: Boolean, space: Number},
|
||||||
|
image: {local: Boolean, inline: Boolean, id: String},
|
||||||
text: String,
|
text: String,
|
||||||
}*/
|
}*/
|
||||||
let style = {};
|
let style = {};
|
||||||
|
let image = {};
|
||||||
|
|
||||||
const onTextNode = async(text) => {// eslint-disable-line no-unused-vars
|
const onTextNode = async(text) => {// eslint-disable-line no-unused-vars
|
||||||
result.push({
|
result.push({
|
||||||
style: Object.assign({}, style),
|
style: Object.assign({}, style),
|
||||||
text: text
|
image,
|
||||||
|
text
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onStartNode = async(elemName) => {// eslint-disable-line no-unused-vars
|
const onStartNode = async(elemName, tail) => {// eslint-disable-line no-unused-vars
|
||||||
switch (elemName) {
|
switch (elemName) {
|
||||||
case 'strong':
|
case 'strong':
|
||||||
style.bold = true;
|
style.bold = true;
|
||||||
@@ -324,6 +452,42 @@ export default class BookParser {
|
|||||||
case 'center':
|
case 'center':
|
||||||
style.center = true;
|
style.center = true;
|
||||||
break;
|
break;
|
||||||
|
case 'space': {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.w && attrs.w.value)
|
||||||
|
style.space = attrs.w.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'image': {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.href && attrs.href.value) {
|
||||||
|
let id = attrs.href.value;
|
||||||
|
let local = false;
|
||||||
|
if (id[0] == '#') {
|
||||||
|
id = id.substr(1);
|
||||||
|
local = true;
|
||||||
|
}
|
||||||
|
image = {local, inline: false, id};
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'image-inline': {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.href && attrs.href.value) {
|
||||||
|
let id = attrs.href.value;
|
||||||
|
let local = false;
|
||||||
|
if (id[0] == '#') {
|
||||||
|
id = id.substr(1);
|
||||||
|
local = true;
|
||||||
|
}
|
||||||
|
result.push({
|
||||||
|
style: Object.assign({}, style),
|
||||||
|
image: {local, inline: true, id},
|
||||||
|
text: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -338,6 +502,14 @@ export default class BookParser {
|
|||||||
case 'center':
|
case 'center':
|
||||||
style.center = false;
|
style.center = false;
|
||||||
break;
|
break;
|
||||||
|
case 'space':
|
||||||
|
style.space = 0;
|
||||||
|
break;
|
||||||
|
case 'image':
|
||||||
|
image = {};
|
||||||
|
break;
|
||||||
|
case 'image-inline':
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -345,27 +517,28 @@ export default class BookParser {
|
|||||||
onStartNode, onEndNode, onTextNode
|
onStartNode, onEndNode, onTextNode
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//длинные слова (или белиберду без пробелов) тоже разобьем
|
//длинные слова (или белиберду без пробелов) тоже разобьем
|
||||||
const maxWordLength = this.maxWordLength;
|
const maxWordLength = this.maxWordLength;
|
||||||
const parts = result;
|
const parts = result;
|
||||||
result = [];
|
result = [];
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
let p = part;
|
let p = part;
|
||||||
let i = 0;
|
if (!p.image.id) {
|
||||||
let spaceIndex = -1;
|
let i = 0;
|
||||||
while (i < p.text.length) {
|
let spaceIndex = -1;
|
||||||
if (p.text[i] == ' ')
|
while (i < p.text.length) {
|
||||||
spaceIndex = i;
|
if (p.text[i] == ' ')
|
||||||
|
spaceIndex = i;
|
||||||
|
|
||||||
if (i - spaceIndex >= maxWordLength && i < p.text.length - 1 &&
|
if (i - spaceIndex >= maxWordLength && i < p.text.length - 1 &&
|
||||||
this.measureText(p.text.substr(spaceIndex + 1, i - spaceIndex), p.style) >= this.w - this.p) {
|
this.measureText(p.text.substr(spaceIndex + 1, i - spaceIndex), p.style) >= this.w - this.p) {
|
||||||
result.push({style: p.style, text: p.text.substr(0, i + 1)});
|
result.push({style: p.style, image: p.image, text: p.text.substr(0, i + 1)});
|
||||||
p = {style: p.style, text: p.text.substr(i + 1)};
|
p = {style: p.style, image: p.image, text: p.text.substr(i + 1)};
|
||||||
spaceIndex = -1;
|
spaceIndex = -1;
|
||||||
i = -1;
|
i = -1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
result.push(p);
|
result.push(p);
|
||||||
}
|
}
|
||||||
@@ -432,7 +605,12 @@ export default class BookParser {
|
|||||||
para.parsed.p === this.p &&
|
para.parsed.p === this.p &&
|
||||||
para.parsed.wordWrap === this.wordWrap &&
|
para.parsed.wordWrap === this.wordWrap &&
|
||||||
para.parsed.maxWordLength === this.maxWordLength &&
|
para.parsed.maxWordLength === this.maxWordLength &&
|
||||||
para.parsed.font === this.font
|
para.parsed.font === this.font &&
|
||||||
|
para.parsed.cutEmptyParagraphs === this.cutEmptyParagraphs &&
|
||||||
|
para.parsed.addEmptyParagraphs === this.addEmptyParagraphs &&
|
||||||
|
para.parsed.showImages === this.showImages &&
|
||||||
|
para.parsed.imageHeightLines === this.imageHeightLines &&
|
||||||
|
para.parsed.imageFitWidth === this.imageFitWidth
|
||||||
)
|
)
|
||||||
return para.parsed;
|
return para.parsed;
|
||||||
|
|
||||||
@@ -442,6 +620,15 @@ export default class BookParser {
|
|||||||
wordWrap: this.wordWrap,
|
wordWrap: this.wordWrap,
|
||||||
maxWordLength: this.maxWordLength,
|
maxWordLength: this.maxWordLength,
|
||||||
font: this.font,
|
font: this.font,
|
||||||
|
cutEmptyParagraphs: this.cutEmptyParagraphs,
|
||||||
|
addEmptyParagraphs: this.addEmptyParagraphs,
|
||||||
|
showImages: this.showImages,
|
||||||
|
imageHeightLines: this.imageHeightLines,
|
||||||
|
imageFitWidth: this.imageFitWidth,
|
||||||
|
visible: !(
|
||||||
|
(this.cutEmptyParagraphs && para.cut) ||
|
||||||
|
(para.addIndex > this.addEmptyParagraphs)
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -453,6 +640,7 @@ export default class BookParser {
|
|||||||
last: Boolean,
|
last: Boolean,
|
||||||
parts: array of {
|
parts: array of {
|
||||||
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
style: {bold: Boolean, italic: Boolean, center: Boolean},
|
||||||
|
image: {local: Boolean, inline: Boolean, id: String, imageLine: Number, lineCount: Number, paraIndex: Number, w: Number, h: Number},
|
||||||
text: String,
|
text: String,
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
@@ -463,16 +651,79 @@ export default class BookParser {
|
|||||||
|
|
||||||
let str = '';//измеряемая строка
|
let str = '';//измеряемая строка
|
||||||
let prevStr = '';//строка без крайнего слова
|
let prevStr = '';//строка без крайнего слова
|
||||||
let prevW = 0;
|
|
||||||
let j = 0;//номер строки
|
let j = 0;//номер строки
|
||||||
let style = {};
|
let style = {};
|
||||||
let ofs = 0;//смещение от начала параграфа para.offset
|
let ofs = 0;//смещение от начала параграфа para.offset
|
||||||
|
let imgW = 0;
|
||||||
// тут начинается самый замес, перенос по слогам и стилизация
|
// тут начинается самый замес, перенос по слогам и стилизация, а также изображения
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
const words = part.text.split(' ');
|
|
||||||
style = part.style;
|
style = part.style;
|
||||||
|
|
||||||
|
//изображения
|
||||||
|
if (part.image.id && !part.image.inline) {
|
||||||
|
parsed.visible = this.showImages;
|
||||||
|
let bin = this.binary[part.image.id];
|
||||||
|
if (!bin)
|
||||||
|
bin = {h: 1, w: 1};
|
||||||
|
|
||||||
|
let lineCount = this.imageHeightLines;
|
||||||
|
let c = Math.ceil(bin.h/this.lineHeight);
|
||||||
|
|
||||||
|
const maxH = lineCount*this.lineHeight;
|
||||||
|
let maxH2 = maxH;
|
||||||
|
if (this.imageFitWidth && bin.w > this.w) {
|
||||||
|
maxH2 = bin.h*this.w/bin.w;
|
||||||
|
c = Math.ceil(maxH2/this.lineHeight);
|
||||||
|
}
|
||||||
|
lineCount = (c < lineCount ? c : lineCount);
|
||||||
|
|
||||||
|
let imageHeight = (maxH2 < maxH ? maxH2 : maxH);
|
||||||
|
imageHeight = (imageHeight <= bin.h ? imageHeight : bin.h);
|
||||||
|
|
||||||
|
let imageWidth = (bin.h > imageHeight ? bin.w*imageHeight/bin.h : bin.w);
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
for (; i < lineCount - 1; i++) {
|
||||||
|
line.end = para.offset + ofs;
|
||||||
|
line.first = (j == 0);
|
||||||
|
line.last = false;
|
||||||
|
line.parts.push({style, text: ' ', image: {
|
||||||
|
local: part.image.local,
|
||||||
|
inline: false,
|
||||||
|
id: part.image.id,
|
||||||
|
imageLine: i,
|
||||||
|
lineCount,
|
||||||
|
paraIndex,
|
||||||
|
w: imageWidth,
|
||||||
|
h: imageHeight,
|
||||||
|
}});
|
||||||
|
lines.push(line);
|
||||||
|
line = {begin: line.end + 1, parts: []};
|
||||||
|
ofs++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
line.first = (j == 0);
|
||||||
|
line.last = true;
|
||||||
|
line.parts.push({style, text: ' ',
|
||||||
|
image: {local: part.image.local, inline: false, id: part.image.id,
|
||||||
|
imageLine: i, lineCount, paraIndex, w: imageWidth, h: imageHeight}
|
||||||
|
});
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (part.image.id && part.image.inline && this.showImages) {
|
||||||
|
const bin = this.binary[part.image.id];
|
||||||
|
if (bin) {
|
||||||
|
let imgH = (bin.h > this.fontSize ? this.fontSize : bin.h);
|
||||||
|
imgW += bin.w*imgH/bin.h;
|
||||||
|
line.parts.push({style, text: '',
|
||||||
|
image: {local: part.image.local, inline: true, id: part.image.id}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let words = part.text.split(' ');
|
||||||
|
|
||||||
let sp1 = '';
|
let sp1 = '';
|
||||||
let sp2 = '';
|
let sp2 = '';
|
||||||
for (let i = 0; i < words.length; i++) {
|
for (let i = 0; i < words.length; i++) {
|
||||||
@@ -484,7 +735,8 @@ export default class BookParser {
|
|||||||
|
|
||||||
str += sp1 + word;
|
str += sp1 + word;
|
||||||
|
|
||||||
let p = (j == 0 ? parsed.p : 0);
|
let p = (j == 0 ? parsed.p : 0) + imgW;
|
||||||
|
p = (style.space ? p + parsed.p*style.space : p);
|
||||||
let w = this.measureText(str, style) + p;
|
let w = this.measureText(str, style) + p;
|
||||||
let wordTail = word;
|
let wordTail = word;
|
||||||
if (w > parsed.w && prevStr != '') {
|
if (w > parsed.w && prevStr != '') {
|
||||||
@@ -510,7 +762,6 @@ export default class BookParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pw) {
|
if (pw) {
|
||||||
prevW = pw;
|
|
||||||
partText += ss + (ss[ss.length - 1] == '-' ? '' : '-');
|
partText += ss + (ss[ss.length - 1] == '-' ? '' : '-');
|
||||||
wordTail = slogi.join('');
|
wordTail = slogi.join('');
|
||||||
}
|
}
|
||||||
@@ -524,7 +775,6 @@ export default class BookParser {
|
|||||||
let t = line.parts[line.parts.length - 1].text;
|
let t = line.parts[line.parts.length - 1].text;
|
||||||
if (t[t.length - 1] == ' ') {
|
if (t[t.length - 1] == ' ') {
|
||||||
line.parts[line.parts.length - 1].text = t.trimRight();
|
line.parts[line.parts.length - 1].text = t.trimRight();
|
||||||
prevW -= this.measureText(' ', style);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,7 +782,6 @@ export default class BookParser {
|
|||||||
if (line.end - line.begin < 0)
|
if (line.end - line.begin < 0)
|
||||||
console.error(`Parse error, empty line in paragraph ${paraIndex}`);
|
console.error(`Parse error, empty line in paragraph ${paraIndex}`);
|
||||||
|
|
||||||
line.width = prevW;
|
|
||||||
line.first = (j == 0);
|
line.first = (j == 0);
|
||||||
line.last = false;
|
line.last = false;
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
@@ -541,6 +790,7 @@ export default class BookParser {
|
|||||||
partText = '';
|
partText = '';
|
||||||
sp2 = '';
|
sp2 = '';
|
||||||
str = wordTail;
|
str = wordTail;
|
||||||
|
imgW = 0;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,7 +798,6 @@ export default class BookParser {
|
|||||||
partText += sp2 + wordTail;
|
partText += sp2 + wordTail;
|
||||||
sp1 = ' ';
|
sp1 = ' ';
|
||||||
sp2 = ' ';
|
sp2 = ' ';
|
||||||
prevW = w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partText != '')
|
if (partText != '')
|
||||||
@@ -560,14 +809,12 @@ export default class BookParser {
|
|||||||
let t = line.parts[line.parts.length - 1].text;
|
let t = line.parts[line.parts.length - 1].text;
|
||||||
if (t[t.length - 1] == ' ') {
|
if (t[t.length - 1] == ' ') {
|
||||||
line.parts[line.parts.length - 1].text = t.trimRight();
|
line.parts[line.parts.length - 1].text = t.trimRight();
|
||||||
prevW -= this.measureText(' ', style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
line.end = para.offset + para.length - 1;
|
line.end = para.offset + para.length - 1;
|
||||||
if (line.end - line.begin < 0)
|
if (line.end - line.begin < 0)
|
||||||
console.error(`Parse error, empty line in paragraph ${paraIndex}`);
|
console.error(`Parse error, empty line in paragraph ${paraIndex}`);
|
||||||
|
|
||||||
line.width = prevW;
|
|
||||||
line.first = (j == 0);
|
line.first = (j == 0);
|
||||||
line.last = true;
|
line.last = true;
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
@@ -614,16 +861,19 @@ export default class BookParser {
|
|||||||
let paraIndex = this.findParaIndex(bookPos);
|
let paraIndex = this.findParaIndex(bookPos);
|
||||||
|
|
||||||
if (paraIndex === undefined)
|
if (paraIndex === undefined)
|
||||||
return result;
|
return null;
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
let parsed = this.parsePara(paraIndex);
|
let parsed = this.parsePara(paraIndex);
|
||||||
let i = this.findLineIndex(bookPos, parsed.lines);
|
let i = this.findLineIndex(bookPos, parsed.lines);
|
||||||
if (i === undefined)
|
if (i === undefined)
|
||||||
return result;
|
return null;
|
||||||
|
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
result.push(parsed.lines[i]);
|
if (parsed.visible) {
|
||||||
|
result.push(parsed.lines[i]);
|
||||||
|
n--;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (i >= parsed.lines.length) {
|
if (i >= parsed.lines.length) {
|
||||||
@@ -631,21 +881,22 @@ export default class BookParser {
|
|||||||
if (paraIndex < this.para.length)
|
if (paraIndex < this.para.length)
|
||||||
parsed = this.parsePara(paraIndex);
|
parsed = this.parsePara(paraIndex);
|
||||||
else
|
else
|
||||||
return result;
|
break;
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
n--;
|
|
||||||
}
|
}
|
||||||
} else if (n < 0) {
|
} else if (n < 0) {
|
||||||
n = -n;
|
n = -n;
|
||||||
let parsed = this.parsePara(paraIndex);
|
let parsed = this.parsePara(paraIndex);
|
||||||
let i = this.findLineIndex(bookPos, parsed.lines);
|
let i = this.findLineIndex(bookPos, parsed.lines);
|
||||||
if (i === undefined)
|
if (i === undefined)
|
||||||
return result;
|
return null;
|
||||||
|
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
result.push(parsed.lines[i]);
|
if (parsed.visible) {
|
||||||
|
result.push(parsed.lines[i]);
|
||||||
|
n--;
|
||||||
|
}
|
||||||
i--;
|
i--;
|
||||||
|
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
@@ -653,16 +904,15 @@ export default class BookParser {
|
|||||||
if (paraIndex >= 0)
|
if (paraIndex >= 0)
|
||||||
parsed = this.parsePara(paraIndex);
|
parsed = this.parsePara(paraIndex);
|
||||||
else
|
else
|
||||||
return result;
|
break;
|
||||||
i = parsed.lines.length - 1;
|
i = parsed.lines.length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
n--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.length)
|
if (!result.length)
|
||||||
result = null;
|
result = null;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,14 +17,44 @@ const bmRecentStore = localForage.createInstance({
|
|||||||
name: 'bmRecentStore'
|
name: 'bmRecentStore'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const bmCacheStore = localForage.createInstance({
|
||||||
|
name: 'bmCacheStore'
|
||||||
|
});
|
||||||
|
|
||||||
class BookManager {
|
class BookManager {
|
||||||
async init(settings) {
|
async init(settings) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.books = {};
|
|
||||||
this.recent = {};
|
//bmCacheStore нужен только для ускорения загрузки читалки
|
||||||
|
this.booksCached = await bmCacheStore.getItem('books');
|
||||||
|
if (!this.booksCached)
|
||||||
|
this.booksCached = {};
|
||||||
|
this.recent = await bmCacheStore.getItem('recent');
|
||||||
|
this.recentLast = await bmCacheStore.getItem('recent-last');
|
||||||
|
if (this.recentLast)
|
||||||
|
this.recent[this.recentLast.key] = this.recentLast;
|
||||||
|
|
||||||
|
this.books = Object.assign({}, this.booksCached);
|
||||||
|
|
||||||
this.recentChanged1 = true;
|
this.recentChanged1 = true;
|
||||||
this.recentChanged2 = true;
|
this.recentChanged2 = true;
|
||||||
|
|
||||||
|
if (!this.books || !this.recent) {
|
||||||
|
this.books = {};
|
||||||
|
this.recent = {};
|
||||||
|
await this.loadMeta(true);
|
||||||
|
} else {
|
||||||
|
this.loadMeta(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//долгая загрузка из хранилища,
|
||||||
|
//хранение в отдельных записях дает относительно
|
||||||
|
//нормальное поведение при нескольких вкладках с читалкой в браузере
|
||||||
|
async loadMeta(immediate) {
|
||||||
|
if (!immediate)
|
||||||
|
await utils.sleep(2000);
|
||||||
|
|
||||||
let len = await bmMetaStore.length();
|
let len = await bmMetaStore.length();
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
const key = await bmMetaStore.key(i);
|
const key = await bmMetaStore.key(i);
|
||||||
@@ -33,7 +63,13 @@ class BookManager {
|
|||||||
if (keySplit.length == 2 && keySplit[0] == 'bmMeta') {
|
if (keySplit.length == 2 && keySplit[0] == 'bmMeta') {
|
||||||
let meta = await bmMetaStore.getItem(key);
|
let meta = await bmMetaStore.getItem(key);
|
||||||
|
|
||||||
|
const oldBook = this.books[meta.key];
|
||||||
this.books[meta.key] = meta;
|
this.books[meta.key] = meta;
|
||||||
|
|
||||||
|
if (oldBook && oldBook.data && oldBook.parsed) {
|
||||||
|
this.books[meta.key].data = oldBook.data;
|
||||||
|
this.books[meta.key].parsed = oldBook.parsed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +81,14 @@ class BookManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.cleanBooks();
|
await this.cleanBooks();
|
||||||
|
await this.cleanRecentBooks();
|
||||||
|
|
||||||
|
this.booksCached = {};
|
||||||
|
for (const key in this.books) {
|
||||||
|
this.booksCached[key] = this.metaOnly(this.books[key]);
|
||||||
|
}
|
||||||
|
await bmCacheStore.setItem('books', this.booksCached);
|
||||||
|
await bmCacheStore.setItem('recent', this.recent);
|
||||||
}
|
}
|
||||||
|
|
||||||
async cleanBooks() {
|
async cleanBooks() {
|
||||||
@@ -80,9 +124,11 @@ class BookManager {
|
|||||||
const result = await this.parseBook(meta, newBook.data, callback);
|
const result = await this.parseBook(meta, newBook.data, callback);
|
||||||
|
|
||||||
this.books[meta.key] = result;
|
this.books[meta.key] = result;
|
||||||
|
this.booksCached[meta.key] = this.metaOnly(result);
|
||||||
|
|
||||||
await bmMetaStore.setItem(`bmMeta-${meta.key}`, this.metaOnly(result));
|
await bmMetaStore.setItem(`bmMeta-${meta.key}`, this.metaOnly(result));
|
||||||
await bmDataStore.setItem(`bmData-${meta.key}`, result.data);
|
await bmDataStore.setItem(`bmData-${meta.key}`, result.data);
|
||||||
|
await bmCacheStore.setItem('books', this.booksCached);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -127,11 +173,15 @@ class BookManager {
|
|||||||
await bmDataStore.removeItem(`bmData-${meta.key}`);
|
await bmDataStore.removeItem(`bmData-${meta.key}`);
|
||||||
|
|
||||||
delete this.books[meta.key];
|
delete this.books[meta.key];
|
||||||
|
delete this.booksCached[meta.key];
|
||||||
|
|
||||||
|
await bmCacheStore.setItem('books', this.booksCached);
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseBook(meta, data, callback) {
|
async parseBook(meta, data, callback) {
|
||||||
if (!this.books)
|
if (!this.books)
|
||||||
await this.init();
|
await this.init();
|
||||||
|
|
||||||
const parsed = new BookParser(this.settings);
|
const parsed = new BookParser(this.settings);
|
||||||
|
|
||||||
const parsedMeta = await parsed.parse(data, callback);
|
const parsedMeta = await parsed.parse(data, callback);
|
||||||
@@ -159,7 +209,7 @@ class BookManager {
|
|||||||
async setRecentBook(value, noTouch) {
|
async setRecentBook(value, noTouch) {
|
||||||
if (!this.recent)
|
if (!this.recent)
|
||||||
await this.init();
|
await this.init();
|
||||||
const result = Object.assign({}, value);
|
const result = this.metaOnly(value);
|
||||||
if (!noTouch)
|
if (!noTouch)
|
||||||
Object.assign(result, {touchTime: Date.now()});
|
Object.assign(result, {touchTime: Date.now()});
|
||||||
|
|
||||||
@@ -169,7 +219,13 @@ class BookManager {
|
|||||||
this.recent[result.key] = result;
|
this.recent[result.key] = result;
|
||||||
|
|
||||||
await bmRecentStore.setItem(result.key, result);
|
await bmRecentStore.setItem(result.key, result);
|
||||||
await this.cleanRecentBooks();
|
|
||||||
|
//кэшируем, аккуратно
|
||||||
|
if (!(this.recentLast && this.recentLast.key == result.key)) {
|
||||||
|
await bmCacheStore.setItem('recent', this.recent);
|
||||||
|
}
|
||||||
|
this.recentLast = result;
|
||||||
|
await bmCacheStore.setItem('recent-last', this.recentLast);
|
||||||
|
|
||||||
this.recentChanged1 = true;
|
this.recentChanged1 = true;
|
||||||
this.recentChanged2 = true;
|
this.recentChanged2 = true;
|
||||||
@@ -188,6 +244,8 @@ class BookManager {
|
|||||||
|
|
||||||
await bmRecentStore.removeItem(value.key);
|
await bmRecentStore.removeItem(value.key);
|
||||||
delete this.recent[value.key];
|
delete this.recent[value.key];
|
||||||
|
await bmCacheStore.setItem('recent', this.recent);
|
||||||
|
|
||||||
this.recentChanged1 = true;
|
this.recentChanged1 = true;
|
||||||
this.recentChanged2 = true;
|
this.recentChanged2 = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import Vue from 'vue';
|
|
||||||
|
|
||||||
const fonts = [
|
const fonts = [
|
||||||
{name: 'ReaderDefault', label: 'По-умолчанию', fontVertShift: 0},
|
{name: 'ReaderDefault', label: 'По-умолчанию', fontVertShift: 0},
|
||||||
{name: 'GEO_1', label: 'BPG Arial', fontVertShift: 10},
|
{name: 'GEO_1', label: 'BPG Arial', fontVertShift: 10},
|
||||||
{name: 'Arimo', fontVertShift: 0},
|
{name: 'Arimo', fontVertShift: 0},
|
||||||
{name: 'Avrile', fontVertShift: -10},
|
{name: 'Avrile', fontVertShift: -10},
|
||||||
{name: 'OpenSans', fontVertShift: -5},
|
{name: 'OpenSans', fontVertShift: -5},
|
||||||
{name: 'Roboto', fontVertShift: 10},
|
{name: 'Roboto', fontVertShift: 0},
|
||||||
{name: 'Rubik', fontVertShift: 0},
|
{name: 'Rubik', fontVertShift: 0},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -163,6 +161,10 @@ const settingDefaults = {
|
|||||||
cutEmptyParagraphs: false,
|
cutEmptyParagraphs: false,
|
||||||
addEmptyParagraphs: 0,
|
addEmptyParagraphs: 0,
|
||||||
blinkCachedLoad: true,
|
blinkCachedLoad: true,
|
||||||
|
showImages: true,
|
||||||
|
showInlineImagesInCenter: true,
|
||||||
|
imageHeightLines: 100,
|
||||||
|
imageFitWidth: true,
|
||||||
|
|
||||||
fontShifts: {},
|
fontShifts: {},
|
||||||
};
|
};
|
||||||
|
|||||||
6
docs/omnireader/old/.htaccess
Normal file
6
docs/omnireader/old/.htaccess
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#RewriteEngine On
|
||||||
|
#RewriteCond %{HTTP_HOST} ^www.bookpauk.ru$ [NC]
|
||||||
|
#RewriteRule ^(.*)$ http://bookpauk.ru/$1 [R=301,L]
|
||||||
|
|
||||||
|
Options None
|
||||||
|
Options +ExecCGI
|
||||||
BIN
docs/omnireader/old/apple-touch-icon-precomposed.png
Normal file
BIN
docs/omnireader/old/apple-touch-icon-precomposed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
BIN
docs/omnireader/old/apple-touch-icon.png
Normal file
BIN
docs/omnireader/old/apple-touch-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
2
docs/omnireader/old/config/config.js
Normal file
2
docs/omnireader/old/config/config.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
siteroot = 'http://old.omnireader.ru/';
|
||||||
|
doRedirect = '';
|
||||||
5
docs/omnireader/old/config/config.php
Normal file
5
docs/omnireader/old/config/config.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
$siteroot = 'http://old.omnireader.ru/';
|
||||||
|
$use_gzip = false;
|
||||||
|
$tmp_dir = '/tmp';
|
||||||
|
?>
|
||||||
447
docs/omnireader/old/f.php
Normal file
447
docs/omnireader/old/f.php
Normal file
@@ -0,0 +1,447 @@
|
|||||||
|
<?php
|
||||||
|
date_default_timezone_set('Europe/Moscow');
|
||||||
|
|
||||||
|
require_once 'config/config.php';
|
||||||
|
require_once 'parser.php';
|
||||||
|
|
||||||
|
define('LOWERCASE',3);
|
||||||
|
define('UPPERCASE',1);
|
||||||
|
|
||||||
|
function getParam($param, $defaultValue = '') {
|
||||||
|
$paramValue = (isset($_REQUEST[$param]) ? $_REQUEST[$param] : $defaultValue);
|
||||||
|
return $paramValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEncoding($str, $check_utf = FALSE) {
|
||||||
|
if (!$check_utf) {
|
||||||
|
$result = getEncoding(mb_convert_encoding($str, 'cp1251', 'UTF-8'), TRUE);
|
||||||
|
if ($result == 'w')
|
||||||
|
return 'u';
|
||||||
|
}
|
||||||
|
|
||||||
|
$charsets = Array(
|
||||||
|
'k' => 0,
|
||||||
|
'w' => 0,
|
||||||
|
'd' => 0,
|
||||||
|
'i' => 0,
|
||||||
|
'm' => 0
|
||||||
|
);
|
||||||
|
|
||||||
|
$length = strlen($str);
|
||||||
|
$block_size = ($length > 5*3000) ? 3000 : $length;
|
||||||
|
$counter = 0;
|
||||||
|
for ( $i = 0; $i < $length; $i++ ) {
|
||||||
|
$char = ord($str[$i]);
|
||||||
|
|
||||||
|
//non-russian characters
|
||||||
|
if ($char < 128 || $char > 256)
|
||||||
|
continue;
|
||||||
|
//CP866
|
||||||
|
if (($char > 159 && $char < 176) || ($char > 223 && $char < 242)) $charsets['d']+=LOWERCASE;
|
||||||
|
if (($char > 127 && $char < 160)) $charsets['d']+=UPPERCASE;
|
||||||
|
|
||||||
|
//KOI8-R
|
||||||
|
if (($char > 191 && $char < 223)) $charsets['k']+=LOWERCASE;
|
||||||
|
if (($char > 222 && $char < 256)) $charsets['k']+=UPPERCASE;
|
||||||
|
|
||||||
|
//WIN-1251
|
||||||
|
if ($char > 223 && $char < 256) $charsets['w']+=LOWERCASE;
|
||||||
|
if ($char > 191 && $char < 224) $charsets['w']+=UPPERCASE;
|
||||||
|
|
||||||
|
//MAC
|
||||||
|
if ($char > 221 && $char < 255) $charsets['m']+=LOWERCASE;
|
||||||
|
if ($char > 127 && $char < 160) $charsets['m']+=UPPERCASE;
|
||||||
|
|
||||||
|
//ISO-8859-5
|
||||||
|
if ($char > 207 && $char < 240) $charsets['i']+=LOWERCASE;
|
||||||
|
if ($char > 175 && $char < 208) $charsets['i']+=UPPERCASE;
|
||||||
|
|
||||||
|
$counter++;
|
||||||
|
if ($counter > $block_size) {
|
||||||
|
$counter = 0;
|
||||||
|
$i += (int)($length/2 - 2*$block_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arsort($charsets);
|
||||||
|
if (preg_match('//u', $str))
|
||||||
|
return 'u';
|
||||||
|
else
|
||||||
|
return key($charsets);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTag($tagName, $book) {
|
||||||
|
$from_tag = '<' . $tagName . '>';
|
||||||
|
$to_tag = '</' . $tagName . '>';
|
||||||
|
$from = strpos($book, $from_tag);
|
||||||
|
$to = strpos($book, $to_tag);
|
||||||
|
if ($from === FALSE || $to === FALSE)
|
||||||
|
return '';
|
||||||
|
$from += strlen($from_tag);
|
||||||
|
return trim(substr($book, $from, $to - $from));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMetaInfoAndFilter($book, &$meta_info) {
|
||||||
|
$meta_info['author'] = '';
|
||||||
|
$meta_info['title'] = getTag('title', $book);
|
||||||
|
|
||||||
|
$out = $book;
|
||||||
|
|
||||||
|
//fb2 ??? ---------------------
|
||||||
|
if (strpos($meta_info['title'], '<p>') !== FALSE) {
|
||||||
|
$s = str_replace('</p>', '', $meta_info['title']);
|
||||||
|
$a = explode('<p>', $s);
|
||||||
|
$meta_info['author'] = parseHtml($a[1], TRUE);
|
||||||
|
$meta_info['title'] = parseHtml($a[2], TRUE);
|
||||||
|
if ($meta_info['title'] === NULL || $meta_info['title'] === '') {
|
||||||
|
$s = parseHtml($s, TRUE);
|
||||||
|
$meta_info['author'] = '';
|
||||||
|
$meta_info['title'] = $s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//samlib ----------------------
|
||||||
|
$samlib_start_sign = '<!----------- Ñîáñòâåííî ïðîèçâåäåíèå --------------->';
|
||||||
|
$samlib_book_idx = strpos($book, $samlib_start_sign);
|
||||||
|
if ($samlib_book_idx !== FALSE) {
|
||||||
|
$samlib_author = getTag('h3', $book);
|
||||||
|
$meta_info['author'] = substr($samlib_author, 0, strpos($samlib_author, ': <small>'));
|
||||||
|
$meta_info['title'] = getTag('h2', $book);;
|
||||||
|
$samlib_book_idx += strlen($samlib_start_sign);
|
||||||
|
$samlib_book_end_idx = strpos($book, '<!---- Áëîê îïèñàíèÿ ïðîèçâåäåíèÿ (ñëåâà âíèçó) ----------------------->');
|
||||||
|
$samlib_book_end_idx = ($samlib_book_end_idx === FALSE ? strlen($book) : $samlib_book_end_idx);
|
||||||
|
$out = '<dd>' . $meta_info['author'] . '<dd>' . $meta_info['title'] . '<empty-line/>' .
|
||||||
|
substr($book, $samlib_book_idx, $samlib_book_end_idx - $samlib_book_idx);
|
||||||
|
$out = preg_replace("/<dd>  [;]*\s*[\r\n]/", '<empty-line/>', $out);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterTextAndGzip($meta_info, $txtin) {
|
||||||
|
global $use_gzip;
|
||||||
|
|
||||||
|
if (strpos($txtin, '<P>') === FALSE) {
|
||||||
|
$len = strlen($txtin);
|
||||||
|
$counts = array();
|
||||||
|
|
||||||
|
$flag = 0;
|
||||||
|
$c = 0;
|
||||||
|
for ($i = 0; $i < $len; $i++) {
|
||||||
|
if ($txtin[$i] == chr(10) || $i == 0) {
|
||||||
|
$counts[$c]++;
|
||||||
|
if ($c > 0)
|
||||||
|
$counts[0]++;
|
||||||
|
$c = 0;
|
||||||
|
$flag = 1;
|
||||||
|
} else
|
||||||
|
if ($txtin[$i] != ' ')
|
||||||
|
$flag = 0;
|
||||||
|
else
|
||||||
|
if ($flag)
|
||||||
|
$c++;
|
||||||
|
}
|
||||||
|
|
||||||
|
arsort($counts);
|
||||||
|
$key = 0;
|
||||||
|
if (count($counts) > 1) {
|
||||||
|
next($counts);
|
||||||
|
$key = key($counts);
|
||||||
|
}
|
||||||
|
|
||||||
|
//$txtout .= print_r($counts, TRUE);
|
||||||
|
//$txtout .= $key;
|
||||||
|
|
||||||
|
$txtout = '';
|
||||||
|
$flag = 0;
|
||||||
|
$c = 0;
|
||||||
|
for ($i = 0; $i < $len; $i++) {
|
||||||
|
if ($txtin[$i] == chr(10) || $i == 0) {
|
||||||
|
$c = 0;
|
||||||
|
$flag = 1;
|
||||||
|
} else
|
||||||
|
if ($txtin[$i] != ' ') {
|
||||||
|
if ($c >= $key && $flag)
|
||||||
|
$txtout .= '<p>';
|
||||||
|
$flag = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if ($flag)
|
||||||
|
$c++;
|
||||||
|
$txtout .= $txtin[$i];
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
$txtout = $txtin;
|
||||||
|
|
||||||
|
$txtout = 'no_file' . '|' . $meta_info['author'] . '|' . $meta_info['title'] .
|
||||||
|
'<<<bpr5A432688AB0467AA396E5A144830248Abpr>>>' . $txtout;
|
||||||
|
|
||||||
|
$supportsGzip = strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false;
|
||||||
|
if ($use_gzip && $supportsGzip && getParam('meta') == '' && getParam('curl') == '') {
|
||||||
|
$txtout = gzencode($txtout, 9);
|
||||||
|
header('Content-Encoding: gzip');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $txtout;
|
||||||
|
}
|
||||||
|
|
||||||
|
function myErrorHandler($errno, $errstr, $errfile, $errline)
|
||||||
|
{
|
||||||
|
if (!(error_reporting() & $errno)) {
|
||||||
|
// Ýòîò êîä îøèáêè íå âêëþ÷åí â error_reporting
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($errno == 8 /*|| $errno == 2*/)
|
||||||
|
return;
|
||||||
|
//throw new Exception("[$errno]: ($errstr) at $errfile line $errline");
|
||||||
|
throw new Exception("$errstr");
|
||||||
|
|
||||||
|
// Íå çàïóñêàåì âíóòðåííèé îáðàáîò÷èê îøèáîê PHP
|
||||||
|
return TRUE; // ñþäà õîäà íåò, íî ïóñòü áóäåò êàê øàáëîí
|
||||||
|
}
|
||||||
|
|
||||||
|
function unzip($filein) {
|
||||||
|
$zip = new ZipArchive;
|
||||||
|
$result = '';
|
||||||
|
if ($zip->open($filein) === TRUE) {
|
||||||
|
$filename = '';
|
||||||
|
$max_size = -1;
|
||||||
|
for($i = 0; $i < $zip->numFiles; $i++) {
|
||||||
|
$stat = $zip->statIndex($i);
|
||||||
|
$size = $stat['size'];
|
||||||
|
if ($size > $max_size) {
|
||||||
|
$max_size = $size;
|
||||||
|
$filename = $zip->getNameIndex($i);
|
||||||
|
$fp = $zip->getStream($filename);
|
||||||
|
if (!$fp)
|
||||||
|
throw new Exception("zip->getStream failed");
|
||||||
|
$result = stream_get_contents($fp);
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$zip->close();
|
||||||
|
} else
|
||||||
|
throw new Exception("zip->open failed");
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_guid($namespace = '') {
|
||||||
|
$uid = md5(uniqid("", true));
|
||||||
|
$data = $namespace;
|
||||||
|
$data .= $_SERVER['REQUEST_TIME'];
|
||||||
|
$data .= $_SERVER['HTTP_USER_AGENT'];
|
||||||
|
$data .= $_SERVER['LOCAL_ADDR'];
|
||||||
|
$data .= $_SERVER['LOCAL_PORT'];
|
||||||
|
$data .= $_SERVER['REMOTE_ADDR'];
|
||||||
|
$data .= $_SERVER['REMOTE_PORT'];
|
||||||
|
$hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data)));
|
||||||
|
return $hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
function microtime_float()
|
||||||
|
{
|
||||||
|
list($usec, $sec) = explode(" ", microtime());
|
||||||
|
return ((float)$usec + (float)$sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
function curlExec(/* Array */$curlOptions='', /* Array */$curlHeaders='', /* Array */$postFields='')
|
||||||
|
{
|
||||||
|
$newUrl = '';
|
||||||
|
$maxRedirection = 10;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ($maxRedirection<1) die('Error: reached the limit of redirections');
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
if (!empty($curlOptions)) curl_setopt_array($ch, $curlOptions);
|
||||||
|
if (!empty($curlHeaders)) curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeaders);
|
||||||
|
if (!empty($postFields))
|
||||||
|
{
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($newUrl)) curl_setopt($ch, CURLOPT_URL, $newUrl); // redirect needed
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||||
|
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
// Then, after your curl_exec call:
|
||||||
|
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||||
|
$header = substr($response, 0, $header_size);
|
||||||
|
$curlResult = substr($response, $header_size);
|
||||||
|
|
||||||
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$info = curl_getinfo($ch);
|
||||||
|
if (getParam('curl') != '') {;
|
||||||
|
throw new Exception("<br>" . str_replace("[", "<br>[", print_r($info, TRUE)) . "<br>$header<br>END");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($code == 301 || $code == 302 || $code == 303 || $code == 307)
|
||||||
|
{
|
||||||
|
if (array_key_exists('redirect_url', $info) && !empty($info['redirect_url'])) {
|
||||||
|
$newUrl = trim($info['redirect_url']);
|
||||||
|
} else {
|
||||||
|
preg_match('/Location:(.*?)\n/', $header, $matches);
|
||||||
|
$newUrl = trim(array_pop($matches));
|
||||||
|
}
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$maxRedirection--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else // no more redirection
|
||||||
|
{
|
||||||
|
if ($curlResult === FALSE || $info['http_code'] != 200) {
|
||||||
|
$curlResult = "ERROR ". $info['http_code'];
|
||||||
|
if (curl_error($ch))
|
||||||
|
$curlResult .= "<br>". curl_error($ch);
|
||||||
|
throw new Exception($curlResult);
|
||||||
|
} else {
|
||||||
|
$code = 0; //OK
|
||||||
|
curl_close($ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while($code);
|
||||||
|
return $curlResult;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
set_error_handler("myErrorHandler");
|
||||||
|
// set_time_limit(300);
|
||||||
|
|
||||||
|
$url = getParam('url');
|
||||||
|
try {
|
||||||
|
$body = '';
|
||||||
|
if ($url == '')
|
||||||
|
throw new Exception("íå çàäàí àäðåñ êíèãè");
|
||||||
|
|
||||||
|
$meta_info = array();
|
||||||
|
$time_start = $time = microtime_float();
|
||||||
|
|
||||||
|
$pid = create_guid();
|
||||||
|
$dir = 'txt/';
|
||||||
|
$encoding = getParam('encoding');
|
||||||
|
|
||||||
|
if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0)
|
||||||
|
$url = 'http://' . $url;
|
||||||
|
$url = str_replace('"', '', $url);
|
||||||
|
$url = str_replace('\'', '', $url);
|
||||||
|
$url = str_replace(']', '%5D', str_replace('[', '%5B', $url));
|
||||||
|
|
||||||
|
$options = array(
|
||||||
|
CURLOPT_RETURNTRANSFER => TRUE,
|
||||||
|
CURLOPT_TIMEOUT => 300,
|
||||||
|
CURLOPT_URL => $url,
|
||||||
|
CURLOPT_BUFFERSIZE => 1024*128,
|
||||||
|
CURLOPT_NOPROGRESS => FALSE,
|
||||||
|
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6",
|
||||||
|
CURLOPT_PROGRESSFUNCTION => function(
|
||||||
|
$DownloadSize, $Downloaded, $UploadSize, $Uploaded
|
||||||
|
) {
|
||||||
|
// If $Downloaded exceeds, returning non-0 breaks the connection!
|
||||||
|
return ($Downloaded > (50 * 1024 * 1024)) ? 1 : 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$out = curlExec($options);
|
||||||
|
|
||||||
|
$meta_info['time_curl'] = microtime_float() - $time;
|
||||||
|
$time = microtime_float();
|
||||||
|
|
||||||
|
//zip
|
||||||
|
if ($out[0] == chr(0x50) && $out[1] == chr(0x4B) && $out[2] == chr(0x03) && $out[3] == chr(0x04)) {
|
||||||
|
$zipped_file = $tmp_dir . "/{$pid}-temp.zip";
|
||||||
|
file_put_contents($zipped_file, $out);
|
||||||
|
$out = unzip($zipped_file);
|
||||||
|
if (file_exists($zipped_file)) unlink($zipped_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
//pdf
|
||||||
|
/* if ($out[0] == chr(0x25) && $out[1] == chr(0x50) && $out[2] == chr(0x44) && $out[3] == chr(0x46)) {
|
||||||
|
$a = new PDF2Text();
|
||||||
|
$a->reset();
|
||||||
|
$a->decodePDF($out);
|
||||||
|
$out = $a->output();
|
||||||
|
file_put_contents('/tmp/1', $out);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
$meta_info['time_unzip'] = microtime_float() - $time;
|
||||||
|
$time = microtime_float();
|
||||||
|
|
||||||
|
//decoding and parsing
|
||||||
|
if ($out !== FALSE) {
|
||||||
|
if ($encoding == '')
|
||||||
|
$encoding = getEncoding($out);
|
||||||
|
|
||||||
|
switch ($encoding) {
|
||||||
|
case 'k':
|
||||||
|
$out = mb_convert_encoding($out, 'cp1251', 'KOI8-R');
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
$out = mb_convert_encoding($out, 'cp1251', 'cp866');
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
$out = mb_convert_encoding($out, 'cp1251', 'ISO-8859-5');
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
$out = mb_convert_encoding($out, 'cp1251', 'MACINTOSH');
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
$out = mb_convert_encoding($out, 'cp1251', 'UTF-8');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//$out = $encoding . '===' . $out;
|
||||||
|
|
||||||
|
//file_put_contents('/tmp/bpr1', $out);
|
||||||
|
$meta_info['time_decodepage'] = microtime_float() - $time;
|
||||||
|
$time = microtime_float();
|
||||||
|
|
||||||
|
$out = getMetaInfoAndFilter($out, $meta_info);
|
||||||
|
|
||||||
|
$meta_info['time_metainfo'] = microtime_float() - $time;
|
||||||
|
$time = microtime_float();
|
||||||
|
|
||||||
|
$out = parseHtml($out);
|
||||||
|
|
||||||
|
$meta_info['time_parsehtml'] = microtime_float() - $time;
|
||||||
|
$time = microtime_float();
|
||||||
|
|
||||||
|
$out = filterTextAndGzip($meta_info, $out);
|
||||||
|
|
||||||
|
$meta_info['time_filter_gzip'] = microtime_float() - $time;
|
||||||
|
$meta_info['time_total'] = microtime_float() - $time_start;
|
||||||
|
|
||||||
|
$meta = getParam('meta');
|
||||||
|
if ($meta != '') {
|
||||||
|
$info = '';
|
||||||
|
foreach ($meta_info as $key => $value) {
|
||||||
|
if (strpos($key, 'time') !== FALSE)
|
||||||
|
$info .= sprintf("%06.3f", $value) . " $key <br>";
|
||||||
|
else
|
||||||
|
$info .= "$key: $value<br>";
|
||||||
|
}
|
||||||
|
throw new Exception("<br>" . $info);
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Content-Type: text/plain; charset=windows-1251');
|
||||||
|
echo $out;
|
||||||
|
//file_put_contents('/tmp/bpr2', $out);
|
||||||
|
return;
|
||||||
|
} else
|
||||||
|
throw new Exception("îøèáêà çàãðóçêè ôàéëà. Ïîïðîáóéòå åùå ðàç.");
|
||||||
|
} catch (Exception $e) {
|
||||||
|
header('Content-Type: text/html; charset=windows-1251');
|
||||||
|
$err = $e->getMessage();
|
||||||
|
if (strpos($err, 'ERROR 404') !== FALSE)
|
||||||
|
$err = 'ñòðàíèöà íå íàéäåíà';
|
||||||
|
$body = "Îøèáêà çàãðóçêè êíèãè: " . ($url == '' ? '' : "($url) ") . $err;
|
||||||
|
}
|
||||||
|
echo $body;
|
||||||
|
}
|
||||||
|
?>
|
||||||
BIN
docs/omnireader/old/favicon.ico
Normal file
BIN
docs/omnireader/old/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 227 B |
279
docs/omnireader/old/index.html
Normal file
279
docs/omnireader/old/index.html
Normal file
@@ -0,0 +1,279 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
|
||||||
|
<meta http-equiv="Content-Language" content="ru">
|
||||||
|
<meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi" />
|
||||||
|
<meta name="description" content="áðàóçåðíàÿ îíëàéí-÷èòàëêà êíèã èç èíòåðíåòà">
|
||||||
|
<meta name="keywords" content="îíëàéí,÷èòàëêà,êíèãè,÷èòàòü,áðàóçåð,èíòåðíåò">
|
||||||
|
<title>Omni Reader - áðàóçåðíàÿ îíëàéí-÷èòàëêà</title>
|
||||||
|
<link rel="icon" type="image/gif" href="js/bpricon.gif">
|
||||||
|
<link rel="shortcut icon" type="image/gif" href="js/bpricon.gif">
|
||||||
|
<link rel="stylesheet" type="text/css" media="screen" href="js/stylex.css">
|
||||||
|
<script src="config/config.js" type="text/javascript"></script>
|
||||||
|
<script src="js/bpr318.js" type="text/javascript"></script>
|
||||||
|
<meta name="yandex-verification" content="be58752dfe93d304" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body onload="onLoa();">
|
||||||
|
|
||||||
|
<div style="display: none;" id="loading">
|
||||||
|
<img style="float:left;padding: 0; margin: 0" src="js/load.gif"></img>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<noscript>
|
||||||
|
<div class="over">JavaScript disabled
|
||||||
|
</div>
|
||||||
|
</noscript>
|
||||||
|
|
||||||
|
<hr id="fhr">
|
||||||
|
|
||||||
|
<div id="win">
|
||||||
|
<div id="header" class="header">
|
||||||
|
</div>
|
||||||
|
<!-- MAIN DIV -->
|
||||||
|
<div id="main">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="podk" id="comm">
|
||||||
|
<div style="background-color: rgb(34, 34, 0); color: rgb(235, 226, 201);" class="menuCross" id="mcross" onclick="menu();return false;">x
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div style="text-decoration: underline; text-align: center"><span>ÌÅÍÞ</span></div>
|
||||||
|
<div class="melem">
|
||||||
|
<br>
|
||||||
|
<a href="/?#" onclick="goTo();return false;">Íà ñòðàíèöó: </a>
|
||||||
|
<b onmousedown="gpa=1;pageGoto(1);" onmouseup="gpa=0;" onmouseout="gpa=0;"><</b>
|
||||||
|
<input value="1" style="color: rgb(34, 34, 0);" id="pageGoto" size="3" maxlength="4" type="text" onkeydown="if (event.keyCode == 13) {goTo();return false;}">
|
||||||
|
<b onmousedown="gpa=1;pageGoto(0);" onmouseup="gpa=0;" onmouseout="gpa=0;">></b>
|
||||||
|
|
||||||
|
<a href="/?#" onclick="goTo();return false;">Ok</a>
|
||||||
|
<br>
|
||||||
|
<a href="/?#" onclick="return statusPanel();">Ïàíåëü ñòàòóñà(px): </a>
|
||||||
|
<input style="color: rgb(34, 34, 0);" id="id_sp_size" size="3" maxlength="3" type="text" onkeydown="if (event.keyCode == 13) return statusPanel();">
|
||||||
|
<a href="/?#" onclick="return statusPanel();">Ok</a>
|
||||||
|
<br>
|
||||||
|
<a href="/?#" onclick="return statusPanel();">Ñêðîëëèíã(ms): </a>
|
||||||
|
<input style="color: rgb(34, 34, 0);" id="id_sc_int" size="3" maxlength="3" type="text" onkeydown="if (event.keyCode == 13) return scrollInterval();">
|
||||||
|
<a href="/?#" onclick="return scrollInterval();">Ok</a>
|
||||||
|
<br>
|
||||||
|
<label>Ïîëîñà ïðîêðóòêè<input id="id_scroll" type="checkbox" onclick="return showScroll()"></label>
|
||||||
|
<br>
|
||||||
|
<label>Óïðàâëåíèå êëèêîì<input id="id_by_click" type="checkbox" onclick="return byClick()"></label>
|
||||||
|
<br><br>
|
||||||
|
<a href="/?#Íàñòðîèòü öâåò è øðèôò" onclick="colorMenu();return false;">Íàñòðîèòü öâåò è øðèôò</a>
|
||||||
|
<br>
|
||||||
|
<a href="/?#Ñïðàâêà" onclick="legend(1);return false;">Ñïðàâêà</a>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="top: 172px; left: 423px" id="colorSelect">
|
||||||
|
<div style="background-color: rgb(34, 34, 0); color: rgb(235, 226, 201);" class="colorCross" id="cross" onclick="colorClose(); return false;">x
|
||||||
|
</div>
|
||||||
|
<div class="colorImage" onclick="colorSet(); return false;">
|
||||||
|
</div>
|
||||||
|
<div style="border-color: rgb(136, 132, 100);" class="colorMenu">
|
||||||
|
<div style="position:absolute;top:180px;left:0px;">
|
||||||
|
<div onclick="colorFontTemp=1; setSelectedFontItem(); return false;" onmouseover="this.style.backgroundColor='#0FA';" onmouseout="this.style.background='none';">
|
||||||
|
<span id="fontItemText"> Òåêñò</span>
|
||||||
|
</div>
|
||||||
|
<input onchange="colorChange(1,this.value);" id="fcolor" size="8" maxlength="7" type="text" onkeydown="if (event.keyCode == 13) {colorChange(1,this.value);return false;}">
|
||||||
|
<br>
|
||||||
|
<div onclick="colorFontTemp=0; setSelectedFontItem(); return false;" onmouseover="this.style.backgroundColor='#0FA';" onmouseout="this.style.background='none';">
|
||||||
|
<span id="fontItemBack"> Ôîí</span>
|
||||||
|
</div>
|
||||||
|
<input onchange="colorChange(2,this.value);" id="bcolor" size="8" maxlength="7" type="text" onkeydown="if (event.keyCode == 13) {colorChange(2,this.value);return false;}">
|
||||||
|
<br>
|
||||||
|
<div>
|
||||||
|
Ðàçìåð
|
||||||
|
</div>
|
||||||
|
<input onchange="colorChange(3,this.value);" id="fsize" size="8" maxlength="3" type="text" onkeydown="if (event.keyCode == 13) {colorChange(3,this.value);return false;}">
|
||||||
|
<br>
|
||||||
|
<div>
|
||||||
|
Øðèôò
|
||||||
|
</div>
|
||||||
|
<select id="ffamily" onchange="gdb('ffamily2').value='';colorChange(4,this.value);">
|
||||||
|
<option>Trebuchet Ms</option>
|
||||||
|
<option>Serif</option>
|
||||||
|
<option>Arial</option>
|
||||||
|
<option>Times New Roman</option>
|
||||||
|
<option>Sans-Serif</option>
|
||||||
|
<option>Tahoma</option>
|
||||||
|
<option>Verdana</option>
|
||||||
|
<option>Lucida Sans Unicode</option>
|
||||||
|
</select>
|
||||||
|
<br>
|
||||||
|
<div>
|
||||||
|
Ñâîé
|
||||||
|
</div>
|
||||||
|
<input onchange="colorChange(4,this.value);" id="ffamily2" size="8" maxlength="70" type="text" onkeydown="if (event.keyCode == 13) {colorChange(4,this.value);return false;}">
|
||||||
|
</div>
|
||||||
|
<div class="colorExample" style="cursor: pointer; height: 24px; bottom: 0px; background-color: rgb(204, 238, 255); border-top: 2px solid rgb(136, 132, 100); line-height: 26px; border-color: rgb(136, 132, 100);" onmouseover="this.style.backgroundColor='#CFC';" onmouseout="this.style.backgroundColor='#CEF';" onclick="colorSubmit();">
|
||||||
|
OK
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="clrdiv" class="colorExample" style="top: 78px; border-bottom: 2px solid rgb(136, 132, 100); color: rgb(34, 34, 0); background-color: rgb(235, 226, 201); border-color: rgb(136, 132, 100);overflow: hidden;">
|
||||||
|
Ïðèìåð.
|
||||||
|
</div>
|
||||||
|
<div id="clrdiv2" class="colorExample" style="top: 0px; font-size: 21px; color: rgb(34, 34, 0); background-color: rgb(235, 226, 201);overflow: hidden;">
|
||||||
|
Ðåçóëüòàò.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="dop" style="display:none">
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<br><h4><strong>Omni Reader - áðàóçåðíàÿ îíëàéí-÷èòàëêà.</strong></h4>
|
||||||
|
<br>Äîáðî ïîæàëîâàòü!
|
||||||
|
<br><br><br>
|
||||||
|
<div class="addr">
|
||||||
|
<div align="left" style="text-indent: 0">Àäðåñ êíèãè (URL):
|
||||||
|
</div>
|
||||||
|
<input class="book" id="book" style="width:70%" type="text" onkeydown="if (event.keyCode == 13) gdb('btnOk').click()">
|
||||||
|
<input class="book" id="btnOk" value="ÎÊ" onclick="location.href=siteroot + '?url=' + gdb('book').value;" type="button">
|
||||||
|
<div align="left" style="text-indent: 0;font-size: 12px;line-height:16px">
|
||||||
|
<b><a href="http://samlib.ru/comment/b/bookpauk/bookpauk_reader" target="_blank">Êîììåíòèðîâàòü</a></b>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="id_add"></div>
|
||||||
|
</center>
|
||||||
|
|
||||||
|
<br><br><strong>Âîçìîæíîñòè ÷èòàëêè:</strong>
|
||||||
|
<p>- çàãðóçêà ëþáîé ñòðàíèöû èíòåðíåòà
|
||||||
|
<p>- ïîäêëþ÷åíèå ê èíòåðíåòó íå îáÿçàòåëüíî äëÿ ÷òåíèÿ êíèãè ïîñëå åå çàãðóçêè
|
||||||
|
<p>- âîçìîæíîñòü èçìåíèòü öâåò ôîíà, òåêñòà, ðàçìåð è òèï øðèôòà, ðàçìåð ïàíåëè ñòàòóñà
|
||||||
|
<p>- çàïîìèíàíèå òåêóùåé ïîçèöèè è íàñòðîåê â áðàóçåðå
|
||||||
|
<p>- ïåðåõîä íà çàäàííóþ ñòðàíèöó
|
||||||
|
<p>- ïëàâíûé ñêðîëëèíã òåêñòà
|
||||||
|
<p>- óïðàâëåíèå êëèêîì äëÿ ñåíñîðíûõ ýêðàíîâ
|
||||||
|
<p>- ðåãèñòðàöèÿ íå òðåáóåòñÿ
|
||||||
|
|
||||||
|
<br><br> êà÷åñòâå URL ìîæíî çàäàâàòü html-ñòðàíè÷êó ñ êíèãîé, ëèáî ïðÿìóþ ññûëêó íà ôàéë èç îíëàéí-áèáëèîòåêè (íàïðèìåð, ñêîïèðîâàâ àäðåñ ññûëêè èëè êíîïêè "ñêà÷àòü fb2").
|
||||||
|
Ïîääåðæèâàåìûå ôîðìàòû: <strong>html, txt, fb2, fb2.zip</strong>
|
||||||
|
|
||||||
|
<br><br>Âû ìîæåòå äîáàâèòü â ñâîé áðàóçåð çàêëàäêó, óêàçàâ â åå ñâîéñòâàõ âìåñòî àäðåñà ñëåäóþùèé êîä:
|
||||||
|
<br><p><strong>javascript:location.href='http://old.omnireader.ru/?url='+location.href;</strong>
|
||||||
|
<br>Òîãäà, íàæàâ íà ïîëó÷èâøóþñÿ êíîïêó íà ëþáîé ñòðàíèöå èíòåðíåòà, âû àâòîìàòè÷åñêè îòêðîåòå åå â Omni Reader.
|
||||||
|
|
||||||
|
<br><br>Äëÿ Chrome íà Android ìîæíî âûçûâàòü çàêëàäêó ïî åå èìåíè (èìÿ ñòîèò ñäåëàòü ïîïðîùå) â àäðåñíîé ñòðîêå áðàóçåðà, ïîñêîëüêó ñòàíäàðòíûé âûçîâ òàêîé çàêëàäêè íå ðàáîòàåò.
|
||||||
|
|
||||||
|
<br><br>Êîëè÷åñòâî è íóìåðàöèÿ ñòðàíèö â ÷èòàëêå çàâèñèò îò ðàçìåðà îêíà áðàóçåðà.
|
||||||
|
|
||||||
|
<br><br><strong>Ïîïóëÿðíûå ðåñóðñû ñ êíèãàìè è ýëåêòðîííûå áèáëèîòåêè:</strong>
|
||||||
|
<br><p><a href="http://samlib.ru" target="_blank">samlib.ru</a>
|
||||||
|
<br><p><a href="http://flibusta.is" target="_blank">flibusta.is</a>
|
||||||
|
<br><p><a href="http://fantasy-worlds.org" target="_blank">fantasy-worlds.org</a>
|
||||||
|
<br><p><a href="http://www.litmir.co" target="_blank">www.litmir.co</a>
|
||||||
|
<br><p><a href="http://lib.ru" target="_blank">lib.ru</a>
|
||||||
|
|
||||||
|
<br><br><strong>Ïðè íåîáõîäèìîñòè çàãðóçèòü ôàéë ñ ëîêàëüíîãî äèñêà â ÷èòàëêó</strong>, ìîæíî âîñïîëüçîâàòüñÿ îäíèì èç ôàéëîîáìåííûõ
|
||||||
|
ñåðâèñîâ. Ðåêîìåíäóåìûå ôàéëîîáìåííèêè:
|
||||||
|
<br><p><a href="http://fayloobmennik.cloud" target="_blank">fayloobmennik.cloud</a>
|
||||||
|
<br><p><a href="http://zaix.ru" target="_blank">zaix.ru</a>
|
||||||
|
|
||||||
|
<br><br>Ïîñëå çàãðóçêè ôàéëà íà îáìåííèê, ïðÿìóþ ññûëêó íà ôàéë íåîáõîäèìî ñêîïèðîâàòü â ïîëå "Àäðåñ êíèãè" (ñì. âûøå).
|
||||||
|
|
||||||
|
<br><br><strong>Èçâåñòíûå ïðîáëåìû:</strong>
|
||||||
|
<p>- ïðè èçìåíåíèè/ïðèìåíåíèè íàñòðîåê áûâàþò ñáîè èç-çà ìàñøòàáèðîâàíèÿ ñòðàíèöû. Ïîìîãàåò îáíîâëåíèå ñòðàíèöû â áðàóçåðå.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="leg" onclick="legend();">
|
||||||
|
<br>
|
||||||
|
<b>Óïðàâëåíèå:</b>
|
||||||
|
<p>M - ÌÅÍÞ
|
||||||
|
<p>PgUp, Left, Shift+Space, Backspace - ñòðàíèöó íàçàä
|
||||||
|
<p>PgDown, Right, Space, Enter - ñòðàíèöó âïåð¸ä
|
||||||
|
<p>Home - â íà÷àëî êíèãè
|
||||||
|
<p>End - â êîíåö êíèãè
|
||||||
|
<p>Up - ñòðî÷êó íàçàä
|
||||||
|
<p>Down - ñòðî÷êó âïåð¸ä
|
||||||
|
<p>A, Shift+A - èçìåíèòü ðàçìåð øðèôòà
|
||||||
|
<p>S - ïîêàçàòü/ñêðûòü ïîëîñó ïðîêðóòêè
|
||||||
|
<p>T - âêëþ÷èòü/îòêëþ÷èòü óïðàâëåíèå êëèêîì
|
||||||
|
<p>F, F11, ` (àïîñòðîô) - âêë./âûêë. ïîëíûé ýêðàí
|
||||||
|
<p>Z, Shift+Down - ïëàâíûé ñêðîëëèíã òåêñòà
|
||||||
|
<p>Shift+Left/Shift+Right - óâåëè÷èòü/óìåíüøèòü èíòåðâàë ñêðîëëèíãà
|
||||||
|
<p>R - ïðèíóäèòåëüíî îáíîâèòü êíèãó â îáõîä êýøà
|
||||||
|
|
||||||
|
<br><br><strong>Óïðàâëåíèå íà ñåíñîðíûõ ýêðàíàõ (êëèêîì):</strong>
|
||||||
|
<p>PgUp-------Up------PgUp
|
||||||
|
<p>PgDown---Menu---PgDown
|
||||||
|
<p>PgDown---Down---PgDown
|
||||||
|
|
||||||
|
<div id="top100">
|
||||||
|
<div id="id_add2"></div>
|
||||||
|
<br>
|
||||||
|
<!-- Yandex.Metrika informer --><a href="https://metrika.yandex.ru/stat/?id=31398038&from=informer"target="_blank" rel="nofollow"><img src="https://mc.yandex.ru/informer/31398038/3_1_FFFFFFFF_EFEFEFFF_0_pageviews"style="width:88px; height:31px; border:0;" alt="ßíäåêñ.Ìåòðèêà" title="ßíäåêñ.Ìåòðèêà: äàííûå çà ñåãîäíÿ (ïðîñìîòðû, âèçèòû è óíèêàëüíûå ïîñåòèòåëè)" onclick="try{Ya.Metrika.informer({i:this,id:31398038,lang:'ru'});return false}catch(e){}" /></a><!-- /Yandex.Metrika informer --> <!-- Yandex.Metrika counter --><script type="text/javascript"> (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter31398038 = new Ya.Metrika({ id:31398038, clickmap:true, trackLinks:true, accurateTrackBounce:true }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks");</script><noscript><div><img src="https://mc.yandex.ru/watch/31398038" style="position:absolute; left:-9999px;" alt="" /></div></noscript><!-- /Yandex.Metrika counter -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="footer" class="footer">
|
||||||
|
<div id="id_lp" style="position: absolute; left: 0">
|
||||||
|
<div id="bmain" class="page">
|
||||||
|
<a href="/"><span title="Âåðíóòüñÿ íà ãëàâíóþ"> <<< </span></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="page">
|
||||||
|
</div>
|
||||||
|
<div class="cpage" onclick="menu();return false;">
|
||||||
|
<span title="M - ïîêàçàòü/ñêðûòü ìåíþ">ÌÅÍÞ</span>
|
||||||
|
</div>
|
||||||
|
<div class="page">
|
||||||
|
</div>
|
||||||
|
<div class="cpage" onclick="toggleFullScreen();return false;">
|
||||||
|
<span title="F, F11, ` (àïîñòðîô) - âêë./âûêë. ïîëíûé ýêðàí"><---></span>
|
||||||
|
</div>
|
||||||
|
<div class="page">
|
||||||
|
</div>
|
||||||
|
<div class="cpage" onclick="incFont(1);return false;">
|
||||||
|
<span title="A - óâåëè÷èòü ðàçìåð øðèôòà">A+</span>
|
||||||
|
</div>
|
||||||
|
<div class="page">
|
||||||
|
</div>
|
||||||
|
<div class="cpage" onclick="incFont(-1);return false;">
|
||||||
|
<span title="Shift+A - óìåíüøèòü ðàçìåð øðèôòà">A-</span>
|
||||||
|
</div>
|
||||||
|
<div class="page">
|
||||||
|
</div>
|
||||||
|
<div class="cpage" onclick="return toggleScroll();">
|
||||||
|
<span title="Z, Shift+Down - âêë./âûêë. ïëàâíûé ñêðîëëèíã òåêñòà">$</span>
|
||||||
|
</div>
|
||||||
|
<div class="page">
|
||||||
|
</div>
|
||||||
|
<div id="reload" class="cpage" onclick="return reloadBook();">
|
||||||
|
<span title="R - ïðèíóäèòåëüíî îáíîâèòü êíèãó â îáõîä êýøà">@</span>
|
||||||
|
</div>
|
||||||
|
<div class="page" style="width: 20px">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="orig" class="page">
|
||||||
|
<a id="orig_href" href="" target="_blank"> </a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="id_rp" style="position: absolute; right: 0">
|
||||||
|
<div id="pageCount" class="page">
|
||||||
|
<div onmousedown="pageMove(1);" onmouseout="pageMoveClear();" onmouseup="pageMoveClear();"><
|
||||||
|
</div>
|
||||||
|
<div onclick="pageMoveShow();" style="visibility:visible;">1/1
|
||||||
|
</div>
|
||||||
|
<div onmousedown="pageMove(0); " onmouseout="pageMoveClear();" onmouseup="pageMoveClear();"> >
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="pagePercent" class="page">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="tm" class="page">
|
||||||
|
</div>
|
||||||
|
<div class="page">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
docs/omnireader/old/info.txt
Normal file
1
docs/omnireader/old/info.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
omnireader.ru
|
||||||
1253
docs/omnireader/old/js/bpr318.js
Normal file
1253
docs/omnireader/old/js/bpr318.js
Normal file
File diff suppressed because it is too large
Load Diff
BIN
docs/omnireader/old/js/bpricon.gif
Normal file
BIN
docs/omnireader/old/js/bpricon.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 246 B |
BIN
docs/omnireader/old/js/colo58.png
Normal file
BIN
docs/omnireader/old/js/colo58.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 193 KiB |
BIN
docs/omnireader/old/js/load.gif
Normal file
BIN
docs/omnireader/old/js/load.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.3 KiB |
438
docs/omnireader/old/js/stylex.css
Normal file
438
docs/omnireader/old/js/stylex.css
Normal file
@@ -0,0 +1,438 @@
|
|||||||
|
*
|
||||||
|
{
|
||||||
|
margin:0px;
|
||||||
|
padding:0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body
|
||||||
|
{
|
||||||
|
font: 21px/26px 'Comic Sans Ms', Fantasy;
|
||||||
|
color: #FFFFFF;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
background-color: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
position:absolute;
|
||||||
|
left:1%;
|
||||||
|
width: 98%;
|
||||||
|
height: 1px;
|
||||||
|
bottom: 22px;
|
||||||
|
color:#000000;
|
||||||
|
border: none;
|
||||||
|
z-index:6;
|
||||||
|
}
|
||||||
|
|
||||||
|
#win {
|
||||||
|
display:none;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main {
|
||||||
|
width: 94.9%;
|
||||||
|
padding-left: 2.5%;
|
||||||
|
padding-right: 2.5%;
|
||||||
|
font: 21px/26px 'Trebuchet Ms', Sans-Serif;
|
||||||
|
color: #220;
|
||||||
|
float:left;
|
||||||
|
position:relative;
|
||||||
|
top:0px;
|
||||||
|
text-align: justify;
|
||||||
|
overflow:hidden;
|
||||||
|
overflow-y:auto;
|
||||||
|
/*border:1px solid #000;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
#main span
|
||||||
|
{
|
||||||
|
display:block;
|
||||||
|
text-indent:7%;
|
||||||
|
clear:both;
|
||||||
|
padding:0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main p
|
||||||
|
{
|
||||||
|
display:block;
|
||||||
|
text-indent:7%;
|
||||||
|
clear:both;
|
||||||
|
padding:0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main dd
|
||||||
|
{
|
||||||
|
display:block;
|
||||||
|
text-indent:7%;
|
||||||
|
clear:both;
|
||||||
|
padding:0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main div
|
||||||
|
{
|
||||||
|
text-indent:7%;
|
||||||
|
clear:both;
|
||||||
|
padding:0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#main span p
|
||||||
|
{
|
||||||
|
text-indent:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#main span div
|
||||||
|
{
|
||||||
|
text-indent:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#main img
|
||||||
|
{
|
||||||
|
border:0px;
|
||||||
|
vertical-align:top;float:left;
|
||||||
|
|
||||||
|
padding:0px;
|
||||||
|
line-height:0px;
|
||||||
|
font-size:0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.podk
|
||||||
|
{
|
||||||
|
position:absolute;
|
||||||
|
border:3px solid #220;
|
||||||
|
display:none;
|
||||||
|
z-index:9;
|
||||||
|
height:280px;
|
||||||
|
width:264px;
|
||||||
|
font: bold 16px 'Trebuchet Ms', Sans-Serif;
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.podk span
|
||||||
|
{
|
||||||
|
text-align:center;
|
||||||
|
font: 21px/21px 'Trebuchet Ms', Sans-Serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.melem {
|
||||||
|
padding-left: 20px;
|
||||||
|
line-height: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.melem label {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.melem label input {
|
||||||
|
cursor: pointer;
|
||||||
|
position: relative;
|
||||||
|
border:0;
|
||||||
|
left: 10px;
|
||||||
|
top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.melem input
|
||||||
|
{
|
||||||
|
background-color:transparent;
|
||||||
|
border:0px solid #fff;
|
||||||
|
font: bold 14px 'Trebuchet Ms', Sans-Serif;
|
||||||
|
text-align:center;
|
||||||
|
height: 18px;
|
||||||
|
border:1px solid #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.melem b
|
||||||
|
{
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.over
|
||||||
|
{
|
||||||
|
display:block;
|
||||||
|
color:#500;
|
||||||
|
background-color:black;
|
||||||
|
text-align:center;
|
||||||
|
vertical-align:middle;
|
||||||
|
width:100%;
|
||||||
|
height:10050px;
|
||||||
|
position:absolute;
|
||||||
|
right:0px;
|
||||||
|
bottom:0px;
|
||||||
|
z-index:15;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#loading
|
||||||
|
{
|
||||||
|
background-color:black;
|
||||||
|
font: 40px 'Trebuchet Ms', Sans-Serif;
|
||||||
|
align:center;
|
||||||
|
color:#FFFFFF;
|
||||||
|
position:absolute;
|
||||||
|
left:48%;
|
||||||
|
bottom:50%;
|
||||||
|
z-index:16;
|
||||||
|
}
|
||||||
|
|
||||||
|
a
|
||||||
|
{
|
||||||
|
text-decoration:none;
|
||||||
|
}
|
||||||
|
a:hover
|
||||||
|
{
|
||||||
|
text-decoration:underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#footer div a:hover, div#comm div a:hover
|
||||||
|
{
|
||||||
|
text-decoration:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tl
|
||||||
|
{
|
||||||
|
width:14px;
|
||||||
|
float:left;
|
||||||
|
}
|
||||||
|
#tr
|
||||||
|
{
|
||||||
|
width:14px;
|
||||||
|
float:right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header
|
||||||
|
{
|
||||||
|
height: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
display: none;
|
||||||
|
font: 18px/21px 'Trebuchet Ms', Sans-Serif;
|
||||||
|
width:100%;
|
||||||
|
height:22px;
|
||||||
|
position:absolute;
|
||||||
|
bottom:0px;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page, .cpage
|
||||||
|
{
|
||||||
|
position:relative;
|
||||||
|
float: left;
|
||||||
|
vertical-align: bottom;
|
||||||
|
border: 0px solid yellow;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cpage
|
||||||
|
{
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tm
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#pageCount
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#pagePercent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#bmain
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
div#pageCount div
|
||||||
|
{
|
||||||
|
overflow:hidden;
|
||||||
|
float:left;
|
||||||
|
cursor:pointer;
|
||||||
|
text-align:center;
|
||||||
|
visibility:hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.l
|
||||||
|
{
|
||||||
|
left:17px;
|
||||||
|
float:left;
|
||||||
|
margin-left:0;
|
||||||
|
}
|
||||||
|
.t
|
||||||
|
{
|
||||||
|
top:4px;
|
||||||
|
}
|
||||||
|
.b
|
||||||
|
{
|
||||||
|
bottom:4px;
|
||||||
|
}
|
||||||
|
.r
|
||||||
|
{
|
||||||
|
right:17px;
|
||||||
|
float:right;
|
||||||
|
}
|
||||||
|
.a
|
||||||
|
{
|
||||||
|
position:absolute;
|
||||||
|
line-height:0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.addr {
|
||||||
|
width:80%;
|
||||||
|
margin-left: 21%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#book
|
||||||
|
{
|
||||||
|
border-right:0px solid #fff !important;
|
||||||
|
}
|
||||||
|
.book
|
||||||
|
{
|
||||||
|
background-color:transparent;
|
||||||
|
border:2px groove #000;
|
||||||
|
font: bold 16px 'Trebuchet Ms', Sans-Serif;
|
||||||
|
height: 26px;
|
||||||
|
padding:0;
|
||||||
|
margin:0;
|
||||||
|
display:block;
|
||||||
|
float:left;
|
||||||
|
}
|
||||||
|
#btnOk
|
||||||
|
{
|
||||||
|
height: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#book:hover
|
||||||
|
{
|
||||||
|
border-left:2px ridge #000;
|
||||||
|
}
|
||||||
|
.book:hover
|
||||||
|
{
|
||||||
|
border:2px ridge #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#leg
|
||||||
|
{
|
||||||
|
font: bold 12px Verdana, Sans-Serif;
|
||||||
|
line-height:12px;
|
||||||
|
width:60%;
|
||||||
|
height:60%;
|
||||||
|
background-color:#fff;
|
||||||
|
color:#000;
|
||||||
|
border:4px double black;
|
||||||
|
padding:20px;
|
||||||
|
text-align: justify;
|
||||||
|
z-index:16;
|
||||||
|
position:absolute;
|
||||||
|
overflow:scroll;
|
||||||
|
top:0;
|
||||||
|
left:0;
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
#leg b
|
||||||
|
{
|
||||||
|
color: #AA2222;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*êåëâ àüþìî÷ ôàåï÷ START*/
|
||||||
|
div#colorSelect
|
||||||
|
{
|
||||||
|
width:758px;
|
||||||
|
height:600px;
|
||||||
|
z-index:20;
|
||||||
|
display:none;
|
||||||
|
position:absolute;
|
||||||
|
color:#220;
|
||||||
|
}
|
||||||
|
div.colorImage
|
||||||
|
{
|
||||||
|
width:600px;
|
||||||
|
height:600px;
|
||||||
|
background:url(/js/colo58.png);
|
||||||
|
float:right;
|
||||||
|
cursor:crosshair;
|
||||||
|
}
|
||||||
|
div.colorMenu
|
||||||
|
{
|
||||||
|
overflow:hidden;
|
||||||
|
width:150px;
|
||||||
|
height:330px;
|
||||||
|
border: 3px solid #000;
|
||||||
|
position:relative;
|
||||||
|
background-color:white;
|
||||||
|
font: 20px/22px 'Trebuchet Ms', Sans-Serif;
|
||||||
|
top:150px;
|
||||||
|
}
|
||||||
|
div.colorMenu div div
|
||||||
|
{
|
||||||
|
cursor:pointer;
|
||||||
|
float:left;
|
||||||
|
width:76px;
|
||||||
|
}
|
||||||
|
div.colorMenu div input
|
||||||
|
{
|
||||||
|
float:right;
|
||||||
|
height:18px;
|
||||||
|
width:70px;
|
||||||
|
border: 1px solid #000;
|
||||||
|
margin:1px 0px;
|
||||||
|
display:block;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.colorMenu div select
|
||||||
|
{
|
||||||
|
width: 70px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.colorExample
|
||||||
|
{
|
||||||
|
position:absolute;
|
||||||
|
width:150px;
|
||||||
|
height:78px;
|
||||||
|
font: 21px/78px 'Trebuchet Ms', Sans-Serif;
|
||||||
|
text-align:center;
|
||||||
|
}
|
||||||
|
div.colorCross
|
||||||
|
{
|
||||||
|
position:absolute;
|
||||||
|
top:143px;
|
||||||
|
left:147px;
|
||||||
|
width:14px;
|
||||||
|
height:14px;
|
||||||
|
z-index:21;
|
||||||
|
cursor:pointer;
|
||||||
|
line-height:7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.menuCross
|
||||||
|
{
|
||||||
|
font: 21px/26px 'Comic Sans Ms', Fantasy;
|
||||||
|
position:absolute;
|
||||||
|
top:-8px;
|
||||||
|
left: 258px;
|
||||||
|
width:14px;
|
||||||
|
height:14px;
|
||||||
|
z-index:21;
|
||||||
|
cursor:pointer;
|
||||||
|
line-height:7px;
|
||||||
|
}
|
||||||
|
/*êåëâ àüþìî÷ ôàåï÷ END*/
|
||||||
|
|
||||||
|
.test {
|
||||||
|
border: 1px solid #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#cbscroll {
|
||||||
|
padding-top: 3px;
|
||||||
|
padding-left: 30px;
|
||||||
|
}
|
||||||
96
docs/omnireader/old/parser.php
Normal file
96
docs/omnireader/old/parser.php
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function parseHtml($data, $remove_tags = FALSE) {
|
||||||
|
$substs = array(
|
||||||
|
//html
|
||||||
|
'TD' => chr(9),
|
||||||
|
'TH' => chr(9),
|
||||||
|
'TR' => chr(13) . chr(10) . '<P>',
|
||||||
|
'BR' => chr(13) . chr(10) . '<P>',
|
||||||
|
'BR/' => chr(13) . chr(10) . '<P>',
|
||||||
|
'DD' => chr(13) . chr(10) . '<P>',
|
||||||
|
'P' => chr(13) . chr(10) . '<P>',
|
||||||
|
'HR' => chr(13) . chr(10),
|
||||||
|
'LI' => chr(13) . chr(10),
|
||||||
|
'OL' => chr(13) . chr(10),
|
||||||
|
'/OL' => chr(13) . chr(10),
|
||||||
|
'TABLE' => chr(13) . chr(10),
|
||||||
|
'/TABLE' => chr(13) . chr(10),
|
||||||
|
'TITLE' => '<br> ',
|
||||||
|
'/TITLE' => '<br> ',
|
||||||
|
'UL' => chr(13) . chr(10) . ' ',
|
||||||
|
'/UL' => chr(13) . chr(10),
|
||||||
|
|
||||||
|
// fb2
|
||||||
|
'EMPTY-LINE/' => '<P> ',
|
||||||
|
'STANZA' => '<P> ',
|
||||||
|
'V' => '<P>',
|
||||||
|
'/POEM' => '<P> ',
|
||||||
|
'SUBTITLE' => '<br> <P>',
|
||||||
|
'/SUBTITLE' => '<br> ',
|
||||||
|
);
|
||||||
|
|
||||||
|
$inner_cut = array(
|
||||||
|
'HEAD' => 1,
|
||||||
|
'SCRIPT' => 1,
|
||||||
|
'STYLE' => 1,
|
||||||
|
//fb2
|
||||||
|
'BINARY' => 1,
|
||||||
|
'DESCRIPTION' => 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($remove_tags)
|
||||||
|
$substs = $inner_cut = array();
|
||||||
|
|
||||||
|
|
||||||
|
$data = str_replace(' ', ' ', $data);
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
$len = strlen($data);
|
||||||
|
$out = '';
|
||||||
|
$cut_counter = 0;
|
||||||
|
$cut_tag = '';
|
||||||
|
while ($i < $len) {
|
||||||
|
$left = strpos($data, '<', $i);
|
||||||
|
if ($left !== FALSE) {
|
||||||
|
$right = strpos($data, '>', $left + 1);
|
||||||
|
if ($right !== FALSE) {
|
||||||
|
$tag = trim(substr($data, $left + 1, $right - $left - 1));
|
||||||
|
$first_space = strpos($tag, ' ');
|
||||||
|
if ($first_space !== FALSE)
|
||||||
|
$tag = substr($tag, 0, $first_space);
|
||||||
|
$tag = strtoupper($tag);
|
||||||
|
|
||||||
|
if (!$cut_counter) {
|
||||||
|
$out .= substr($data, $i, $left - $i);
|
||||||
|
if (isset($substs[$tag]))
|
||||||
|
$out .= $substs[$tag];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($inner_cut[$tag]) && (!$cut_counter || $cut_tag == $tag))
|
||||||
|
{
|
||||||
|
if (!$cut_counter)
|
||||||
|
$cut_tag = $tag;
|
||||||
|
$cut_counter++;
|
||||||
|
}
|
||||||
|
if ($tag != '' && $tag[0] == '/' && $cut_tag == substr($tag, 1)) {
|
||||||
|
$cut_counter = ($cut_counter > 0) ? $cut_counter - 1 : 0;
|
||||||
|
if (!$cut_counter)
|
||||||
|
$cut_tag = '';
|
||||||
|
}
|
||||||
|
//$close_tag = substr($tag, 1);
|
||||||
|
//$out .= "<br>$cut_counter, $cut_tag == $close_tag";
|
||||||
|
|
||||||
|
$i = $right + 1;
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($i < $len && !$cut_counter)
|
||||||
|
$out .= substr($data, $i, $len - $i);
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
2
docs/omnireader/old/robots.txt
Normal file
2
docs/omnireader/old/robots.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
User-agent: *
|
||||||
|
Disallow: /?*url=
|
||||||
4
docs/omnireader/old/test.php
Normal file
4
docs/omnireader/old/test.php
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: text/html; charset=windows-1251');
|
||||||
|
echo getcwd();
|
||||||
|
?>
|
||||||
2
docs/omnireader/old/txt/.htaccess
Normal file
2
docs/omnireader/old/txt/.htaccess
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
AddType 'text/plain; charset=windows-1251' .txz .txt
|
||||||
|
AddEncoding gzip .txz
|
||||||
@@ -23,3 +23,26 @@ server {
|
|||||||
root /home/liberama/public;
|
root /home/liberama/public;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name old.omnireader.ru;
|
||||||
|
|
||||||
|
client_max_body_size 50m;
|
||||||
|
|
||||||
|
gzip on;
|
||||||
|
gzip_min_length 1024;
|
||||||
|
gzip_proxied expired no-cache no-store private auth;
|
||||||
|
gzip_types *;
|
||||||
|
|
||||||
|
root /home/oldreader;
|
||||||
|
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
# Обработка php файлов с помощью fpm
|
||||||
|
location ~ \.php$ {
|
||||||
|
try_files $uri =404;
|
||||||
|
include /etc/nginx/fastcgi.conf;
|
||||||
|
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,30 @@
|
|||||||
sudo bash
|
sudo bash
|
||||||
|
|
||||||
mkdir /home/liberama
|
mkdir /home/liberama
|
||||||
chown www-data /home/liberama
|
chown www-data.www-data /home/liberama
|
||||||
chgrp www-data /home/liberama
|
|
||||||
|
### oldreader
|
||||||
|
# ubuntu 18
|
||||||
|
apt install php7.2 php7.2-curl php7.2-mbstring php7.2-fpm
|
||||||
|
service php7.2-fpm restart
|
||||||
|
|
||||||
|
mkdir /home/oldreader
|
||||||
|
chown www-data /home/oldreader
|
||||||
|
chgrp www-data /home/oldreader
|
||||||
|
sudo -u www-data cp -r ./old/* /home/oldreader
|
||||||
|
###
|
||||||
|
|
||||||
|
### external converter
|
||||||
|
# calibre releases https://download.calibre-ebook.com/
|
||||||
|
# download, unpack to data/calibre
|
||||||
|
# 3.39.1
|
||||||
|
wget "https://download.calibre-ebook.com/3.39.1/calibre-3.39.1-x86_64.txz"
|
||||||
|
sudo -u www-data mkdir -p /home/liberama/data/calibre
|
||||||
|
sudo -u www-data tar xvf calibre-3.39.1-x86_64.txz -C /home/liberama/data/calibre
|
||||||
|
|
||||||
|
apt install libreoffice
|
||||||
|
apt install poppler-utils
|
||||||
|
###
|
||||||
|
|
||||||
apt install nginx
|
apt install nginx
|
||||||
|
|
||||||
@@ -11,5 +33,7 @@ ln -s /etc/nginx/sites-available/omnireader /etc/nginx/sites-enabled/omnireader
|
|||||||
rm /etc/nginx/sites-enabled/default
|
rm /etc/nginx/sites-enabled/default
|
||||||
service nginx reload
|
service nginx reload
|
||||||
|
|
||||||
|
chown -R www-data.www-data /var/www
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
sudo -u www-data /home/liberama/liberama
|
sudo -H -u www-data sh -c "cd /var/www; /home/liberama/liberama"
|
||||||
326
package-lock.json
generated
326
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.2.0",
|
"version": "0.5.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1597,9 +1597,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"base64-js": {
|
"base64-js": {
|
||||||
"version": "0.0.8",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-0.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz",
|
||||||
"integrity": "sha1-EQHpVE9KdrG8OybUUsqW16NeeXg="
|
"integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw=="
|
||||||
},
|
},
|
||||||
"bcrypt-pbkdf": {
|
"bcrypt-pbkdf": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@@ -1622,12 +1622,23 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"bl": {
|
"bl": {
|
||||||
"version": "1.2.2",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/bl/-/bl-3.0.0.tgz",
|
||||||
"integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==",
|
"integrity": "sha512-EUAyP5UHU5hxF8BPT0LKW8gjYLhq1DQIcneOX/pL/m2Alo+OYDQAJlHq+yseMP50Os2nHXOSic6Ss3vSQeyf4A==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"readable-stream": "^2.3.5",
|
"readable-stream": "^3.0.1"
|
||||||
"safe-buffer": "^5.1.1"
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"readable-stream": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-RV20kLjdmpZuTF1INEb9IA3L68Nmi+Ri7ppZqo78wj//Pn62fCoJyV9zalccNzDD/OuJpMG4f+pfMl8+L6QdGw==",
|
||||||
|
"requires": {
|
||||||
|
"inherits": "^2.0.3",
|
||||||
|
"string_decoder": "^1.1.1",
|
||||||
|
"util-deprecate": "^1.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bluebird": {
|
"bluebird": {
|
||||||
@@ -1809,39 +1820,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"buffer": {
|
"buffer": {
|
||||||
"version": "3.6.0",
|
"version": "5.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-3.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz",
|
||||||
"integrity": "sha1-pyyTb3e5a/UvX357RnGAYoVR3vs=",
|
"integrity": "sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"base64-js": "0.0.8",
|
"base64-js": "^1.0.2",
|
||||||
"ieee754": "^1.1.4",
|
"ieee754": "^1.1.4"
|
||||||
"isarray": "^1.0.0"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"buffer-alloc": {
|
|
||||||
"version": "1.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz",
|
|
||||||
"integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==",
|
|
||||||
"requires": {
|
|
||||||
"buffer-alloc-unsafe": "^1.1.0",
|
|
||||||
"buffer-fill": "^1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"buffer-alloc-unsafe": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg=="
|
|
||||||
},
|
|
||||||
"buffer-crc32": {
|
|
||||||
"version": "0.2.13",
|
|
||||||
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
|
|
||||||
"integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI="
|
|
||||||
},
|
|
||||||
"buffer-fill": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw="
|
|
||||||
},
|
|
||||||
"buffer-from": {
|
"buffer-from": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||||
@@ -2354,14 +2340,6 @@
|
|||||||
"delayed-stream": "~1.0.0"
|
"delayed-stream": "~1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"commander": {
|
|
||||||
"version": "2.8.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz",
|
|
||||||
"integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=",
|
|
||||||
"requires": {
|
|
||||||
"graceful-readlink": ">= 1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"commondir": {
|
"commondir": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
|
||||||
@@ -3080,21 +3058,6 @@
|
|||||||
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
|
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"decompress": {
|
|
||||||
"version": "4.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress/-/decompress-4.2.0.tgz",
|
|
||||||
"integrity": "sha1-eu3YVCflqS2s/lVnSnxQXpbQH50=",
|
|
||||||
"requires": {
|
|
||||||
"decompress-tar": "^4.0.0",
|
|
||||||
"decompress-tarbz2": "^4.0.0",
|
|
||||||
"decompress-targz": "^4.0.0",
|
|
||||||
"decompress-unzip": "^4.0.1",
|
|
||||||
"graceful-fs": "^4.1.10",
|
|
||||||
"make-dir": "^1.0.0",
|
|
||||||
"pify": "^2.3.0",
|
|
||||||
"strip-dirs": "^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-response": {
|
"decompress-response": {
|
||||||
"version": "3.3.0",
|
"version": "3.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz",
|
||||||
@@ -3103,63 +3066,6 @@
|
|||||||
"mimic-response": "^1.0.0"
|
"mimic-response": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"decompress-tar": {
|
|
||||||
"version": "4.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-tar/-/decompress-tar-4.1.1.tgz",
|
|
||||||
"integrity": "sha512-JdJMaCrGpB5fESVyxwpCx4Jdj2AagLmv3y58Qy4GE6HMVjWz1FeVQk1Ct4Kye7PftcdOo/7U7UKzYBJgqnGeUQ==",
|
|
||||||
"requires": {
|
|
||||||
"file-type": "^5.2.0",
|
|
||||||
"is-stream": "^1.1.0",
|
|
||||||
"tar-stream": "^1.5.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-tarbz2": {
|
|
||||||
"version": "4.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-tarbz2/-/decompress-tarbz2-4.1.1.tgz",
|
|
||||||
"integrity": "sha512-s88xLzf1r81ICXLAVQVzaN6ZmX4A6U4z2nMbOwobxkLoIIfjVMBg7TeguTUXkKeXni795B6y5rnvDw7rxhAq9A==",
|
|
||||||
"requires": {
|
|
||||||
"decompress-tar": "^4.1.0",
|
|
||||||
"file-type": "^6.1.0",
|
|
||||||
"is-stream": "^1.1.0",
|
|
||||||
"seek-bzip": "^1.0.5",
|
|
||||||
"unbzip2-stream": "^1.0.9"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"file-type": {
|
|
||||||
"version": "6.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-6.2.0.tgz",
|
|
||||||
"integrity": "sha512-YPcTBDV+2Tm0VqjybVd32MHdlEGAtuxS3VAYsumFokDSMG+ROT5wawGlnHDoz7bfMcMDt9hxuXvXwoKUx2fkOg=="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-targz": {
|
|
||||||
"version": "4.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-targz/-/decompress-targz-4.1.1.tgz",
|
|
||||||
"integrity": "sha512-4z81Znfr6chWnRDNfFNqLwPvm4db3WuZkqV+UgXQzSngG3CEKdBkw5jrv3axjjL96glyiiKjsxJG3X6WBZwX3w==",
|
|
||||||
"requires": {
|
|
||||||
"decompress-tar": "^4.1.1",
|
|
||||||
"file-type": "^5.2.0",
|
|
||||||
"is-stream": "^1.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"decompress-unzip": {
|
|
||||||
"version": "4.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/decompress-unzip/-/decompress-unzip-4.0.1.tgz",
|
|
||||||
"integrity": "sha1-3qrM39FK6vhVePczroIQ+bSEj2k=",
|
|
||||||
"requires": {
|
|
||||||
"file-type": "^3.8.0",
|
|
||||||
"get-stream": "^2.2.0",
|
|
||||||
"pify": "^2.3.0",
|
|
||||||
"yauzl": "^2.4.2"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"file-type": {
|
|
||||||
"version": "3.9.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz",
|
|
||||||
"integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"deep-extend": {
|
"deep-extend": {
|
||||||
"version": "0.6.0",
|
"version": "0.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
|
||||||
@@ -3267,11 +3173,6 @@
|
|||||||
"integrity": "sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=",
|
"integrity": "sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"detect-file-type": {
|
|
||||||
"version": "0.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/detect-file-type/-/detect-file-type-0.2.0.tgz",
|
|
||||||
"integrity": "sha512-RO/pUyKObaN3KZFVAxTzq6zUIweCu45deaUj2ZpbA1wCrmHeHYHpCXT6ZMLtlMtYSgEbpGuCxzQz8a9IuwOfNw=="
|
|
||||||
},
|
|
||||||
"detect-indent": {
|
"detect-indent": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz",
|
||||||
@@ -4153,6 +4054,43 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"extract-zip": {
|
||||||
|
"version": "1.6.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.7.tgz",
|
||||||
|
"integrity": "sha1-qEC0uK9kAyZMjbV/Txp0Mz74H+k=",
|
||||||
|
"requires": {
|
||||||
|
"concat-stream": "1.6.2",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"mkdirp": "0.5.1",
|
||||||
|
"yauzl": "2.4.1"
|
||||||
|
},
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fd-slicer": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=",
|
||||||
|
"requires": {
|
||||||
|
"pend": "~1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"yauzl": {
|
||||||
|
"version": "2.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz",
|
||||||
|
"integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=",
|
||||||
|
"requires": {
|
||||||
|
"fd-slicer": "~1.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"extsprintf": {
|
"extsprintf": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
|
||||||
@@ -4194,14 +4132,6 @@
|
|||||||
"integrity": "sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ==",
|
"integrity": "sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"fd-slicer": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
|
|
||||||
"integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=",
|
|
||||||
"requires": {
|
|
||||||
"pend": "~1.2.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"fg-loadcss": {
|
"fg-loadcss": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/fg-loadcss/-/fg-loadcss-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/fg-loadcss/-/fg-loadcss-2.1.0.tgz",
|
||||||
@@ -4242,11 +4172,6 @@
|
|||||||
"schema-utils": "^1.0.0"
|
"schema-utils": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"file-type": {
|
|
||||||
"version": "5.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-5.2.0.tgz",
|
|
||||||
"integrity": "sha1-LdvqfHP/42No365J3DOMBYwritY="
|
|
||||||
},
|
|
||||||
"fill-range": {
|
"fill-range": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz",
|
||||||
@@ -5038,15 +4963,6 @@
|
|||||||
"integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==",
|
"integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"get-stream": {
|
|
||||||
"version": "2.3.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz",
|
|
||||||
"integrity": "sha1-Xzj5PzRgCWZu4BUKBUFn+Rvdld4=",
|
|
||||||
"requires": {
|
|
||||||
"object-assign": "^4.0.1",
|
|
||||||
"pinkie-promise": "^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"get-value": {
|
"get-value": {
|
||||||
"version": "2.0.6",
|
"version": "2.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz",
|
||||||
@@ -5201,11 +5117,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz",
|
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz",
|
||||||
"integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA=="
|
"integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA=="
|
||||||
},
|
},
|
||||||
"graceful-readlink": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU="
|
|
||||||
},
|
|
||||||
"har-schema": {
|
"har-schema": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
||||||
@@ -5948,11 +5859,6 @@
|
|||||||
"is-extglob": "^2.1.1"
|
"is-extglob": "^2.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"is-natural-number": {
|
|
||||||
"version": "4.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-natural-number/-/is-natural-number-4.0.1.tgz",
|
|
||||||
"integrity": "sha1-q5124dtM7VHjXeDHLr7PCfc0zeg="
|
|
||||||
},
|
|
||||||
"is-number": {
|
"is-number": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz",
|
||||||
@@ -6012,7 +5918,8 @@
|
|||||||
"is-stream": {
|
"is-stream": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
|
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"is-svg": {
|
"is-svg": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
@@ -6317,6 +6224,7 @@
|
|||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
|
||||||
"integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==",
|
"integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==",
|
||||||
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"pify": "^3.0.0"
|
"pify": "^3.0.0"
|
||||||
},
|
},
|
||||||
@@ -6324,7 +6232,8 @@
|
|||||||
"pify": {
|
"pify": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
|
||||||
"integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY="
|
"integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=",
|
||||||
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -7394,20 +7303,17 @@
|
|||||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||||
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
|
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
|
||||||
},
|
},
|
||||||
"pify": {
|
|
||||||
"version": "2.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
|
||||||
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
|
|
||||||
},
|
|
||||||
"pinkie": {
|
"pinkie": {
|
||||||
"version": "2.0.4",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz",
|
||||||
"integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA="
|
"integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"pinkie-promise": {
|
"pinkie-promise": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz",
|
||||||
"integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=",
|
"integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=",
|
||||||
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"pinkie": "^2.0.0"
|
"pinkie": "^2.0.0"
|
||||||
}
|
}
|
||||||
@@ -10028,14 +9934,6 @@
|
|||||||
"ajv-keywords": "^3.1.0"
|
"ajv-keywords": "^3.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"seek-bzip": {
|
|
||||||
"version": "1.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/seek-bzip/-/seek-bzip-1.0.5.tgz",
|
|
||||||
"integrity": "sha1-z+kXyz0nS8/6x5J1ivUxc+sfq9w=",
|
|
||||||
"requires": {
|
|
||||||
"commander": "~2.8.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"semver": {
|
"semver": {
|
||||||
"version": "5.6.0",
|
"version": "5.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
|
||||||
@@ -10544,14 +10442,6 @@
|
|||||||
"ansi-regex": "^2.0.0"
|
"ansi-regex": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"strip-dirs": {
|
|
||||||
"version": "2.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/strip-dirs/-/strip-dirs-2.1.0.tgz",
|
|
||||||
"integrity": "sha512-JOCxOeKLm2CAS73y/U4ZeZPTkE+gNVCzKt7Eox84Iej1LT/2pTWYpZKJuxwQpvX1LiZb1xokNR7RLfuBAa7T3g==",
|
|
||||||
"requires": {
|
|
||||||
"is-natural-number": "^4.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"strip-eof": {
|
"strip-eof": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
|
||||||
@@ -10751,18 +10641,50 @@
|
|||||||
"yallist": "^3.0.2"
|
"yallist": "^3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tar-stream": {
|
"tar-fs": {
|
||||||
"version": "1.6.2",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.0.0.tgz",
|
||||||
"integrity": "sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==",
|
"integrity": "sha512-vaY0obB6Om/fso8a8vakQBzwholQ7v5+uy+tF3Ozvxv1KNezmVQAiWtcNmMHFSFPqL3dJA8ha6gdtFbfX9mcxA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"bl": "^1.0.0",
|
"chownr": "^1.1.1",
|
||||||
"buffer-alloc": "^1.2.0",
|
"mkdirp": "^0.5.1",
|
||||||
"end-of-stream": "^1.0.0",
|
"pump": "^3.0.0",
|
||||||
|
"tar-stream": "^2.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"pump": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
|
||||||
|
"requires": {
|
||||||
|
"end-of-stream": "^1.1.0",
|
||||||
|
"once": "^1.3.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tar-stream": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-I6OJF7wE62BC6zNPdHDtseK0D0187PBjbKSLYY4ffvVkBM6tyBn2O9plDvVM2229/mozfEL/X3++qSvYYQE2xw==",
|
||||||
|
"requires": {
|
||||||
|
"bl": "^3.0.0",
|
||||||
|
"end-of-stream": "^1.4.1",
|
||||||
"fs-constants": "^1.0.0",
|
"fs-constants": "^1.0.0",
|
||||||
"readable-stream": "^2.3.0",
|
"inherits": "^2.0.3",
|
||||||
"to-buffer": "^1.1.1",
|
"readable-stream": "^3.1.1"
|
||||||
"xtend": "^4.0.0"
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"readable-stream": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-RV20kLjdmpZuTF1INEb9IA3L68Nmi+Ri7ppZqo78wj//Pn62fCoJyV9zalccNzDD/OuJpMG4f+pfMl8+L6QdGw==",
|
||||||
|
"requires": {
|
||||||
|
"inherits": "^2.0.3",
|
||||||
|
"string_decoder": "^1.1.1",
|
||||||
|
"util-deprecate": "^1.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"terser": {
|
"terser": {
|
||||||
@@ -11017,11 +10939,6 @@
|
|||||||
"integrity": "sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=",
|
"integrity": "sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"to-buffer": {
|
|
||||||
"version": "1.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz",
|
|
||||||
"integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg=="
|
|
||||||
},
|
|
||||||
"to-fast-properties": {
|
"to-fast-properties": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz",
|
||||||
@@ -11182,12 +11099,12 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"unbzip2-stream": {
|
"unbzip2-stream": {
|
||||||
"version": "1.3.1",
|
"version": "1.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/unbzip2-stream/-/unbzip2-stream-1.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/unbzip2-stream/-/unbzip2-stream-1.3.3.tgz",
|
||||||
"integrity": "sha512-fIZnvdjblYs7Cru/xC6tCPVhz7JkYcVQQkePwMLyQELzYTds2Xn8QefPVnvdVhhZqubxNA1cASXEH5wcK0Bucw==",
|
"integrity": "sha512-fUlAF7U9Ah1Q6EieQ4x4zLNejrRvDWUYmxXUpN3uziFYCHapjWFaCAnreY9bGgxzaMCFAPPpYNng57CypwJVhg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"buffer": "^3.0.1",
|
"buffer": "^5.2.1",
|
||||||
"through": "^2.3.6"
|
"through": "^2.3.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"union-value": {
|
"union-value": {
|
||||||
@@ -11984,15 +11901,6 @@
|
|||||||
"camelcase": "^5.0.0",
|
"camelcase": "^5.0.0",
|
||||||
"decamelize": "^1.2.0"
|
"decamelize": "^1.2.0"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"yauzl": {
|
|
||||||
"version": "2.10.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",
|
|
||||||
"integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=",
|
|
||||||
"requires": {
|
|
||||||
"buffer-crc32": "~0.2.3",
|
|
||||||
"fd-slicer": "~1.1.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Liberama",
|
"name": "Liberama",
|
||||||
"version": "0.2.2",
|
"version": "0.5.6",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
},
|
},
|
||||||
@@ -29,7 +29,6 @@
|
|||||||
"clean-webpack-plugin": "^1.0.0",
|
"clean-webpack-plugin": "^1.0.0",
|
||||||
"copy-webpack-plugin": "^4.6.0",
|
"copy-webpack-plugin": "^4.6.0",
|
||||||
"css-loader": "^1.0.0",
|
"css-loader": "^1.0.0",
|
||||||
"decompress-targz": "^4.1.1",
|
|
||||||
"disable-output-webpack-plugin": "^1.0.1",
|
"disable-output-webpack-plugin": "^1.0.1",
|
||||||
"element-theme-chalk": "^2.4.11",
|
"element-theme-chalk": "^2.4.11",
|
||||||
"eslint": "^5.11.1",
|
"eslint": "^5.11.1",
|
||||||
@@ -59,10 +58,9 @@
|
|||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
"chardet": "^0.7.0",
|
"chardet": "^0.7.0",
|
||||||
"compression": "^1.7.3",
|
"compression": "^1.7.3",
|
||||||
"decompress": "^4.2.0",
|
|
||||||
"detect-file-type": "^0.2.0",
|
|
||||||
"element-ui": "^2.4.11",
|
"element-ui": "^2.4.11",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
|
"extract-zip": "^1.6.7",
|
||||||
"fg-loadcss": "^2.1.0",
|
"fg-loadcss": "^2.1.0",
|
||||||
"fs-extra": "^7.0.1",
|
"fs-extra": "^7.0.1",
|
||||||
"got": "^9.5.1",
|
"got": "^9.5.1",
|
||||||
@@ -75,6 +73,8 @@
|
|||||||
"path-browserify": "^1.0.0",
|
"path-browserify": "^1.0.0",
|
||||||
"sql-template-strings": "^2.2.2",
|
"sql-template-strings": "^2.2.2",
|
||||||
"sqlite": "^3.0.0",
|
"sqlite": "^3.0.0",
|
||||||
|
"tar-fs": "^2.0.0",
|
||||||
|
"unbzip2-stream": "^1.3.3",
|
||||||
"vue": "^2.5.21",
|
"vue": "^2.5.21",
|
||||||
"vue-router": "^3.0.2",
|
"vue-router": "^3.0.2",
|
||||||
"vuex": "^3.0.1",
|
"vuex": "^3.0.1",
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ module.exports = {
|
|||||||
maxTempPublicDirSize: 512*1024*1024,//512Мб
|
maxTempPublicDirSize: 512*1024*1024,//512Мб
|
||||||
maxUploadPublicDirSize: 200*1024*1024,//100Мб
|
maxUploadPublicDirSize: 200*1024*1024,//100Мб
|
||||||
|
|
||||||
|
useExternalBookConverter: false,
|
||||||
|
|
||||||
servers: [
|
servers: [
|
||||||
{
|
{
|
||||||
serverName: '1',
|
serverName: '1',
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ const propsToSave = [
|
|||||||
'maxUploadFileSize',
|
'maxUploadFileSize',
|
||||||
'maxTempPublicDirSize',
|
'maxTempPublicDirSize',
|
||||||
'maxUploadPublicDirSize',
|
'maxUploadPublicDirSize',
|
||||||
|
'useExternalBookConverter',
|
||||||
|
|
||||||
'servers',
|
'servers',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
142
server/core/BookConverter/ConvertBase.js
Normal file
142
server/core/BookConverter/ConvertBase.js
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const iconv = require('iconv-lite');
|
||||||
|
const chardet = require('chardet');
|
||||||
|
|
||||||
|
const textUtils = require('./textUtils');
|
||||||
|
const utils = require('../utils');
|
||||||
|
|
||||||
|
let execConverterCounter = 0;
|
||||||
|
|
||||||
|
class ConvertBase {
|
||||||
|
constructor(config) {
|
||||||
|
this.config = config;
|
||||||
|
|
||||||
|
this.calibrePath = `${config.dataDir}/calibre/ebook-convert`;
|
||||||
|
this.sofficePath = '/usr/bin/soffice';
|
||||||
|
this.pdfToHtmlPath = '/usr/bin/pdftohtml';
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {// eslint-disable-line no-unused-vars
|
||||||
|
//override
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkExternalConverterPresent() {
|
||||||
|
if (!await fs.pathExists(this.calibrePath))
|
||||||
|
throw new Error('Внешний конвертер calibre не найден');
|
||||||
|
|
||||||
|
if (!await fs.pathExists(this.sofficePath))
|
||||||
|
throw new Error('Внешний конвертер LibreOffice не найден');
|
||||||
|
|
||||||
|
if (!await fs.pathExists(this.pdfToHtmlPath))
|
||||||
|
throw new Error('Внешний конвертер pdftohtml не найден');
|
||||||
|
}
|
||||||
|
|
||||||
|
async execConverter(path, args, onData) {
|
||||||
|
execConverterCounter++;
|
||||||
|
try {
|
||||||
|
if (execConverterCounter > 10)
|
||||||
|
throw new Error('Слишком большая очередь конвертирования. Пожалуйста, попробуйте позже.');
|
||||||
|
|
||||||
|
const result = await utils.spawnProcess(path, {args, onData});
|
||||||
|
if (result.code != 0) {
|
||||||
|
let error = result.code;
|
||||||
|
if (this.config.branch == 'development')
|
||||||
|
error = `exec: ${path}, stdout: ${result.stdout}, stderr: ${result.stderr}`;
|
||||||
|
throw new Error(`Внешний конвертер завершился с ошибкой: ${error}`);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
if (e.status == 'killed') {
|
||||||
|
throw new Error('Слишком долгое ожидание конвертера');
|
||||||
|
} else if (e.status == 'error') {
|
||||||
|
throw new Error(e.error);
|
||||||
|
} else {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
execConverterCounter--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
decode(data) {
|
||||||
|
let selected = textUtils.getEncoding(data);
|
||||||
|
|
||||||
|
if (selected == 'ISO-8859-5') {
|
||||||
|
const charsetAll = chardet.detectAll(data.slice(0, 20000));
|
||||||
|
for (const charset of charsetAll) {
|
||||||
|
if (charset.name.indexOf('ISO-8859') < 0) {
|
||||||
|
selected = charset.name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected.toLowerCase() != 'utf-8')
|
||||||
|
return iconv.decode(data, selected);
|
||||||
|
else
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
repSpaces(text) {
|
||||||
|
return text.replace(/ |[\t\n\r]/g, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
formatFb2(fb2) {
|
||||||
|
let out = '<?xml version="1.0" encoding="utf-8"?>';
|
||||||
|
out += '<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink">';
|
||||||
|
out += this.formatFb2Node(fb2);
|
||||||
|
out += '</FictionBook>';
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
formatFb2Node(node, name) {
|
||||||
|
let out = '';
|
||||||
|
|
||||||
|
if (Array.isArray(node)) {
|
||||||
|
for (const n of node) {
|
||||||
|
out += this.formatFb2Node(n);
|
||||||
|
}
|
||||||
|
} else if (typeof node == 'string') {
|
||||||
|
if (name)
|
||||||
|
out += `<${name}>${this.repSpaces(node)}</${name}>`;
|
||||||
|
else
|
||||||
|
out += this.repSpaces(node);
|
||||||
|
} else {
|
||||||
|
if (node._n)
|
||||||
|
name = node._n;
|
||||||
|
|
||||||
|
let attrs = '';
|
||||||
|
if (node._attrs) {
|
||||||
|
for (let attrName in node._attrs) {
|
||||||
|
attrs += ` ${attrName}="${node._attrs[attrName]}"`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let tOpen = '';
|
||||||
|
let tBody = '';
|
||||||
|
let tClose = '';
|
||||||
|
if (name)
|
||||||
|
tOpen += `<${name}${attrs}>`;
|
||||||
|
if (node.hasOwnProperty('_t'))
|
||||||
|
tBody += this.repSpaces(node._t);
|
||||||
|
|
||||||
|
for (let nodeName in node) {
|
||||||
|
if (nodeName && nodeName[0] == '_' && nodeName != '_a')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const n = node[nodeName];
|
||||||
|
tBody += this.formatFb2Node(n, nodeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name)
|
||||||
|
tClose += `</${name}>`;
|
||||||
|
|
||||||
|
if (attrs == '' && name == 'p' && tBody.trim() == '')
|
||||||
|
out += '<empty-line/>'
|
||||||
|
else
|
||||||
|
out += `${tOpen}${tBody}${tClose}`;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertBase;
|
||||||
33
server/core/BookConverter/ConvertDoc.js
Normal file
33
server/core/BookConverter/ConvertDoc.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const ConvertDocX = require('./ConvertDocX');
|
||||||
|
|
||||||
|
class ConvertDoc extends ConvertDocX {
|
||||||
|
check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
return this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'msi';
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
if (!this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
await this.checkExternalConverterPresent();
|
||||||
|
|
||||||
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
|
const docFile = `${outFile}.doc`;
|
||||||
|
const docxFile = `${outFile}.docx`;
|
||||||
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
|
await fs.copy(inputFiles.sourceFile, docFile);
|
||||||
|
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.filesDir, docFile]);
|
||||||
|
|
||||||
|
return await super.convert(docxFile, fb2File, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertDoc;
|
||||||
49
server/core/BookConverter/ConvertDocX.js
Normal file
49
server/core/BookConverter/ConvertDocX.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const ConvertBase = require('./ConvertBase');
|
||||||
|
|
||||||
|
class ConvertDocX extends ConvertBase {
|
||||||
|
check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
if (this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'zip') {
|
||||||
|
//ищем файл '[Content_Types].xml'
|
||||||
|
for (const file of inputFiles.files) {
|
||||||
|
if (file.path == '[Content_Types].xml') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async convert(docxFile, fb2File, callback) {
|
||||||
|
let perc = 0;
|
||||||
|
await this.execConverter(this.calibrePath, [docxFile, fb2File], () => {
|
||||||
|
perc = (perc < 100 ? perc + 5 : 50);
|
||||||
|
callback(perc);
|
||||||
|
});
|
||||||
|
|
||||||
|
return await fs.readFile(fb2File);
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
if (!this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
await this.checkExternalConverterPresent();
|
||||||
|
|
||||||
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
|
const docxFile = `${outFile}.docx`;
|
||||||
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
|
await fs.copy(inputFiles.sourceFile, docxFile);
|
||||||
|
|
||||||
|
return await this.convert(docxFile, fb2File, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertDocX;
|
||||||
49
server/core/BookConverter/ConvertEpub.js
Normal file
49
server/core/BookConverter/ConvertEpub.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const ConvertBase = require('./ConvertBase');
|
||||||
|
|
||||||
|
class ConvertEpub extends ConvertBase {
|
||||||
|
async check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
if (this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'zip') {
|
||||||
|
//ищем файл 'mimetype'
|
||||||
|
for (const file of inputFiles.files) {
|
||||||
|
if (file.path == 'mimetype') {
|
||||||
|
const mt = await fs.readFile(`${inputFiles.filesDir}/${file.path}`);
|
||||||
|
if (mt.toString().trim() == 'application/epub+zip')
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
if (!await this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
await this.checkExternalConverterPresent();
|
||||||
|
|
||||||
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
|
const epubFile = `${outFile}.epub`;
|
||||||
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
|
await fs.copy(inputFiles.sourceFile, epubFile);
|
||||||
|
|
||||||
|
let perc = 0;
|
||||||
|
await this.execConverter(this.calibrePath, [epubFile, fb2File], () => {
|
||||||
|
perc = (perc < 100 ? perc + 5 : 50);
|
||||||
|
callback(perc);
|
||||||
|
});
|
||||||
|
|
||||||
|
return await fs.readFile(fb2File);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertEpub;
|
||||||
41
server/core/BookConverter/ConvertFb2.js
Normal file
41
server/core/BookConverter/ConvertFb2.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
const ConvertBase = require('./ConvertBase');
|
||||||
|
const iconv = require('iconv-lite');
|
||||||
|
|
||||||
|
class ConvertFb2 extends ConvertBase {
|
||||||
|
check(data, opts) {
|
||||||
|
const {dataType} = opts;
|
||||||
|
|
||||||
|
return (dataType && dataType.ext == 'xml' && data.toString().indexOf('<FictionBook') >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
if (!this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return this.checkEncoding(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkEncoding(data) {
|
||||||
|
let result = data;
|
||||||
|
|
||||||
|
const left = data.indexOf('<?xml version="1.0"');
|
||||||
|
if (left >= 0) {
|
||||||
|
const right = data.indexOf('?>', left);
|
||||||
|
if (right >= 0) {
|
||||||
|
const head = data.slice(left, right + 2).toString();
|
||||||
|
const m = head.match(/encoding="(.*)"/);
|
||||||
|
if (m) {
|
||||||
|
let encoding = m[1].toLowerCase();
|
||||||
|
if (encoding != 'utf-8') {
|
||||||
|
result = iconv.decode(data, encoding);
|
||||||
|
result = Buffer.from(result.toString().replace(m[0], 'encoding="utf-8"'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertFb2;
|
||||||
255
server/core/BookConverter/ConvertHtml.js
Normal file
255
server/core/BookConverter/ConvertHtml.js
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
const ConvertBase = require('./ConvertBase');
|
||||||
|
const sax = require('./sax');
|
||||||
|
const textUtils = require('./textUtils');
|
||||||
|
|
||||||
|
class ConvertHtml extends ConvertBase {
|
||||||
|
check(data, opts) {
|
||||||
|
const {dataType} = opts;
|
||||||
|
|
||||||
|
if (dataType && (dataType.ext == 'html' || dataType.ext == 'xml'))
|
||||||
|
return {isText: false};
|
||||||
|
|
||||||
|
//может это чистый текст?
|
||||||
|
if (textUtils.checkIfText(data)) {
|
||||||
|
return {isText: true};
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
let isText = false;
|
||||||
|
if (!opts.skipCheck) {
|
||||||
|
const checkResult = this.check(data, opts);
|
||||||
|
if (!checkResult)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
isText = checkResult.isText;
|
||||||
|
} else {
|
||||||
|
isText = opts.isText;
|
||||||
|
}
|
||||||
|
const {cutTitle} = opts;
|
||||||
|
|
||||||
|
let titleInfo = {};
|
||||||
|
let desc = {_n: 'description', 'title-info': titleInfo};
|
||||||
|
let pars = [];
|
||||||
|
let body = {_n: 'body', section: {_a: []}};
|
||||||
|
let binary = [];
|
||||||
|
let fb2 = [desc, body, binary];
|
||||||
|
|
||||||
|
let title = '';
|
||||||
|
let inTitle = false;
|
||||||
|
let inImage = false;
|
||||||
|
let image = {};
|
||||||
|
let bold = false;
|
||||||
|
let italic = false;
|
||||||
|
|
||||||
|
let spaceCounter = [];
|
||||||
|
|
||||||
|
const repCrLfTab = (text) => text.replace(/[\n\r]/g, '').replace(/\t/g, ' ');
|
||||||
|
|
||||||
|
const newParagraph = () => {
|
||||||
|
pars.push({_n: 'p', _t: ''});
|
||||||
|
};
|
||||||
|
|
||||||
|
const growParagraph = (text) => {
|
||||||
|
if (!pars.length)
|
||||||
|
newParagraph();
|
||||||
|
|
||||||
|
const l = pars.length;
|
||||||
|
pars[l - 1]._t += text;
|
||||||
|
|
||||||
|
//посчитаем отступы у текста, чтобы выделить потом параграфы
|
||||||
|
const lines = text.split('\n');
|
||||||
|
for (let line of lines) {
|
||||||
|
if (line.trim() == '')
|
||||||
|
continue;
|
||||||
|
line = repCrLfTab(line);
|
||||||
|
|
||||||
|
let l = 0;
|
||||||
|
while (l < line.length && line[l] == ' ') {
|
||||||
|
l++;
|
||||||
|
}
|
||||||
|
if (!spaceCounter[l])
|
||||||
|
spaceCounter[l] = 0;
|
||||||
|
spaceCounter[l]++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const newPara = new Set(['tr', '/table', 'hr', 'br', 'br/', 'li', 'dt', 'dd', 'p', 'title', '/title', 'h1', 'h2', 'h3', '/h1', '/h2', '/h3']);
|
||||||
|
|
||||||
|
const onTextNode = (text, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (!cutCounter && !(cutTitle && inTitle)) {
|
||||||
|
let tOpen = (bold ? '<strong>' : '');
|
||||||
|
tOpen += (italic ? '<emphasis>' : '');
|
||||||
|
let tClose = (italic ? '</emphasis>' : '');
|
||||||
|
tClose += (bold ? '</strong>' : '');
|
||||||
|
|
||||||
|
growParagraph(`${tOpen}${text}${tClose}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inTitle && !title)
|
||||||
|
title = text;
|
||||||
|
|
||||||
|
if (inImage) {
|
||||||
|
image._t = text;
|
||||||
|
binary.push(image);
|
||||||
|
|
||||||
|
pars.push({_n: 'image', _attrs: {'l:href': '#' + image._attrs.id}, _t: ''});
|
||||||
|
newParagraph();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (!cutCounter) {
|
||||||
|
if (newPara.has(tag))
|
||||||
|
newParagraph();
|
||||||
|
|
||||||
|
switch (tag) {
|
||||||
|
case 'i':
|
||||||
|
case 'em':
|
||||||
|
italic = true;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
case 'strong':
|
||||||
|
case 'h1':
|
||||||
|
case 'h2':
|
||||||
|
case 'h3':
|
||||||
|
bold = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'title')
|
||||||
|
inTitle = true;
|
||||||
|
|
||||||
|
if (tag == 'fb2-image') {
|
||||||
|
inImage = true;
|
||||||
|
const attrs = sax.getAttrsSync(tail);
|
||||||
|
image = {_n: 'binary', _attrs: {id: attrs.name.value, 'content-type': attrs.type.value}, _t: ''};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onEndNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (!cutCounter) {
|
||||||
|
if (newPara.has('/' + tag))
|
||||||
|
newParagraph();
|
||||||
|
|
||||||
|
switch (tag) {
|
||||||
|
case 'i':
|
||||||
|
case 'em':
|
||||||
|
italic = false;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
case 'strong':
|
||||||
|
case 'h1':
|
||||||
|
case 'h2':
|
||||||
|
case 'h3':
|
||||||
|
bold = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'title')
|
||||||
|
inTitle = false;
|
||||||
|
|
||||||
|
if (tag == 'fb2-image')
|
||||||
|
inImage = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
let buf = this.decode(data).toString();
|
||||||
|
|
||||||
|
sax.parseSync(buf, {
|
||||||
|
onStartNode, onEndNode, onTextNode,
|
||||||
|
innerCut: new Set(['head', 'script', 'style', 'binary', 'fb2-image'])
|
||||||
|
});
|
||||||
|
|
||||||
|
titleInfo['book-title'] = title;
|
||||||
|
|
||||||
|
//подозрение на чистый текст, надо разбить на параграфы
|
||||||
|
if (isText || pars.length < buf.length/2000) {
|
||||||
|
let total = 0;
|
||||||
|
let count = 1;
|
||||||
|
for (let i = 0; i < spaceCounter.length; i++) {
|
||||||
|
const sc = (spaceCounter[i] ? spaceCounter[i] : 0);
|
||||||
|
if (sc) count++;
|
||||||
|
total += sc;
|
||||||
|
}
|
||||||
|
|
||||||
|
let d = 0;
|
||||||
|
const mid = total/count;
|
||||||
|
for (let i = 0; i < spaceCounter.length; i++) {
|
||||||
|
const sc = (spaceCounter[i] ? spaceCounter[i] : 0);
|
||||||
|
if (sc > mid) d++;
|
||||||
|
}
|
||||||
|
|
||||||
|
let i = 0;
|
||||||
|
//если разброс не слишком большой, выделяем параграфы
|
||||||
|
if (d < 10 && spaceCounter.length) {
|
||||||
|
total /= 20;
|
||||||
|
i = spaceCounter.length - 1;
|
||||||
|
while (i > 0 && (!spaceCounter[i] || spaceCounter[i] < total)) i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parIndent = (i > 0 ? i : 0);
|
||||||
|
|
||||||
|
let newPars = [];
|
||||||
|
const newPar = () => {
|
||||||
|
newPars.push({_n: 'p', _t: ''});
|
||||||
|
};
|
||||||
|
|
||||||
|
const growPar = (text) => {
|
||||||
|
if (!newPars.length)
|
||||||
|
newPar();
|
||||||
|
|
||||||
|
const l = newPars.length;
|
||||||
|
newPars[l - 1]._t += text;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
for (const par of pars) {
|
||||||
|
if (par._n != 'p') {
|
||||||
|
newPars.push(par);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > 0)
|
||||||
|
newPar();
|
||||||
|
i++;
|
||||||
|
|
||||||
|
let j = 0;
|
||||||
|
const lines = par._t.split('\n');
|
||||||
|
for (let line of lines) {
|
||||||
|
line = repCrLfTab(line);
|
||||||
|
|
||||||
|
let l = 0;
|
||||||
|
while (l < line.length && line[l] == ' ') {
|
||||||
|
l++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l >= parIndent) {
|
||||||
|
if (j > 0)
|
||||||
|
newPar();
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
growPar(line.trim() + ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body.section._a[0] = newPars;
|
||||||
|
} else {
|
||||||
|
body.section._a[0] = pars;
|
||||||
|
}
|
||||||
|
|
||||||
|
//убираем лишнее
|
||||||
|
pars = body.section._a[0];
|
||||||
|
for (let i = 0; i < pars.length; i++)
|
||||||
|
pars[i]._t = this.repSpaces(pars[i]._t).trim();
|
||||||
|
|
||||||
|
return this.formatFb2(fb2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertHtml;
|
||||||
37
server/core/BookConverter/ConvertMobi.js
Normal file
37
server/core/BookConverter/ConvertMobi.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const ConvertBase = require('./ConvertBase');
|
||||||
|
|
||||||
|
class ConvertMobi extends ConvertBase {
|
||||||
|
async check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
return (this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'mobi');
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
if (!await this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
await this.checkExternalConverterPresent();
|
||||||
|
|
||||||
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
|
const mobiFile = `${outFile}.mobi`;
|
||||||
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
|
await fs.copy(inputFiles.sourceFile, mobiFile);
|
||||||
|
|
||||||
|
let perc = 0;
|
||||||
|
await this.execConverter(this.calibrePath, [mobiFile, fb2File], () => {
|
||||||
|
perc = (perc < 100 ? perc + 5 : 50);
|
||||||
|
callback(perc);
|
||||||
|
});
|
||||||
|
|
||||||
|
return await fs.readFile(fb2File);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertMobi;
|
||||||
219
server/core/BookConverter/ConvertPdf.js
Normal file
219
server/core/BookConverter/ConvertPdf.js
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const sax = require('./sax');
|
||||||
|
const utils = require('../utils');
|
||||||
|
const ConvertHtml = require('./ConvertHtml');
|
||||||
|
|
||||||
|
class ConvertPdf extends ConvertHtml {
|
||||||
|
check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
return this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'pdf';
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(notUsed, opts) {
|
||||||
|
if (!this.check(notUsed, opts))
|
||||||
|
return false;
|
||||||
|
await this.checkExternalConverterPresent();
|
||||||
|
|
||||||
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
|
const outFile = `${inputFiles.filesDir}/${utils.randomHexString(10)}.xml`;
|
||||||
|
|
||||||
|
//конвертируем в xml
|
||||||
|
let perc = 0;
|
||||||
|
await this.execConverter(this.pdfToHtmlPath, ['-c', '-s', '-xml', inputFiles.sourceFile, outFile], () => {
|
||||||
|
perc = (perc < 80 ? perc + 10 : 40);
|
||||||
|
callback(perc);
|
||||||
|
});
|
||||||
|
callback(80);
|
||||||
|
|
||||||
|
const data = await fs.readFile(outFile);
|
||||||
|
callback(90);
|
||||||
|
|
||||||
|
//парсим xml
|
||||||
|
let lines = [];
|
||||||
|
let images = [];
|
||||||
|
let loading = [];
|
||||||
|
let inText = false;
|
||||||
|
let bold = false;
|
||||||
|
let italic = false;
|
||||||
|
let title = '';
|
||||||
|
let prevTop = 0;
|
||||||
|
let i = -1;
|
||||||
|
let titleCount = 0;
|
||||||
|
|
||||||
|
const loadImage = async(image) => {
|
||||||
|
const src = path.parse(image.src);
|
||||||
|
let type = 'unknown';
|
||||||
|
switch (src.ext) {
|
||||||
|
case '.jpg': type = 'image/jpeg'; break;
|
||||||
|
case '.png': type = 'image/png'; break;
|
||||||
|
}
|
||||||
|
if (type != 'unknown') {
|
||||||
|
image.data = (await fs.readFile(image.src)).toString('base64');
|
||||||
|
image.type = type;
|
||||||
|
image.name = src.base;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const putImage = (curTop) => {
|
||||||
|
if (!isNaN(curTop) && images.length) {
|
||||||
|
while (images.length && images[0].top < curTop) {
|
||||||
|
i++;
|
||||||
|
lines[i] = images[0];
|
||||||
|
images.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onTextNode = (text, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (!cutCounter && inText) {
|
||||||
|
let tOpen = (bold ? '<b>' : '');
|
||||||
|
tOpen += (italic ? '<i>' : '');
|
||||||
|
let tClose = (italic ? '</i>' : '');
|
||||||
|
tClose += (bold ? '</b>' : '');
|
||||||
|
|
||||||
|
lines[i].text += `${tOpen}${text}${tClose} `;
|
||||||
|
if (titleCount < 2 && text.trim() != '') {
|
||||||
|
title += text + (titleCount ? '' : ' - ');
|
||||||
|
titleCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (!cutCounter) {
|
||||||
|
if (inText) {
|
||||||
|
switch (tag) {
|
||||||
|
case 'i':
|
||||||
|
italic = true;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
bold = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'text' && !inText) {
|
||||||
|
let attrs = sax.getAttrsSync(tail);
|
||||||
|
const line = {
|
||||||
|
text: '',
|
||||||
|
top: parseInt((attrs.top && attrs.top.value ? attrs.top.value : null), 10),
|
||||||
|
left: parseInt((attrs.left && attrs.left.value ? attrs.left.value : null), 10),
|
||||||
|
width: parseInt((attrs.width && attrs.width.value ? attrs.width.value : null), 10),
|
||||||
|
height: parseInt((attrs.height && attrs.height.value ? attrs.height.value : null), 10),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (line.width != 0 || line.height != 0) {
|
||||||
|
inText = true;
|
||||||
|
if (isNaN(line.top) || isNaN(prevTop) || (Math.abs(prevTop - line.top) > 3)) {
|
||||||
|
putImage(line.top);
|
||||||
|
i++;
|
||||||
|
lines[i] = line;
|
||||||
|
}
|
||||||
|
prevTop = line.top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'image') {
|
||||||
|
const attrs = sax.getAttrsSync(tail);
|
||||||
|
const src = (attrs.src && attrs.src.value ? attrs.src.value : '');
|
||||||
|
if (src) {
|
||||||
|
const image = {
|
||||||
|
isImage: true,
|
||||||
|
src,
|
||||||
|
data: '',
|
||||||
|
type: '',
|
||||||
|
top: parseInt((attrs.top && attrs.top.value ? attrs.top.value : null), 10) || 0,
|
||||||
|
};
|
||||||
|
loading.push(loadImage(image));
|
||||||
|
images.push(image);
|
||||||
|
images.sort((a, b) => a.top - b.top)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'page') {
|
||||||
|
putImage(100000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onEndNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (inText) {
|
||||||
|
switch (tag) {
|
||||||
|
case 'i':
|
||||||
|
italic = false;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
bold = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag == 'text')
|
||||||
|
inText = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
let buf = this.decode(data).toString();
|
||||||
|
sax.parseSync(buf, {
|
||||||
|
onStartNode, onEndNode, onTextNode
|
||||||
|
});
|
||||||
|
|
||||||
|
putImage(100000);
|
||||||
|
|
||||||
|
await Promise.all(loading);
|
||||||
|
|
||||||
|
//найдем параграфы и отступы
|
||||||
|
const indents = [];
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.isImage)
|
||||||
|
continue;
|
||||||
|
if (!isNaN(line.left)) {
|
||||||
|
indents[line.left] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let j = 0;
|
||||||
|
for (let i = 0; i < indents.length; i++) {
|
||||||
|
if (indents[i]) {
|
||||||
|
j++;
|
||||||
|
indents[i] = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
indents[0] = 0;
|
||||||
|
|
||||||
|
//формируем текст
|
||||||
|
let text = `<title>${title}</title>`;
|
||||||
|
let concat = '';
|
||||||
|
let sp = '';
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.isImage) {
|
||||||
|
text += `<fb2-image type="${line.type}" name="${line.name}">${line.data}</fb2-image>`;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (concat == '') {
|
||||||
|
const left = line.left || 0;
|
||||||
|
sp = ' '.repeat(indents[left]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let t = line.text.trim();
|
||||||
|
if (t.substr(-1) == '-') {
|
||||||
|
t = t.substr(0, t.length - 1);
|
||||||
|
concat += t;
|
||||||
|
} else {
|
||||||
|
text += sp + concat + t + "\n";
|
||||||
|
concat = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (concat)
|
||||||
|
text += sp + concat + "\n";
|
||||||
|
|
||||||
|
return await super.run(Buffer.from(text), {skipCheck: true, isText: true, cutTitle: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertPdf;
|
||||||
33
server/core/BookConverter/ConvertRtf.js
Normal file
33
server/core/BookConverter/ConvertRtf.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const ConvertDocX = require('./ConvertDocX');
|
||||||
|
|
||||||
|
class ConvertRtf extends ConvertDocX {
|
||||||
|
check(data, opts) {
|
||||||
|
const {inputFiles} = opts;
|
||||||
|
|
||||||
|
return this.config.useExternalBookConverter &&
|
||||||
|
inputFiles.sourceFileType && inputFiles.sourceFileType.ext == 'rtf';
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
if (!this.check(data, opts))
|
||||||
|
return false;
|
||||||
|
await this.checkExternalConverterPresent();
|
||||||
|
|
||||||
|
const {inputFiles, callback} = opts;
|
||||||
|
|
||||||
|
const outFile = `${inputFiles.filesDir}/${path.basename(inputFiles.sourceFile)}`;
|
||||||
|
const rtfFile = `${outFile}.rtf`;
|
||||||
|
const docxFile = `${outFile}.docx`;
|
||||||
|
const fb2File = `${outFile}.fb2`;
|
||||||
|
|
||||||
|
await fs.copy(inputFiles.sourceFile, rtfFile);
|
||||||
|
await this.execConverter(this.sofficePath, ['--headless', '--convert-to', 'docx', '--outdir', inputFiles.filesDir, rtfFile]);
|
||||||
|
|
||||||
|
return await super.convert(docxFile, fb2File, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertRtf;
|
||||||
276
server/core/BookConverter/ConvertSamlib.js
Normal file
276
server/core/BookConverter/ConvertSamlib.js
Normal file
@@ -0,0 +1,276 @@
|
|||||||
|
const _ = require('lodash');
|
||||||
|
const URL = require('url').URL;
|
||||||
|
|
||||||
|
const sax = require('./sax');
|
||||||
|
const ConvertBase = require('./ConvertBase');
|
||||||
|
|
||||||
|
class ConvertSamlib extends ConvertBase {
|
||||||
|
check(data, opts) {
|
||||||
|
const {url, dataType} = opts;
|
||||||
|
|
||||||
|
const parsedUrl = new URL(url);
|
||||||
|
if (dataType && dataType.ext == 'html' &&
|
||||||
|
(parsedUrl.hostname == 'samlib.ru' ||
|
||||||
|
parsedUrl.hostname == 'budclub.ru' ||
|
||||||
|
parsedUrl.hostname == 'zhurnal.lib.ru')) {
|
||||||
|
return {hostname: parsedUrl.hostname};
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(data, opts) {
|
||||||
|
const checkResult = this.check(data, opts);
|
||||||
|
if (!checkResult)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const {hostname} = checkResult;
|
||||||
|
let titleInfo = {};
|
||||||
|
let desc = {_n: 'description', 'title-info': titleInfo};
|
||||||
|
let pars = [];
|
||||||
|
let body = {_n: 'body', section: {_a: pars}};
|
||||||
|
let fb2 = [desc, body];
|
||||||
|
|
||||||
|
let inSubtitle = false;
|
||||||
|
let inJustify = true;
|
||||||
|
let inImage = false;
|
||||||
|
let isFirstPara = false;
|
||||||
|
let path = '';
|
||||||
|
let tag = '';// eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
|
let inText = false;
|
||||||
|
let textFound = false;
|
||||||
|
let node = {_a: pars};
|
||||||
|
|
||||||
|
let inPara = false;
|
||||||
|
let italic = false;
|
||||||
|
let bold = false;
|
||||||
|
|
||||||
|
const openTag = (name, attrs) => {
|
||||||
|
if (name == 'p')
|
||||||
|
inPara = true;
|
||||||
|
let n = {_n: name, _attrs: attrs, _a: [], _p: node};
|
||||||
|
node._a.push(n);
|
||||||
|
node = n;
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeTag = (name) => {
|
||||||
|
if (name == 'p')
|
||||||
|
inPara = false;
|
||||||
|
if (node._p) {
|
||||||
|
const exact = (node._n == name);
|
||||||
|
node = node._p;
|
||||||
|
if (!exact)
|
||||||
|
closeTag(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const growParagraph = (text) => {
|
||||||
|
if (!node._p) {
|
||||||
|
if (text.trim() != '')
|
||||||
|
openTag('p');
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (node._n == 'p' && node._a.length == 0)
|
||||||
|
text = text.trimLeft();
|
||||||
|
node._a.push({_t: text});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onStartNode = (elemName, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (elemName == '')
|
||||||
|
return;
|
||||||
|
if (!inText) {
|
||||||
|
path += '/' + elemName;
|
||||||
|
tag = elemName;
|
||||||
|
} else {
|
||||||
|
switch (elemName) {
|
||||||
|
case 'li':
|
||||||
|
case 'p':
|
||||||
|
case 'dd':
|
||||||
|
case 'br':
|
||||||
|
if (!(inSubtitle && isFirstPara)) {
|
||||||
|
if (inPara)
|
||||||
|
closeTag('p');
|
||||||
|
openTag('p');
|
||||||
|
}
|
||||||
|
isFirstPara = false;
|
||||||
|
break;
|
||||||
|
case 'h1':
|
||||||
|
case 'h2':
|
||||||
|
case 'h3':
|
||||||
|
if (inPara)
|
||||||
|
closeTag('p');
|
||||||
|
openTag('p');
|
||||||
|
bold = true;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
case 'em':
|
||||||
|
italic = true;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
case 'strong':
|
||||||
|
bold = true;
|
||||||
|
break;
|
||||||
|
case 'div':
|
||||||
|
if (inPara)
|
||||||
|
closeTag('p');
|
||||||
|
if (tail.indexOf('align="center"') >= 0) {
|
||||||
|
openTag('subtitle');
|
||||||
|
inSubtitle = true;
|
||||||
|
isFirstPara = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tail.indexOf('align="justify"') >= 0) {
|
||||||
|
openTag('p');
|
||||||
|
inJustify = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'img': {
|
||||||
|
if (inPara)
|
||||||
|
closeTag('p');
|
||||||
|
const attrs = sax.getAttrsSync(tail);
|
||||||
|
if (attrs.src && attrs.src.value) {
|
||||||
|
let href = attrs.src.value;
|
||||||
|
if (href[0] == '/')
|
||||||
|
href = `http://${hostname}${href}`;
|
||||||
|
openTag('image', {'l:href': href});
|
||||||
|
inImage = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onEndNode = (elemName, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (!inText) {
|
||||||
|
const oldPath = path;
|
||||||
|
let t = '';
|
||||||
|
do {
|
||||||
|
let i = path.lastIndexOf('/');
|
||||||
|
t = path.substr(i + 1);
|
||||||
|
path = path.substr(0, i);
|
||||||
|
} while (t != elemName && path);
|
||||||
|
|
||||||
|
if (t != elemName) {
|
||||||
|
path = oldPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
let i = path.lastIndexOf('/');
|
||||||
|
tag = path.substr(i + 1);
|
||||||
|
} else {
|
||||||
|
switch (elemName) {
|
||||||
|
case 'li':
|
||||||
|
case 'p':
|
||||||
|
case 'dd':
|
||||||
|
closeTag('p');
|
||||||
|
break;
|
||||||
|
case 'h1':
|
||||||
|
case 'h2':
|
||||||
|
case 'h3':
|
||||||
|
closeTag('p');
|
||||||
|
bold = false;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
case 'em':
|
||||||
|
italic = false;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
case 'strong':
|
||||||
|
bold = false;
|
||||||
|
break;
|
||||||
|
case 'div':
|
||||||
|
if (inSubtitle) {
|
||||||
|
closeTag('subtitle');
|
||||||
|
inSubtitle = false;
|
||||||
|
isFirstPara = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inJustify) {
|
||||||
|
closeTag('p');
|
||||||
|
inJustify = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'img':
|
||||||
|
if (inImage)
|
||||||
|
closeTag('image');
|
||||||
|
inImage = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onComment = (text) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (text == '--------- Собственно произведение -------------') {
|
||||||
|
inText = true;
|
||||||
|
textFound = true;
|
||||||
|
}
|
||||||
|
if (text == '-----------------------------------------------')
|
||||||
|
inText = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onTextNode = (text) => {// eslint-disable-line no-unused-vars
|
||||||
|
if (text && text.trim() == '')
|
||||||
|
text = (text.indexOf(' ') >= 0 ? ' ' : '');
|
||||||
|
|
||||||
|
if (!text)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (path) {
|
||||||
|
case '/html/body/center/h2':
|
||||||
|
titleInfo['book-title'] = text;
|
||||||
|
return;
|
||||||
|
case '/html/body/div/h3':
|
||||||
|
if (!titleInfo.author)
|
||||||
|
titleInfo.author = {};
|
||||||
|
text = text.replace(':', '').trim().split(' ');
|
||||||
|
if (text[0])
|
||||||
|
titleInfo.author['last-name'] = text[0];
|
||||||
|
if (text[1])
|
||||||
|
titleInfo.author['first-name'] = text[1];
|
||||||
|
if (text[2])
|
||||||
|
titleInfo.author['middle-name'] = text[2];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let tOpen = (bold ? '<strong>' : '');
|
||||||
|
tOpen += (italic ? '<emphasis>' : '');
|
||||||
|
let tClose = (italic ? '</emphasis>' : '');
|
||||||
|
tClose += (bold ? '</strong>' : '');
|
||||||
|
|
||||||
|
if (inText)
|
||||||
|
growParagraph(`${tOpen}${text}${tClose}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
sax.parseSync(this.decode(data).toString().replace(/ /g, ' '), {
|
||||||
|
onStartNode, onEndNode, onTextNode, onComment,
|
||||||
|
innerCut: new Set(['head', 'script', 'style'])
|
||||||
|
});
|
||||||
|
|
||||||
|
//текст не найден на странице, обработать корректно не получилось
|
||||||
|
if (!textFound)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const title = (titleInfo['book-title'] ? titleInfo['book-title'] : '');
|
||||||
|
let author = '';
|
||||||
|
if (titleInfo.author) {
|
||||||
|
author = _.compact([
|
||||||
|
(titleInfo.author['last-name'] ? titleInfo.author['last-name'] : ''),
|
||||||
|
(titleInfo.author['first-name'] ? titleInfo.author['first-name'] : ''),
|
||||||
|
(titleInfo.author['middle-name'] ? titleInfo.author['middle-name'] : ''),
|
||||||
|
]).join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
pars.unshift({_n: 'title', _a: [
|
||||||
|
{_n: 'p', _t: author}, {_n: 'p', _t: ''},
|
||||||
|
{_n: 'p', _t: title}, {_n: 'p', _t: ''},
|
||||||
|
]})
|
||||||
|
|
||||||
|
return this.formatFb2(fb2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConvertSamlib;
|
||||||
@@ -1,466 +1,57 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const URL = require('url').URL;
|
|
||||||
const iconv = require('iconv-lite');
|
|
||||||
const chardet = require('chardet');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const sax = require('./sax');
|
|
||||||
const textUtils = require('./textUtils');
|
|
||||||
|
|
||||||
const FileDetector = require('../FileDetector');
|
const FileDetector = require('../FileDetector');
|
||||||
|
|
||||||
const repSpaces = (text) => text.replace(/ |[\t\n\r]/g, ' ');
|
//порядок важен
|
||||||
|
const convertClassFactory = [
|
||||||
|
require('./ConvertEpub'),
|
||||||
|
require('./ConvertPdf'),
|
||||||
|
require('./ConvertRtf'),
|
||||||
|
require('./ConvertDocX'),
|
||||||
|
require('./ConvertDoc'),
|
||||||
|
require('./ConvertMobi'),
|
||||||
|
require('./ConvertFb2'),
|
||||||
|
require('./ConvertSamlib'),
|
||||||
|
require('./ConvertHtml'),
|
||||||
|
];
|
||||||
|
|
||||||
class BookConverter {
|
class BookConverter {
|
||||||
constructor() {
|
constructor(config) {
|
||||||
this.detector = new FileDetector();
|
this.detector = new FileDetector();
|
||||||
}
|
|
||||||
|
|
||||||
async convertToFb2(inputFile, outputFile, url, callback) {
|
this.convertFactory = [];
|
||||||
const fileType = await this.detector.detectFile(inputFile);
|
for (const convertClass of convertClassFactory) {
|
||||||
|
this.convertFactory.push(new convertClass(config));
|
||||||
const data = await fs.readFile(inputFile);
|
|
||||||
callback(100);
|
|
||||||
|
|
||||||
if (fileType && (fileType.ext == 'html' || fileType.ext == 'xml')) {
|
|
||||||
if (data.toString().indexOf('<FictionBook') >= 0) {
|
|
||||||
await fs.writeFile(outputFile, this.checkEncoding(data));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedUrl = new URL(url);
|
|
||||||
if (parsedUrl.hostname == 'samlib.ru' ||
|
|
||||||
parsedUrl.hostname == 'budclub.ru' ||
|
|
||||||
parsedUrl.hostname == 'zhurnal.lib.ru') {
|
|
||||||
await fs.writeFile(outputFile, this.convertSamlib(data));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.writeFile(outputFile, this.convertHtml(data));
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
if (fileType)
|
|
||||||
throw new Error(`Этот формат файла не поддерживается: ${fileType.mime}`);
|
|
||||||
else {
|
|
||||||
//может это чистый текст?
|
|
||||||
if (textUtils.checkIfText(data)) {
|
|
||||||
await fs.writeFile(outputFile, this.convertHtml(data, true));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(`Не удалось определить формат файла: ${url}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decode(data) {
|
async convertToFb2(inputFiles, outputFile, url, callback) {
|
||||||
const charsetAll = chardet.detectAll(data.slice(0, 20000));
|
const selectedFileType = await this.detector.detectFile(inputFiles.selectedFile);
|
||||||
|
const data = await fs.readFile(inputFiles.selectedFile);
|
||||||
|
|
||||||
let selected = 'ISO-8859-5';
|
let result = false;
|
||||||
for (const charset of charsetAll) {
|
for (const convert of this.convertFactory) {
|
||||||
if (charset.name.indexOf('ISO-8859') < 0) {
|
result = await convert.run(data, {inputFiles, url, callback, dataType: selectedFileType});
|
||||||
selected = charset.name;
|
if (result) {
|
||||||
|
await fs.writeFile(outputFile, result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selected == 'ISO-8859-5') {
|
if (!result && inputFiles.nesting) {
|
||||||
selected = textUtils.getEncoding(data);
|
result = await this.convertToFb2(inputFiles.nesting, outputFile, url, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
return iconv.decode(data, selected);
|
if (!result) {
|
||||||
}
|
if (selectedFileType)
|
||||||
|
throw new Error(`Этот формат файла не поддерживается: ${selectedFileType.mime}`);
|
||||||
checkEncoding(data) {
|
else {
|
||||||
let result = data;
|
throw new Error(`Не удалось определить формат файла: ${url}`);
|
||||||
|
|
||||||
const left = data.indexOf('<?xml version="1.0"');
|
|
||||||
if (left >= 0) {
|
|
||||||
const right = data.indexOf('?>', left);
|
|
||||||
if (right >= 0) {
|
|
||||||
const head = data.slice(left, right + 2).toString();
|
|
||||||
const m = head.match(/encoding="(.*)"/);
|
|
||||||
if (m) {
|
|
||||||
let encoding = m[1].toLowerCase();
|
|
||||||
if (encoding != 'utf-8') {
|
|
||||||
result = iconv.decode(data, encoding);
|
|
||||||
result = Buffer.from(result.toString().replace(m[0], 'encoding="utf-8"'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callback(100);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
convertHtml(data, isText) {
|
|
||||||
let titleInfo = {};
|
|
||||||
let desc = {_n: 'description', 'title-info': titleInfo};
|
|
||||||
let pars = [];
|
|
||||||
let body = {_n: 'body', section: {_a: []}};
|
|
||||||
let fb2 = [desc, body];
|
|
||||||
|
|
||||||
let title = '';
|
|
||||||
let inTitle = false;
|
|
||||||
|
|
||||||
let spaceCounter = [];
|
|
||||||
|
|
||||||
const newParagraph = () => {
|
|
||||||
pars.push({_n: 'p', _t: ''});
|
|
||||||
};
|
|
||||||
|
|
||||||
const growParagraph = (text) => {
|
|
||||||
const l = pars.length;
|
|
||||||
if (l) {
|
|
||||||
if (pars[l - 1]._t == '')
|
|
||||||
text = text.trimLeft();
|
|
||||||
pars[l - 1]._t += text;
|
|
||||||
}
|
|
||||||
|
|
||||||
//посчитаем отступы у текста, чтобы выделить потом параграфы
|
|
||||||
const lines = text.split('\n');
|
|
||||||
for (const line of lines) {
|
|
||||||
const sp = line.split(' ');
|
|
||||||
let l = 0;
|
|
||||||
while (l < sp.length && sp[l].trim() == '') {
|
|
||||||
l++;
|
|
||||||
}
|
|
||||||
if (!spaceCounter[l])
|
|
||||||
spaceCounter[l] = 0;
|
|
||||||
spaceCounter[l]++;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
newParagraph();
|
|
||||||
const newPara = new Set(['tr', 'br', 'br/', 'dd', 'p', 'title', '/title', 'h1', 'h2', 'h3', '/h1', '/h2', '/h3']);
|
|
||||||
|
|
||||||
const onTextNode = (text, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
|
||||||
if (!cutCounter) {
|
|
||||||
growParagraph(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inTitle && !title)
|
|
||||||
title = text;
|
|
||||||
};
|
|
||||||
|
|
||||||
const onStartNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
|
||||||
if (!cutCounter) {
|
|
||||||
if (newPara.has(tag))
|
|
||||||
newParagraph();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tag == 'title')
|
|
||||||
inTitle = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const onEndNode = (tag, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
|
||||||
if (tag == 'title')
|
|
||||||
inTitle = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
let buf = this.decode(data).toString();
|
|
||||||
|
|
||||||
sax.parseSync(buf, {
|
|
||||||
onStartNode, onEndNode, onTextNode,
|
|
||||||
innerCut: new Set(['head', 'script', 'style'])
|
|
||||||
});
|
|
||||||
|
|
||||||
titleInfo['book-title'] = title;
|
|
||||||
|
|
||||||
//подозрение на чистый текст, надо разбить на параграфы
|
|
||||||
if (isText || pars.length < buf.length/2000) {
|
|
||||||
let total = 0;
|
|
||||||
for (let i = 0; i < spaceCounter.length; i++) {
|
|
||||||
total += (spaceCounter[i] ? spaceCounter[i] : 0);
|
|
||||||
}
|
|
||||||
total /= 10;
|
|
||||||
let i = spaceCounter.length - 1;
|
|
||||||
while (i > 0 && (!spaceCounter[i] || spaceCounter[i] < total)) i--;
|
|
||||||
|
|
||||||
const parIndent = (i > 0 ? i : 0);
|
|
||||||
|
|
||||||
let newPars = [];
|
|
||||||
const newPar = () => {
|
|
||||||
newPars.push({_n: 'p', _t: ''});
|
|
||||||
};
|
|
||||||
|
|
||||||
const growPar = (text) => {
|
|
||||||
const l = newPars.length;
|
|
||||||
if (l) {
|
|
||||||
newPars[l - 1]._t += text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const par of pars) {
|
|
||||||
newPar();
|
|
||||||
|
|
||||||
const lines = par._t.split('\n');
|
|
||||||
for (const line of lines) {
|
|
||||||
const sp = line.split(' ');
|
|
||||||
let l = 0;
|
|
||||||
while (l < sp.length && sp[l].trim() == '') {
|
|
||||||
l++;
|
|
||||||
}
|
|
||||||
if (l >= parIndent)
|
|
||||||
newPar();
|
|
||||||
growPar(line.trim() + ' ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
body.section._a[0] = newPars;
|
|
||||||
} else {
|
|
||||||
body.section._a[0] = pars;
|
|
||||||
}
|
|
||||||
|
|
||||||
//убираем лишнее
|
|
||||||
for (let i = 0; i < pars.length; i++)
|
|
||||||
pars[i]._t = repSpaces(pars[i]._t).trim();
|
|
||||||
|
|
||||||
return this.formatFb2(fb2);
|
|
||||||
}
|
|
||||||
|
|
||||||
convertSamlib(data) {
|
|
||||||
let titleInfo = {};
|
|
||||||
let desc = {_n: 'description', 'title-info': titleInfo};
|
|
||||||
let pars = [];
|
|
||||||
let body = {_n: 'body', section: {_a: pars}};
|
|
||||||
let fb2 = [desc, body];
|
|
||||||
|
|
||||||
let inSubtitle = false;
|
|
||||||
let inJustify = true;
|
|
||||||
let path = '';
|
|
||||||
let tag = '';// eslint-disable-line no-unused-vars
|
|
||||||
|
|
||||||
let inText = false;
|
|
||||||
let node = {_a: pars};
|
|
||||||
|
|
||||||
let inPara = false;
|
|
||||||
let italic = false;
|
|
||||||
let bold = false;
|
|
||||||
|
|
||||||
const openTag = (name) => {
|
|
||||||
if (name == 'p')
|
|
||||||
inPara = true;
|
|
||||||
let n = {_n: name, _a: [], _p: node};
|
|
||||||
node._a.push(n);
|
|
||||||
node = n;
|
|
||||||
};
|
|
||||||
|
|
||||||
const closeTag = (name) => {
|
|
||||||
if (name == 'p')
|
|
||||||
inPara = false;
|
|
||||||
if (node._p) {
|
|
||||||
const exact = (node._n == name);
|
|
||||||
node = node._p;
|
|
||||||
if (!exact)
|
|
||||||
closeTag(name);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const growParagraph = (text) => {
|
|
||||||
if (node._n == 'p' && node._a.length == 0)
|
|
||||||
text = text.trimLeft();
|
|
||||||
node._a.push({_t: text});
|
|
||||||
};
|
|
||||||
|
|
||||||
openTag('p');
|
|
||||||
|
|
||||||
const onStartNode = (elemName, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
|
||||||
if (elemName == '')
|
|
||||||
return;
|
|
||||||
if (!inText) {
|
|
||||||
path += '/' + elemName;
|
|
||||||
tag = elemName;
|
|
||||||
} else {
|
|
||||||
if (inPara && elemName != 'i' && elemName != 'b')
|
|
||||||
closeTag('p');
|
|
||||||
|
|
||||||
switch (elemName) {
|
|
||||||
case 'li':
|
|
||||||
case 'p':
|
|
||||||
case 'dd':
|
|
||||||
case 'h1':
|
|
||||||
case 'h2':
|
|
||||||
case 'h3':
|
|
||||||
openTag('p');
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
openTag('emphasis');
|
|
||||||
italic = true;
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
openTag('strong');
|
|
||||||
bold = true;
|
|
||||||
break;
|
|
||||||
case 'div':
|
|
||||||
if (tail.indexOf('align="center"') >= 0) {
|
|
||||||
openTag('subtitle');
|
|
||||||
inSubtitle = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tail.indexOf('align="justify"') >= 0) {
|
|
||||||
openTag('p');
|
|
||||||
inJustify = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onEndNode = (elemName, tail, singleTag, cutCounter, cutTag) => {// eslint-disable-line no-unused-vars
|
|
||||||
if (!inText) {
|
|
||||||
const oldPath = path;
|
|
||||||
let t = '';
|
|
||||||
do {
|
|
||||||
let i = path.lastIndexOf('/');
|
|
||||||
t = path.substr(i + 1);
|
|
||||||
path = path.substr(0, i);
|
|
||||||
} while (t != elemName && path);
|
|
||||||
|
|
||||||
if (t != elemName) {
|
|
||||||
path = oldPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
let i = path.lastIndexOf('/');
|
|
||||||
tag = path.substr(i + 1);
|
|
||||||
} else {
|
|
||||||
switch (elemName) {
|
|
||||||
case 'li':
|
|
||||||
case 'p':
|
|
||||||
case 'dd':
|
|
||||||
case 'h1':
|
|
||||||
case 'h2':
|
|
||||||
case 'h3':
|
|
||||||
closeTag('p');
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
closeTag('emphasis');
|
|
||||||
italic = false;
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
closeTag('strong');
|
|
||||||
bold = false;
|
|
||||||
break;
|
|
||||||
case 'div':
|
|
||||||
if (inSubtitle) {
|
|
||||||
closeTag('subtitle');
|
|
||||||
inSubtitle = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inJustify) {
|
|
||||||
closeTag('p');
|
|
||||||
inJustify = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onComment = (text) => {// eslint-disable-line no-unused-vars
|
|
||||||
if (text == '--------- Собственно произведение -------------')
|
|
||||||
inText = true;
|
|
||||||
if (text == '-----------------------------------------------')
|
|
||||||
inText = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const onTextNode = (text) => {// eslint-disable-line no-unused-vars
|
|
||||||
if (text != ' ' && text.trim() == '')
|
|
||||||
text = text.trim();
|
|
||||||
|
|
||||||
if (text == '')
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (path) {
|
|
||||||
case '/html/body/center/h2':
|
|
||||||
titleInfo['book-title'] = text;
|
|
||||||
return;
|
|
||||||
case '/html/body/div/h3':
|
|
||||||
if (!titleInfo.author)
|
|
||||||
titleInfo.author = {};
|
|
||||||
text = text.replace(':', '').trim().split(' ');
|
|
||||||
if (text[0])
|
|
||||||
titleInfo.author['last-name'] = text[0];
|
|
||||||
if (text[1])
|
|
||||||
titleInfo.author['first-name'] = text[1];
|
|
||||||
if (text[2])
|
|
||||||
titleInfo.author['middle-name'] = text[2];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let tOpen = (bold ? '<strong>' : '');
|
|
||||||
tOpen += (italic ? '<emphasis>' : '');
|
|
||||||
let tClose = (italic ? '</emphasis>' : '');
|
|
||||||
tClose += (bold ? '</strong>' : '');
|
|
||||||
|
|
||||||
if (inText)
|
|
||||||
growParagraph(`${tOpen}${text}${tClose}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
sax.parseSync(repSpaces(this.decode(data).toString()), {
|
|
||||||
onStartNode, onEndNode, onTextNode, onComment,
|
|
||||||
innerCut: new Set(['head', 'script', 'style'])
|
|
||||||
});
|
|
||||||
|
|
||||||
const title = (titleInfo['book-title'] ? titleInfo['book-title'] : '');
|
|
||||||
let author = '';
|
|
||||||
if (titleInfo.author) {
|
|
||||||
author = _.compact([
|
|
||||||
(titleInfo.author['last-name'] ? titleInfo.author['last-name'] : ''),
|
|
||||||
(titleInfo.author['first-name'] ? titleInfo.author['first-name'] : ''),
|
|
||||||
(titleInfo.author['middle-name'] ? titleInfo.author['middle-name'] : ''),
|
|
||||||
]).join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
pars.unshift({_n: 'title', _a: [
|
|
||||||
{_n: 'p', _t: author}, {_n: 'p', _t: ''},
|
|
||||||
{_n: 'p', _t: title}, {_n: 'p', _t: ''},
|
|
||||||
]})
|
|
||||||
|
|
||||||
return this.formatFb2(fb2);
|
|
||||||
}
|
|
||||||
|
|
||||||
formatFb2(fb2) {
|
|
||||||
let out = '<?xml version="1.0" encoding="utf-8"?>';
|
|
||||||
out += '<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink">';
|
|
||||||
out += this.formatFb2Node(fb2);
|
|
||||||
out += '</FictionBook>';
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
formatFb2Node(node, name) {
|
|
||||||
let out = '';
|
|
||||||
|
|
||||||
if (Array.isArray(node)) {
|
|
||||||
for (const n of node) {
|
|
||||||
out += this.formatFb2Node(n);
|
|
||||||
}
|
|
||||||
} else if (typeof node == 'string') {
|
|
||||||
if (name)
|
|
||||||
out += `<${name}>${repSpaces(node)}</${name}>`;
|
|
||||||
else
|
|
||||||
out += repSpaces(node);
|
|
||||||
} else {
|
|
||||||
if (node._n)
|
|
||||||
name = node._n;
|
|
||||||
|
|
||||||
if (name)
|
|
||||||
out += `<${name}>`;
|
|
||||||
if (node.hasOwnProperty('_t'))
|
|
||||||
out += repSpaces(node._t);
|
|
||||||
|
|
||||||
for (let nodeName in node) {
|
|
||||||
if (nodeName && nodeName[0] == '_' && nodeName != '_a')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const n = node[nodeName];
|
|
||||||
out += this.formatFb2Node(n, nodeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name)
|
|
||||||
out += `</${name}>`;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = BookConverter;
|
module.exports = BookConverter;
|
||||||
@@ -276,7 +276,84 @@ async function parse(xstr, options) {
|
|||||||
await _onProgress(100);
|
await _onProgress(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAttrsSync(tail) {
|
||||||
|
let result = {};
|
||||||
|
let name = '';
|
||||||
|
let value = '';
|
||||||
|
let vOpen = '';
|
||||||
|
let inName = false;
|
||||||
|
let inValue = false;
|
||||||
|
let waitValue = false;
|
||||||
|
let waitEq = false;
|
||||||
|
|
||||||
|
const pushResult = () => {
|
||||||
|
if (name != '') {
|
||||||
|
let ns = '';
|
||||||
|
if (name.indexOf(':') >= 0) {
|
||||||
|
[ns, name] = name.split(':');
|
||||||
|
}
|
||||||
|
|
||||||
|
result[name] = {value, ns};
|
||||||
|
}
|
||||||
|
name = '';
|
||||||
|
value = '';
|
||||||
|
vOpen = '';
|
||||||
|
inName = false;
|
||||||
|
inValue = false;
|
||||||
|
waitValue = false;
|
||||||
|
waitEq = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
tail = tail.replace(/[\t\n\r]/g, ' ');
|
||||||
|
for (let i = 0; i < tail.length; i++) {
|
||||||
|
const c = tail.charAt(i);
|
||||||
|
if (c == ' ') {
|
||||||
|
if (inValue) {
|
||||||
|
if (vOpen == '"')
|
||||||
|
value += c;
|
||||||
|
else
|
||||||
|
pushResult();
|
||||||
|
} else if (inName) {
|
||||||
|
waitEq = true;
|
||||||
|
inName = false;
|
||||||
|
}
|
||||||
|
} else if (!inValue && c == '=') {
|
||||||
|
waitEq = false;
|
||||||
|
waitValue = true;
|
||||||
|
inName = false;
|
||||||
|
} else if (c == '"') {
|
||||||
|
if (inValue) {
|
||||||
|
pushResult();
|
||||||
|
} else if (waitValue) {
|
||||||
|
inValue = true;
|
||||||
|
vOpen = '"';
|
||||||
|
}
|
||||||
|
} else if (inValue) {
|
||||||
|
value += c;
|
||||||
|
} else if (inName) {
|
||||||
|
name += c;
|
||||||
|
} else if (waitEq) {
|
||||||
|
pushResult();
|
||||||
|
inName = true;
|
||||||
|
name = c;
|
||||||
|
} else if (waitValue) {
|
||||||
|
waitValue = false;
|
||||||
|
inValue = true;
|
||||||
|
vOpen = ' ';
|
||||||
|
value = c;
|
||||||
|
} else {
|
||||||
|
inName = true;
|
||||||
|
name = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name != '')
|
||||||
|
pushResult();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
parseSync,
|
parseSync,
|
||||||
|
getAttrsSync,
|
||||||
parse
|
parse
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
function getEncoding(buf) {
|
function getEncoding(buf, returnAll) {
|
||||||
const lowerCase = 3;
|
const lowerCase = 3;
|
||||||
const upperCase = 1;
|
const upperCase = 1;
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ function getEncoding(buf) {
|
|||||||
'd': 'cp866',
|
'd': 'cp866',
|
||||||
'i': 'ISO-8859-5',
|
'i': 'ISO-8859-5',
|
||||||
'm': 'maccyrillic',
|
'm': 'maccyrillic',
|
||||||
|
'u': 'utf-8',
|
||||||
};
|
};
|
||||||
|
|
||||||
let charsets = {
|
let charsets = {
|
||||||
@@ -15,38 +16,47 @@ function getEncoding(buf) {
|
|||||||
'w': 0,
|
'w': 0,
|
||||||
'd': 0,
|
'd': 0,
|
||||||
'i': 0,
|
'i': 0,
|
||||||
'm': 0
|
'm': 0,
|
||||||
|
'u': 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const len = buf.length;
|
const len = buf.length;
|
||||||
const blockSize = (len > 5*3000 ? 3000 : len);
|
const blockSize = (len > 5*3000 ? 3000 : len);
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
let totalChecked = 0;
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
const char = buf[i];
|
const char = buf[i];
|
||||||
|
const nextChar = (i < len - 1 ? buf[i + 1] : 0);
|
||||||
|
totalChecked++;
|
||||||
i++;
|
i++;
|
||||||
//non-russian characters
|
//non-russian characters
|
||||||
if (char < 128 || char > 256)
|
if (char < 128 || char > 256)
|
||||||
continue;
|
continue;
|
||||||
//CP866
|
//UTF-8
|
||||||
if ((char > 159 && char < 176) || (char > 223 && char < 242)) charsets['d'] += lowerCase;
|
if ((char == 208 || char == 209) && nextChar >= 128 && nextChar <= 190)
|
||||||
if ((char > 127 && char < 160)) charsets['d'] += upperCase;
|
charsets['u'] += lowerCase;
|
||||||
|
else {
|
||||||
|
//CP866
|
||||||
|
if ((char > 159 && char < 176) || (char > 223 && char < 242)) charsets['d'] += lowerCase;
|
||||||
|
if ((char > 127 && char < 160)) charsets['d'] += upperCase;
|
||||||
|
|
||||||
//KOI8-R
|
//KOI8-R
|
||||||
if ((char > 191 && char < 223)) charsets['k'] += lowerCase;
|
if ((char > 191 && char < 223)) charsets['k'] += lowerCase;
|
||||||
if ((char > 222 && char < 256)) charsets['k'] += upperCase;
|
if ((char > 222 && char < 256)) charsets['k'] += upperCase;
|
||||||
|
|
||||||
//WIN-1251
|
//WIN-1251
|
||||||
if (char > 223 && char < 256) charsets['w'] += lowerCase;
|
if (char > 223 && char < 256) charsets['w'] += lowerCase;
|
||||||
if (char > 191 && char < 224) charsets['w'] += upperCase;
|
if (char > 191 && char < 224) charsets['w'] += upperCase;
|
||||||
|
|
||||||
//MAC
|
//MAC
|
||||||
if (char > 221 && char < 255) charsets['m'] += lowerCase;
|
if (char > 221 && char < 255) charsets['m'] += lowerCase;
|
||||||
if (char > 127 && char < 160) charsets['m'] += upperCase;
|
if (char > 127 && char < 160) charsets['m'] += upperCase;
|
||||||
|
|
||||||
//ISO-8859-5
|
//ISO-8859-5
|
||||||
if (char > 207 && char < 240) charsets['i'] += lowerCase;
|
if (char > 207 && char < 240) charsets['i'] += lowerCase;
|
||||||
if (char > 175 && char < 208) charsets['i'] += upperCase;
|
if (char > 175 && char < 208) charsets['i'] += upperCase;
|
||||||
|
}
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
@@ -57,18 +67,24 @@ function getEncoding(buf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sorted = Object.keys(charsets).map(function(key) {
|
let sorted = Object.keys(charsets).map(function(key) {
|
||||||
return { codePage: codePage[key], c: charsets[key] };
|
return { codePage: codePage[key], c: charsets[key], totalChecked };
|
||||||
});
|
});
|
||||||
|
|
||||||
sorted.sort((a, b) => b.c - a.c);
|
sorted.sort((a, b) => b.c - a.c);
|
||||||
|
|
||||||
if (sorted[0].c > 0)
|
if (returnAll)
|
||||||
|
return sorted;
|
||||||
|
else if (sorted[0].c > 0)
|
||||||
return sorted[0].codePage;
|
return sorted[0].codePage;
|
||||||
else
|
else
|
||||||
return 'ISO-8859-5';
|
return 'ISO-8859-5';
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkIfText(buf) {
|
function checkIfText(buf) {
|
||||||
|
const enc = getEncoding(buf, true);
|
||||||
|
if (enc[0].c > enc[0].totalChecked*0.9)
|
||||||
|
return true;
|
||||||
|
|
||||||
let spaceCount = 0;
|
let spaceCount = 0;
|
||||||
let crCount = 0;
|
let crCount = 0;
|
||||||
let lfCount = 0;
|
let lfCount = 0;
|
||||||
@@ -85,7 +101,7 @@ function checkIfText(buf) {
|
|||||||
const crFreq = crCount/(buf.length + 1);
|
const crFreq = crCount/(buf.length + 1);
|
||||||
const lfFreq = lfCount/(buf.length + 1);
|
const lfFreq = lfCount/(buf.length + 1);
|
||||||
|
|
||||||
return (spaceFreq > 0.1 || crFreq > 0.03 || lfFreq > 0.03);
|
return (buf.length < 1000 || spaceFreq > 0.1 || crFreq > 0.03 || lfFreq > 0.03);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
const path = require('path');
|
||||||
|
const extractZip = require('extract-zip');
|
||||||
|
const unbzip2Stream = require('unbzip2-stream');
|
||||||
|
const tar = require('tar-fs')
|
||||||
|
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const decompress = require('decompress');
|
|
||||||
const FileDetector = require('./FileDetector');
|
const FileDetector = require('./FileDetector');
|
||||||
|
|
||||||
class FileDecompressor {
|
class FileDecompressor {
|
||||||
@@ -10,29 +14,188 @@ class FileDecompressor {
|
|||||||
this.detector = new FileDetector();
|
this.detector = new FileDetector();
|
||||||
}
|
}
|
||||||
|
|
||||||
async decompressFile(filename, outputDir) {
|
async decompressNested(filename, outputDir) {
|
||||||
|
await fs.ensureDir(outputDir);
|
||||||
|
|
||||||
const fileType = await this.detector.detectFile(filename);
|
const fileType = await this.detector.detectFile(filename);
|
||||||
|
|
||||||
if (!fileType || !(fileType.ext == 'zip' || fileType.ext == 'bz2'))
|
let result = {
|
||||||
return filename;
|
sourceFile: filename,
|
||||||
|
sourceFileType: fileType,
|
||||||
|
selectedFile: filename,
|
||||||
|
filesDir: outputDir,
|
||||||
|
files: []
|
||||||
|
};
|
||||||
|
|
||||||
const files = await decompress(filename, outputDir);
|
if (!fileType || !(fileType.ext == 'zip' || fileType.ext == 'bz2' || fileType.ext == 'gz' || fileType.ext == 'tar')) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
let result = filename;
|
result.files = await this.decompressTarZZ(fileType.ext, filename, outputDir);
|
||||||
|
|
||||||
|
let sel = filename;
|
||||||
let max = 0;
|
let max = 0;
|
||||||
if (files.length) {
|
if (result.files.length) {
|
||||||
//ищем файл с максимальным размером
|
//ищем файл с максимальным размером
|
||||||
for (let file of files) {
|
for (let file of result.files) {
|
||||||
if (file.data.length > max) {
|
if (file.size > max) {
|
||||||
result = `${outputDir}/${file.path}`;
|
sel = `${outputDir}/${file.path}`;
|
||||||
max = file.data.length;
|
max = file.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
result.selectedFile = sel;
|
||||||
|
|
||||||
|
if (sel != filename) {
|
||||||
|
result.nesting = await this.decompressNested(sel, `${outputDir}/${utils.randomHexString(10)}`);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async unpack(filename, outputDir) {
|
||||||
|
const fileType = await this.detector.detectFile(filename);
|
||||||
|
if (!fileType)
|
||||||
|
throw new Error('Не удалось определить формат файла');
|
||||||
|
|
||||||
|
return await this.decompress(fileType.ext, filename, outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
async unpackTarZZ(filename, outputDir) {
|
||||||
|
const fileType = await this.detector.detectFile(filename);
|
||||||
|
if (!fileType)
|
||||||
|
throw new Error('Не удалось определить формат файла');
|
||||||
|
|
||||||
|
return await this.decompressTarZZ(fileType.ext, filename, outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
async decompressTarZZ(fileExt, filename, outputDir) {
|
||||||
|
const files = await this.decompress(fileExt, filename, outputDir);
|
||||||
|
if (fileExt == 'tar' || files.length != 1)
|
||||||
|
return files;
|
||||||
|
|
||||||
|
const tarFilename = `${outputDir}/${files[0].path}`;
|
||||||
|
const fileType = await this.detector.detectFile(tarFilename);
|
||||||
|
if (!fileType || fileType.ext != 'tar')
|
||||||
|
return files;
|
||||||
|
|
||||||
|
const newTarFilename = `${outputDir}/${utils.randomHexString(30)}`;
|
||||||
|
await fs.rename(tarFilename, newTarFilename);
|
||||||
|
|
||||||
|
const tarFiles = await this.decompress('tar', newTarFilename, outputDir);
|
||||||
|
await fs.remove(newTarFilename);
|
||||||
|
|
||||||
|
return tarFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
async decompress(fileExt, filename, outputDir) {
|
||||||
|
let files = [];
|
||||||
|
|
||||||
|
switch (fileExt) {
|
||||||
|
case 'zip':
|
||||||
|
files = await this.unZip(filename, outputDir);
|
||||||
|
break;
|
||||||
|
case 'bz2':
|
||||||
|
files = await this.unBz2(filename, outputDir);
|
||||||
|
break;
|
||||||
|
case 'gz':
|
||||||
|
files = await this.unGz(filename, outputDir);
|
||||||
|
break;
|
||||||
|
case 'tar':
|
||||||
|
files = await this.unTar(filename, outputDir);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`FileDecompressor: неизвестный формат файла '${fileExt}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
async unZip(filename, outputDir) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const files = [];
|
||||||
|
extractZip(filename, {
|
||||||
|
dir: outputDir,
|
||||||
|
onEntry: (entry) => {
|
||||||
|
files.push({path: entry.fileName, size: entry.uncompressedSize});
|
||||||
|
}
|
||||||
|
}, (err) => {
|
||||||
|
if (err)
|
||||||
|
reject(err);
|
||||||
|
resolve(files);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
unBz2(filename, outputDir) {
|
||||||
|
return this.decompressByStream(unbzip2Stream(), filename, outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
unGz(filename, outputDir) {
|
||||||
|
return this.decompressByStream(zlib.createGunzip(), filename, outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
unTar(filename, outputDir) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const files = [];
|
||||||
|
|
||||||
|
const tarExtract = tar.extract(outputDir, {
|
||||||
|
map: (header) => {
|
||||||
|
files.push({path: header.name, size: header.size});
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tarExtract.on('finish', () => {
|
||||||
|
resolve(files);
|
||||||
|
});
|
||||||
|
|
||||||
|
tarExtract.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
const inputStream = fs.createReadStream(filename);
|
||||||
|
inputStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
inputStream.pipe(tarExtract);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
decompressByStream(stream, filename, outputDir) {
|
||||||
|
return new Promise(async(resolve, reject) => {
|
||||||
|
const file = {path: path.parse(filename).name};
|
||||||
|
let outFilename = `${outputDir}/${file.path}`;
|
||||||
|
if (await fs.pathExists(outFilename)) {
|
||||||
|
file.path = `${utils.randomHexString(10)}-${file.path}`;
|
||||||
|
outFilename = `${outputDir}/${file.path}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputStream = fs.createReadStream(filename);
|
||||||
|
const outputStream = fs.createWriteStream(outFilename);
|
||||||
|
|
||||||
|
outputStream.on('finish', async() => {
|
||||||
|
try {
|
||||||
|
file.size = (await fs.stat(outFilename)).size;
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
resolve([file]);
|
||||||
|
});
|
||||||
|
|
||||||
|
inputStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
outputStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
inputStream.pipe(stream).pipe(outputStream);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async gzipBuffer(buf) {
|
async gzipBuffer(buf) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
zlib.gzip(buf, {level: 1}, (err, result) => {
|
zlib.gzip(buf, {level: 1}, (err, result) => {
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
const detect = require('detect-file-type');
|
|
||||||
|
|
||||||
//html
|
|
||||||
detect.addSignature(
|
|
||||||
{
|
|
||||||
"type": "html",
|
|
||||||
"ext": "html",
|
|
||||||
"mime": "text/html",
|
|
||||||
"rules": [
|
|
||||||
{ "type": "or", "rules":
|
|
||||||
[
|
|
||||||
{ "type": "contains", "bytes": "3c68746d6c" },
|
|
||||||
{ "type": "contains", "bytes": "3c00680074006d006c00" },
|
|
||||||
|
|
||||||
{ "type": "contains", "bytes": "3c21646f6374797065" },
|
|
||||||
{ "type": "contains", "bytes": "3c626f6479" },
|
|
||||||
{ "type": "contains", "bytes": "3c68656164" },
|
|
||||||
{ "type": "contains", "bytes": "3c696672616d65" },
|
|
||||||
{ "type": "contains", "bytes": "3c696d67" },
|
|
||||||
{ "type": "contains", "bytes": "3c6f626a656374" },
|
|
||||||
{ "type": "contains", "bytes": "3c736372697074" },
|
|
||||||
{ "type": "contains", "bytes": "3c7461626c65" },
|
|
||||||
{ "type": "contains", "bytes": "3c7469746c65" },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
//xml 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22
|
|
||||||
detect.addSignature(
|
|
||||||
{
|
|
||||||
"type": "xml",
|
|
||||||
"ext": "xml",
|
|
||||||
"mime": "application/xml",
|
|
||||||
"rules": [
|
|
||||||
{ "type": "or", "rules":
|
|
||||||
[
|
|
||||||
{ "type": "contains", "bytes": "3c3f786d6c2076657273696f6e3d22312e3022" },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
class FileDetector {
|
|
||||||
detectFile(filename) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
detect.fromFile(filename, (err, result) => {
|
|
||||||
if (err) reject(err);
|
|
||||||
resolve(result);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = FileDetector;
|
|
||||||
274
server/core/FileDetector/index.js
Normal file
274
server/core/FileDetector/index.js
Normal file
@@ -0,0 +1,274 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const signatures = require('./signatures.json');
|
||||||
|
|
||||||
|
class FileDetector {
|
||||||
|
detectFile(filename) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.fromFile(filename, 2000, (err, result) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//все, что ниже, взято здесь: https://github.com/dimapaloskin/detect-file-type
|
||||||
|
fromFile(filePath, bufferLength, callback) {
|
||||||
|
if (typeof bufferLength === 'function') {
|
||||||
|
callback = bufferLength;
|
||||||
|
bufferLength = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getFileSize(filePath, (err, fileSize) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.open(filePath, 'r', (err, fd) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
let bufferSize = bufferLength;
|
||||||
|
if (!bufferSize) {
|
||||||
|
bufferSize = 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileSize < bufferSize) {
|
||||||
|
bufferSize = fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
const buffer = Buffer.alloc(bufferSize);
|
||||||
|
|
||||||
|
fs.read(fd, buffer, 0, bufferSize, 0, (err) => {
|
||||||
|
fs.close(fd);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.fromBuffer(buffer, callback);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fromBuffer(buffer, callback) {
|
||||||
|
let result = null;
|
||||||
|
|
||||||
|
const invalidSignaturesList = this.validateSigantures();
|
||||||
|
if (invalidSignaturesList.length) {
|
||||||
|
return callback(invalidSignaturesList);
|
||||||
|
}
|
||||||
|
|
||||||
|
signatures.every((signature) => {
|
||||||
|
if (this.detect(buffer, signature.rules)) {
|
||||||
|
result = {
|
||||||
|
ext: signature.ext,
|
||||||
|
mime: signature.mime
|
||||||
|
};
|
||||||
|
|
||||||
|
if (signature.iana)
|
||||||
|
result.iana = signature.iana;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
detect(buffer, receivedRules, type) {
|
||||||
|
if (!type) {
|
||||||
|
type = 'and';
|
||||||
|
}
|
||||||
|
|
||||||
|
const rules = [...receivedRules];
|
||||||
|
|
||||||
|
let isDetected = true;
|
||||||
|
rules.every((rule) => {
|
||||||
|
if (rule.type === 'equal') {
|
||||||
|
const slicedHex = buffer.slice(rule.start || 0, rule.end || buffer.length).toString('hex');
|
||||||
|
isDetected = (slicedHex === rule.bytes);
|
||||||
|
return this.isReturnFalse(isDetected, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.type === 'notEqual') {
|
||||||
|
const slicedHex = buffer.slice(rule.start || 0, rule.end || buffer.length).toString('hex');
|
||||||
|
isDetected = !(slicedHex === rule.bytes);
|
||||||
|
return this.isReturnFalse(isDetected, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.type === 'contains') {
|
||||||
|
const slicedHex = buffer.slice(rule.start || 0, rule.end || buffer.length).toString('hex');
|
||||||
|
if (typeof rule.bytes === 'string') {
|
||||||
|
rule.bytes = [rule.bytes];
|
||||||
|
}
|
||||||
|
|
||||||
|
rule.bytes.every((bytes) => {
|
||||||
|
isDetected = (slicedHex.indexOf(bytes) !== -1);
|
||||||
|
return isDetected;
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.isReturnFalse(isDetected, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.type === 'notContains') {
|
||||||
|
const slicedHex = buffer.slice(rule.start || 0, rule.end || buffer.length).toString('hex');
|
||||||
|
if (typeof rule.bytes === 'string') {
|
||||||
|
rule.bytes = [rule.bytes];
|
||||||
|
}
|
||||||
|
|
||||||
|
rule.bytes.every((bytes) => {
|
||||||
|
isDetected = (slicedHex.indexOf(bytes) === -1);
|
||||||
|
return isDetected;
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.isReturnFalse(isDetected, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.type === 'or') {
|
||||||
|
isDetected = this.detect(buffer, rule.rules, 'or');
|
||||||
|
return this.isReturnFalse(isDetected, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.type === 'and') {
|
||||||
|
isDetected = this.detect(buffer, rule.rules, 'and');
|
||||||
|
return this.isReturnFalse(isDetected, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return isDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
isReturnFalse(isDetected, type) {
|
||||||
|
if (!isDetected && type === 'and') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDetected && type === 'or') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
validateRuleType(rule) {
|
||||||
|
const types = ['or', 'and', 'contains', 'notContains', 'equal', 'notEqual'];
|
||||||
|
return (types.indexOf(rule.type) !== -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
validateSigantures() {
|
||||||
|
let invalidSignatures = signatures.map((signature) => {
|
||||||
|
return this.validateSignature(signature);
|
||||||
|
});
|
||||||
|
|
||||||
|
invalidSignatures = this.cleanArray(invalidSignatures);
|
||||||
|
|
||||||
|
if (invalidSignatures.length) {
|
||||||
|
return invalidSignatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
validateSignature(signature) {
|
||||||
|
if (!('type' in signature)) {
|
||||||
|
return {
|
||||||
|
message: 'signature does not contain "type" field',
|
||||||
|
signature
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!('ext' in signature)) {
|
||||||
|
return {
|
||||||
|
message: 'signature does not contain "ext" field',
|
||||||
|
signature
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!('mime' in signature)) {
|
||||||
|
return {
|
||||||
|
message: 'signature does not contain "mime" field',
|
||||||
|
signature
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!('rules' in signature)) {
|
||||||
|
return {
|
||||||
|
message: 'signature does not contain "rules" field',
|
||||||
|
signature
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const invalidRules = this.validateRules(signature.rules);
|
||||||
|
|
||||||
|
if (invalidRules && invalidRules.length) {
|
||||||
|
return {
|
||||||
|
message: 'signature has invalid rule',
|
||||||
|
signature,
|
||||||
|
rules: invalidRules
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validateRules(rules) {
|
||||||
|
let invalidRules = rules.map((rule) => {
|
||||||
|
let isRuleTypeValid = this.validateRuleType(rule);
|
||||||
|
|
||||||
|
if (!isRuleTypeValid) {
|
||||||
|
return {
|
||||||
|
message: 'rule type does not supported',
|
||||||
|
rule
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((rule.type === 'or' || rule.type === 'and') && !('rules' in rule)) {
|
||||||
|
return {
|
||||||
|
message: 'rule should contains "rules" field',
|
||||||
|
rule
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.type === 'or' || rule.type === 'and') {
|
||||||
|
return this.validateRules(rule.rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
invalidRules = this.cleanArray(invalidRules);
|
||||||
|
|
||||||
|
if (invalidRules.length) {
|
||||||
|
return invalidRules;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanArray(actual) {
|
||||||
|
let newArray = new Array();
|
||||||
|
for (let i = 0; i < actual.length; i++) {
|
||||||
|
if (actual[i]) {
|
||||||
|
newArray.push(actual[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
addSignature(signature) {
|
||||||
|
signatures.push(signature);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFileSize(filePath, callback) {
|
||||||
|
fs.stat(filePath, (err, stat) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(null, stat.size);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = FileDetector;
|
||||||
725
server/core/FileDetector/signatures.json
Normal file
725
server/core/FileDetector/signatures.json
Normal file
@@ -0,0 +1,725 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "jpg",
|
||||||
|
"ext": "jpg",
|
||||||
|
"mime": "image/jpeg",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "ffd8" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "png",
|
||||||
|
"ext": "png",
|
||||||
|
"mime": "image/png",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0,"end": 4, "bytes": "89504e47" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "gif",
|
||||||
|
"ext": "gif",
|
||||||
|
"mime": "image/gif",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0,"end": 3, "bytes": "474946" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "bmp",
|
||||||
|
"ext": "bmp",
|
||||||
|
"mime": "image/bmp",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0,"end": 2, "bytes": "424d" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "webp",
|
||||||
|
"ext": "webp",
|
||||||
|
"mime": "image/webp",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 8,"end": 12, "bytes": "57454250" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "tif",
|
||||||
|
"ext": "tif",
|
||||||
|
"mime": "image/tiff",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "and", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "49492a00" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "4d4d002a" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "notEqual", "start": 8, "end": 10, "bytes": "4352" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "cr2",
|
||||||
|
"ext": "cr2",
|
||||||
|
"mime": "image/x-canon-cr2",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "and", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "49492a00" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "4d4d002a" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "equal", "start": 8, "end": 10, "bytes": "4352" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "jxr",
|
||||||
|
"ext": "jxr",
|
||||||
|
"mime": "image/vnd.ms-photo",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 3, "bytes": "4949bc" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "psd",
|
||||||
|
"ext": "psd",
|
||||||
|
"mime": "image/vnd.adobe.photoshop",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "38425053" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "flif",
|
||||||
|
"ext": "flif",
|
||||||
|
"mime": "image/flif",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "464c4946" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "zip",
|
||||||
|
"ext": "zip",
|
||||||
|
"mime": "application/zip",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "504b" },
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 2, "end": 3, "bytes": "03" },
|
||||||
|
{ "type": "equal", "start": 2, "end": 3, "bytes": "05" },
|
||||||
|
{ "type": "equal", "start": 2, "end": 3, "bytes": "07" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "04" },
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "06" },
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "08" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "notEqual", "start": 30, "end": 50, "bytes": "4d4554412d494e462f6d6f7a696c6c612e727361" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "xpi",
|
||||||
|
"ext": "xpi",
|
||||||
|
"mime": "application/x-xpinstall",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "504b0304" },
|
||||||
|
{ "type": "equal", "start": 30, "end": 50, "bytes": "4d4554412d494e462f6d6f7a696c6c612e727361" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "tar",
|
||||||
|
"ext": "tar",
|
||||||
|
"mime": "application/x-tar",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 257, "end": 262, "bytes": "7573746172" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "rar",
|
||||||
|
"ext": "rar",
|
||||||
|
"mime": "application/x-rar-compressed",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 6, "bytes": "526172211a07" },
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 6, "end": 7, "bytes": "00" },
|
||||||
|
{ "type": "equal", "start": 6, "end": 7, "bytes": "01" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "gz",
|
||||||
|
"ext": "gz",
|
||||||
|
"mime": "application/gzip",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 3, "bytes": "1f8b08" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bz2",
|
||||||
|
"ext": "bz2",
|
||||||
|
"mime": "application/x-bzip2",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 3, "bytes": "425a68" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "7z",
|
||||||
|
"ext": "7z",
|
||||||
|
"mime": "application/x-7z-compressed",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 6, "bytes": "377abcaf271c" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "dmg",
|
||||||
|
"ext": "dmg",
|
||||||
|
"mime": "application/x-apple-diskimage",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "7801" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "mp4",
|
||||||
|
"ext": "mp4",
|
||||||
|
"mime": "video/mp4",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "and", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 0, "end": 3, "bytes": "000000" },
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "18" },
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "20" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "equal", "start": 4, "end": 8, "bytes": "66747970" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "33677035" },
|
||||||
|
{ "type": "and", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 0, "end": 11, "bytes": "0000001c667479706d7034" },
|
||||||
|
{ "type": "equal", "start": 16, "end": 28, "bytes": "6d7034316d70343269736f6d" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "equal", "start": 0, "end": 12, "bytes": "0000001c6674797069736f6d" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 16, "bytes": "0000001c667479706d70343200000000" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "m4v",
|
||||||
|
"ext": "m4v",
|
||||||
|
"mime": "video/x-m4v",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 11, "bytes": "0000001c667479704d3456" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "mid",
|
||||||
|
"ext": "mid",
|
||||||
|
"mime": "audio/midi",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "4d546864" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "mkv",
|
||||||
|
"ext": "mkv",
|
||||||
|
"mime": "video/x-matroska",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 31, "end": 39, "bytes": "6d6174726f736b61" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "webm",
|
||||||
|
"ext": "webm",
|
||||||
|
"mime": "video/webm",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "1a45dfa3" },
|
||||||
|
{ "type": "notEqual", "start": 31, "end": 39, "bytes": "6d6174726f736b61" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "wmv",
|
||||||
|
"ext": "wmv",
|
||||||
|
"mime": "video/x-ms-wmv",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 10, "bytes": "3026b2758e66cf11a6d9" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "mpg",
|
||||||
|
"ext": "mpg",
|
||||||
|
"mime": "video/mpeg",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 3, "bytes": "000001" },
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b0"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b1"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b2"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b3"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b4"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b5"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b6"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b7"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b8"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "b9"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "ba"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "bb"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "bc"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "bd"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "be"},
|
||||||
|
{ "type": "equal", "start": 3, "end": 4, "bytes": "bf"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "mp3",
|
||||||
|
"ext": "mp3",
|
||||||
|
"mime": "audio/mpeg",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 0, "end": 3, "bytes": "494433" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "fffb" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "m4a",
|
||||||
|
"ext": "m4a",
|
||||||
|
"mime": "audio/m4a",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 4, "end": 11, "bytes": "667479704d3441" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "4d344120" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "opus",
|
||||||
|
"ext": "opus",
|
||||||
|
"mime": "audio/opus",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 28, "end": 36, "bytes": "4f70757348656164" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "ogg",
|
||||||
|
"ext": "ogg",
|
||||||
|
"mime": "audio/ogg",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "4f676753" },
|
||||||
|
{ "type": "notEqual", "start": 28, "end": 36, "bytes": "4f70757348656164" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "flac",
|
||||||
|
"ext": "flac",
|
||||||
|
"mime": "audio/x-flac",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "664c6143" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "wav",
|
||||||
|
"ext": "wav",
|
||||||
|
"mime": "audio/x-wav",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "52494646" },
|
||||||
|
{ "type": "equal", "start": 8, "end": 12, "bytes": "57415645" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "amr",
|
||||||
|
"ext": "amr",
|
||||||
|
"mime": "audio/amr",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 6, "bytes": "2321414d520a" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "pdf",
|
||||||
|
"ext": "pdf",
|
||||||
|
"mime": "application/pdf",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "25504446" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "exe",
|
||||||
|
"ext": "exe",
|
||||||
|
"mime": "application/x-msdownload",
|
||||||
|
"iana": "application/vnd.microsoft.portable-executable",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "4d5a" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "4d7a" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "6d7a" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "6d5a" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "swf",
|
||||||
|
"ext": "swf",
|
||||||
|
"mime": "application/x-shockwave-flash",
|
||||||
|
"iana": "application/vnd.adobe.flash.movie",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 0, "end": 1, "bytes": "43" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 1, "bytes": "46" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "equal", "start": 1, "end": 3, "bytes": "5753" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "rtf",
|
||||||
|
"ext": "rtf",
|
||||||
|
"mime": "application/rtf",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 5, "bytes": "7b5c727466" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "mov",
|
||||||
|
"ext": "mov",
|
||||||
|
"mime": "video/quicktime",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 8, "bytes": "0000001466747970" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "avi",
|
||||||
|
"ext": "avi",
|
||||||
|
"mime": "video/x-msvideo",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "52494646" },
|
||||||
|
{ "type": "equal", "start": 8, "end": 11, "bytes": "415649" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "woff",
|
||||||
|
"ext": "woff",
|
||||||
|
"mime": "application/font-woff",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "774f4646" },
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 4, "end": 8, "bytes": "00010000" },
|
||||||
|
{ "type": "equal", "start": 4, "end": 8, "bytes": "4f54544f" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "woff2",
|
||||||
|
"ext": "woff2",
|
||||||
|
"mime": "application/font-woff",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "774f4632" },
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 4, "end": 8, "bytes": "00010000" },
|
||||||
|
{ "type": "equal", "start": 4, "end": 8, "bytes": "4f54544f" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "eot",
|
||||||
|
"ext": "eot",
|
||||||
|
"mime": "application/octet-stream",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 34, "end": 36, "bytes": "4c50" },
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 8, "end": 11, "bytes": "000001" },
|
||||||
|
{ "type": "equal", "start": 8, "end": 11, "bytes": "010002" },
|
||||||
|
{ "type": "equal", "start": 8, "end": 11, "bytes": "020002" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "ttf",
|
||||||
|
"ext": "ttf",
|
||||||
|
"mime": "application/font-sfnt",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 5, "bytes": "0001000000" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "otf",
|
||||||
|
"ext": "otf",
|
||||||
|
"mime": "application/font-sfnt",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 5, "bytes": "4f54544f00" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "ico",
|
||||||
|
"ext": "ico",
|
||||||
|
"mime": "application/x-icon",
|
||||||
|
"iana": "image/vnd.microsoft.icon",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "00000100" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "flv",
|
||||||
|
"ext": "flv",
|
||||||
|
"mime": "application/x-flv",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "464c5601" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "ps",
|
||||||
|
"ext": "ps",
|
||||||
|
"mime": "application/postscript",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "2521" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "xz",
|
||||||
|
"ext": "xz",
|
||||||
|
"mime": "application/x-xz",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 6, "bytes": "fd377a585a00" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "sqlite",
|
||||||
|
"ext": "sqlite",
|
||||||
|
"mime": "application/x-sqlite3",
|
||||||
|
"iana": "application/vnd.sqlite3",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "53514c69" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "nes",
|
||||||
|
"ext": "nes",
|
||||||
|
"mime": "application/x-nintendo-nes-rom",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "4e45531a" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "crx",
|
||||||
|
"ext": "crx",
|
||||||
|
"mime": "application/x-google-chrome-extension",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "43723234" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "cab",
|
||||||
|
"ext": "cab",
|
||||||
|
"mime": "application/vnd.ms-cab-compressed",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "4d534346" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "49536328" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "ar",
|
||||||
|
"ext": "ar",
|
||||||
|
"mime": "application/x-unix-archive",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 7, "bytes": "213c617263683e" },
|
||||||
|
{ "type": "notEqual", "start": 0, "end": 21, "bytes": "213c617263683e0a64656269616e2d62696e617279" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "deb",
|
||||||
|
"ext": "deb",
|
||||||
|
"mime": "application/x-deb",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 21, "bytes": "213c617263683e0a64656269616e2d62696e617279" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "rpm",
|
||||||
|
"ext": "rpm",
|
||||||
|
"mime": "application/x-rpm",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "edabeedb" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "Z",
|
||||||
|
"ext": "Z",
|
||||||
|
"mime": "application/x-compress",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "1fa0" },
|
||||||
|
{ "type": "equal", "start": 0, "end": 2, "bytes": "1f9d" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "lz",
|
||||||
|
"ext": "lz",
|
||||||
|
"mime": "application/x-lzip",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 4, "bytes": "4c5a4950" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "msi",
|
||||||
|
"ext": "msi",
|
||||||
|
"mime": "application/x-msi",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 0, "end": 8, "bytes": "d0cf11e0a1b11ae1" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "svg",
|
||||||
|
"ext": "svg",
|
||||||
|
"mime": "image/svg+xml",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "contains", "bytes": "3c737667" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "html",
|
||||||
|
"ext": "html",
|
||||||
|
"mime": "text/html",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "contains", "bytes": "3c68746d6c" },
|
||||||
|
{ "type": "contains", "bytes": "3c00680074006d006c00" },
|
||||||
|
{ "type": "equal", "end": 5, "bytes": "3c68746d6c" },
|
||||||
|
{ "type": "equal", "end": 10, "bytes": "3c00680074006d006c00" },
|
||||||
|
{ "type": "equal", "end": 9, "bytes": "3c21646f6374797065" },
|
||||||
|
{ "type": "equal", "end": 5, "bytes": "3c626f6479" },
|
||||||
|
{ "type": "equal", "end": 5, "bytes": "3c68656164" },
|
||||||
|
{ "type": "equal", "end": 7, "bytes": "3c696672616d65" },
|
||||||
|
{ "type": "equal", "end": 4, "bytes": "3c696d67" },
|
||||||
|
{ "type": "equal", "end": 7, "bytes": "3c6f626a656374" },
|
||||||
|
{ "type": "equal", "end": 7, "bytes": "3c736372697074" },
|
||||||
|
{ "type": "equal", "end": 6, "bytes": "3c7461626c65" },
|
||||||
|
{ "type": "equal", "end": 6, "bytes": "3c7469746c65" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "docx",
|
||||||
|
"ext": "docx",
|
||||||
|
"mime": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "contains", "bytes": "6170706c69636174696f6e2f766e642e6f70656e786d6c666f726d6174732d6f6666696365646f63756d656e74" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "xml",
|
||||||
|
"ext": "xml",
|
||||||
|
"mime": "application/xml",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "or", "rules":
|
||||||
|
[
|
||||||
|
{ "type": "equal", "end": 19, "bytes": "3c3f786d6c2076657273696f6e3d22312e3022" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "mobi",
|
||||||
|
"ext": "mobi",
|
||||||
|
"mime": "application/x-mobipocket-ebook",
|
||||||
|
"rules": [
|
||||||
|
{ "type": "equal", "start": 64, "end": 68, "bytes": "4d4f4249" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
@@ -8,8 +8,14 @@ class FileDownloader {
|
|||||||
|
|
||||||
async load(url, callback) {
|
async load(url, callback) {
|
||||||
let errMes = '';
|
let errMes = '';
|
||||||
|
const options = {
|
||||||
|
encoding: null,
|
||||||
|
headers: {
|
||||||
|
'user-agent': 'Mozilla/5.0 (X11; HasCodingOs 1.0; Linux x64) AppleWebKit/637.36 (KHTML, like Gecko) Chrome/70.0.3112.101 Safari/637.36 HasBrowser/5.0'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const response = await got(url, {method: 'HEAD'});
|
const response = await got(url, Object.assign({}, options, {method: 'HEAD'}));
|
||||||
|
|
||||||
let estSize = 0;
|
let estSize = 0;
|
||||||
if (response.headers['content-length']) {
|
if (response.headers['content-length']) {
|
||||||
@@ -17,7 +23,7 @@ class FileDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let prevProg = 0;
|
let prevProg = 0;
|
||||||
const request = got(url, {encoding: null}).on('downloadProgress', progress => {
|
const request = got(url, options).on('downloadProgress', progress => {
|
||||||
if (progress.transferred > maxDownloadSize) {
|
if (progress.transferred > maxDownloadSize) {
|
||||||
errMes = 'file too big';
|
errMes = 'file too big';
|
||||||
request.cancel();
|
request.cancel();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class ReaderWorker {
|
|||||||
|
|
||||||
this.down = new FileDownloader();
|
this.down = new FileDownloader();
|
||||||
this.decomp = new FileDecompressor();
|
this.decomp = new FileDecompressor();
|
||||||
this.bookConverter = new BookConverter();
|
this.bookConverter = new BookConverter(this.config);
|
||||||
|
|
||||||
if (!singleCleanExecute) {
|
if (!singleCleanExecute) {
|
||||||
this.periodicCleanDir(this.config.tempPublicDir, this.config.maxTempPublicDirSize, 60*60*1000);//1 раз в час
|
this.periodicCleanDir(this.config.tempPublicDir, this.config.maxTempPublicDirSize, 60*60*1000);//1 раз в час
|
||||||
@@ -63,17 +63,24 @@ class ReaderWorker {
|
|||||||
//decompress
|
//decompress
|
||||||
wState.set({state: 'decompress', step: 2, progress: 0});
|
wState.set({state: 'decompress', step: 2, progress: 0});
|
||||||
decompDir = `${this.config.tempDownloadDir}/${decompDirname}`;
|
decompDir = `${this.config.tempDownloadDir}/${decompDirname}`;
|
||||||
const decompFilename = await this.decomp.decompressFile(downloadedFilename, decompDir);
|
let decompFiles = {};
|
||||||
|
try {
|
||||||
|
decompFiles = await this.decomp.decompressNested(downloadedFilename, decompDir);
|
||||||
|
} catch (e) {
|
||||||
|
if (this.config.branch == 'development')
|
||||||
|
console.error(e);
|
||||||
|
throw new Error('Ошибка распаковки');
|
||||||
|
}
|
||||||
wState.set({progress: 100});
|
wState.set({progress: 100});
|
||||||
|
|
||||||
//parse book
|
//конвертирование в fb2
|
||||||
wState.set({state: 'convert', step: 3, progress: 0});
|
wState.set({state: 'convert', step: 3, progress: 0});
|
||||||
convertFilename = `${this.config.tempDownloadDir}/${tempFilename2}`;
|
convertFilename = `${this.config.tempDownloadDir}/${tempFilename2}`;
|
||||||
await this.bookConverter.convertToFb2(decompFilename, convertFilename, url, progress => {
|
await this.bookConverter.convertToFb2(decompFiles, convertFilename, url, progress => {
|
||||||
wState.set({progress});
|
wState.set({progress});
|
||||||
});
|
});
|
||||||
|
|
||||||
//compress file to tmp dir, if not exists with the same hashname
|
//сжимаем файл в tmp, если там уже нет с тем же именем-sha256
|
||||||
const compFilename = await this.decomp.gzipFileIfNotExists(convertFilename, `${this.config.tempPublicDir}`);
|
const compFilename = await this.decomp.gzipFileIfNotExists(convertFilename, `${this.config.tempPublicDir}`);
|
||||||
|
|
||||||
wState.set({progress: 100});
|
wState.set({progress: 100});
|
||||||
@@ -83,8 +90,9 @@ class ReaderWorker {
|
|||||||
wState.finish({path: `/tmp/${finishFilename}`});
|
wState.finish({path: `/tmp/${finishFilename}`});
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (this.config.branch == 'development')
|
||||||
|
console.error(e);
|
||||||
wState.set({state: 'error', error: (errMes ? errMes : e.message)});
|
wState.set({state: 'error', error: (errMes ? errMes : e.message)});
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
//clean
|
//clean
|
||||||
if (decompDir)
|
if (decompDir)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const { spawn } = require('child_process');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
@@ -13,8 +14,48 @@ async function touchFile(filename) {
|
|||||||
await fs.utimes(filename, Date.now()/1000, Date.now()/1000);
|
await fs.utimes(filename, Date.now()/1000, Date.now()/1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function spawnProcess(cmd, opts) {
|
||||||
|
let {args, killAfter, onData} = opts;
|
||||||
|
killAfter = (killAfter ? killAfter : 120*1000);
|
||||||
|
onData = (onData ? onData : () => {});
|
||||||
|
args = (args ? args : []);
|
||||||
|
|
||||||
|
return new Promise(async(resolve, reject) => {
|
||||||
|
let resolved = false;
|
||||||
|
const proc = spawn(cmd, args, {detached: true});
|
||||||
|
|
||||||
|
let stdout = '';
|
||||||
|
proc.stdout.on('data', (data) => {
|
||||||
|
stdout += data;
|
||||||
|
onData(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
let stderr = '';
|
||||||
|
proc.stderr.on('data', (data) => {
|
||||||
|
stderr += data;
|
||||||
|
onData(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
proc.on('close', (code) => {
|
||||||
|
resolved = true;
|
||||||
|
resolve({status: 'close', code, stdout, stderr});
|
||||||
|
});
|
||||||
|
|
||||||
|
proc.on('error', (error) => {
|
||||||
|
reject({status: 'error', error, stdout, stderr});
|
||||||
|
});
|
||||||
|
|
||||||
|
await sleep(killAfter);
|
||||||
|
if (!resolved) {
|
||||||
|
process.kill(proc.pid);
|
||||||
|
reject({status: 'killed', stdout, stderr});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sleep,
|
sleep,
|
||||||
randomHexString,
|
randomHexString,
|
||||||
touchFile
|
touchFile,
|
||||||
|
spawnProcess
|
||||||
};
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const {initLogger, getLog} = require('./core/getLogger');
|
const logger = require('./core/getLogger');
|
||||||
initLogger(config);
|
logger.initLogger(config);
|
||||||
const log = getLog();
|
const log = logger.getLog();
|
||||||
|
|
||||||
const configSaver = require('./config/configSaver');
|
const configSaver = require('./config/configSaver');
|
||||||
const argv = require('minimist')(process.argv.slice(2));
|
const argv = require('minimist')(process.argv.slice(2));
|
||||||
@@ -31,6 +31,7 @@ async function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
log(`${config.name} v${config.version}`);
|
||||||
log('Initializing');
|
log('Initializing');
|
||||||
await init();
|
await init();
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ async function main() {
|
|||||||
try {
|
try {
|
||||||
await main();
|
await main();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
Reference in New Issue
Block a user