Fix #1863
This commit is contained in:
parent
a79675c879
commit
940f187041
8 changed files with 37 additions and 22 deletions
|
@ -95,7 +95,7 @@ export default class GenerateImageAnalysis extends Script {
|
||||||
if (fs.existsSync(targetPath)) {
|
if (fs.existsSync(targetPath)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const attribution = await Imgur.singleton.DownloadAttribution(image)
|
const attribution = await Imgur.singleton.DownloadAttribution({ url: image, })
|
||||||
|
|
||||||
if ((attribution.artist ?? "") === "") {
|
if ((attribution.artist ?? "") === "") {
|
||||||
// This is an invalid attribution. We save the raw response as well
|
// This is an invalid attribution. We save the raw response as well
|
||||||
|
@ -215,7 +215,7 @@ export default class GenerateImageAnalysis extends Script {
|
||||||
skipped++
|
skipped++
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
attribution = await Imgur.singleton.DownloadAttribution(image)
|
attribution = await Imgur.singleton.DownloadAttribution({ url: image })
|
||||||
await ScriptUtils.sleep(500)
|
await ScriptUtils.sleep(500)
|
||||||
writeFileSync(cachedView, JSON.stringify(attribution))
|
writeFileSync(cachedView, JSON.stringify(attribution))
|
||||||
dloaded++
|
dloaded++
|
||||||
|
|
|
@ -40,7 +40,7 @@ export default class GenericImageProvider extends ImageProvider {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadAttribution(url: string) {
|
public DownloadAttribution(_) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ export default abstract class ImageProvider {
|
||||||
|
|
||||||
public abstract ExtractUrls(key: string, value: string): Promise<Promise<ProvidedImage>[]>
|
public abstract ExtractUrls(key: string, value: string): Promise<Promise<ProvidedImage>[]>
|
||||||
|
|
||||||
public abstract DownloadAttribution(url: string): Promise<LicenseInfo>
|
public abstract DownloadAttribution(providedImage: ProvidedImage): Promise<LicenseInfo>
|
||||||
|
|
||||||
public abstract apiUrls(): string[]
|
public abstract apiUrls(): string[]
|
||||||
|
|
||||||
|
|
|
@ -92,8 +92,9 @@ export class Imgur extends ImageProvider implements ImageUploader {
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async DownloadAttribution(url: string): Promise<LicenseInfo> {
|
public async DownloadAttribution(providedImage: {url: string}): Promise<LicenseInfo> {
|
||||||
const hash = url.substr("https://i.imgur.com/".length).split(/\.jpe?g/i)[0]
|
const url = providedImage.url
|
||||||
|
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, {
|
||||||
|
|
|
@ -133,12 +133,21 @@ export class Mapillary extends ImageProvider {
|
||||||
return [this.PrepareUrlAsync(key, value)]
|
return [this.PrepareUrlAsync(key, value)]
|
||||||
}
|
}
|
||||||
|
|
||||||
public async DownloadAttribution(_: string): Promise<LicenseInfo> {
|
public async DownloadAttribution(providedImage: ProvidedImage): Promise<LicenseInfo> {
|
||||||
|
const mapillaryId = providedImage.id
|
||||||
|
const metadataUrl =
|
||||||
|
"https://graph.mapillary.com/" +
|
||||||
|
mapillaryId +
|
||||||
|
"?fields=thumb_1024_url,thumb_original_url,captured_at,creator&access_token=" +
|
||||||
|
Constants.mapillary_client_token_v4
|
||||||
|
const response = await Utils.downloadJsonCached(metadataUrl, 60 * 60)
|
||||||
|
|
||||||
const license = new LicenseInfo()
|
const license = new LicenseInfo()
|
||||||
license.artist = undefined
|
license.artist = response["creator"]["username"]
|
||||||
license.license = "CC BY-SA 4.0"
|
license.license = "CC BY-SA 4.0"
|
||||||
// license.license = "Creative Commons Attribution-ShareAlike 4.0 International License";
|
// license.license = "Creative Commons Attribution-ShareAlike 4.0 International License";
|
||||||
license.attributionRequired = true
|
license.attributionRequired = true
|
||||||
|
license.date = new Date(response["captured_at"])
|
||||||
return license
|
return license
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,16 +160,19 @@ export class Mapillary extends ImageProvider {
|
||||||
const metadataUrl =
|
const metadataUrl =
|
||||||
"https://graph.mapillary.com/" +
|
"https://graph.mapillary.com/" +
|
||||||
mapillaryId +
|
mapillaryId +
|
||||||
"?fields=thumb_1024_url,thumb_original_url&access_token=" +
|
"?fields=thumb_1024_url,thumb_original_url,captured_at,creator&access_token=" +
|
||||||
Constants.mapillary_client_token_v4
|
Constants.mapillary_client_token_v4
|
||||||
const response = await Utils.downloadJsonCached(metadataUrl, 60 * 60)
|
const response = await Utils.downloadJsonCached(metadataUrl, 60 * 60)
|
||||||
const url = <string>response["thumb_1024_url"]
|
const url = <string>response["thumb_1024_url"]
|
||||||
const url_hd = <string>response["thumb_original_url"]
|
const url_hd = <string>response["thumb_original_url"]
|
||||||
return {
|
const date = new Date()
|
||||||
|
date.setTime(response["captured_at"])
|
||||||
|
return <ProvidedImage> {
|
||||||
id: "" + mapillaryId,
|
id: "" + mapillaryId,
|
||||||
url,
|
url,
|
||||||
url_hd,
|
url_hd,
|
||||||
provider: this,
|
provider: this,
|
||||||
|
date,
|
||||||
key,
|
key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ export class WikidataImageProvider extends ImageProvider {
|
||||||
return allImages
|
return allImages
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadAttribution(_: string): Promise<any> {
|
public DownloadAttribution(_): Promise<any> {
|
||||||
throw new Error("Method not implemented; shouldn't be needed!")
|
throw new Error("Method not implemented; shouldn't be needed!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,8 +114,8 @@ export class WikimediaImageProvider extends ImageProvider {
|
||||||
return [Promise.resolve(this.UrlForImage("File:" + value))]
|
return [Promise.resolve(this.UrlForImage("File:" + value))]
|
||||||
}
|
}
|
||||||
|
|
||||||
public async DownloadAttribution(filename: string): Promise<LicenseInfo> {
|
public async DownloadAttribution(img: ProvidedImage): Promise<LicenseInfo> {
|
||||||
filename = WikimediaImageProvider.ExtractFileName(filename)
|
const filename = WikimediaImageProvider.ExtractFileName(img.url)
|
||||||
|
|
||||||
if (filename === "") {
|
if (filename === "") {
|
||||||
return undefined
|
return undefined
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
*/
|
*/
|
||||||
export let image: ProvidedImage
|
export let image: ProvidedImage
|
||||||
let license: Store<LicenseInfo> = UIEventSource.FromPromise(
|
let license: Store<LicenseInfo> = UIEventSource.FromPromise(
|
||||||
image.provider?.DownloadAttribution(image.url)
|
image.provider?.DownloadAttribution(image)
|
||||||
)
|
)
|
||||||
let icon = image.provider?.SourceIcon(image.id)?.SetClass("block h-8 w-8 pr-2")
|
let icon = image.provider?.SourceIcon(image.id)?.SetClass("block h-8 w-8 pr-2")
|
||||||
</script>
|
</script>
|
||||||
|
@ -38,26 +38,28 @@
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between w-full gap-x-1">
|
||||||
{#if $license.license !== undefined || $license.licenseShortName !== undefined}
|
{#if $license.license !== undefined || $license.licenseShortName !== undefined}
|
||||||
<div>
|
<div>
|
||||||
{$license?.license ?? $license?.licenseShortName}
|
{$license?.license ?? $license?.licenseShortName}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if $license.date}
|
{#if $license.views}
|
||||||
<div>
|
<div class="flex justify-around self-center">
|
||||||
{$license.date.toLocaleDateString()}
|
<EyeIcon class="h-4 w-4 pr-1" />
|
||||||
|
{$license.views}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if $license.views}
|
{#if $license.date}
|
||||||
<div class="flex justify-around self-center">
|
<div>
|
||||||
<EyeIcon class="h-4 w-4 pr-1" />
|
{$license.date.toLocaleDateString()}
|
||||||
{$license.views}
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue