forked from MapComplete/MapComplete
Move imageAttributionSources around, improve fixTheme script
This commit is contained in:
parent
8bca83d708
commit
aaaf876257
15 changed files with 125 additions and 43 deletions
|
@ -1,4 +1,4 @@
|
|||
import {ImagesInCategory, Wikidata, Wikimedia} from "../Web/Wikimedia";
|
||||
import {ImagesInCategory, Wikidata, Wikimedia} from "../ImageProviders/Wikimedia";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
|
||||
/**
|
||||
|
|
9
Logic/ImageProviders/AllImageProviders.ts
Normal file
9
Logic/ImageProviders/AllImageProviders.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import {Mapillary} from "./Mapillary";
|
||||
import {Wikimedia} from "./Wikimedia";
|
||||
import {Imgur} from "./Imgur";
|
||||
|
||||
export default class AllImageProviders{
|
||||
|
||||
public static ImageAttributionSource = [Imgur.singleton, Mapillary.singleton, Wikimedia.singleton]
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@ import BaseUIElement from "../../UI/BaseUIElement";
|
|||
|
||||
export default abstract class ImageAttributionSource {
|
||||
|
||||
|
||||
private _cache = new Map<string, UIEventSource<LicenseInfo>>()
|
||||
|
||||
GetAttributionFor(url: string): UIEventSource<LicenseInfo> {
|
||||
|
@ -22,6 +21,7 @@ export default abstract class ImageAttributionSource {
|
|||
|
||||
public abstract SourceIcon(backlinkSource?: string) : BaseUIElement;
|
||||
protected abstract DownloadAttribution(url: string): UIEventSource<LicenseInfo>;
|
||||
/*Converts a value to a URL. Can return null if not applicable*/
|
||||
public PrepareUrl(value: string): string{
|
||||
return value;
|
||||
}
|
|
@ -4,6 +4,7 @@ import BaseUIElement from "../../UI/BaseUIElement";
|
|||
import Svg from "../../Svg";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import Link from "../../UI/Base/Link";
|
||||
import {Utils} from "../../Utils";
|
||||
|
||||
/**
|
||||
* This module provides endpoints for wikipedia/wikimedia and others
|
||||
|
@ -138,21 +139,28 @@ export class Wikimedia extends ImageAttributionSource {
|
|||
"api.php?action=query&prop=imageinfo&iiprop=extmetadata&" +
|
||||
"titles=" + filename +
|
||||
"&format=json&origin=*";
|
||||
console.log("Getting attribution at ", url)
|
||||
$.getJSON(url, function (data) {
|
||||
const licenseInfo = new LicenseInfo();
|
||||
const license = data.query.pages[-1].imageinfo[0].extmetadata;
|
||||
Utils.downloadJson(url).then(
|
||||
data =>{
|
||||
const licenseInfo = new LicenseInfo();
|
||||
const license = (data.query.pages[-1].imageinfo ?? [])[0]?.extmetadata;
|
||||
if(license === undefined){
|
||||
console.error("This file has no usable metedata or license attached... Please fix the license info file yourself!")
|
||||
source.setData(null)
|
||||
return;
|
||||
}
|
||||
|
||||
licenseInfo.artist = license.Artist?.value;
|
||||
licenseInfo.license = license.License?.value;
|
||||
licenseInfo.copyrighted = license.Copyrighted?.value;
|
||||
licenseInfo.attributionRequired = license.AttributionRequired?.value;
|
||||
licenseInfo.usageTerms = license.UsageTerms?.value;
|
||||
licenseInfo.licenseShortName = license.LicenseShortName?.value;
|
||||
licenseInfo.credit = license.Credit?.value;
|
||||
licenseInfo.description = license.ImageDescription?.value;
|
||||
source.setData(licenseInfo);
|
||||
});
|
||||
licenseInfo.artist = license.Artist?.value;
|
||||
licenseInfo.license = license.License?.value;
|
||||
licenseInfo.copyrighted = license.Copyrighted?.value;
|
||||
licenseInfo.attributionRequired = license.AttributionRequired?.value;
|
||||
licenseInfo.usageTerms = license.UsageTerms?.value;
|
||||
licenseInfo.licenseShortName = license.LicenseShortName?.value;
|
||||
licenseInfo.credit = license.Credit?.value;
|
||||
licenseInfo.description = license.ImageDescription?.value;
|
||||
source.setData(licenseInfo);
|
||||
}
|
||||
)
|
||||
|
||||
return source;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue