Initial commit

App works locally. No intention to bring this live.
This commit is contained in:
2026-04-23 16:35:12 -04:00
commit de3ab5d2a6
12 changed files with 1975 additions and 0 deletions

327
static/app.js Normal file
View File

@@ -0,0 +1,327 @@
import { createApp, ref, reactive, computed, onMounted, onUnmounted } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.prod.js'
const App = {
setup() {
const view = ref('settings')
const config = reactive({
sources: '',
date_start: '',
date_end: '',
destination: '',
})
const configError = ref('')
const downloadStatus = reactive({
status: 'downloading',
error_message: null,
progress: { copied: 0, total: 0, current_folder: '' },
})
let pollInterval = null
const photo = reactive({
filename: '',
folder_name: '',
folder_index: 0,
folder_count: 1,
photo_index: 0,
photo_total: 0,
already_accepted: false,
session_done: false,
loading: false,
imageUrl: '',
})
const upcomingUrls = ref([])
onMounted(async () => {
document.addEventListener('keydown', handleKey)
const res = await fetch('/api/config')
const data = await res.json()
if (data.configured) {
config.sources = data.sources.join('\n')
config.date_start = data.date_start
config.date_end = data.date_end
config.destination = data.destination
}
const statusRes = await fetch('/api/session/status')
if (statusRes.ok) {
const s = await statusRes.json()
if (s.status === 'ready') {
view.value = 'viewer'
await loadCurrentPhoto()
} else if (s.status === 'downloading') {
Object.assign(downloadStatus, s)
view.value = 'downloading'
startPolling()
}
}
})
onUnmounted(() => {
document.removeEventListener('keydown', handleKey)
stopPolling()
})
function handleKey(e) {
if (view.value !== 'viewer' || photo.loading) return
if (e.key === 'ArrowRight') sendAction('accept')
else if (e.key === 'ArrowLeft') sendAction('ignore')
else if (e.key === 'ArrowUp') sendAction('remind')
}
async function startSession() {
configError.value = ''
const sources = config.sources.split('\n').map(s => s.trim()).filter(Boolean)
if (!sources.length) { configError.value = 'Enter at least one source path'; return }
if (!config.date_start || !config.date_end) { configError.value = 'Select a date range'; return }
if (!config.destination.trim()) { configError.value = 'Enter a destination folder'; return }
const cfgRes = await fetch('/api/config', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sources,
date_start: config.date_start,
date_end: config.date_end,
destination: config.destination.trim(),
}),
})
if (!cfgRes.ok) {
const err = await cfgRes.json()
configError.value = err.detail || 'Failed to save config'
return
}
const startRes = await fetch('/api/session/start', { method: 'POST' })
if (!startRes.ok) {
const err = await startRes.json()
configError.value = err.detail || 'Failed to start session'
return
}
downloadStatus.status = 'downloading'
downloadStatus.error_message = null
downloadStatus.progress = { copied: 0, total: 0, current_folder: sources[0] }
view.value = 'downloading'
startPolling()
}
function startPolling() {
pollInterval = setInterval(async () => {
const res = await fetch('/api/session/status')
if (!res.ok) { stopPolling(); return }
const data = await res.json()
Object.assign(downloadStatus, data)
if (data.status === 'ready') {
stopPolling()
view.value = 'viewer'
await loadCurrentPhoto()
} else if (data.status === 'error' || data.status === 'empty') {
stopPolling()
}
}, 1000)
}
function stopPolling() {
if (pollInterval) { clearInterval(pollInterval); pollInterval = null }
}
function refreshUpcoming() {
const t = Date.now()
upcomingUrls.value = [1, 2, 3].map(offset => `/api/photo/image?offset=${offset}&t=${t}`)
}
async function loadCurrentPhoto() {
photo.loading = true
const res = await fetch('/api/photo/current')
if (!res.ok) { photo.loading = false; return }
const data = await res.json()
if (data.session_done) { view.value = 'done'; photo.loading = false; return }
if (data.loading) {
await new Promise(r => setTimeout(r, 2000))
return loadCurrentPhoto()
}
Object.assign(photo, data)
photo.imageUrl = `/api/photo/image?t=${Date.now()}`
photo.loading = false
refreshUpcoming()
}
async function sendAction(action) {
if (photo.loading) return
photo.loading = true
const res = await fetch('/api/photo/action', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action }),
})
if (!res.ok) { photo.loading = false; return }
const data = await res.json()
if (data.next.session_done) { view.value = 'done'; photo.loading = false; return }
if (data.next.loading) {
await new Promise(r => setTimeout(r, 2000))
return loadCurrentPhoto()
}
Object.assign(photo, data.next)
photo.imageUrl = `/api/photo/image?t=${Date.now()}`
photo.loading = false
refreshUpcoming()
}
async function resetSession() {
await fetch('/api/session', { method: 'DELETE' })
view.value = 'settings'
}
const progressPct = computed(() => {
const { copied, total } = downloadStatus.progress
if (!total) return 0
return Math.min(100, Math.round((copied / total) * 100))
})
return {
view, config, configError,
downloadStatus, progressPct,
photo, upcomingUrls,
startSession, sendAction, resetSession,
}
},
template: `
<!-- Settings -->
<div v-if="view === 'settings'" class="view settings-view">
<h1>tafa</h1>
<div class="card">
<div class="form-group">
<label>Cloud source paths (one per line)</label>
<textarea
v-model="config.sources"
rows="4"
placeholder="remote:Photos/2024&#10;remote:Photos/2025"
></textarea>
</div>
<div class="form-row">
<div class="form-group">
<label>From</label>
<input type="date" v-model="config.date_start">
</div>
<div class="form-group">
<label>To</label>
<input type="date" v-model="config.date_end">
</div>
</div>
<div class="form-group">
<label>Accepted photos destination</label>
<input
type="text"
v-model="config.destination"
placeholder="/home/user/Pictures/Accepted"
>
</div>
<p v-if="configError" class="error-msg">{{ configError }}</p>
<button class="btn btn-primary" @click="startSession">Start Triage</button>
</div>
</div>
<!-- Downloading -->
<div v-else-if="view === 'downloading'" class="view downloading-view">
<template v-if="downloadStatus.status === 'downloading'">
<template v-if="downloadStatus.progress.phase === 'scanning'">
<h2>Scanning folder…</h2>
<p class="folder-label">{{ downloadStatus.progress.current_folder }}</p>
<div class="progress-bar">
<div class="progress-fill progress-indeterminate"></div>
</div>
<p class="progress-text">Reading file list from cloud</p>
</template>
<template v-else>
<h2>Downloading photos…</h2>
<p class="folder-label">{{ downloadStatus.progress.current_folder }}</p>
<div class="progress-bar">
<div class="progress-fill" :style="{ width: progressPct + '%' }"></div>
</div>
<p class="progress-text">
{{ downloadStatus.progress.copied }} / {{ downloadStatus.progress.total }} files
</p>
</template>
</template>
<template v-else-if="downloadStatus.status === 'error'">
<h2>Download failed</h2>
<p class="error-msg">{{ downloadStatus.error_message }}</p>
<button class="btn btn-secondary" @click="resetSession">Back to Settings</button>
</template>
<template v-else-if="downloadStatus.status === 'empty'">
<h2>No photos found</h2>
<p style="color:#999">No photos matched the selected date range.</p>
<button class="btn btn-secondary" @click="resetSession">Back to Settings</button>
</template>
</div>
<!-- Viewer -->
<div v-else-if="view === 'viewer'" class="view viewer-view">
<div class="viewer-header">
<span class="folder-info">
{{ photo.folder_name }}
<span v-if="photo.folder_count > 1"> ({{ photo.folder_index + 1 }}/{{ photo.folder_count }})</span>
</span>
<span class="photo-progress">{{ photo.photo_index + 1 }} / {{ photo.photo_total }}</span>
</div>
<div class="viewer-image">
<div v-if="photo.loading" class="loading-overlay">Loading…</div>
<div v-if="photo.already_accepted" class="already-accepted-badge">Already accepted</div>
<img
v-if="photo.imageUrl"
:src="photo.imageUrl"
:key="photo.imageUrl"
:class="{ 'already-accepted': photo.already_accepted }"
@load="photo.loading = false"
>
</div>
<div class="viewer-actions">
<button class="btn btn-ignore" :disabled="photo.loading" @click="sendAction('ignore')">
← Ignore
</button>
<button class="btn btn-remind" :disabled="photo.loading" @click="sendAction('remind')">
↑ Remind Me
</button>
<button class="btn btn-accept" :disabled="photo.loading" @click="sendAction('accept')">
Accept →
</button>
</div>
<div class="upcoming-strip">
<span class="upcoming-label">Up next</span>
<div class="upcoming-thumbs">
<img
v-for="(url, i) in upcomingUrls"
:key="url"
:src="url"
class="upcoming-thumb"
@error="e => e.target.style.display = 'none'"
>
</div>
</div>
<div class="key-hints">
<span class="key-hint"><kbd>←</kbd> ignore</span>
<span class="key-hint"><kbd>↑</kbd> remind me</span>
<span class="key-hint"><kbd>→</kbd> accept</span>
</div>
</div>
<!-- Done -->
<div v-else-if="view === 'done'" class="view done-view">
<h2>All done! 🎉</h2>
<p>Accepted photos are in:</p>
<code>{{ config.destination }}</code>
<button class="btn btn-primary" style="margin-top:0.5rem; max-width:240px" @click="resetSession">
Start New Session
</button>
</div>
`
}
createApp(App).mount('#app')

13
static/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>tafa</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<div id="app"></div>
<script type="module" src="/static/app.js"></script>
</body>
</html>

371
static/style.css Normal file
View File

@@ -0,0 +1,371 @@
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background: #111;
color: #e8e8e8;
height: 100vh;
overflow: hidden;
}
/* ── Layout ──────────────────────────────────────────────────────────── */
.view {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
padding: 1.5rem;
}
/* ── Settings ────────────────────────────────────────────────────────── */
.settings-view h1 {
font-size: 2rem;
font-weight: 700;
letter-spacing: 0.1em;
margin-bottom: 2rem;
color: #fff;
}
.card {
background: #1e1e1e;
border: 1px solid #333;
border-radius: 12px;
padding: 2rem;
width: 100%;
max-width: 480px;
display: flex;
flex-direction: column;
gap: 1.2rem;
}
.form-group {
display: flex;
flex-direction: column;
gap: 0.4rem;
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
}
label {
font-size: 0.8rem;
color: #999;
text-transform: uppercase;
letter-spacing: 0.05em;
}
input[type="text"],
input[type="date"],
textarea {
background: #2a2a2a;
border: 1px solid #444;
border-radius: 6px;
color: #e8e8e8;
font-size: 0.95rem;
padding: 0.6rem 0.75rem;
width: 100%;
outline: none;
transition: border-color 0.15s;
}
input[type="text"]:focus,
input[type="date"]:focus,
textarea:focus {
border-color: #666;
}
textarea {
resize: vertical;
min-height: 90px;
font-family: monospace;
font-size: 0.85rem;
}
.error-msg {
color: #f87171;
font-size: 0.85rem;
text-align: center;
}
/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 0.95rem;
font-weight: 600;
padding: 0.7rem 1.4rem;
transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-primary {
background: #3b82f6;
color: #fff;
width: 100%;
padding: 0.85rem;
}
.btn-primary:hover:not(:disabled) { opacity: 0.88; }
.btn-secondary {
background: #2a2a2a;
border: 1px solid #444;
color: #e8e8e8;
}
.btn-secondary:hover:not(:disabled) { background: #333; }
/* ── Downloading ─────────────────────────────────────────────────────── */
.downloading-view {
gap: 1.2rem;
text-align: center;
max-width: 480px;
}
.downloading-view h2 { font-size: 1.4rem; }
.folder-label {
font-family: monospace;
font-size: 0.85rem;
color: #999;
word-break: break-all;
}
.progress-bar {
width: 100%;
max-width: 360px;
height: 8px;
background: #2a2a2a;
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: #3b82f6;
border-radius: 4px;
transition: width 0.4s ease;
}
.progress-indeterminate {
width: 40%;
animation: slide 1.4s infinite ease-in-out;
}
@keyframes slide {
0% { transform: translateX(-100%); }
100% { transform: translateX(350%); }
}
.progress-text {
font-size: 0.85rem;
color: #888;
}
/* ── Viewer ──────────────────────────────────────────────────────────── */
.viewer-view {
padding: 0;
justify-content: stretch;
}
.viewer-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.7rem 1.2rem;
background: #1a1a1a;
border-bottom: 1px solid #2a2a2a;
flex-shrink: 0;
width: 100%;
}
.folder-info {
font-size: 0.85rem;
color: #aaa;
}
.photo-progress {
font-size: 0.85rem;
color: #aaa;
font-variant-numeric: tabular-nums;
}
.viewer-image {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
position: relative;
background: #0d0d0d;
}
.viewer-image img.already-accepted {
box-shadow: 0 0 0 4px #22c55e;
border-radius: 2px;
}
.already-accepted-badge {
position: absolute;
top: 1rem;
left: 50%;
transform: translateX(-50%);
background: #15803d;
color: #dcfce7;
font-size: 0.8rem;
font-weight: 600;
padding: 0.3rem 0.85rem;
border-radius: 999px;
z-index: 10;
letter-spacing: 0.04em;
}
.viewer-image img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
display: block;
}
.loading-overlay {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
background: rgba(13, 13, 13, 0.7);
font-size: 0.9rem;
color: #666;
}
.upcoming-strip {
display: flex;
align-items: center;
gap: 0.75rem;
padding: 0.5rem 1.5rem;
background: #161616;
border-top: 1px solid #2a2a2a;
flex-shrink: 0;
width: 100%;
}
.upcoming-label {
font-size: 0.7rem;
color: #555;
text-transform: uppercase;
letter-spacing: 0.05em;
white-space: nowrap;
}
.upcoming-thumbs {
display: flex;
gap: 0.5rem;
}
.upcoming-thumb {
width: 64px;
height: 64px;
object-fit: cover;
border-radius: 4px;
border: 1px solid #333;
opacity: 0.7;
transition: opacity 0.15s;
}
.upcoming-thumb:hover { opacity: 1; }
.viewer-actions {
display: flex;
justify-content: center;
gap: 1.5rem;
padding: 1rem 1.5rem;
background: #1a1a1a;
border-top: 1px solid #2a2a2a;
flex-shrink: 0;
width: 100%;
}
.btn-ignore {
background: #7f1d1d;
color: #fca5a5;
min-width: 130px;
}
.btn-ignore:hover:not(:disabled) { background: #991b1b; }
.btn-remind {
background: #78350f;
color: #fcd34d;
min-width: 130px;
}
.btn-remind:hover:not(:disabled) { background: #92400e; }
.btn-accept {
background: #14532d;
color: #86efac;
min-width: 130px;
}
.btn-accept:hover:not(:disabled) { background: #166534; }
/* ── Done ────────────────────────────────────────────────────────────── */
.done-view {
gap: 1.2rem;
text-align: center;
}
.done-view h2 { font-size: 1.6rem; }
.done-view p { color: #999; }
.done-view code {
background: #2a2a2a;
border: 1px solid #444;
border-radius: 6px;
display: inline-block;
font-size: 0.85rem;
padding: 0.4rem 0.75rem;
color: #86efac;
word-break: break-all;
max-width: 480px;
}
/* ── Keyboard hint ───────────────────────────────────────────────────── */
.key-hints {
display: flex;
gap: 1.2rem;
justify-content: center;
margin-top: 0.3rem;
}
.key-hint {
font-size: 0.75rem;
color: #555;
display: flex;
align-items: center;
gap: 0.3rem;
}
kbd {
background: #2a2a2a;
border: 1px solid #444;
border-radius: 4px;
font-size: 0.7rem;
padding: 0.15rem 0.4rem;
color: #999;
}