Fix attribution display for imgur images with .jpeg extension

This commit is contained in:
Pieter Vander Vennet 2024-03-07 00:22:36 +01:00
parent 77f07f55ec
commit 7aaf7e2896

View file

@ -85,9 +85,15 @@ export class Imgur extends ImageProvider implements ImageUploader {
* expected.date = new Date(1655052078000) * expected.date = new Date(1655052078000)
* expected.views = 2 * expected.views = 2
* licenseInfo // => expected * licenseInfo // => expected
* const licenseInfoJpeg = await Imgur.singleton.DownloadAttribution("https://i.imgur.com/E0RuAK3.jpeg")
* licenseInfoJpeg // => expected
* const licenseInfoUpperCase = await Imgur.singleton.DownloadAttribution("https://i.imgur.com/E0RuAK3.JPEG")
* licenseInfoUpperCase // => expected
*
*
*/ */
public async DownloadAttribution(url: string): Promise<LicenseInfo> { public async DownloadAttribution(url: string): Promise<LicenseInfo> {
const hash = url.substr("https://i.imgur.com/".length).split(".jpg")[0] const hash = url.substr("https://i.imgur.com/".length).split(/\.jpe?g/i)[0]
const apiUrl = "https://api.imgur.com/3/image/" + hash const apiUrl = "https://api.imgur.com/3/image/" + hash
const response = await Utils.downloadJsonCached(apiUrl, 365 * 24 * 60 * 60, { const response = await Utils.downloadJsonCached(apiUrl, 365 * 24 * 60 * 60, {