| 
									
										
										
										
											2021-10-23 16:42:20 -08:00
										 |  |  | import { BaseAPI } from "../_base"; | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const prefix = "/api"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-16 03:38:11 +01:00
										 |  |  | interface DownloadData { | 
					
						
							|  |  |  |   fileToken: string, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  | export class UtilsAPI extends BaseAPI { | 
					
						
							|  |  |  |   async download(url: string) { | 
					
						
							| 
									
										
										
										
											2022-01-16 03:38:11 +01:00
										 |  |  |     const { response } = await this.requests.get<DownloadData>(url); | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!response) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     const token: string = response.data.fileToken; | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const tokenURL = prefix + "/utils/download?token=" + token; | 
					
						
							|  |  |  |     window.open(tokenURL, "_blank"); | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     return response; | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } |