| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { BaseAPI } from "../base/base-clients"; | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | import type { FileTokenResponse } from "~/lib/api/types/response"; | 
					
						
							| 
									
										
										
										
											2021-08-21 00:46:43 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const prefix = "/api"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export class UtilsAPI extends BaseAPI { | 
					
						
							|  |  |  |   async download(url: string) { | 
					
						
							| 
									
										
										
										
											2022-05-21 21:22:02 +02:00
										 |  |  |     const { response } = await this.requests.get<FileTokenResponse>(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
										 |  |  |   } | 
					
						
							|  |  |  | } |