aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/server/ServerApi.ts
diff options
context:
space:
mode:
authorLibravatar MCMXC <16797721+mcmxcdev@users.noreply.github.com>2023-07-29 21:12:16 -0600
committerLibravatar GitHub <noreply@github.com>2023-07-30 08:42:16 +0530
commit32f76b74a69ad4d60a014bf075c39517888436bc (patch)
tree753378cc30f52d1e0e51be64b5a83d39f08f39c8 /src/api/server/ServerApi.ts
parent6.4.1-nightly.15 [skip ci] (diff)
downloadferdium-app-32f76b74a69ad4d60a014bf075c39517888436bc.tar.gz
ferdium-app-32f76b74a69ad4d60a014bf075c39517888436bc.tar.zst
ferdium-app-32f76b74a69ad4d60a014bf075c39517888436bc.zip
refactor: various improvements (#1296)
* refactor: various improvements - enable no-use-before-define eslint rule - shuffle code to conform to no-use-before-define eslint rule - remove btoa dependency which is deprecated and replace with Buffer.from(string).toString('base64') - convert some any types into useful ones - add type annotations where possible - remove unused @types/expect.js - install @types/semver and ts-node which were missing - repair and rewrite add-crowdin-contributors script - remove export keyword from variables which are never consumed in another file - remove unity indicator hack where linked issue was closed - remove module declaration for kebab-case which is unused - add missing state interface for certain components - remove default exports for files which already have a named export - export IRecipePreview so it can be used throughout codebase - remove unused removeCacheForCallWith method from CachedRequest.ts - cleanup unused colors and styles inside legacy theme * - improve ColorPickerInput - fix invalid DOM nesting with div inside p in EditSettingsForm - fix progressbarAccentColor color picker not updating input when using slider - install missing @types/react-color dependency
Diffstat (limited to 'src/api/server/ServerApi.ts')
-rw-r--r--src/api/server/ServerApi.ts30
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
17import ServiceModel from '../../models/Service'; 17import ServiceModel from '../../models/Service';
18import RecipePreviewModel from '../../models/RecipePreview'; 18import RecipePreviewModel, { IRecipePreview } from '../../models/RecipePreview';
19import RecipeModel from '../../models/Recipe'; 19import RecipeModel, { IRecipe } from '../../models/Recipe';
20import UserModel from '../../models/User'; 20import UserModel from '../../models/User';
21 21
22import sleep from '../../helpers/async-helpers'; 22import sleep from '../../helpers/async-helpers';
@@ -44,9 +44,9 @@ const debug = require('../../preload-safe-debug')('Ferdium:ServerApi');
44module.paths.unshift(getDevRecipeDirectory(), getRecipeDirectory()); 44module.paths.unshift(getDevRecipeDirectory(), getRecipeDirectory());
45 45
46export default class ServerApi { 46export 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)