| 
									
										
										
										
											2021-09-29 23:56:59 +02:00
										 |  |  | import ImageProvider, {ProvidedImage} from "./ImageProvider"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default class GenericImageProvider extends ImageProvider { | 
					
						
							|  |  |  |     public defaultKeyPrefixes: string[] = ["image"]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private readonly _valuePrefixBlacklist: string[]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public constructor(valuePrefixBlacklist: string[]) { | 
					
						
							|  |  |  |         super(); | 
					
						
							|  |  |  |         this._valuePrefixBlacklist = valuePrefixBlacklist; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async ExtractUrls(key: string, value: string): Promise<Promise<ProvidedImage>[]> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (this._valuePrefixBlacklist.some(prefix => value.startsWith(prefix))) { | 
					
						
							|  |  |  |             return [] | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         try { | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |             new URL(value) | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |         } catch (_) { | 
					
						
							| 
									
										
										
										
											2021-10-06 02:30:23 +02:00
										 |  |  |             // Not a valid URL
 | 
					
						
							|  |  |  |             return [] | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-29 23:56:59 +02:00
										 |  |  |         return [Promise.resolve({ | 
					
						
							|  |  |  |             key: key, | 
					
						
							|  |  |  |             url: value, | 
					
						
							|  |  |  |             provider: this | 
					
						
							|  |  |  |         })] | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     SourceIcon(backlinkSource?: string) { | 
					
						
							|  |  |  |         return undefined; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 16:34:51 +01:00
										 |  |  |     protected DownloadAttribution(url: string) { | 
					
						
							|  |  |  |         return undefined | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-29 23:56:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |