2023-04-06 01:33:08 +02:00
|
|
|
<script lang="ts">
|
2024-11-24 23:19:17 +01:00
|
|
|
import FileSelector from "./Base/FileSelector.svelte"
|
|
|
|
import { UIEventSource } from "../Logic/UIEventSource"
|
|
|
|
import ExifReader from "exifreader"
|
|
|
|
import Constants from "../Models/Constants"
|
|
|
|
import { AuthorizedPanoramax, ImageData } from "panoramax-js"
|
|
|
|
import PanoramaxImageProvider from "../Logic/ImageProviders/Panoramax"
|
|
|
|
|
|
|
|
let log = new UIEventSource<string[]>(["Select a file to test..."])
|
|
|
|
|
|
|
|
function l(...txt: ReadonlyArray<string | number>) {
|
|
|
|
console.log(...txt)
|
|
|
|
log.set([...log.data, txt.join(" ")])
|
|
|
|
}
|
|
|
|
|
|
|
|
async function onSubmit(fs: FileList) {
|
|
|
|
const f = fs[0]
|
|
|
|
l("Files are", f.name)
|
|
|
|
|
|
|
|
let [lon, lat] = [3.5, 51.2]
|
|
|
|
let datetime = new Date().toISOString()
|
|
|
|
try {
|
|
|
|
l("Trying to read EXIF-data from the file...")
|
|
|
|
const tags = await ExifReader.load(f)
|
|
|
|
l("Exif data loaded")
|
|
|
|
l("GPSLatitude.value is :", JSON.stringify(tags?.GPSLatitude.value))
|
|
|
|
l("GPSLongitude.value is :", JSON.stringify(tags?.GPSLongitude.value))
|
|
|
|
|
|
|
|
const [[latD], [latM], [latS, latSDenom]] = <
|
|
|
|
[[number, number], [number, number], [number, number]]
|
2024-11-28 12:00:23 +01:00
|
|
|
>tags?.GPSLatitude?.value
|
2024-11-24 23:19:17 +01:00
|
|
|
const [[lonD], [lonM], [lonS, lonSDenom]] = <
|
|
|
|
[[number, number], [number, number], [number, number]]
|
2024-11-28 12:00:23 +01:00
|
|
|
>tags?.GPSLongitude?.value
|
2024-11-25 11:13:13 +01:00
|
|
|
const exifLat = latD + latM / 60 + latS / (3600 * latSDenom)
|
|
|
|
const exifLon = lonD + lonM / 60 + lonS / (3600 * lonSDenom)
|
2024-12-10 02:38:00 +01:00
|
|
|
const directValueLat = tags?.GPSLatitude?.description
|
|
|
|
const directValueLon = tags?.GPSLongitude?.description
|
|
|
|
|
2024-11-28 12:00:23 +01:00
|
|
|
if (
|
|
|
|
typeof exifLat === "number" &&
|
|
|
|
!isNaN(exifLat) &&
|
|
|
|
typeof exifLon === "number" &&
|
|
|
|
!isNaN(exifLon) &&
|
|
|
|
!(exifLat === 0 && exifLon === 0)
|
|
|
|
) {
|
2024-11-25 11:13:13 +01:00
|
|
|
lat = exifLat
|
|
|
|
lon = exifLon
|
2024-12-11 02:45:44 +01:00
|
|
|
if (tags?.GPSLatitudeRef?.value?.[0] === "S") {
|
2024-12-10 02:38:00 +01:00
|
|
|
lat *= -1
|
|
|
|
}
|
2024-12-11 02:45:44 +01:00
|
|
|
if (tags?.GPSLongitudeRef?.value?.[0] === "W") {
|
2024-12-10 02:38:00 +01:00
|
|
|
lon *= -1
|
|
|
|
}
|
2024-11-25 11:13:13 +01:00
|
|
|
l("Using EXIFLAT + EXIFLON")
|
2024-11-28 12:00:23 +01:00
|
|
|
} else {
|
2024-11-25 11:13:13 +01:00
|
|
|
l("NOT using exifLat and exifLon: invalid value detected")
|
|
|
|
}
|
2024-11-24 23:19:17 +01:00
|
|
|
l("Lat and lon are", lat, lon)
|
2024-12-11 02:45:44 +01:00
|
|
|
l(
|
|
|
|
"ref lat is",
|
|
|
|
tags?.GPSLatitudeRef?.description,
|
|
|
|
JSON.stringify(tags?.GPSLatitudeRef?.value)
|
|
|
|
)
|
|
|
|
l(
|
|
|
|
"ref lon is",
|
|
|
|
tags?.GPSLongitudeRef?.description,
|
|
|
|
JSON.stringify(tags?.GPSLongitudeRef?.value)
|
|
|
|
)
|
2024-12-10 02:38:00 +01:00
|
|
|
|
2024-12-11 02:45:44 +01:00
|
|
|
l("Direct values are", directValueLat, directValueLon, "corrected:", lat, lon)
|
2024-11-24 23:19:17 +01:00
|
|
|
l("Datetime value is", JSON.stringify(tags.DateTime))
|
|
|
|
const [date, time] = tags.DateTime.value[0].split(" ")
|
|
|
|
datetime = new Date(date.replaceAll(":", "-") + "T" + time).toISOString()
|
|
|
|
l("Datetime parsed is", datetime)
|
|
|
|
console.log("Tags are", tags)
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Could not read EXIF-tags")
|
|
|
|
l("Could not read the exif tags:", e, JSON.stringify(e))
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2024-11-28 12:00:23 +01:00
|
|
|
const p = new AuthorizedPanoramax(Constants.panoramax.url, Constants.panoramax.token)
|
2024-11-24 23:19:17 +01:00
|
|
|
const sequenceId = "7f34cf53-27ff-46c9-ac22-78511fa8457a" // test-sequence
|
|
|
|
l("Fetching sequence number...")
|
|
|
|
const sequence: { id: string; "stats:items": { count: number } } = (
|
|
|
|
await p.mySequences()
|
|
|
|
).find((s) => s.id === sequenceId)
|
|
|
|
l("Sequence number is", sequence["stats:items"].count, "now attempting upload")
|
|
|
|
const img = <ImageData>await p.addImage(f, sequence, {
|
|
|
|
lon,
|
|
|
|
lat,
|
|
|
|
datetime,
|
|
|
|
isBlurred: false,
|
|
|
|
exifOverride: {
|
2024-11-28 12:00:23 +01:00
|
|
|
Artist: "TEST ACCOUNT",
|
2024-11-24 23:19:17 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
l("Upload completed. Adding meta")
|
|
|
|
PanoramaxImageProvider.singleton.addKnownMeta(img)
|
|
|
|
l("Meta added")
|
|
|
|
} catch (e) {
|
|
|
|
l("Error while uploading:", e)
|
|
|
|
}
|
|
|
|
}
|
2024-02-22 18:58:34 +01:00
|
|
|
</script>
|
2024-11-24 23:19:17 +01:00
|
|
|
|
|
|
|
<FileSelector accept="image/jpg" multiple={false} on:submit={(f) => onSubmit(f.detail)}>
|
|
|
|
<div class="border border-black p-1">Select file</div>
|
|
|
|
</FileSelector>
|
|
|
|
<div class="flex flex-col">
|
|
|
|
{#each $log as logl}
|
|
|
|
<div>{logl}</div>
|
|
|
|
{/each}
|
|
|
|
</div>
|