forked from MapComplete/MapComplete
		
	Merge develop
This commit is contained in:
		
						commit
						fec3608ca4
					
				
					 57 changed files with 1160 additions and 594 deletions
				
			
		
							
								
								
									
										30
									
								
								src/Utils.ts
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								src/Utils.ts
									
										
									
									
									
								
							|  | @ -401,6 +401,19 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be | |||
|         return newArr | ||||
|     } | ||||
| 
 | ||||
|     public static DedupT<T>(arr: T[]): T[]{ | ||||
|         if(!arr){ | ||||
|             return arr | ||||
|         } | ||||
|         const items = [] | ||||
|         for (const item of arr) { | ||||
|             if(items.indexOf(item) < 0){ | ||||
|                 items.push(item) | ||||
|             } | ||||
|         } | ||||
|         return items | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Finds all duplicates in a list of strings | ||||
|      * | ||||
|  | @ -1064,19 +1077,22 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be | |||
|     public static async downloadJsonCached<T = object | []>( | ||||
|         url: string, | ||||
|         maxCacheTimeMs: number, | ||||
|         headers?: Record<string, string> | ||||
|         headers?: Record<string, string>, | ||||
|         dontCacheErrors: boolean = false | ||||
|     ): Promise<T> { | ||||
|         const result = await Utils.downloadJsonCachedAdvanced(url, maxCacheTimeMs, headers) | ||||
|         const result = await Utils.downloadJsonCachedAdvanced(url, maxCacheTimeMs, headers, dontCacheErrors) | ||||
|         if (result["content"]) { | ||||
|             return result["content"] | ||||
|         } | ||||
|         throw result["error"] | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     public static async downloadJsonCachedAdvanced<T = object | []>( | ||||
|         url: string, | ||||
|         maxCacheTimeMs: number, | ||||
|         headers?: Record<string, string> | ||||
|         headers?: Record<string, string>, | ||||
|         dontCacheErrors = false | ||||
|     ): Promise<{ content: T } | { error: string; url: string; statuscode?: number }> { | ||||
|         const cached = Utils._download_cache.get(url) | ||||
|         if (cached !== undefined) { | ||||
|  | @ -1090,7 +1106,15 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be | |||
|                 headers | ||||
|             ) | ||||
|         Utils._download_cache.set(url, { promise, timestamp: new Date().getTime() }) | ||||
|         try { | ||||
| 
 | ||||
|         return await promise | ||||
|         }catch (e) { | ||||
|                 if(dontCacheErrors){ | ||||
|                     Utils._download_cache.delete(url) | ||||
|                 } | ||||
|             throw e | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static async downloadJson<T = object | []>( | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue