Scripts(imagurToPanoramax): delete 404-images automatically

This commit is contained in:
Pieter Vander Vennet 2024-11-14 18:31:36 +01:00
parent c0b11a81e9
commit 8eb59383d6

View file

@ -40,9 +40,9 @@ export class ImgurToPanoramax extends Script {
private readonly sequenceIds = { private readonly sequenceIds = {
test: "7f34cf53-27ff-46c9-ac22-78511fa8457a", test: "7f34cf53-27ff-46c9-ac22-78511fa8457a",
cc0: "1de6f4a1-73ac-4c75-ab7f-2a2aabddf50a", // "f0d6f78a-ff95-4db1-8494-6eb44a17bb37", cc0: "e9bcb8c0-8ade-4ac9-bc9f-cfa464221fd6", // "1de6f4a1-73ac-4c75-ab7f-2a2aabddf50a", // "f0d6f78a-ff95-4db1-8494-6eb44a17bb37",
ccby: "288a8052-b475-422c-811a-4f6f1a00015e", ccby: "288a8052-b475-422c-811a-4f6f1a00015e",
ccbysa: "f3d02893-b4c1-4cd6-8b27-e27ab57eb59a", ccbysa: "f3d02893-b4c1-4cd6-8b27-e27ab57eb59a"
} as const } as const
constructor() { constructor() {
@ -145,7 +145,7 @@ export class ImgurToPanoramax extends Script {
console.log("Already uploaded", panohash) console.log("Already uploaded", panohash)
return new And([ return new And([
new Tag(key.replace("image", "panoramax"), panohash), new Tag(key.replace("image", "panoramax"), panohash),
new Tag(key, ""), new Tag(key, "")
]) ])
} }
} }
@ -159,7 +159,17 @@ export class ImgurToPanoramax extends Script {
if (!path) { if (!path) {
return undefined return undefined
} }
const license: LicenseInfo = await this.getLicenseFor(v) let license: LicenseInfo
try {
license = await this.getLicenseFor(v)
} catch (e) {
console.error("Could not fetch license due to", e)
if(e === 404){
console.log("NOT FOUND")
return new Tag(key, "")
}
throw e
}
if (license === undefined) { if (license === undefined) {
return undefined return undefined
} }
@ -176,7 +186,7 @@ export class ImgurToPanoramax extends Script {
const file = new MyFile([], path) const file = new MyFile([], path)
file.stream = function () { file.stream = function() {
return handle.readableWebStream() return handle.readableWebStream()
} }
@ -213,7 +223,7 @@ export class ImgurToPanoramax extends Script {
const license = await this.getRawInfo("https://i.imgur.com/" + imgurkey + ".jpg") const license = await this.getRawInfo("https://i.imgur.com/" + imgurkey + ".jpg")
const date = new Date(license.datetime * 1000) const date = new Date(license.datetime * 1000)
const panolicense = await this.panoramax.panoramax.search({ const panolicense = await this.panoramax.panoramax.search({
ids: [panokey], ids: [panokey]
}) })
const panodata = panolicense[0] const panodata = panolicense[0]
const collection: string = panodata.collection const collection: string = panodata.collection
@ -224,13 +234,13 @@ export class ImgurToPanoramax extends Script {
method: "PATCH", method: "PATCH",
headers: { "content-type": "application/json" }, headers: { "content-type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({
ts: date.getTime(), ts: date.getTime()
}), })
}) })
console.log( console.log(
"Patched date of ", "Patched date of ",
p.createViewLink({ p.createViewLink({
imageId: panokey, imageId: panokey
}), }),
url, url,
"result is", "result is",
@ -251,8 +261,14 @@ export class ImgurToPanoramax extends Script {
}*/ }*/
const bounds = new BBox([ const bounds = new BBox([
[4.025057189545606, 49.588777455920024], [
[-16.063346185815476, 61.187350355346894], 5.051208080670676,
45.55085138791583
],
[
14.998934008628453,
55.163232765096495
]
]) ])
const maxcount = 10000 const maxcount = 10000
const overpassfilters: RegexTag[] = [] const overpassfilters: RegexTag[] = []
@ -308,7 +324,7 @@ export class ImgurToPanoramax extends Script {
f.properties, f.properties,
{ {
theme: "image-mover", theme: "image-mover",
changeType: "link-image", changeType: "link-image"
} }
) )
changes.push(...(await action.CreateChangeDescriptions())) changes.push(...(await action.CreateChangeDescriptions()))