aboutsummaryrefslogtreecommitdiffstats
path: root/src/models/Recipe.ts
diff options
context:
space:
mode:
authorLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-08-17 05:07:38 +0530
committerLibravatar GitHub <noreply@github.com>2021-08-17 05:07:38 +0530
commit0fbee32c27a6efdfe88534303922d189ddbba817 (patch)
tree2b9dddba64ff1519e293c64b3b42b4d9172ec4d3 /src/models/Recipe.ts
parentRevert "chore: update outdated node_modules (#1807)" (diff)
downloadferdium-app-0fbee32c27a6efdfe88534303922d189ddbba817.tar.gz
ferdium-app-0fbee32c27a6efdfe88534303922d189ddbba817.tar.zst
ferdium-app-0fbee32c27a6efdfe88534303922d189ddbba817.zip
Typescript conversion (#1805)
Diffstat (limited to 'src/models/Recipe.ts')
-rw-r--r--src/models/Recipe.ts122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/models/Recipe.ts b/src/models/Recipe.ts
new file mode 100644
index 000000000..33d383983
--- /dev/null
+++ b/src/models/Recipe.ts
@@ -0,0 +1,122 @@
1import semver from 'semver';
2import { pathExistsSync } from 'fs-extra';
3import { join } from 'path';
4
5interface IRecipe {
6 id: string;
7 name: string;
8 version: string;
9 aliases?: string[];
10 path: string;
11 config: {
12 serviceURL?: string;
13 hasDirectMessages?: boolean;
14 hasIndirectMessages?: boolean;
15 hasNotificationSound?: boolean;
16 hasTeamId?: boolean;
17 hasCustomUrl?: boolean;
18 hasHostedOption?: boolean;
19 urlInputPrefix?: string;
20 urlInputSuffix?: string;
21 disablewebsecurity?: boolean;
22 autoHibernate?: boolean;
23 partition?: string;
24 message?: string;
25 };
26}
27
28export default class Recipe {
29 // Note: Do NOT change these default values. If they change, then the corresponding changes in the recipes needs to be done
30 id: string = '';
31
32 name: string = '';
33
34 description = '';
35
36 version: string = '';
37
38 aliases: string[] = [];
39
40 path: string = '';
41
42 serviceURL: string = '';
43
44 hasDirectMessages: boolean = true;
45
46 hasIndirectMessages: boolean = false;
47
48 hasNotificationSound: boolean = false;
49
50 hasTeamId: boolean = false;
51
52 hasCustomUrl: boolean = false;
53
54 hasHostedOption: boolean = false;
55
56 urlInputPrefix: string = '';
57
58 urlInputSuffix: string = '';
59
60 message: string = '';
61
62 disablewebsecurity: boolean = false;
63
64 autoHibernate: boolean = false;
65
66 partition: string = '';
67
68 // TODO: Need to reconcile which of these are optional/mandatory
69 constructor(data: IRecipe) {
70 if (!data) {
71 throw Error('Recipe config not valid');
72 }
73
74 if (!data.id) {
75 // Ferdi 4 recipes do not have an Id
76 throw Error(`Recipe '${data.name}' requires Id`);
77 }
78
79 try {
80 if (!semver.valid(data.version)) {
81 throw Error(`Version ${data.version} of recipe '${data.name}' is not a valid semver version`);
82 }
83 } catch (e) {
84 console.warn(e.message);
85 }
86
87 this.id = data.id || this.id;
88 this.name = data.name || this.name;
89 this.version = data.version || this.version;
90 this.aliases = data.aliases || this.aliases;
91 this.path = data.path;
92
93 this.serviceURL = data.config.serviceURL || this.serviceURL;
94
95 this.hasDirectMessages = data.config.hasDirectMessages || this.hasDirectMessages;
96 this.hasIndirectMessages = data.config.hasIndirectMessages || this.hasIndirectMessages;
97 this.hasNotificationSound = data.config.hasNotificationSound || this.hasNotificationSound;
98 this.hasTeamId = data.config.hasTeamId || this.hasTeamId;
99 this.hasCustomUrl = data.config.hasCustomUrl || this.hasCustomUrl;
100 this.hasHostedOption = data.config.hasHostedOption || this.hasHostedOption;
101
102 this.urlInputPrefix = data.config.urlInputPrefix || this.urlInputPrefix;
103 this.urlInputSuffix = data.config.urlInputSuffix || this.urlInputSuffix;
104
105 this.disablewebsecurity = data.config.disablewebsecurity || this.disablewebsecurity;
106
107 this.autoHibernate = data.config.autoHibernate || this.autoHibernate;
108
109 this.partition = data.config.partition || this.partition;
110
111 this.message = data.config.message || this.message;
112 }
113
114 // TODO: Need to remove this if its not used anywhere
115 get author(): string[] {
116 return [];
117 }
118
119 get hasDarkMode(): boolean {
120 return pathExistsSync(join(this.path, 'darkmode.css'));
121 }
122}