Notify user whether uploaded images are saved
This commit is contained in:
parent
dad0f282c6
commit
8b0b07a367
3 changed files with 58 additions and 4 deletions
|
|
@ -6,12 +6,24 @@ import CPhotoButtonGallery from "./components/CPhotoButtonGallery.vue";
|
||||||
import CPhotoButtonRecord from "./components/CPhotoButtonRecord.vue";
|
import CPhotoButtonRecord from "./components/CPhotoButtonRecord.vue";
|
||||||
import { assert } from "./lib/assert";
|
import { assert } from "./lib/assert";
|
||||||
|
|
||||||
|
const endpoint = "api/image";
|
||||||
const video = useTemplateRef<HTMLVideoElement>("video");
|
const video = useTemplateRef<HTMLVideoElement>("video");
|
||||||
|
|
||||||
const stream = ref<MediaStream>();
|
const stream = ref<MediaStream>();
|
||||||
const facing = ref<string>();
|
const facing = ref<string>();
|
||||||
const mirrored = computed(() => facing.value === "user");
|
const mirrored = computed(() => facing.value === "user");
|
||||||
const covered = ref(false);
|
const covered = ref(false);
|
||||||
|
const originals = ref<boolean>();
|
||||||
|
|
||||||
|
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 {
|
function getFacingModeFromStream(stream: MediaStream): string | undefined {
|
||||||
const videos = stream.getVideoTracks();
|
const videos = stream.getVideoTracks();
|
||||||
|
|
@ -44,6 +56,12 @@ async function initStream(facingMode?: string) {
|
||||||
video_.srcObject = stream.value;
|
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) {
|
async function waitAtLeast(duration: number, since: number) {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const wait = duration - (now - since);
|
const wait = duration - (now - since);
|
||||||
|
|
@ -60,7 +78,7 @@ async function postImage(image: Blob | File) {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
covered.value = true;
|
covered.value = true;
|
||||||
try {
|
try {
|
||||||
await fetch("api/image", { method: "POST", body: form });
|
await fetch(endpoint, { method: "POST", body: form });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error uploading image:", e);
|
console.error("Error uploading image:", e);
|
||||||
}
|
}
|
||||||
|
|
@ -102,13 +120,17 @@ async function onFlip() {
|
||||||
await initStream(facingOpposite);
|
await initStream(facingOpposite);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(() => {
|
||||||
await initStream();
|
void initStream();
|
||||||
|
void initOriginals();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<video ref="video" :class="{ mirrored }" autoplay playsinline></video>
|
<video ref="video" :class="{ mirrored }" autoplay playsinline></video>
|
||||||
|
<div class="originals">
|
||||||
|
<p>{{ originalsInfo }}</p>
|
||||||
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<CPhotoButtonGallery @click="onGallery" />
|
<CPhotoButtonGallery @click="onGallery" />
|
||||||
<CPhotoButtonRecord :disabled="stream === undefined" @click="onRecord" />
|
<CPhotoButtonRecord :disabled="stream === undefined" @click="onRecord" />
|
||||||
|
|
@ -140,6 +162,23 @@ video.mirrored {
|
||||||
scale: -1 1;
|
scale: -1 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.originals {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.originals p {
|
||||||
|
margin: 0;
|
||||||
|
margin-top: 20px;
|
||||||
|
padding: 0.2em 0.8em;
|
||||||
|
border-radius: 10em;
|
||||||
|
background-color: #fffa;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.buttons {
|
.buttons {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use std::{fs, io::Cursor};
|
||||||
|
|
||||||
use anyhow::{Context, anyhow, bail};
|
use anyhow::{Context, anyhow, bail};
|
||||||
use axum::{
|
use axum::{
|
||||||
|
Json,
|
||||||
extract::{Multipart, State},
|
extract::{Multipart, State},
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
|
|
@ -169,3 +170,14 @@ pub async fn post(server: State<Server>, mut multipart: Multipart) -> somehow::R
|
||||||
server.print_typst(typst).await?;
|
server.print_typst(typst).await?;
|
||||||
Ok(().into_response())
|
Ok(().into_response())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct Info {
|
||||||
|
originals: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get(server: State<Server>) -> impl IntoResponse {
|
||||||
|
Json(Info {
|
||||||
|
originals: server.originals.is_some(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,10 @@ pub async fn run(
|
||||||
.route("/api/cells", post(documents::cells::post))
|
.route("/api/cells", post(documents::cells::post))
|
||||||
.route("/api/chat", post(documents::chat::post))
|
.route("/api/chat", post(documents::chat::post))
|
||||||
.route("/api/egg", post(documents::egg::post))
|
.route("/api/egg", post(documents::egg::post))
|
||||||
.route("/api/image", post(documents::image::post))
|
.route(
|
||||||
|
"/api/image",
|
||||||
|
post(documents::image::post).get(documents::image::get),
|
||||||
|
)
|
||||||
.route("/api/sunrise", post(documents::sunrise::post))
|
.route("/api/sunrise", post(documents::sunrise::post))
|
||||||
.route("/api/text", post(documents::text::post))
|
.route("/api/text", post(documents::text::post))
|
||||||
.route("/api/tictactoe", post(documents::tictactoe::post))
|
.route("/api/tictactoe", post(documents::tictactoe::post))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue