forked from MapComplete/MapComplete
		
	Feat: check if the image was blurred, attempt to reload if it is done; refactoring of ImageProvider code
This commit is contained in:
		
							parent
							
								
									590591dd31
								
							
						
					
					
						commit
						4650170db4
					
				
					 14 changed files with 224 additions and 190 deletions
				
			
		|  | @ -37,7 +37,7 @@ export class WikimediaImageProvider extends ImageProvider { | |||
|             return value | ||||
|         } | ||||
|         const baseUrl = `https://commons.wikimedia.org/wiki/Special:FilePath/${encodeURIComponent( | ||||
|             value | ||||
|             value, | ||||
|         )}` | ||||
|         if (useHd) { | ||||
|             return baseUrl | ||||
|  | @ -97,28 +97,27 @@ export class WikimediaImageProvider extends ImageProvider { | |||
|         return this.UrlForImage("File:" + value) | ||||
|     } | ||||
| 
 | ||||
|     public async ExtractUrls(key: string, value: string): Promise<Promise<ProvidedImage>[]> { | ||||
|     public async ExtractUrls(key: string, value: string): undefined | Promise<ProvidedImage[]> { | ||||
|         const hasCommonsPrefix = WikimediaImageProvider.startsWithCommonsPrefix(value) | ||||
|         if (key !== undefined && key !== this.commons_key && !hasCommonsPrefix) { | ||||
|             return [] | ||||
|             return undefined | ||||
|         } | ||||
| 
 | ||||
|         value = WikimediaImageProvider.removeCommonsPrefix(value) | ||||
|         if (value.startsWith("Category:")) { | ||||
|             const urls = await Wikimedia.GetCategoryContents(value) | ||||
|             return urls | ||||
|                 .filter((url) => url.startsWith("File:")) | ||||
|                 .map((image) => Promise.resolve(this.UrlForImage(image))) | ||||
|             return urls.filter((url) => url.startsWith("File:")) | ||||
|                 .map((image) => this.UrlForImage(image)) | ||||
|         } | ||||
|         if (value.startsWith("File:")) { | ||||
|             return [Promise.resolve(this.UrlForImage(value))] | ||||
|             return [this.UrlForImage(value)] | ||||
|         } | ||||
|         if (value.startsWith("http")) { | ||||
|             // PRobably an error
 | ||||
|             return [] | ||||
|             // Probably an error
 | ||||
|             return undefined | ||||
|         } | ||||
|         // We do a last effort and assume this is a file
 | ||||
|         return [Promise.resolve(this.UrlForImage("File:" + value))] | ||||
|         return [(this.UrlForImage("File:" + value))] | ||||
|     } | ||||
| 
 | ||||
|     public async DownloadAttribution(img: { url: string }): Promise<LicenseInfo> { | ||||
|  | @ -148,7 +147,7 @@ export class WikimediaImageProvider extends ImageProvider { | |||
|             console.warn( | ||||
|                 "The file", | ||||
|                 filename, | ||||
|                 "has no usable metedata or license attached... Please fix the license info file yourself!" | ||||
|                 "has no usable metedata or license attached... Please fix the license info file yourself!", | ||||
|             ) | ||||
|             return undefined | ||||
|         } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue