diff options
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/server/ServerApi.ts | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/api/server/ServerApi.ts b/src/api/server/ServerApi.ts index 860b7b76e..de8e0a85c 100644 --- a/src/api/server/ServerApi.ts +++ b/src/api/server/ServerApi.ts | |||
@@ -15,8 +15,8 @@ import { | |||
15 | } from 'fs-extra'; | 15 | } from 'fs-extra'; |
16 | 16 | ||
17 | import ServiceModel from '../../models/Service'; | 17 | import ServiceModel from '../../models/Service'; |
18 | import RecipePreviewModel from '../../models/RecipePreview'; | 18 | import RecipePreviewModel, { IRecipePreview } from '../../models/RecipePreview'; |
19 | import RecipeModel from '../../models/Recipe'; | 19 | import RecipeModel, { IRecipe } from '../../models/Recipe'; |
20 | import UserModel from '../../models/User'; | 20 | import UserModel from '../../models/User'; |
21 | 21 | ||
22 | import sleep from '../../helpers/async-helpers'; | 22 | import sleep from '../../helpers/async-helpers'; |
@@ -44,9 +44,9 @@ const debug = require('../../preload-safe-debug')('Ferdium:ServerApi'); | |||
44 | module.paths.unshift(getDevRecipeDirectory(), getRecipeDirectory()); | 44 | module.paths.unshift(getDevRecipeDirectory(), getRecipeDirectory()); |
45 | 45 | ||
46 | export default class ServerApi { | 46 | export default class ServerApi { |
47 | recipePreviews: any[] = []; | 47 | recipePreviews: IRecipePreview[] = []; |
48 | 48 | ||
49 | recipes: any[] = []; | 49 | recipes: IRecipe[] = []; |
50 | 50 | ||
51 | // User | 51 | // User |
52 | async login(email: string, passwordHash: string) { | 52 | async login(email: string, passwordHash: string) { |
@@ -55,7 +55,9 @@ export default class ServerApi { | |||
55 | { | 55 | { |
56 | method: 'POST', | 56 | method: 'POST', |
57 | headers: { | 57 | headers: { |
58 | Authorization: `Basic ${window.btoa(`${email}:${passwordHash}`)}`, | 58 | Authorization: `Basic ${Buffer.from( |
59 | `${email}:${passwordHash}`, | ||
60 | ).toString('base64')}`, | ||
59 | }, | 61 | }, |
60 | }, | 62 | }, |
61 | false, | 63 | false, |
@@ -346,6 +348,7 @@ export default class ServerApi { | |||
346 | }) | 348 | }) |
347 | .filter(recipe => recipe.id); | 349 | .filter(recipe => recipe.id); |
348 | 350 | ||
351 | // @ts-expect-error Type 'boolean' is not assignable to type 'ConcatArray<IRecipe>'. | ||
349 | // eslint-disable-next-line unicorn/prefer-spread | 352 | // eslint-disable-next-line unicorn/prefer-spread |
350 | this.recipes = this.recipes.concat(this._getDevRecipes()); | 353 | this.recipes = this.recipes.concat(this._getDevRecipes()); |
351 | 354 | ||
@@ -515,9 +518,8 @@ export default class ServerApi { | |||
515 | } | 518 | } |
516 | 519 | ||
517 | async _prepareServiceModel(service: { recipeId: string }) { | 520 | async _prepareServiceModel(service: { recipeId: string }) { |
518 | let recipe: undefined; | ||
519 | try { | 521 | try { |
520 | recipe = this.recipes.find(r => r.id === service.recipeId); | 522 | const recipe = this.recipes.find(r => r.id === service.recipeId); |
521 | 523 | ||
522 | if (!recipe) { | 524 | if (!recipe) { |
523 | console.warn(`Recipe ${service.recipeId} not loaded`); | 525 | console.warn(`Recipe ${service.recipeId} not loaded`); |
@@ -531,11 +533,10 @@ export default class ServerApi { | |||
531 | } | 533 | } |
532 | } | 534 | } |
533 | 535 | ||
534 | async _bulkRecipeCheck(unfilteredRecipes: any[]) { | 536 | async _bulkRecipeCheck(unfilteredRecipes: string[]) { |
535 | // Filter recipe duplicates as we don't need to download 3 Slack recipes | 537 | // Filter recipe duplicates as we don't need to download 3 Slack recipes |
536 | const recipes = unfilteredRecipes.filter( | 538 | const recipes = unfilteredRecipes.filter( |
537 | (elem: any, pos: number, arr: string | any[]) => | 539 | (elem: string, pos: number, arr: string[]) => arr.indexOf(elem) === pos, |
538 | arr.indexOf(elem) === pos, | ||
539 | ); | 540 | ); |
540 | 541 | ||
541 | return Promise.all( | 542 | return Promise.all( |
@@ -565,7 +566,7 @@ export default class ServerApi { | |||
565 | ).catch(error => console.error("Can't load recipe", error)); | 566 | ).catch(error => console.error("Can't load recipe", error)); |
566 | } | 567 | } |
567 | 568 | ||
568 | _mapRecipePreviewModel(recipes: any[]) { | 569 | _mapRecipePreviewModel(recipes: IRecipePreview[]) { |
569 | return recipes | 570 | return recipes |
570 | .map(recipe => { | 571 | .map(recipe => { |
571 | try { | 572 | try { |
@@ -575,7 +576,7 @@ export default class ServerApi { | |||
575 | return null; | 576 | return null; |
576 | } | 577 | } |
577 | }) | 578 | }) |
578 | .filter(recipe => recipe !== null); | 579 | .filter(Boolean); |
579 | } | 580 | } |
580 | 581 | ||
581 | _getDevRecipes() { | 582 | _getDevRecipes() { |
@@ -589,15 +590,14 @@ export default class ServerApi { | |||
589 | 590 | ||
590 | const recipes = paths | 591 | const recipes = paths |
591 | .map(id => { | 592 | .map(id => { |
592 | let Recipe; | ||
593 | try { | 593 | try { |
594 | // eslint-disable-next-line import/no-dynamic-require | 594 | // eslint-disable-next-line import/no-dynamic-require |
595 | Recipe = require(id)(RecipeModel); | 595 | const Recipe = require(id)(RecipeModel); |
596 | |||
596 | return new Recipe(loadRecipeConfig(id)); | 597 | return new Recipe(loadRecipeConfig(id)); |
597 | } catch (error) { | 598 | } catch (error) { |
598 | console.error(error); | 599 | console.error(error); |
599 | } | 600 | } |
600 | |||
601 | return false; | 601 | return false; |
602 | }) | 602 | }) |
603 | .filter(recipe => recipe.id) | 603 | .filter(recipe => recipe.id) |