listpage-next 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -73,5 +73,35 @@ function setupClient(HttpClient) {
|
|
|
73
73
|
const client = this.client;
|
|
74
74
|
return client.delete(url, config);
|
|
75
75
|
};
|
|
76
|
+
HttpClient.prototype.download = async function(url, params, downloadOptions, config) {
|
|
77
|
+
let { filename, type } = downloadOptions || {};
|
|
78
|
+
const client = this.client;
|
|
79
|
+
const response = await client.post(url, params, {
|
|
80
|
+
...config,
|
|
81
|
+
headers: {
|
|
82
|
+
Accept: type,
|
|
83
|
+
...config?.headers
|
|
84
|
+
},
|
|
85
|
+
responseType: 'blob'
|
|
86
|
+
});
|
|
87
|
+
const blob = new Blob([
|
|
88
|
+
response.data
|
|
89
|
+
], {
|
|
90
|
+
type
|
|
91
|
+
});
|
|
92
|
+
const downloadUrl = window.URL.createObjectURL(blob);
|
|
93
|
+
const link = document.createElement('a');
|
|
94
|
+
link.href = downloadUrl;
|
|
95
|
+
const contentDisposition = response.headers['content-disposition'];
|
|
96
|
+
if (contentDisposition) {
|
|
97
|
+
const filenameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
|
|
98
|
+
if (filenameMatch && filenameMatch[1]) filename = decodeURIComponent(filenameMatch[1].replace(/['"]/g, ''));
|
|
99
|
+
}
|
|
100
|
+
link.download = filename;
|
|
101
|
+
document.body.appendChild(link);
|
|
102
|
+
link.click();
|
|
103
|
+
document.body.removeChild(link);
|
|
104
|
+
window.URL.revokeObjectURL(url);
|
|
105
|
+
};
|
|
76
106
|
}
|
|
77
107
|
export { setupClient };
|
|
@@ -15,4 +15,8 @@ export declare class HttpClient implements IHttpClient {
|
|
|
15
15
|
post<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<ApiResponse<T>>>;
|
|
16
16
|
patch<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<ApiResponse<T>>>;
|
|
17
17
|
delete<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<ApiResponse<T>>>;
|
|
18
|
+
download<D = any>(url: string, params?: D, downloadOptions?: {
|
|
19
|
+
filename?: string;
|
|
20
|
+
type?: string;
|
|
21
|
+
}, config?: AxiosRequestConfig<D>): Promise<void>;
|
|
18
22
|
}
|
|
@@ -48,5 +48,8 @@ class HttpClient {
|
|
|
48
48
|
delete(url, config) {
|
|
49
49
|
throw new Error('Method should be implemented by setupClient');
|
|
50
50
|
}
|
|
51
|
+
download(url, params, downloadOptions, config) {
|
|
52
|
+
throw new Error('Method should be implemented by setupClient');
|
|
53
|
+
}
|
|
51
54
|
}
|
|
52
55
|
export { HttpClient };
|
|
@@ -24,4 +24,8 @@ export interface IHttpClient {
|
|
|
24
24
|
post<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<ApiResponse<T>>>;
|
|
25
25
|
patch<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<ApiResponse<T>>>;
|
|
26
26
|
delete<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<AxiosResponse<ApiResponse<T>>>;
|
|
27
|
+
download<D = any>(url: string, params?: D, downloadOptions?: {
|
|
28
|
+
filename?: string;
|
|
29
|
+
type?: string;
|
|
30
|
+
}, config?: AxiosRequestConfig<D>): Promise<void>;
|
|
27
31
|
}
|