forked from MapComplete/MapComplete
Add imgur attribution
This commit is contained in:
parent
31a64887a1
commit
9e9a600488
5 changed files with 115 additions and 21 deletions
|
@ -4,6 +4,7 @@ import {WikimediaImage} from "../UI/Image/WikimediaImage";
|
|||
import {SimpleImageElement} from "../UI/Image/SimpleImageElement";
|
||||
import {UIElement} from "../UI/UIElement";
|
||||
import {Changes} from "./Changes";
|
||||
import {ImgurImage} from "../UI/Image/ImgurImage";
|
||||
|
||||
/**
|
||||
* There are multiple way to fetch images for an object
|
||||
|
@ -170,12 +171,13 @@ export class ImageSearcher extends UIEventSource<string[]> {
|
|||
* @constructor
|
||||
*/
|
||||
static CreateImageElement(url: string): UIElement {
|
||||
const urlSource = new UIEventSource<string>(url);
|
||||
// @ts-ignore
|
||||
if (url.startsWith("File:")) {
|
||||
return new WikimediaImage(urlSource.data);
|
||||
return new WikimediaImage(url);
|
||||
}else if(url.startsWith("https://i.imgur.com/")){
|
||||
return new ImgurImage(url);
|
||||
} else {
|
||||
return new SimpleImageElement(urlSource);
|
||||
return new SimpleImageElement(new UIEventSource<string>(url));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import $ from "jquery"
|
||||
import {LicenseInfo} from "./Wikimedia";
|
||||
|
||||
export class Imgur {
|
||||
|
||||
|
@ -27,6 +28,50 @@ export class Imgur {
|
|||
);
|
||||
|
||||
|
||||
}
|
||||
static getDescriptionOfImage(url: string,
|
||||
handleDescription: ((license: LicenseInfo) => void)) {
|
||||
|
||||
const hash = url.substr("https://i.imgur.com/".length).split(".jpg")[0];
|
||||
|
||||
const apiUrl = 'https://api.imgur.com/3/image/'+hash;
|
||||
const apiKey = '7070e7167f0a25a';
|
||||
|
||||
var settings = {
|
||||
async: true,
|
||||
crossDomain: true,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
type: 'GET',
|
||||
url: apiUrl,
|
||||
headers: {
|
||||
Authorization: 'Client-ID ' + apiKey,
|
||||
Accept: 'application/json',
|
||||
},
|
||||
};
|
||||
$.ajax(settings).done(function (response) {
|
||||
const descr : string= response.data.description;
|
||||
const data : any = {};
|
||||
for (const tag of descr.split("\n")) {
|
||||
const kv = tag.split(":");
|
||||
const k = kv[0];
|
||||
const v = kv[1].replace("\r", "");
|
||||
data[k] = v;
|
||||
}
|
||||
|
||||
|
||||
console.log(data);
|
||||
const licenseInfo = new LicenseInfo();
|
||||
|
||||
licenseInfo.licenseShortName = data.license;
|
||||
licenseInfo.artist = data.author;
|
||||
|
||||
handleDescription(licenseInfo);
|
||||
|
||||
}).fail((reason) => {
|
||||
console.log("Getting metadata from to IMGUR failed", reason)
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
static uploadImage(title: string, description: string, blob,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue