forked from MapComplete/MapComplete
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import ImageProvider, { ProvidedImage } from "./ImageProvider"
|
|
|
|
export default class GenericImageProvider extends ImageProvider {
|
|
public defaultKeyPrefixes: string[] = ["image"]
|
|
public readonly name = "Generic"
|
|
|
|
public apiUrls(): string[] {
|
|
return []
|
|
}
|
|
|
|
private readonly _valuePrefixBlacklist: string[]
|
|
|
|
public constructor(valuePrefixBlacklist: string[]) {
|
|
super()
|
|
this._valuePrefixBlacklist = valuePrefixBlacklist
|
|
}
|
|
|
|
ExtractUrls(key: string, value: string): undefined | ProvidedImage[] {
|
|
if (this._valuePrefixBlacklist.some((prefix) => value.startsWith(prefix))) {
|
|
return undefined
|
|
}
|
|
|
|
try {
|
|
new URL(value)
|
|
} catch (_) {
|
|
// Not a valid URL
|
|
return undefined
|
|
}
|
|
|
|
return [
|
|
{
|
|
key: key,
|
|
url: value,
|
|
provider: this,
|
|
id: value,
|
|
isSpherical: undefined,
|
|
originalAttribute: {
|
|
key, value
|
|
}
|
|
},
|
|
]
|
|
}
|
|
|
|
SourceIcon() {
|
|
return undefined
|
|
}
|
|
|
|
public DownloadAttribution(_) {
|
|
return undefined
|
|
}
|
|
|
|
getPanoramaInfo(): undefined {
|
|
return undefined
|
|
}
|
|
|
|
visitUrl(image: { url: string }): string | undefined {
|
|
return image.url
|
|
}
|
|
}
|