diff --git a/showbits-thermal-printer-ui/src/AppPhoto.vue b/showbits-thermal-printer-ui/src/AppPhoto.vue index 3e1acb4..fc2866f 100644 --- a/showbits-thermal-printer-ui/src/AppPhoto.vue +++ b/showbits-thermal-printer-ui/src/AppPhoto.vue @@ -6,12 +6,24 @@ import CPhotoButtonGallery from "./components/CPhotoButtonGallery.vue"; import CPhotoButtonRecord from "./components/CPhotoButtonRecord.vue"; import { assert } from "./lib/assert"; +const endpoint = "api/image"; const video = useTemplateRef("video"); const stream = ref(); const facing = ref(); const mirrored = computed(() => facing.value === "user"); const covered = ref(false); +const originals = ref(); + +const originalsInfo = computed(() => { + if (originals.value === true) { + return "Uploaded images are saved."; + } else if (originals.value === false) { + return "Uploaded images are not saved."; + } else { + return "Uploaded images may be saved."; + } +}); function getFacingModeFromStream(stream: MediaStream): string | undefined { const videos = stream.getVideoTracks(); @@ -44,6 +56,12 @@ async function initStream(facingMode?: string) { video_.srcObject = stream.value; } +async function initOriginals() { + const response = await fetch(endpoint); + const info = (await response.json()) as { originals?: boolean }; + originals.value = info.originals ?? false; +} + async function waitAtLeast(duration: number, since: number) { const now = Date.now(); const wait = duration - (now - since); @@ -60,7 +78,7 @@ async function postImage(image: Blob | File) { const start = Date.now(); covered.value = true; try { - await fetch("api/image", { method: "POST", body: form }); + await fetch(endpoint, { method: "POST", body: form }); } catch (e) { console.error("Error uploading image:", e); } @@ -102,13 +120,17 @@ async function onFlip() { await initStream(facingOpposite); } -onMounted(async () => { - await initStream(); +onMounted(() => { + void initStream(); + void initOriginals(); });