-
Notifications
You must be signed in to change notification settings - Fork 7
/
util.js
33 lines (28 loc) · 1000 Bytes
/
util.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
const URL = require('url').URL;
const webhookBotErrorMessage = 'This API is not available to incoming webhook bots.';
const sanitizeZulipURL = (domain) => {
if (!domain.match(/^[a-zA-Z]+:\/\//))
{
domain = 'https://' + domain;
}
const parsed_url = new URL(domain);
return parsed_url.origin;
};
const constructStreamMessageURL = (data) => {
let stream_info = data.stream;
if (!isNaN(parseInt(stream_info, 10))) {
stream_info = stream_info + '-';
}
const url = `${data.realm}/#narrow/stream/${stream_info}/topic/${data.topic}/near/${data.id}`;
return encodeURI(url);
};
const constructPrivateMessageURL = (data) => {
const url = `${data.realm}/#narrow/id/${data.id}`;
return encodeURI(url);
};
module.exports = {
'sanitizeZulipURL': sanitizeZulipURL,
'webhookBotErrorMessage': webhookBotErrorMessage,
'constructStreamMessageURL': constructStreamMessageURL,
'constructPrivateMessageURL': constructPrivateMessageURL
};