From dfc92d2d9aa940c692d04d9e24b35c1ff7b6d448 Mon Sep 17 00:00:00 2001 From: MechaCat02 Date: Thu, 2 Apr 2026 20:20:35 +0200 Subject: [PATCH] feat: implement camera capture integration Add CameraCapture component with full photo/video support via getUserMedia, integrated into the upload page alongside the existing library picker. Co-Authored-By: Claude Sonnet 4.6 --- .../src/lib/components/CameraCapture.svelte | 4 +- frontend/src/routes/upload/+page.svelte | 67 ++++++++++++++----- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/frontend/src/lib/components/CameraCapture.svelte b/frontend/src/lib/components/CameraCapture.svelte index 2b01998..67698e6 100644 --- a/frontend/src/lib/components/CameraCapture.svelte +++ b/frontend/src/lib/components/CameraCapture.svelte @@ -8,8 +8,8 @@ let { oncapture, onclose }: Props = $props(); - let videoEl: HTMLVideoElement; - let canvasEl: HTMLCanvasElement; + let videoEl: HTMLVideoElement = $state()!; + let canvasEl: HTMLCanvasElement = $state()!; let stream: MediaStream | null = $state(null); let facingMode = $state<'environment' | 'user'>('environment'); let recording = $state(false); diff --git a/frontend/src/routes/upload/+page.svelte b/frontend/src/routes/upload/+page.svelte index 1368d2e..e6205ec 100644 --- a/frontend/src/routes/upload/+page.svelte +++ b/frontend/src/routes/upload/+page.svelte @@ -3,11 +3,13 @@ import { getToken } from '$lib/auth'; import { addToQueue, loadQueue } from '$lib/upload-queue'; import UploadQueue from '$lib/components/UploadQueue.svelte'; + import CameraCapture from '$lib/components/CameraCapture.svelte'; import { onMount } from 'svelte'; let caption = $state(''); let hashtags = $state(''); let fileInput: HTMLInputElement; + let showCamera = $state(false); onMount(() => { if (!getToken()) { @@ -30,8 +32,23 @@ hashtags = ''; if (fileInput) fileInput.value = ''; } + + async function handleCapture(blob: Blob, type: 'photo' | 'video') { + const ext = type === 'photo' ? 'jpg' : blob.type.includes('mp4') ? 'mp4' : 'webm'; + const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); + const fileName = `${type}_${timestamp}.${ext}`; + const file = new File([blob], fileName, { type: blob.type }); + await addToQueue(file, caption, hashtags); + } +{#if showCamera} + (showCamera = false)} + /> +{/if} +
@@ -40,23 +57,39 @@
- +
+ + + + + +