Add image upload functionality with imgur

This commit is contained in:
Pieter Vander Vennet 2020-06-25 03:39:31 +02:00
parent 6187122294
commit 2acd53d150
21 changed files with 458 additions and 69 deletions

View file

@ -19,7 +19,6 @@ export class ImageSearcher extends UIEventSource<string[]> {
constructor(tags: UIEventSource<any>) {
super([]);
// this.ListenTo(this._embeddedImages);
this._tags = tags;
@ -27,7 +26,8 @@ export class ImageSearcher extends UIEventSource<string[]> {
this._wdItem.addCallback(() => {
// Load the wikidata item, then detect usage on 'commons'
let wikidataId = self._wdItem.data;
if (wikidataId.startsWith("Q")) {
// @ts-ignore
if (wikidataId.startsWith("Q")) {
wikidataId = wikidataId.substr(1);
}
Wikimedia.GetWikiData(parseInt(wikidataId), (wd: Wikidata) => {
@ -44,14 +44,17 @@ export class ImageSearcher extends UIEventSource<string[]> {
this._commons.addCallback(() => {
const commons: string = self._commons.data;
// @ts-ignore
if (commons.startsWith("Category:")) {
Wikimedia.GetCategoryFiles(commons, (images: ImagesInCategory) => {
for (const image of images.images) {
self.AddImage(image.filename);
}
})
} else if (commons.startsWith("File:")) {
self.AddImage(commons);
} else { // @ts-ignore
if (commons.startsWith("File:")) {
self.AddImage(commons);
}
}
});
@ -79,7 +82,7 @@ export class ImageSearcher extends UIEventSource<string[]> {
}
private LoadImages(): void {
if(!this._activated){
if (!this._activated) {
return;
}
const imageTag = this._tags.data.image;
@ -90,6 +93,18 @@ export class ImageSearcher extends UIEventSource<string[]> {
}
}
const image0 = this._tags.data["image:0"];
if (image0 !== undefined) {
this.AddImage(image0);
}
let imageIndex = 1;
let imagei = this._tags.data["image:" + imageIndex];
while (imagei !== undefined) {
this.AddImage(imagei);
imageIndex++;
imagei = this._tags.data["image:" + imageIndex];
}
const wdItem = this._tags.data.wikidata;
if (wdItem !== undefined) {
this._wdItem.setData(wdItem);