Skip to content

Commit 84312aa

Browse files
committed
Add csrf to newNote
1 parent 485ba88 commit 84312aa

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/api.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,26 @@ class API {
103103
}
104104

105105
async newNote(body: string) {
106-
const contentType = 'text/markdown;charset=UTF-8'
107-
const response = await this.fetch(`${this.serverUrl}/new`, {
108-
method: 'POST',
109-
body,
110-
headers: {
111-
'Content-Type': contentType
112-
}
113-
})
106+
let response
107+
if (this.enterprise) {
108+
response = await this.fetch(`${this.serverUrl}/new`, {
109+
method: 'POST',
110+
body: encodeFormComponent({content: body}),
111+
headers: await this.wrapHeaders({
112+
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
113+
})
114+
})
115+
} else {
116+
const contentType = 'text/markdown;charset=UTF-8'
117+
response = await this.fetch(`${this.serverUrl}/new`, {
118+
method: 'POST',
119+
body,
120+
headers: {
121+
'Content-Type': contentType
122+
}
123+
})
124+
}
125+
114126
if (response.status === 200) {
115127
return response.url
116128
} else {

0 commit comments

Comments
 (0)