Browse Source

Merge branch 'release/1.0.1'

Book Pauk 2 years ago
parent
commit
eb9bf89854

+ 1 - 1
client/components/Search/Search.vue

@@ -842,7 +842,7 @@ class Search {
                 d.click();
             } else if (action == 'copyLink') {
                 //копирование ссылки
-                if (utils.copyTextToClipboard(href))
+                if (await utils.copyTextToClipboard(href))
                     this.$root.notify.success('Ссылка успешно скопирована');
                 else
                     this.$root.notify.error('Копирование ссылки не удалось');

+ 22 - 0
client/share/utils.js

@@ -48,7 +48,29 @@ export function wordEnding(num, type = 0) {
     }
 }
 
+export function fallbackCopyTextToClipboard(text) {
+    let textArea = document.createElement('textarea');
+    textArea.value = text;
+    document.body.appendChild(textArea);
+    textArea.focus();
+    textArea.select();
+
+    let result = false;
+    try {
+         result = document.execCommand('copy');
+    } catch (e) {
+        console.error(e);
+    }
+
+    document.body.removeChild(textArea);
+    return result;
+}
+
 export async function copyTextToClipboard(text) {
+    if (!navigator.clipboard) {
+        return fallbackCopyTextToClipboard(text);
+    }
+
     let result = false;
     try {
         await navigator.clipboard.writeText(text);

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "inpx-web",
-  "version": "1.0.0",
+  "version": "1.0.1",
   "author": "Book Pauk <bookpauk@gmail.com>",
   "license": "CC0-1.0",
   "repository": "bookpauk/inpx-web",

+ 8 - 1
server/core/RemoteLib.js

@@ -66,8 +66,15 @@ class RemoteLib {
 
             const buf = await this.down.load(`${this.remoteHost}${link}`);
 
+            const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
+            const tmpFile2 = `${this.config.tempDir}/${utils.randomHexString(30)}`;
             const publicPath = `${this.config.publicDir}${link}`;
-            await fs.writeFile(publicPath, buf);
+            
+            await fs.writeFile(tmpFile, buf);
+
+            await utils.gzipFile(tmpFile, tmpFile2, 4);
+            await fs.remove(tmpFile);
+            await fs.move(tmpFile2, publicPath, {overwrite: true});
 
             return path.basename(link);
         } catch (e) {

+ 1 - 16
server/core/WebWorker.js

@@ -1,7 +1,6 @@
 const os = require('os');
 const path = require('path');
 const fs = require('fs-extra');
-const zlib = require('zlib');
 const _ = require('lodash');
 
 const ZipReader = require('./ZipReader');
@@ -310,20 +309,6 @@ class WebWorker {
         }
     }
 
-    //async
-    gzipFile(inputFile, outputFile, level = 1) {
-        return new Promise((resolve, reject) => {
-            const gzip = zlib.createGzip({level});
-            const input = fs.createReadStream(inputFile);
-            const output = fs.createWriteStream(outputFile);
-
-            input.pipe(gzip).pipe(output).on('finish', (err) => {
-                if (err) reject(err);
-                else resolve();
-            });
-        });
-    }
-
     async restoreBook(bookPath, downFileName) {
         const db = this.db;
 
@@ -344,7 +329,7 @@ class WebWorker {
             await fs.ensureDir(path.dirname(publicPath));
 
             const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
-            await this.gzipFile(extractedFile, tmpFile, 4);
+            await utils.gzipFile(extractedFile, tmpFile, 4);
             await fs.remove(extractedFile);
             await fs.move(tmpFile, publicPath, {overwrite: true});
         } else {

+ 16 - 0
server/core/utils.js

@@ -1,5 +1,6 @@
 const fs = require('fs-extra');
 const path = require('path');
+const zlib = require('zlib');
 const crypto = require('crypto');
 
 function sleep(ms) {
@@ -93,6 +94,20 @@ function randomHexString(len) {
     return crypto.randomBytes(len).toString('hex')
 }
 
+//async
+function gzipFile(inputFile, outputFile, level = 1) {
+    return new Promise((resolve, reject) => {
+        const gzip = zlib.createGzip({level});
+        const input = fs.createReadStream(inputFile);
+        const output = fs.createWriteStream(outputFile);
+
+        input.pipe(gzip).pipe(output).on('finish', (err) => {
+            if (err) reject(err);
+            else resolve();
+        });
+    });
+}
+
 module.exports = {
     sleep,
     versionText,
@@ -104,4 +119,5 @@ module.exports = {
     getBufHash,
     intersectSet,
     randomHexString,
+    gzipFile,
 };