瀏覽代碼

Merge branch 'release/1.1.1'

Book Pauk 2 年之前
父節點
當前提交
a7af7342b6
共有 5 個文件被更改,包括 19 次插入13 次删除
  1. 2 2
      package-lock.json
  2. 1 1
      package.json
  3. 1 1
      server/core/RemoteLib.js
  4. 11 8
      server/core/WebWorker.js
  5. 4 1
      server/core/utils.js

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
 {
   "name": "inpx-web",
   "name": "inpx-web",
-  "version": "1.1.0",
+  "version": "1.1.1",
   "lockfileVersion": 2,
   "lockfileVersion": 2,
   "requires": true,
   "requires": true,
   "packages": {
   "packages": {
     "": {
     "": {
       "name": "inpx-web",
       "name": "inpx-web",
-      "version": "1.1.0",
+      "version": "1.1.1",
       "hasInstallScript": true,
       "hasInstallScript": true,
       "license": "CC0-1.0",
       "license": "CC0-1.0",
       "dependencies": {
       "dependencies": {

+ 1 - 1
package.json

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

+ 1 - 1
server/core/RemoteLib.js

@@ -65,7 +65,7 @@ class RemoteLib {
 
 
             const buf = await this.down.load(`${this.remoteHost}${link}`, {decompress: false});
             const buf = await this.down.load(`${this.remoteHost}${link}`, {decompress: false});
 
 
-            const publicPath = `${this.config.publicDir}${link}`;
+            const publicPath = `${this.config.publicFilesDir}${link}`;
             
             
             await fs.writeFile(publicPath, buf);
             await fs.writeFile(publicPath, buf);
 
 

+ 11 - 8
server/core/WebWorker.js

@@ -370,12 +370,14 @@ class WebWorker {
         const bookFileDesc = `${bookFile}.json`;
         const bookFileDesc = `${bookFile}.json`;
 
 
         if (!await fs.pathExists(bookFile) || !await fs.pathExists(bookFileDesc)) {
         if (!await fs.pathExists(bookFile) || !await fs.pathExists(bookFileDesc)) {
-            await fs.ensureDir(path.dirname(bookFile));
-
-            const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
-            await utils.gzipFile(extractedFile, tmpFile, 4);
-            await fs.remove(extractedFile);
-            await fs.move(tmpFile, bookFile, {overwrite: true});
+            if (!await fs.pathExists(bookFile) && extractedFile) {
+                const tmpFile = `${this.config.tempDir}/${utils.randomHexString(30)}`;
+                await utils.gzipFile(extractedFile, tmpFile, 4);
+                await fs.remove(extractedFile);
+                await fs.move(tmpFile, bookFile, {overwrite: true});
+            } else {
+                await utils.touchFile(bookFile);
+            }
 
 
             await fs.writeFile(bookFileDesc, JSON.stringify({bookPath, downFileName}));
             await fs.writeFile(bookFileDesc, JSON.stringify({bookPath, downFileName}));
         } else {
         } else {
@@ -411,9 +413,10 @@ class WebWorker {
             const rows = await db.select({table: 'file_hash', where: `@@id(${db.esc(bookPath)})`});
             const rows = await db.select({table: 'file_hash', where: `@@id(${db.esc(bookPath)})`});
             if (rows.length) {//хеш найден по bookPath
             if (rows.length) {//хеш найден по bookPath
                 const hash = rows[0].hash;
                 const hash = rows[0].hash;
-                const bookFileDesc = `${this.config.filesDir}/${hash}.json`;
+                const bookFile = `${this.config.filesDir}/${hash}`;
+                const bookFileDesc = `${bookFile}.json`;
 
 
-                if (await fs.pathExists(bookFileDesc)) {
+                if (await fs.pathExists(bookFile) && await fs.pathExists(bookFileDesc)) {
                     link = `${this.config.filesPathStatic}/${hash}`;
                     link = `${this.config.filesPathStatic}/${hash}`;
                 }
                 }
             }
             }

+ 4 - 1
server/core/utils.js

@@ -105,7 +105,10 @@ function gzipFile(inputFile, outputFile, level = 1) {
         const input = fs.createReadStream(inputFile);
         const input = fs.createReadStream(inputFile);
         const output = fs.createWriteStream(outputFile);
         const output = fs.createWriteStream(outputFile);
 
 
-        input.pipe(gzip).pipe(output).on('finish', (err) => {
+        input.on('error', reject)
+            .pipe(gzip).on('error', reject)
+            .pipe(output).on('error', reject)
+            .on('finish', (err) => {
             if (err) reject(err);
             if (err) reject(err);
             else resolve();
             else resolve();
         });
         });