@@ -69,12 +69,12 @@ class API {
69
69
const fetch : nodeFetchType = require ( 'fetch-cookie' ) ( nodeFetch , new tough . CookieJar ( jar as any ) )
70
70
71
71
this . _fetch = fetch
72
- this . serverUrl = serverUrl
72
+ this . serverUrl = url . parse ( serverUrl ) . href
73
73
this . enterprise = enterprise
74
74
}
75
75
76
76
async login ( email : string , password : string ) {
77
- await this . fetch ( ` ${ this . serverUrl } / login` , {
77
+ await this . fetch ( url . resolve ( this . serverUrl , ' login' ) , {
78
78
method : 'post' ,
79
79
body : encodeFormComponent ( { email, password} ) ,
80
80
headers : await this . wrapHeaders ( {
@@ -84,7 +84,7 @@ class API {
84
84
}
85
85
86
86
async loginLdap ( username : string , password : string ) {
87
- await this . fetch ( ` ${ this . serverUrl } / auth/ldap` , {
87
+ await this . fetch ( url . resolve ( this . serverUrl , ' auth/ldap' ) , {
88
88
method : 'post' ,
89
89
body : encodeFormComponent ( { username, password} ) ,
90
90
headers : await this . wrapHeaders ( {
@@ -94,7 +94,7 @@ class API {
94
94
}
95
95
96
96
async logout ( ) {
97
- const response = await this . fetch ( ` ${ this . serverUrl } / logout` , {
97
+ const response = await this . fetch ( url . resolve ( this . serverUrl , ' logout' ) , {
98
98
method : this . enterprise ? 'POST' : 'GET' ,
99
99
headers : await this . wrapHeaders ( {
100
100
'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8' ,
@@ -113,12 +113,12 @@ class API {
113
113
}
114
114
115
115
async getMe ( ) {
116
- const response = await this . fetch ( ` ${ this . serverUrl } /me` , this . defaultFetchOptions )
116
+ const response = await this . fetch ( url . resolve ( this . serverUrl , 'me' ) , this . defaultFetchOptions )
117
117
return response . json ( )
118
118
}
119
119
120
120
async getHistory ( ) : Promise < { history : HistoryItem [ ] } > {
121
- const response = await this . fetch ( ` ${ this . serverUrl } / history` , this . defaultFetchOptions )
121
+ const response = await this . fetch ( url . resolve ( this . serverUrl , ' history' ) , this . defaultFetchOptions )
122
122
return response . json ( )
123
123
}
124
124
@@ -127,9 +127,9 @@ class API {
127
127
if ( this . enterprise ) {
128
128
let newNoteUrl
129
129
if ( options ?. team ) {
130
- newNoteUrl = ` ${ this . serverUrl } / team/${ options . team } /new`
130
+ newNoteUrl = url . resolve ( this . serverUrl , ` team/${ options . team } /new`)
131
131
} else {
132
- newNoteUrl = ` ${ this . serverUrl } / new`
132
+ newNoteUrl = url . resolve ( this . serverUrl , ' new' )
133
133
}
134
134
135
135
response = await this . fetch ( newNoteUrl , {
@@ -141,7 +141,7 @@ class API {
141
141
} )
142
142
} else {
143
143
const contentType = 'text/markdown;charset=UTF-8'
144
- response = await this . fetch ( ` ${ this . serverUrl } / new` , {
144
+ response = await this . fetch ( url . resolve ( this . serverUrl , ' new' ) , {
145
145
method : 'POST' ,
146
146
body,
147
147
headers : await this . wrapHeaders ( {
@@ -161,17 +161,17 @@ class API {
161
161
let res : Response
162
162
switch ( type ) {
163
163
case ExportType . PDF :
164
- res = await this . fetch ( ` ${ this . serverUrl } / ${ noteId } /pdf`, this . defaultFetchOptions )
164
+ res = await this . fetch ( url . resolve ( this . serverUrl , ` ${ noteId } /pdf`) , this . defaultFetchOptions )
165
165
break
166
166
case ExportType . HTML :
167
- res = await this . fetch ( ` ${ this . serverUrl } / s/${ noteId } `, this . defaultFetchOptions )
167
+ res = await this . fetch ( url . resolve ( this . serverUrl , ` s/${ noteId } `) , this . defaultFetchOptions )
168
168
break
169
169
case ExportType . SLIDE :
170
- res = await this . fetch ( ` ${ this . serverUrl } / ${ noteId } /slide`, this . defaultFetchOptions )
170
+ res = await this . fetch ( url . resolve ( this . serverUrl , ` ${ noteId } /slide`) , this . defaultFetchOptions )
171
171
break
172
172
case ExportType . MD :
173
173
default :
174
- res = await this . fetch ( ` ${ this . serverUrl } / ${ noteId } /download`, this . defaultFetchOptions )
174
+ res = await this . fetch ( url . resolve ( this . serverUrl , ` ${ noteId } /download`) , this . defaultFetchOptions )
175
175
}
176
176
177
177
return res
@@ -233,7 +233,7 @@ class API {
233
233
}
234
234
235
235
private async loadCSRFToken ( ) {
236
- const html = await this . fetch ( ` ${ this . serverUrl } ` ) . then ( r => r . text ( ) )
236
+ const html = await this . fetch ( this . serverUrl ) . then ( r => r . text ( ) )
237
237
const $ = cheerio . load ( html )
238
238
239
239
return $ ( 'meta[name="csrf-token"]' ) . attr ( 'content' ) || ''
0 commit comments