Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c06552278 | ||
|
|
000f8dde82 | ||
|
|
9ffc218002 | ||
|
|
68a188f099 | ||
|
|
8829bb3810 | ||
|
|
5164d2f536 |
@@ -6,6 +6,7 @@ server {
|
|||||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
|
||||||
|
|
||||||
server_name beta.liberama.top;
|
server_name beta.liberama.top;
|
||||||
|
set $liberama http://127.0.0.1:34082;
|
||||||
|
|
||||||
client_max_body_size 50m;
|
client_max_body_size 50m;
|
||||||
proxy_read_timeout 1h;
|
proxy_read_timeout 1h;
|
||||||
@@ -15,15 +16,20 @@ server {
|
|||||||
gzip_proxied expired no-cache no-store private auth;
|
gzip_proxied expired no-cache no-store private auth;
|
||||||
gzip_types *;
|
gzip_types *;
|
||||||
|
|
||||||
|
location @liberama {
|
||||||
|
proxy_pass $liberama;
|
||||||
|
}
|
||||||
|
|
||||||
location /api {
|
location /api {
|
||||||
proxy_pass http://127.0.0.1:34082;
|
proxy_pass $liberama;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /ws {
|
location /ws {
|
||||||
proxy_pass http://127.0.0.1:34082;
|
proxy_pass $liberama;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_read_timeout 600s;
|
||||||
}
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
@@ -32,6 +38,11 @@ server {
|
|||||||
location /tmp {
|
location /tmp {
|
||||||
types { } default_type "application/xml; charset=utf-8";
|
types { } default_type "application/xml; charset=utf-8";
|
||||||
add_header Content-Encoding gzip;
|
add_header Content-Encoding gzip;
|
||||||
|
try_files $uri @liberama;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /upload {
|
||||||
|
try_files $uri @liberama;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~* \.(?:manifest|appcache|html)$ {
|
location ~* \.(?:manifest|appcache|html)$ {
|
||||||
@@ -50,6 +61,7 @@ server {
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name b.beta.liberama.top;
|
server_name b.beta.liberama.top;
|
||||||
|
set $liberama http://127.0.0.1:34082;
|
||||||
|
|
||||||
client_max_body_size 50m;
|
client_max_body_size 50m;
|
||||||
proxy_read_timeout 1h;
|
proxy_read_timeout 1h;
|
||||||
@@ -59,15 +71,20 @@ server {
|
|||||||
gzip_proxied expired no-cache no-store private auth;
|
gzip_proxied expired no-cache no-store private auth;
|
||||||
gzip_types *;
|
gzip_types *;
|
||||||
|
|
||||||
|
location @liberama {
|
||||||
|
proxy_pass $liberama;
|
||||||
|
}
|
||||||
|
|
||||||
location /api {
|
location /api {
|
||||||
proxy_pass http://127.0.0.1:34082;
|
proxy_pass $liberama;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /ws {
|
location /ws {
|
||||||
proxy_pass http://127.0.0.1:34082;
|
proxy_pass $liberama;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_read_timeout 600s;
|
||||||
}
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
@@ -76,6 +93,11 @@ server {
|
|||||||
location /tmp {
|
location /tmp {
|
||||||
types { } default_type "application/xml; charset=utf-8";
|
types { } default_type "application/xml; charset=utf-8";
|
||||||
add_header Content-Encoding gzip;
|
add_header Content-Encoding gzip;
|
||||||
|
try_files $uri @liberama;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /upload {
|
||||||
|
try_files $uri @liberama;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~* \.(?:manifest|appcache|html)$ {
|
location ~* \.(?:manifest|appcache|html)$ {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ server {
|
|||||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
|
||||||
|
|
||||||
server_name beta.omnireader.ru;
|
server_name beta.omnireader.ru;
|
||||||
|
set $liberama http://127.0.0.1:34081;
|
||||||
|
|
||||||
client_max_body_size 50m;
|
client_max_body_size 50m;
|
||||||
proxy_read_timeout 1h;
|
proxy_read_timeout 1h;
|
||||||
@@ -15,15 +16,20 @@ server {
|
|||||||
gzip_proxied expired no-cache no-store private auth;
|
gzip_proxied expired no-cache no-store private auth;
|
||||||
gzip_types *;
|
gzip_types *;
|
||||||
|
|
||||||
|
location @liberama {
|
||||||
|
proxy_pass $liberama;
|
||||||
|
}
|
||||||
|
|
||||||
location /api {
|
location /api {
|
||||||
proxy_pass http://127.0.0.1:34081;
|
proxy_pass $liberama;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /ws {
|
location /ws {
|
||||||
proxy_pass http://127.0.0.1:34081;
|
proxy_pass $liberama;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_read_timeout 600s;
|
||||||
}
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
@@ -32,6 +38,11 @@ server {
|
|||||||
location /tmp {
|
location /tmp {
|
||||||
types { } default_type "application/xml; charset=utf-8";
|
types { } default_type "application/xml; charset=utf-8";
|
||||||
add_header Content-Encoding gzip;
|
add_header Content-Encoding gzip;
|
||||||
|
try_files $uri @liberama;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /upload {
|
||||||
|
try_files $uri @liberama;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~* \.(?:manifest|appcache|html)$ {
|
location ~* \.(?:manifest|appcache|html)$ {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name beta.omnireader.ru;
|
server_name beta.omnireader.ru;
|
||||||
|
set $liberama http://127.0.0.1:34081;
|
||||||
|
|
||||||
client_max_body_size 50m;
|
client_max_body_size 50m;
|
||||||
proxy_read_timeout 1h;
|
proxy_read_timeout 1h;
|
||||||
@@ -10,15 +11,20 @@ server {
|
|||||||
gzip_proxied expired no-cache no-store private auth;
|
gzip_proxied expired no-cache no-store private auth;
|
||||||
gzip_types *;
|
gzip_types *;
|
||||||
|
|
||||||
|
location @liberama {
|
||||||
|
proxy_pass $liberama;
|
||||||
|
}
|
||||||
|
|
||||||
location /api {
|
location /api {
|
||||||
proxy_pass http://127.0.0.1:34081;
|
proxy_pass $liberama;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /ws {
|
location /ws {
|
||||||
proxy_pass http://127.0.0.1:34081;
|
proxy_pass $liberama;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_read_timeout 600s;
|
||||||
}
|
}
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
@@ -27,6 +33,11 @@ server {
|
|||||||
location /tmp {
|
location /tmp {
|
||||||
types { } default_type "application/xml; charset=utf-8";
|
types { } default_type "application/xml; charset=utf-8";
|
||||||
add_header Content-Encoding gzip;
|
add_header Content-Encoding gzip;
|
||||||
|
try_files $uri @liberama;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /upload {
|
||||||
|
try_files $uri @liberama;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~* \.(?:manifest|appcache|html)$ {
|
location ~* \.(?:manifest|appcache|html)$ {
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
remoteWebDavStorage: false,
|
|
||||||
/*
|
/*
|
||||||
|
remoteWebDavStorage: false,
|
||||||
remoteWebDavStorage: {
|
remoteWebDavStorage: {
|
||||||
url: '127.0.0.1:1900',
|
url: '127.0.0.1:1900',
|
||||||
username: '',
|
username: '',
|
||||||
@@ -64,5 +64,12 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
remoteStorage: false,
|
||||||
|
/*
|
||||||
|
remoteStorage: {
|
||||||
|
url: 'https://127.0.0.1:11900',
|
||||||
|
accessToken: '',
|
||||||
|
},
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const WorkerState = require('../WorkerState');//singleton
|
|||||||
const FileDownloader = require('../FileDownloader');
|
const FileDownloader = require('../FileDownloader');
|
||||||
const FileDecompressor = require('../FileDecompressor');
|
const FileDecompressor = require('../FileDecompressor');
|
||||||
const BookConverter = require('./BookConverter');
|
const BookConverter = require('./BookConverter');
|
||||||
const RemoteWebDavStorage = require('../RemoteWebDavStorage');
|
const RemoteStorage = require('../RemoteStorage');
|
||||||
|
|
||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
const log = new (require('../AppLogger'))().log;//singleton
|
const log = new (require('../AppLogger'))().log;//singleton
|
||||||
@@ -33,10 +33,10 @@ class ReaderWorker {
|
|||||||
this.decomp = new FileDecompressor(3*config.maxUploadFileSize);
|
this.decomp = new FileDecompressor(3*config.maxUploadFileSize);
|
||||||
this.bookConverter = new BookConverter(this.config);
|
this.bookConverter = new BookConverter(this.config);
|
||||||
|
|
||||||
this.remoteWebDavStorage = false;
|
this.remoteStorage = false;
|
||||||
if (config.remoteWebDavStorage) {
|
if (config.remoteStorage) {
|
||||||
this.remoteWebDavStorage = new RemoteWebDavStorage(
|
this.remoteStorage = new RemoteStorage(
|
||||||
Object.assign({maxContentLength: 3*config.maxUploadFileSize}, config.remoteWebDavStorage)
|
Object.assign({maxContentLength: 3*config.maxUploadFileSize}, config.remoteStorage)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,8 +235,8 @@ class ReaderWorker {
|
|||||||
|
|
||||||
if (!await fs.pathExists(targetName)) {
|
if (!await fs.pathExists(targetName)) {
|
||||||
let found = false;
|
let found = false;
|
||||||
if (this.remoteWebDavStorage) {
|
if (this.remoteStorage) {
|
||||||
found = await this.remoteWebDavStorage.getFileSuccess(targetName, remoteDir);
|
found = await this.remoteStorage.getFileSuccess(targetName, remoteDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
@@ -271,15 +271,15 @@ class ReaderWorker {
|
|||||||
|
|
||||||
files.sort((a, b) => a.stat.mtimeMs - b.stat.mtimeMs);
|
files.sort((a, b) => a.stat.mtimeMs - b.stat.mtimeMs);
|
||||||
|
|
||||||
if (moveToRemote && this.remoteWebDavStorage) {
|
if (moveToRemote && this.remoteStorage) {
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (sent[file.name])
|
if (sent[file.name])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//отправляем в remoteWebDavStorage
|
//отправляем в remoteStorage
|
||||||
try {
|
try {
|
||||||
log(`remoteWebDavStorage.putFile ${remoteDir}/${path.basename(file.name)}`);
|
log(`remoteStorage.putFile ${remoteDir}/${path.basename(file.name)}`);
|
||||||
await this.remoteWebDavStorage.putFile(file.name, remoteDir);
|
await this.remoteStorage.putFile(file.name, remoteDir);
|
||||||
sent[file.name] = true;
|
sent[file.name] = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(LM_ERR, e.stack);
|
log(LM_ERR, e.stack);
|
||||||
@@ -294,8 +294,11 @@ class ReaderWorker {
|
|||||||
const oldFile = file.name;
|
const oldFile = file.name;
|
||||||
|
|
||||||
//реально удаляем только если сохранили в хранилище или размер dir увеличен в 1.5 раза
|
//реально удаляем только если сохранили в хранилище или размер dir увеличен в 1.5 раза
|
||||||
if ((moveToRemote && this.remoteWebDavStorage && sent[oldFile]) || size > maxSize*1.5) {
|
if (!(moveToRemote && this.remoteStorage)
|
||||||
|
|| (moveToRemote && this.remoteStorage && sent[oldFile])
|
||||||
|
|| size > maxSize*1.5) {
|
||||||
await fs.remove(oldFile);
|
await fs.remove(oldFile);
|
||||||
|
delete sent[oldFile];
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
97
server/core/RemoteStorage.js
Normal file
97
server/core/RemoteStorage.js
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const WebSocketConnection = require('./WebSocketConnection');
|
||||||
|
|
||||||
|
class RemoteStorage {
|
||||||
|
constructor(config) {
|
||||||
|
this.config = Object.assign({}, config);
|
||||||
|
this.config.maxContentLength = this.config.maxContentLength || 10*1024*1024;
|
||||||
|
|
||||||
|
this.accessToken = this.config.accessToken;
|
||||||
|
|
||||||
|
this.wsc = new WebSocketConnection(config.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
async wsQuery(query) {
|
||||||
|
const response = await this.wsc.message(
|
||||||
|
await this.wsc.send(Object.assign({accessToken: this.accessToken}, query))
|
||||||
|
);
|
||||||
|
if (response.error)
|
||||||
|
throw new Error(response.error);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
async wsStat(fileName) {
|
||||||
|
return await this.wsQuery({action: 'get-stat', fileName});
|
||||||
|
}
|
||||||
|
|
||||||
|
async wsGetFile(fileName) {
|
||||||
|
return this.wsQuery({action: 'get-file', fileName});
|
||||||
|
}
|
||||||
|
|
||||||
|
async wsPutFile(fileName, data) {//data base64 encoded string
|
||||||
|
return this.wsQuery({action: 'put-file', fileName, data});
|
||||||
|
}
|
||||||
|
|
||||||
|
async wsDelFile(fileName) {
|
||||||
|
return this.wsQuery({action: 'del-file', fileName});
|
||||||
|
}
|
||||||
|
|
||||||
|
makeRemoteFileName(fileName, dir = '') {
|
||||||
|
const base = path.basename(fileName);
|
||||||
|
if (base.length > 3) {
|
||||||
|
return `${dir}/${base.substr(0, 3)}/${base}`;
|
||||||
|
} else {
|
||||||
|
return `${dir}/${base}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async putFile(fileName, dir = '') {
|
||||||
|
if (!await fs.pathExists(fileName)) {
|
||||||
|
throw new Error(`File not found: ${fileName}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const remoteFilename = this.makeRemoteFileName(fileName, dir);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const localStat = await fs.stat(fileName);
|
||||||
|
let remoteStat = await this.wsStat(remoteFilename);
|
||||||
|
remoteStat = remoteStat.stat;
|
||||||
|
|
||||||
|
if (remoteStat.isFile && localStat.size == remoteStat.size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.wsDelFile(remoteFilename);
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await fs.readFile(fileName, 'base64');
|
||||||
|
await this.wsPutFile(remoteFilename, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFile(fileName, dir = '') {
|
||||||
|
if (await fs.pathExists(fileName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const remoteFilename = this.makeRemoteFileName(fileName, dir);
|
||||||
|
|
||||||
|
const response = await this.wsGetFile(remoteFilename);
|
||||||
|
await fs.writeFile(fileName, response.data, 'base64');
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFileSuccess(filename, dir = '') {
|
||||||
|
try {
|
||||||
|
await this.getFile(filename, dir);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = RemoteStorage;
|
||||||
Reference in New Issue
Block a user