Fix: style issue, types

This commit is contained in:
Pieter Vander Vennet 2024-07-19 11:57:53 +02:00
parent 3c20d2ca8d
commit 5932dc7ad4
7 changed files with 71 additions and 73 deletions

View file

@ -68,7 +68,7 @@ export default abstract class ImageProvider {
public abstract ExtractUrls(key: string, value: string): Promise<Promise<ProvidedImage>[]>
public abstract DownloadAttribution(providedImage: ProvidedImage): Promise<LicenseInfo>
public abstract DownloadAttribution(providedImage: {url: string, id: string}): Promise<LicenseInfo>
public abstract apiUrls(): string[]
}

View file

@ -97,11 +97,11 @@ export class Imgur extends ImageProvider implements ImageUploader {
const hash = url.substr("https://i.imgur.com/".length).split(/\.jpe?g/i)[0]
const apiUrl = "https://api.imgur.com/3/image/" + hash
const response = await Utils.downloadJsonCached(apiUrl, 365 * 24 * 60 * 60, {
const response = await Utils.downloadJsonCached<{data: {description: string, datetime: string, views: number}}>(apiUrl, 365 * 24 * 60 * 60, {
Authorization: "Client-ID " + Constants.ImgurApiKey,
})
const descr: string = response.data.description ?? ""
const descr = response.data.description ?? ""
const data: any = {}
const imgurData = response.data

View file

@ -133,7 +133,7 @@ export class Mapillary extends ImageProvider {
return [this.PrepareUrlAsync(key, value)]
}
public async DownloadAttribution(providedImage: ProvidedImage): Promise<LicenseInfo> {
public async DownloadAttribution(providedImage: {id: string}): Promise<LicenseInfo> {
const mapillaryId = providedImage.id
const metadataUrl =
"https://graph.mapillary.com/" +

View file

@ -120,7 +120,7 @@ export class WikimediaImageProvider extends ImageProvider {
return [Promise.resolve(this.UrlForImage("File:" + value))]
}
public async DownloadAttribution(img: ProvidedImage): Promise<LicenseInfo> {
public async DownloadAttribution(img: {url: string}): Promise<LicenseInfo> {
const filename = WikimediaImageProvider.ExtractFileName(img.url)
if (filename === "") {

View file

@ -215,6 +215,9 @@ class MapillaryFetcher implements ImageFetcher {
for (const img of response.data) {
const c = img.computed_geometry.coordinates
if(img.thumb_original_url === undefined){
continue
}
pics.push({
pictureUrl: img.thumb_original_url,
provider: "Mapillary",
@ -269,7 +272,20 @@ export class CombinedFetcher {
if (src.data === undefined) {
src.setData(pics)
} else {
const newList = [...src.data, ...pics]
const newList = []
const seenIds = new Set<string>()
for (const p4CPicture of [...src.data, ...pics]) {
const id = p4CPicture.pictureUrl
if(seenIds.has(id)){
continue
}
newList.push(p4CPicture)
seenIds.add(id)
if(id === undefined){
console.log("Img:", p4CPicture)
}
}
NearbyImageUtils.sortByDistance(newList, lon, lat)
src.setData(newList)
}