Add Send-Id header for access requests (#400)

* Add Send-Id header to postSendAccess request

* Add Send Id header to file access requests

* fix linting
This commit is contained in:
Thomas Rittson 2021-06-07 18:50:35 -07:00 committed by GitHub
parent ff387622e0
commit 2e16aef6a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -428,13 +428,19 @@ export class ApiService implements ApiServiceAbstraction {
}
async postSendAccess(id: string, request: SendAccessRequest, apiUrl?: string): Promise<SendAccessResponse> {
const r = await this.send('POST', '/sends/access/' + id, request, false, true, apiUrl);
const addSendIdHeader = (headers: Headers) => {
headers.set('Send-Id', id);
};
const r = await this.send('POST', '/sends/access/' + id, request, false, true, apiUrl, addSendIdHeader);
return new SendAccessResponse(r);
}
async getSendFileDownloadData(send: SendAccessView, request: SendAccessRequest, apiUrl?: string): Promise<SendFileDownloadDataResponse> {
const r = await this.send('POST', '/sends/' + send.id + '/access/file/' + send.file.id, request, false, true, apiUrl);
const addSendIdHeader = (headers: Headers) => {
headers.set('Send-Id', send.id);
};
const r = await this.send('POST', '/sends/' + send.id + '/access/file/' + send.file.id, request, false, true,
apiUrl, addSendIdHeader);
return new SendFileDownloadDataResponse(r);
}
@ -1353,7 +1359,8 @@ export class ApiService implements ApiServiceAbstraction {
}
private async send(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body: any,
authed: boolean, hasResponse: boolean, apiUrl?: string): Promise<any> {
authed: boolean, hasResponse: boolean, apiUrl?: string,
alterHeaders?: (headers: Headers) => void): Promise<any> {
apiUrl = Utils.isNullOrWhitespace(apiUrl) ? this.apiBaseUrl : apiUrl;
const headers = new Headers({
'Device-Type': this.deviceType,
@ -1388,6 +1395,9 @@ export class ApiService implements ApiServiceAbstraction {
if (hasResponse) {
headers.set('Accept', 'application/json');
}
if (alterHeaders != null) {
alterHeaders(headers);
}
requestInit.headers = headers;
const response = await this.fetch(new Request(apiUrl + path, requestInit));