2021-09-29 23:56:59 +02:00
|
|
|
import ImageProvider, { ProvidedImage } from "./ImageProvider"
|
|
|
|
|
|
|
|
export default class GenericImageProvider extends ImageProvider {
|
|
|
|
public defaultKeyPrefixes: string[] = ["image"]
|
2024-07-27 12:59:38 +02:00
|
|
|
public readonly name = "Generic"
|
2021-09-29 23:56:59 +02:00
|
|
|
|
2023-09-27 22:21:35 +02:00
|
|
|
public apiUrls(): string[] {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
2021-09-29 23:56:59 +02:00
|
|
|
private readonly _valuePrefixBlacklist: string[]
|
|
|
|
|
|
|
|
public constructor(valuePrefixBlacklist: string[]) {
|
|
|
|
super()
|
|
|
|
this._valuePrefixBlacklist = valuePrefixBlacklist
|
|
|
|
}
|
|
|
|
|
2024-09-28 02:04:14 +02:00
|
|
|
ExtractUrls(key: string, value: string): undefined | ProvidedImage[] {
|
2021-09-29 23:56:59 +02:00
|
|
|
if (this._valuePrefixBlacklist.some((prefix) => value.startsWith(prefix))) {
|
2024-09-28 02:04:14 +02:00
|
|
|
return undefined
|
2021-09-29 23:56:59 +02:00
|
|
|
}
|
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
|
2024-09-28 02:04:14 +02:00
|
|
|
return undefined
|
2021-10-06 02:30:23 +02:00
|
|
|
}
|
2021-11-07 16:34:51 +01:00
|
|
|
|
2024-09-28 02:04:14 +02:00
|
|
|
return [{
|
|
|
|
key: key,
|
|
|
|
url: value,
|
|
|
|
provider: this,
|
|
|
|
id: value,
|
|
|
|
}]
|
2021-09-29 23:56:59 +02:00
|
|
|
}
|
|
|
|
|
2023-12-02 03:12:34 +01:00
|
|
|
SourceIcon() {
|
2021-09-29 23:56:59 +02:00
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
2024-04-01 02:00:48 +02:00
|
|
|
public DownloadAttribution(_) {
|
2021-11-07 16:34:51 +01:00
|
|
|
return undefined
|
|
|
|
}
|
2021-09-29 23:56:59 +02:00
|
|
|
}
|