Edited OfficeFolderAnchors to re-add filename

This commit is contained in:
Vins 2024-02-20 14:33:09 +01:00
parent 7cbfb1cff5
commit 6de6ed0bd5
2 changed files with 6 additions and 6 deletions

View File

@ -43,13 +43,13 @@ export default abstract class BaseApiService {
return JSON.stringify(body); return JSON.stringify(body);
} }
protected async getRequest<T>(url: URL, token?: string, contentType?: ContentType, ref?: IRef) { protected async getRequest<T>(url: URL, token?: string, contentType?: ContentType, ref?: IRef, fileName?: string) {
const request = async () => const request = async () =>
await fetch(url, { await fetch(url, {
method: "GET", method: "GET",
headers: this.buildHeaders(contentType ?? ContentType.JSON), headers: this.buildHeaders(contentType ?? ContentType.JSON),
}); });
return this.sendRequest<T>(request, ref); return this.sendRequest<T>(request, ref, fileName);
} }
protected async postRequest<T>(url: URL, body: { [key: string]: unknown } = {}, token?: string) { protected async postRequest<T>(url: URL, body: { [key: string]: unknown } = {}, token?: string) {
@ -118,13 +118,13 @@ export default abstract class BaseApiService {
return this.sendRequest<T>(request); return this.sendRequest<T>(request);
} }
private async sendRequest<T>(request: () => Promise<Response>, ref?: IRef): Promise<T> { private async sendRequest<T>(request: () => Promise<Response>, ref?: IRef, fileName?: string): Promise<T> {
const response = await request(); const response = await request();
return this.processResponse<T>(response, request, ref); return this.processResponse<T>(response, request, ref, fileName);
} }
protected async processResponse<T>(response: Response, request: () => Promise<Response>, ref?: IRef): Promise<T> { protected async processResponse<T>(response: Response, request: () => Promise<Response>, ref?: IRef, fileName?: string): Promise<T> {
let responseContent: T; let responseContent: T;
ref && (ref["response"] = response); ref && (ref["response"] = response);
if (response.ok) { if (response.ok) {

View File

@ -60,7 +60,7 @@ export default class OfficeFolderAnchors extends BaseNotary {
public async download(uid: string): Promise<any> { public async download(uid: string): Promise<any> {
const url = new URL(this.baseUrl.concat(`/download/${uid}`)); const url = new URL(this.baseUrl.concat(`/download/${uid}`));
try { try {
return await this.getRequest<any>(url, undefined, ContentType.PDF, `${uid}.pdf`); return await this.getRequest<any>(url, undefined, ContentType.PDF, undefined, `${uid}.pdf`);
} catch (err) { } catch (err) {
this.onError(err); this.onError(err);
return Promise.reject(err); return Promise.reject(err);