-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlUtils.js
48 lines (40 loc) · 1.46 KB
/
urlUtils.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
const url = require('url')
const URL_TO_SIGNIN_PAGE = url.format({protocol: 'https:', hostname: 'www.riminder.net', pathname: 'signin/team/'})
// const REGEXP_INTERNAL_LINK = new RegExp(url.format({protocol: 'https:', hostname: 'www.riminder.net'}))
const REGEXP_INTERNAL_LINK = new RegExp(/http[s]{0,1}:\/\/.+\.riminder\.net\/.*/)
const REGEXP_IS_PDF_LINK = new RegExp(/.+pdf$/)
// RiminderUrlUtils gathers url related function
class RiminderUrlUtils {
static isExternalUrl (url) {
return (!REGEXP_INTERNAL_LINK.test(url))
}
// getDirectLoginUrl create an url to user's dashboard for autologin
// it's need the user's team (the url is {user's team}.riminder.net/dashboard)
static genDirectLoginUrl (team) {
let _hostname = team + '.riminder.net'
let res = url.format({
protocol: 'https:',
hostname: _hostname,
pathname: 'dashboard'
})
return res
}
// return url to sigin page if team is undefined
// because a team is needed to generate an url to dashboard
static selectSigninUrl (team = undefined) {
let url = URL_TO_SIGNIN_PAGE
if (team !== undefined) {
url = this.genDirectLoginUrl(team)
}
return url
}
static genPdfViewerUrlSrc (url) {
let baseUrl = 'https://mozilla.github.io/pdf.js/web/viewer.html?file='
return baseUrl + encodeURIComponent(url)
}
static isPdfLink (link) {
let pdfregex = REGEXP_IS_PDF_LINK
return pdfregex.test(link)
}
}
module.exports = RiminderUrlUtils