fix(core): update
This commit is contained in:
		
							
								
								
									
										24
									
								
								ts/index.ts
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								ts/index.ts
									
									
									
									
									
								
							| @@ -1,5 +1,9 @@ | ||||
| import * as plugins from './webrequest.plugins.js'; | ||||
|  | ||||
| export interface IWebrequestContructorOptions { | ||||
|   logging?: boolean; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * web request | ||||
|  */ | ||||
| @@ -26,7 +30,13 @@ export class WebRequest { | ||||
|     storeName: 'webrequest', | ||||
|   }); | ||||
|  | ||||
|   constructor() { | ||||
|   public options: IWebrequestContructorOptions; | ||||
|  | ||||
|   constructor(public optionsArg: IWebrequestContructorOptions = {}) { | ||||
|     this.options = { | ||||
|       logging: true, | ||||
|       ...optionsArg | ||||
|     } | ||||
|     WebRequest.loadNeededPolyfills(); | ||||
|   } | ||||
|  | ||||
| @@ -133,7 +143,7 @@ export class WebRequest { | ||||
|       const buffer = await response.clone().arrayBuffer(); | ||||
|       await this.cacheStore.set(urlArg, buffer); | ||||
|     } | ||||
|     console.log(`${urlArg} answers with status: ${response.status}`); | ||||
|     this.log(`${urlArg} answers with status: ${response.status}`); | ||||
|     return response; | ||||
|   } | ||||
|  | ||||
| @@ -185,7 +195,7 @@ export class WebRequest { | ||||
|       if (!urlToUse) { | ||||
|         throw new Error('request failed permanently'); | ||||
|       } | ||||
|       console.log(`Getting ${urlToUse} with method ${optionsArg.method}`); | ||||
|       this.log(`Getting ${urlToUse} with method ${optionsArg.method}`); | ||||
|       const response = await fetch(urlToUse, { | ||||
|         method: optionsArg.method, | ||||
|         headers: { | ||||
| @@ -194,7 +204,7 @@ export class WebRequest { | ||||
|         }, | ||||
|         body: optionsArg.body, | ||||
|       }); | ||||
|       console.log(`${urlToUse} answers with status: ${response.status}`); | ||||
|       this.log(`${urlToUse} answers with status: ${response.status}`); | ||||
|  | ||||
|       if (response.status >= 200 && response.status < 300) { | ||||
|         return response; | ||||
| @@ -210,4 +220,10 @@ export class WebRequest { | ||||
|     const finalResponse: Response = await doRequest(allUrls[usedUrlIndex]); | ||||
|     return finalResponse; | ||||
|   } | ||||
|  | ||||
|   public log(logArg: string) { | ||||
|     if (this.options.logging) { | ||||
|       console.log(logArg); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user