-
Notifications
You must be signed in to change notification settings - Fork 578
/
Copy pathRecipe.js
111 lines (77 loc) · 2.79 KB
/
Recipe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import emailParser from 'address-rfc2822';
import semver from 'semver';
import fs from 'fs-extra';
import path from 'path';
import userAgent from '../helpers/userAgent-helpers';
export default class Recipe {
id = '';
name = '';
description = '';
version = '';
path = '';
serviceURL = '';
hasDirectMessages = true;
hasIndirectMessages = false;
hasNotificationSound = false;
hasTeamId = false;
hasPredefinedUrl = false;
hasCustomUrl = false;
hasHostedOption = false;
urlInputPrefix = '';
urlInputSuffix = '';
message = '';
disablewebsecurity = false;
autoHibernate = false;
partition = '';
constructor(data) {
if (!data) {
throw Error('Recipe config not valid');
}
if (!data.id) {
// Franz 4 recipes do not have an Id
throw Error(`Recipe '${data.name}' requires Id`);
}
try {
if (!semver.valid(data.version)) {
throw Error(`Version ${data.version} of recipe '${data.name}' is not a valid semver version`);
}
} catch (e) {
console.warn(e.message);
}
this.id = data.id || this.id;
this.name = data.name || this.name;
this.rawAuthor = data.author || this.author;
this.description = data.description || this.description;
this.version = data.version || this.version;
this.path = data.path;
this.serviceURL = data.config.serviceURL || this.serviceURL;
this.hasDirectMessages = data.config.hasDirectMessages || this.hasDirectMessages;
this.hasIndirectMessages = data.config.hasIndirectMessages || this.hasIndirectMessages;
this.hasNotificationSound = data.config.hasNotificationSound || this.hasNotificationSound;
this.hasTeamId = data.config.hasTeamId || this.hasTeamId;
this.hasPredefinedUrl = data.config.hasPredefinedUrl || this.hasPredefinedUrl;
this.hasCustomUrl = data.config.hasCustomUrl || this.hasCustomUrl;
this.hasHostedOption = data.config.hasHostedOption || this.hasHostedOption;
this.urlInputPrefix = data.config.urlInputPrefix || this.urlInputPrefix;
this.urlInputSuffix = data.config.urlInputSuffix || this.urlInputSuffix;
this.disablewebsecurity = data.config.disablewebsecurity || this.disablewebsecurity;
this.autoHibernate = data.config.autoHibernate || this.autoHibernate;
this.partition = data.config.partition || this.partition;
this.message = data.config.message || this.message;
}
get author() {
try {
const addresses = emailParser.parse(this.rawAuthor);
return addresses.map(a => ({ email: a.address, name: a.phrase }));
} catch (err) {
console.warn(`Not a valid author for ${this.name}`);
}
return [];
}
get hasDarkMode() {
return fs.pathExistsSync(path.join(this.path, 'darkmode.css'));
}
mockUserAgent(chromless = false) {
return userAgent(chromless);
}
}