mirror of
https://github.com/timvisee/send.git
synced 2025-10-04 10:09:17 +02:00
added hmac auth to report route
This commit is contained in:
parent
2f6119e2f1
commit
d9cbe058ab
7 changed files with 39 additions and 50 deletions
19
app/api.js
19
app/api.js
|
@ -61,7 +61,10 @@ async function fetchWithAuth(url, params, keychain) {
|
|||
const result = {};
|
||||
params = params || {};
|
||||
const h = await keychain.authHeader();
|
||||
params.headers = new Headers({ Authorization: h });
|
||||
params.headers = new Headers({
|
||||
Authorization: h,
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
const response = await fetch(url, params);
|
||||
result.response = response;
|
||||
result.ok = response.ok;
|
||||
|
@ -439,15 +442,19 @@ export async function getConstants() {
|
|||
throw new Error(response.status);
|
||||
}
|
||||
|
||||
export async function reportLink(id, key, reason) {
|
||||
const response = await fetch(
|
||||
export async function reportLink(id, keychain, reason) {
|
||||
const result = await fetchWithAuthAndRetry(
|
||||
getApiUrl(`/api/report/${id}`),
|
||||
post({ key, reason })
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ reason })
|
||||
},
|
||||
keychain
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
if (result.ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error(response.status);
|
||||
throw new Error(result.response.status);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue