feat: enhance photo upload and management features
Deploy Development / deploy (push) Successful in 1m4s
Build Test / pytest-backend (push) Successful in 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 17s

- Added `taken_at` timestamp to the photos table for improved photo metadata.
- Updated the photo upload API to support optional EXIF data extraction and file last modified timestamp.
- Enhanced the photo upload process to allow skipping EXIF data, defaulting to today's date if no other date is provided.
- Improved the photo display in various components to utilize a unified caption format.
- Refactored photo sorting and grouping logic for better organization in the UI.
This commit is contained in:
Lars committed 2026-04-19 10:13:22 +02:00
1 parent c91317df8e
commit 0035d08149
12 files changed
+225 -36

No files matched your search

@@ -1,6 +1,7 @@
import { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'
import { api } from '../../utils/api'
import { formatPhotoCaption } from '../../utils/photoDisplay'
/**
* Fortschrittsfotos (Galerie wie Verlauf-Tab Fotos).
@@ -76,7 +77,7 @@ export default function ProgressPhotosWidget({ refreshTick = 0 }) {
borderRadius: 3,
}}
>
{p.date?.slice(0, 10) || p.created?.slice(0, 10)}
{formatPhotoCaption(p)}
</div>
</div>
))}
+1 -1
View File
@@ -49,7 +49,7 @@ export default function CircumScreen() {
FIELDS.forEach(k=>{ if(form[k]!=='') payload[k]=parseFloat(form[k]) })
if(form.notes) payload.notes = form.notes
if(photoFile) {
const pr = await api.uploadPhoto(photoFile, form.date)
const pr = await api.uploadPhoto(photoFile, form.date, { skipExif: true })
payload.photo_id = pr.id
}
await api.upsertCirc(payload)
+4 -12
View File
@@ -8,6 +8,7 @@ import {
} from 'recharts'
import { ChevronRight, Brain, ChevronDown, ChevronUp, Trash2 } from 'lucide-react'
import { api } from '../utils/api'
import { photoMonthKey, photoSortKey, formatPhotoCaption } from '../utils/photoDisplay'
import { getBfCategory } from '../utils/calc'
import { getInterpretation, getStatusColor, getStatusBg } from '../utils/interpret'
import Markdown from '../utils/Markdown'
@@ -897,15 +898,6 @@ function CorrelationSection({ corrData, insights, profile, onRequest, loadingSlu
}
// ── Photo Grid ────────────────────────────────────────────────────────────────
function monthKeyFromPhoto(p) {
if (p.date) return p.date.slice(0, 7)
return (p.created || '').slice(0, 7) || '0000-00'
}
function sortPhotoDateKey(p) {
return (p.date || p.created || '').slice(0, 10)
}
function PhotoGrid() {
const [photos, setPhotos] = useState([])
const [big, setBig] = useState(null)
@@ -931,10 +923,10 @@ function PhotoGrid() {
return <EmptySection text="Noch keine Fotos." to="/photos" toLabel="Fotos erfassen" />
}
const sorted = [...photos].sort((a, b) => sortPhotoDateKey(b).localeCompare(sortPhotoDateKey(a)))
const sorted = [...photos].sort((a, b) => photoSortKey(b).localeCompare(photoSortKey(a)))
const byMonth = new Map()
for (const p of sorted) {
const mk = monthKeyFromPhoto(p)
const mk = photoMonthKey(p)
if (!byMonth.has(mk)) byMonth.set(mk, [])
byMonth.get(mk).push(p)
}
@@ -993,7 +985,7 @@ function PhotoGrid() {
borderRadius: 3,
}}
>
{p.date?.slice(0, 10) || p.created?.slice(0, 10)}
{formatPhotoCaption(p)}
</div>
<button
type="button"
+1 -1
View File
@@ -102,7 +102,7 @@ export default function NewMeasurement() {
if (id) { await api.updateMeasurement(id, payload) }
else { const r = await api.createMeasurement(payload); mid = r.id }
if (photoFile && mid) {
const pr = await api.uploadPhoto(photoFile, form.date)
const pr = await api.uploadPhoto(photoFile, form.date, { skipExif: true })
await api.updateMeasurement(mid, {photo_id: pr.id})
}
setSaved(true); setTimeout(()=>nav('/'), 1200)
+22 -5
View File
@@ -3,6 +3,7 @@ import { Camera, Trash2 } from 'lucide-react'
import dayjs from 'dayjs'
import { api } from '../utils/api'
import UsageBadge from '../components/UsageBadge'
import { formatPhotoCaption } from '../utils/photoDisplay'
export default function PhotosCapturePage() {
const [date, setDate] = useState(() => dayjs().format('YYYY-MM-DD'))
@@ -11,6 +12,7 @@ export default function PhotosCapturePage() {
const [uploading, setUploading] = useState(false)
const [error, setError] = useState(null)
const [big, setBig] = useState(null)
const [skipExif, setSkipExif] = useState(false)
const fileRef = useRef(null)
const load = () => api.listPhotos().then(setPhotos).catch(() => setPhotos([]))
@@ -38,7 +40,7 @@ export default function PhotosCapturePage() {
setUploading(true)
try {
for (const file of files) {
await api.uploadPhoto(file, date)
await api.uploadPhoto(file, date, { skipExif })
}
await load()
await loadUsage()
@@ -74,11 +76,12 @@ export default function PhotosCapturePage() {
{photoUsage && <UsageBadge {...photoUsage} />}
</div>
<p style={{ fontSize: 13, color: 'var(--text2)', marginTop: 0, marginBottom: 14, lineHeight: 1.5 }}>
Fortschrittsfotos unabhängig von Umfängen. Pro Tag beliebig viele Aufnahmen möglich — Datum ist das
Zuordnungsdatum (z. B. Aufnahmezeitpunkt).
Reihenfolge: zuerst <strong>EXIF</strong> (Aufnahme aus dem Bild), sonst die{' '}
<strong>Datei-Zeit</strong> (Letzte Änderung der Datei, wie vom Browser übermittelt), sonst das
Fallback-Datum unten (Standard: heute).
</p>
<div className="form-row">
<label className="form-label">Zuordnungsdatum</label>
<label className="form-label">Datum (Fallback ohne EXIF)</label>
<input
type="date"
className="form-input"
@@ -88,6 +91,20 @@ export default function PhotosCapturePage() {
/>
<span className="form-unit" />
</div>
<label
style={{
display: 'flex',
alignItems: 'center',
gap: 8,
fontSize: 13,
color: 'var(--text2)',
marginBottom: 12,
cursor: 'pointer',
}}
>
<input type="checkbox" checked={skipExif} onChange={(e) => setSkipExif(e.target.checked)} />
EXIF und Datei-Zeit ignorieren — nur das Fallback-Datum verwenden
</label>
<input
ref={fileRef}
type="file"
@@ -171,7 +188,7 @@ export default function PhotosCapturePage() {
borderRadius: 3,
}}
>
{p.date?.slice(0, 10) || p.created?.slice(0, 10)}
{formatPhotoCaption(p)}
</div>
<button
type="button"
+6 -2
View File
@@ -170,11 +170,15 @@ export const api = {
const d=await r.json();if(!r.ok)throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)));return d
},
// Photos
uploadPhoto: async (file, date = '') => {
// Photos: EXIF → File.lastModified → date-Feld → heute; skipExif nur Formular/heute
uploadPhoto: async (file, date = '', opts = {}) => {
const fd = new FormData()
fd.append('file', file)
fd.append('date', date)
if (opts.skipExif) fd.append('skip_exif', '1')
if (file && typeof file.lastModified === 'number' && !Number.isNaN(file.lastModified) && file.lastModified > 0) {
fd.append('file_last_modified', String(file.lastModified))
}
const r = await fetch(`${BASE}/photos`, { method: 'POST', body: fd, headers: hdrs() })
const d = await r.json().catch(() => ({}))
if (!r.ok) throw new Error(formatFastApiDetail(d.detail, JSON.stringify(d)))
+25
View File
@@ -0,0 +1,25 @@
import dayjs from 'dayjs'
/** Monatsschlüssel YYYY-MM für Gruppierung (EXIF-Zeit bevorzugt). */
export function photoMonthKey(p) {
if (p.taken_at) return p.taken_at.slice(0, 7)
if (p.date) {
return typeof p.date === 'string' ? p.date.slice(0, 7) : dayjs(p.date).format('YYYY-MM')
}
return (p.created || '').slice(0, 7) || '0000-00'
}
/** Sortierung: ISO-Zeit oder Datum. */
export function photoSortKey(p) {
if (p.taken_at) return p.taken_at
const d = p.date || p.created || ''
return typeof d === 'string' ? d.slice(0, 10) : dayjs(d).format('YYYY-MM-DD')
}
/** Badge / Untertitel: mit Uhrzeit wenn EXIF vorhanden. */
export function formatPhotoCaption(p) {
if (p.taken_at) return dayjs(p.taken_at).format('DD.MM.YYYY HH:mm')
const raw = p.date || p.created
if (!raw) return ''
return typeof raw === 'string' ? raw.slice(0, 10) : dayjs(raw).format('DD.MM.YYYY')
}