diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-24 22:08:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-24 22:08:33 +0200 |
commit | 390f39fd248efb969ebe082b0d3e4beff255cfdc (patch) | |
tree | 5ce5f611e2e20ca805d65e550633cc19f4571253 /src/api/server/ServerApi.js | |
parent | updates to nl-BE locale based on Woordenlijst and Van Dale (diff) | |
parent | Merge pull request #100 from meetfranz/feature/zoomin-alias (diff) | |
download | ferdium-app-390f39fd248efb969ebe082b0d3e4beff255cfdc.tar.gz ferdium-app-390f39fd248efb969ebe082b0d3e4beff255cfdc.tar.zst ferdium-app-390f39fd248efb969ebe082b0d3e4beff255cfdc.zip |
Merge branch 'develop' into master
Diffstat (limited to 'src/api/server/ServerApi.js')
-rw-r--r-- | src/api/server/ServerApi.js | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 86f4c99e7..8b0b7563c 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js | |||
@@ -1,6 +1,6 @@ | |||
1 | import os from 'os'; | 1 | import os from 'os'; |
2 | import path from 'path'; | 2 | import path from 'path'; |
3 | import targz from 'tar.gz'; | 3 | import tar from 'tar'; |
4 | import fs from 'fs-extra'; | 4 | import fs from 'fs-extra'; |
5 | import { remote } from 'electron'; | 5 | import { remote } from 'electron'; |
6 | 6 | ||
@@ -293,7 +293,11 @@ export default class ServerApi { | |||
293 | const buffer = await res.buffer(); | 293 | const buffer = await res.buffer(); |
294 | fs.writeFileSync(archivePath, buffer); | 294 | fs.writeFileSync(archivePath, buffer); |
295 | 295 | ||
296 | await targz().extract(archivePath, recipeTempDirectory); | 296 | tar.x({ |
297 | file: archivePath, | ||
298 | cwd: recipeTempDirectory, | ||
299 | sync: true, | ||
300 | }); | ||
297 | 301 | ||
298 | const { id } = fs.readJsonSync(path.join(recipeTempDirectory, 'package.json')); | 302 | const { id } = fs.readJsonSync(path.join(recipeTempDirectory, 'package.json')); |
299 | const recipeDirectory = path.join(recipesDirectory, id); | 303 | const recipeDirectory = path.join(recipesDirectory, id); |
@@ -443,6 +447,10 @@ export default class ServerApi { | |||
443 | 447 | ||
444 | // Helper | 448 | // Helper |
445 | async _mapServiceModels(services) { | 449 | async _mapServiceModels(services) { |
450 | const recipes = services.map(s => s.recipeId); | ||
451 | |||
452 | await this._bulkRecipeCheck(recipes); | ||
453 | |||
446 | return Promise.all(services | 454 | return Promise.all(services |
447 | .map(async service => await this._prepareServiceModel(service)) // eslint-disable-line | 455 | .map(async service => await this._prepareServiceModel(service)) // eslint-disable-line |
448 | ); | 456 | ); |
@@ -454,19 +462,8 @@ export default class ServerApi { | |||
454 | recipe = this.recipes.find(r => r.id === service.recipeId); | 462 | recipe = this.recipes.find(r => r.id === service.recipeId); |
455 | 463 | ||
456 | if (!recipe) { | 464 | if (!recipe) { |
457 | console.warn(`Recipe '${service.recipeId}' not installed, trying to fetch from server`); | 465 | console.warn(`Recipe ${service.recipeId} not loaded`); |
458 | 466 | return null; | |
459 | await this.getRecipePackage(service.recipeId); | ||
460 | |||
461 | console.debug('Rerun ServerAPI::getInstalledRecipes'); | ||
462 | await this.getInstalledRecipes(); | ||
463 | |||
464 | recipe = this.recipes.find(r => r.id === service.recipeId); | ||
465 | |||
466 | if (!recipe) { | ||
467 | console.warn(`Could not load recipe ${service.recipeId}`); | ||
468 | return null; | ||
469 | } | ||
470 | } | 467 | } |
471 | 468 | ||
472 | return new ServiceModel(service, recipe); | 469 | return new ServiceModel(service, recipe); |
@@ -476,6 +473,35 @@ export default class ServerApi { | |||
476 | } | 473 | } |
477 | } | 474 | } |
478 | 475 | ||
476 | async _bulkRecipeCheck(unfilteredRecipes) { | ||
477 | // Filter recipe duplicates as we don't need to download 3 Slack recipes | ||
478 | const recipes = unfilteredRecipes.filter((elem, pos, arr) => arr.indexOf(elem) === pos); | ||
479 | |||
480 | return Promise.all(recipes | ||
481 | .map(async (recipeId) => { | ||
482 | let recipe = this.recipes.find(r => r.id === recipeId); | ||
483 | |||
484 | if (!recipe) { | ||
485 | console.warn(`Recipe '${recipeId}' not installed, trying to fetch from server`); | ||
486 | |||
487 | await this.getRecipePackage(recipeId); | ||
488 | |||
489 | console.debug('Rerun ServerAPI::getInstalledRecipes'); | ||
490 | await this.getInstalledRecipes(); | ||
491 | |||
492 | recipe = this.recipes.find(r => r.id === recipeId); | ||
493 | |||
494 | if (!recipe) { | ||
495 | console.warn(`Could not load recipe ${recipeId}`); | ||
496 | return null; | ||
497 | } | ||
498 | } | ||
499 | |||
500 | return recipe; | ||
501 | }), | ||
502 | ).catch(err => console.error(err)); | ||
503 | } | ||
504 | |||
479 | _mapRecipePreviewModel(recipes) { | 505 | _mapRecipePreviewModel(recipes) { |
480 | return recipes.map((recipe) => { | 506 | return recipes.map((recipe) => { |
481 | try { | 507 | try { |