fix(core): update
This commit is contained in:
		
							
								
								
									
										25
									
								
								ts/index.ts
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								ts/index.ts
									
									
									
									
									
								
							| @@ -1,16 +1,22 @@ | ||||
| import * as plugins from './webrequest.plugins'; | ||||
| import * as plugins from './webrequest.plugins.js'; | ||||
|  | ||||
| /** | ||||
|  * web request | ||||
|  */ | ||||
| export class WebRequest { | ||||
|   private static polyfillsLoaded = false; | ||||
|   public static loadNeededPolyfills() { | ||||
|     const smartenv = new plugins.smartenv.Smartenv(); | ||||
|     if (!smartenv.isBrowser && !this.polyfillsLoaded) { | ||||
|       this.polyfillsLoaded = true; | ||||
|       globalThis.fetch = smartenv.getSafeNodeModule('node-fetch'); | ||||
|   private static polyfillStatusEvaluated = false; | ||||
|   private static neededPolyfillsLoadedDeferred = plugins.smartpromise.defer(); | ||||
|   public static async loadNeededPolyfills() { | ||||
|     if (this.polyfillStatusEvaluated) { | ||||
|       return this.neededPolyfillsLoadedDeferred.promise; | ||||
|     } | ||||
|     this.polyfillStatusEvaluated = true; | ||||
|     const smartenv = new plugins.smartenv.Smartenv(); | ||||
|     if (!smartenv.isBrowser) { | ||||
|       this.polyfillStatusEvaluated = true; | ||||
|       await smartenv.getSafeNodeModule('node-fetch'); | ||||
|     } | ||||
|     this.neededPolyfillsLoadedDeferred.resolve(); | ||||
|   } | ||||
|  | ||||
|   constructor() { | ||||
| @@ -18,6 +24,7 @@ export class WebRequest { | ||||
|   } | ||||
|  | ||||
|   public async getJson(urlArg: string | string[]) { | ||||
|     await WebRequest.neededPolyfillsLoadedDeferred.promise; | ||||
|     const response: Response = await this.request(urlArg, { | ||||
|       method: 'GET', | ||||
|     }); | ||||
| @@ -30,6 +37,7 @@ export class WebRequest { | ||||
|    * postJson | ||||
|    */ | ||||
|   public async postJson(urlArg: string, requestBody?: any) { | ||||
|     await WebRequest.neededPolyfillsLoadedDeferred.promise; | ||||
|     const response: Response = await this.request(urlArg, { | ||||
|       body: plugins.smartjson.stringify(requestBody), | ||||
|       method: 'POST', | ||||
| @@ -43,6 +51,7 @@ export class WebRequest { | ||||
|    * put js | ||||
|    */ | ||||
|   public async putJson(urlArg: string, requestBody?: any) { | ||||
|     await WebRequest.neededPolyfillsLoadedDeferred.promise; | ||||
|     const response: Response = await this.request(urlArg, { | ||||
|       body: plugins.smartjson.stringify(requestBody), | ||||
|       method: 'PUT', | ||||
| @@ -56,6 +65,7 @@ export class WebRequest { | ||||
|    * put js | ||||
|    */ | ||||
|   public async deleteJson(urlArg: string) { | ||||
|     await WebRequest.neededPolyfillsLoadedDeferred.promise; | ||||
|     const response: Response = await this.request(urlArg, { | ||||
|       method: 'GET', | ||||
|     }); | ||||
| @@ -75,6 +85,7 @@ export class WebRequest { | ||||
|       headers?: HeadersInit; | ||||
|     } | ||||
|   ): Promise<Response> { | ||||
|     await WebRequest.neededPolyfillsLoadedDeferred.promise; | ||||
|     let allUrls: string[]; | ||||
|     let usedUrlIndex = 0; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user