1033 lines
36 KiB
HTML
1033 lines
36 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>{{ site_name }} Recounting Upload</title>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<style>
|
|
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&family=Orbitron:wght@400;500;700;900&display=swap');
|
|
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
|
|
:root {
|
|
--bg-deep: #06080e;
|
|
--bg-surface: rgba(12, 16, 28, 0.9);
|
|
--border-glow: rgba(0, 240, 255, 0.12);
|
|
--accent: #00f0ff;
|
|
--accent2: #7b2fff;
|
|
--accent3: #ff2d78;
|
|
--accent4: #00ff88;
|
|
--text-primary: #dce2f0;
|
|
--text-secondary: #6b7394;
|
|
--glass: rgba(12, 16, 32, 0.7);
|
|
--cell-bg: rgba(255, 255, 255, 0.02);
|
|
--cell-border: rgba(255, 255, 255, 0.05);
|
|
--card-bg: rgba(255, 255, 255, 0.025);
|
|
--divider: rgba(255, 255, 255, 0.05);
|
|
--input-bg: rgba(0, 0, 0, 0.4);
|
|
--radius: 18px;
|
|
}
|
|
|
|
body {
|
|
font-family: 'JetBrains Mono', monospace;
|
|
background: var(--bg-deep);
|
|
color: var(--text-primary);
|
|
min-height: 100vh;
|
|
overflow-x: hidden;
|
|
}
|
|
|
|
.bg-grid {
|
|
position: fixed; inset: 0; z-index: 0;
|
|
background-image:
|
|
linear-gradient(rgba(0, 240, 255, 0.025) 1px, transparent 1px),
|
|
linear-gradient(90deg, rgba(0, 240, 255, 0.025) 1px, transparent 1px);
|
|
background-size: 64px 64px;
|
|
animation: gridScroll 20s linear infinite;
|
|
pointer-events: none;
|
|
}
|
|
@keyframes gridScroll {
|
|
0% { background-position: 0 0; }
|
|
100% { background-position: 64px 64px; }
|
|
}
|
|
|
|
.orb {
|
|
position: fixed; border-radius: 50%; filter: blur(140px); pointer-events: none;
|
|
animation: orbFloat 18s ease-in-out infinite;
|
|
}
|
|
.orb-1 { width: 600px; height: 600px; background: rgba(0, 240, 255, 0.04); top: -250px; left: -150px; }
|
|
.orb-2 { width: 500px; height: 500px; background: rgba(123, 47, 255, 0.04); bottom: -200px; right: -100px; animation-delay: -6s; }
|
|
@keyframes orbFloat {
|
|
0%, 100% { transform: translate(0, 0) scale(1); }
|
|
33% { transform: translate(50px, -40px) scale(1.06); }
|
|
66% { transform: translate(-30px, 30px) scale(0.94); }
|
|
}
|
|
|
|
.container {
|
|
position: relative; z-index: 1;
|
|
max-width: 1600px; margin: 0 auto; padding: 24px 20px;
|
|
}
|
|
|
|
.header {
|
|
display: flex; align-items: center; justify-content: space-between;
|
|
padding: 18px 28px; margin-bottom: 24px;
|
|
background: var(--glass);
|
|
backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
|
|
border: 1px solid var(--border-glow); border-radius: var(--radius);
|
|
}
|
|
.header-left { display: flex; align-items: center; gap: 14px; }
|
|
.logo-icon {
|
|
width: 44px; height: 44px;
|
|
background: linear-gradient(135deg, var(--accent3), var(--accent2));
|
|
border-radius: 11px; font-size: 22px;
|
|
display: flex; align-items: center; justify-content: center;
|
|
box-shadow: 0 0 28px rgba(255, 45, 120, 0.35);
|
|
animation: logoPulse 3s ease-in-out infinite;
|
|
}
|
|
@keyframes logoPulse {
|
|
0%, 100% { box-shadow: 0 0 22px rgba(255, 45, 120, 0.3); }
|
|
50% { box-shadow: 0 0 44px rgba(255, 45, 120, 0.6); }
|
|
}
|
|
.header h1 {
|
|
font-family: 'Orbitron', sans-serif; font-size: 20px; font-weight: 700; letter-spacing: 3px;
|
|
background: linear-gradient(90deg, var(--accent3), var(--accent2));
|
|
-webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
|
|
}
|
|
.header-sub { font-size: 10px; color: var(--text-secondary); letter-spacing: 2px; text-transform: uppercase; }
|
|
.header-right { display: flex; align-items: center; gap: 18px; }
|
|
.live-chip {
|
|
display: flex; align-items: center; gap: 8px;
|
|
font-size: 9px; letter-spacing: 1.5px; padding: 5px 12px; border-radius: 12px;
|
|
font-weight: 600; text-transform: uppercase;
|
|
background: rgba(255, 45, 120, 0.1); color: var(--accent3);
|
|
border: 1px solid rgba(255, 45, 120, 0.2);
|
|
}
|
|
.live-chip .dot {
|
|
width: 7px; height: 7px; border-radius: 50%;
|
|
background: var(--accent3); box-shadow: 0 0 8px var(--accent3);
|
|
animation: blink 1.5s ease-in-out infinite;
|
|
}
|
|
.live-chip.live-chip-green {
|
|
background: rgba(0, 255, 136, 0.1); color: var(--accent4);
|
|
border: 1px solid rgba(0, 255, 136, 0.2);
|
|
}
|
|
.live-chip.live-chip-green .dot {
|
|
background: var(--accent4); box-shadow: 0 0 8px var(--accent4);
|
|
}
|
|
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
|
|
|
|
.section-title {
|
|
font-family: 'Orbitron', sans-serif; font-size: 13px; font-weight: 600; letter-spacing: 2px;
|
|
margin-bottom: 16px;
|
|
background: linear-gradient(90deg, var(--accent), var(--accent2));
|
|
-webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
|
|
display: inline-block;
|
|
}
|
|
|
|
.counters-row {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 20px;
|
|
margin-bottom: 24px;
|
|
}
|
|
.panel {
|
|
background: var(--glass);
|
|
backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
|
|
border: 1px solid var(--border-glow); border-radius: var(--radius);
|
|
padding: 24px 26px;
|
|
position: relative; overflow: hidden;
|
|
}
|
|
.counter-card {
|
|
text-align: center;
|
|
padding: 20px 0;
|
|
}
|
|
.counter-card .counter-val {
|
|
font-family: 'Orbitron', sans-serif; font-size: 56px; font-weight: 700;
|
|
background: linear-gradient(180deg, #fff 0%, var(--accent) 100%);
|
|
-webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
|
|
transition: all 0.15s ease;
|
|
}
|
|
.counter-card.recount .counter-val {
|
|
background: linear-gradient(180deg, #fff 0%, var(--accent3) 100%);
|
|
-webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
|
|
}
|
|
.counter-card .counter-label { font-size: 10px; color: var(--text-secondary); letter-spacing: 2px; text-transform: uppercase; }
|
|
.counter-card .counter-sub {
|
|
font-size: 9px; color: var(--text-secondary); margin-top: 6px;
|
|
}
|
|
.counter-card .counter-sub .batch-num {
|
|
font-family: 'Orbitron', sans-serif; font-size: 18px; font-weight: 700;
|
|
color: var(--accent);
|
|
}
|
|
.counter-status {
|
|
font-size: 9px; letter-spacing: 1px; margin-top: 10px;
|
|
padding: 4px 12px; border-radius: 6px; display: inline-block;
|
|
}
|
|
.counter-status.connected {
|
|
color: var(--accent4); background: rgba(0, 255, 136, 0.06);
|
|
}
|
|
.counter-status.disconnected {
|
|
color: var(--accent3); background: rgba(255, 45, 120, 0.06);
|
|
}
|
|
|
|
.bottom-row {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 20px;
|
|
margin-bottom: 24px;
|
|
}
|
|
|
|
.video-panel {
|
|
background: var(--glass);
|
|
backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
|
|
border: 1px solid var(--border-glow); border-radius: var(--radius);
|
|
padding: 12px;
|
|
position: relative; overflow: hidden;
|
|
min-height: 340px;
|
|
display: flex; flex-direction: column;
|
|
}
|
|
.video-header {
|
|
display: flex; align-items: center; justify-content: space-between;
|
|
margin-bottom: 10px; padding: 0 12px;
|
|
}
|
|
.video-container {
|
|
flex: 1; display: flex; align-items: center; justify-content: center;
|
|
background: #000; border-radius: 10px;
|
|
overflow: hidden; position: relative;
|
|
aspect-ratio: 4 / 3; max-height: 480px;
|
|
}
|
|
.video-container img {
|
|
width: 100%; height: 100%; object-fit: contain; display: block;
|
|
}
|
|
.video-placeholder {
|
|
text-align: center; color: var(--text-secondary);
|
|
padding: 40px;
|
|
}
|
|
.video-placeholder .vp-icon {
|
|
font-size: 48px; opacity: 0.15; margin-bottom: 12px;
|
|
}
|
|
.video-placeholder .vp-text {
|
|
font-size: 11px; letter-spacing: 1px;
|
|
}
|
|
.video-placeholder .vp-hint {
|
|
font-size: 9px; margin-top: 8px; opacity: 0.5;
|
|
}
|
|
.video-status {
|
|
font-size: 9px; letter-spacing: 1px;
|
|
display: flex; align-items: center; gap: 6px;
|
|
padding: 4px 10px; border-radius: 6px;
|
|
}
|
|
.video-status.connected {
|
|
color: var(--accent4); background: rgba(0, 255, 136, 0.06);
|
|
}
|
|
.video-status.stopped {
|
|
color: var(--text-secondary); background: var(--cell-bg);
|
|
}
|
|
.video-toggle {
|
|
background: none; border: 1px solid var(--cell-border);
|
|
border-radius: 8px; padding: 6px 14px; cursor: pointer;
|
|
font-family: 'JetBrains Mono', monospace;
|
|
font-size: 10px; letter-spacing: 1px;
|
|
color: var(--text-secondary);
|
|
transition: border-color 0.3s, color 0.3s;
|
|
}
|
|
.video-toggle:hover { border-color: var(--accent); color: var(--text-primary); }
|
|
.video-toggle.active { border-color: var(--accent4); color: var(--accent4); }
|
|
|
|
.file-panel {
|
|
background: var(--glass);
|
|
backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
|
|
border: 1px solid var(--border-glow); border-radius: var(--radius);
|
|
padding: 20px;
|
|
display: flex; flex-direction: column;
|
|
}
|
|
.file-panel .fp-header {
|
|
display: flex; align-items: center; justify-content: space-between;
|
|
margin-bottom: 12px;
|
|
}
|
|
.upload-area {
|
|
border: 2px dashed var(--cell-border);
|
|
border-radius: 10px;
|
|
padding: 16px;
|
|
margin-bottom: 12px;
|
|
text-align: center;
|
|
cursor: pointer;
|
|
transition: border-color 0.2s, background 0.2s;
|
|
}
|
|
.upload-area:hover {
|
|
border-color: var(--accent2);
|
|
background: rgba(123, 47, 255, 0.04);
|
|
}
|
|
.upload-area.dragover {
|
|
border-color: var(--accent);
|
|
background: rgba(0, 240, 255, 0.04);
|
|
}
|
|
.upload-area .upload-icon {
|
|
font-size: 28px;
|
|
color: var(--text-secondary);
|
|
opacity: 0.4;
|
|
margin-bottom: 6px;
|
|
}
|
|
.upload-area .upload-text {
|
|
font-size: 10px;
|
|
color: var(--text-secondary);
|
|
letter-spacing: 1px;
|
|
}
|
|
.upload-area .upload-hint {
|
|
font-size: 8px;
|
|
color: var(--text-secondary);
|
|
opacity: 0.5;
|
|
margin-top: 4px;
|
|
}
|
|
.upload-row {
|
|
display: flex;
|
|
align-items: center; gap: 8px;
|
|
margin-bottom: 14px;
|
|
}
|
|
.upload-row .file-name {
|
|
flex: 1;
|
|
font-size: 9px;
|
|
color: var(--text-secondary);
|
|
word-break: break-all;
|
|
padding: 6px 10px;
|
|
background: var(--cell-bg);
|
|
border: 1px solid var(--cell-border);
|
|
border-radius: 6px;
|
|
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|
}
|
|
.upload-row .file-name.has-file {
|
|
color: var(--accent4);
|
|
}
|
|
.file-list {
|
|
flex: 1; overflow-y: auto; max-height: 300px;
|
|
}
|
|
.file-item {
|
|
display: flex; align-items: center; justify-content: space-between;
|
|
padding: 10px 12px; margin-bottom: 4px;
|
|
background: var(--cell-bg);
|
|
border: 1px solid var(--cell-border); border-radius: 8px;
|
|
cursor: pointer; transition: border-color 0.2s, background 0.2s;
|
|
}
|
|
.file-item:hover { border-color: var(--border-glow); background: var(--card-bg); }
|
|
.file-item.selected {
|
|
border-color: var(--accent2);
|
|
background: rgba(123, 47, 255, 0.08);
|
|
}
|
|
.file-item.streaming {
|
|
border-color: var(--accent3);
|
|
background: rgba(255, 45, 120, 0.08);
|
|
}
|
|
.file-item .fi-name {
|
|
font-size: 10px; color: var(--text-primary);
|
|
word-break: break-all; flex: 1;
|
|
}
|
|
.file-item .fi-size {
|
|
font-size: 8px; color: var(--text-secondary);
|
|
margin-left: 8px; white-space: nowrap;
|
|
}
|
|
.file-item .fi-icon {
|
|
font-size: 14px; margin-right: 8px;
|
|
color: var(--accent3);
|
|
}
|
|
.file-item.streaming .fi-icon { color: var(--accent4); animation: blink 1.5s ease-in-out infinite; }
|
|
|
|
.file-item .fi-delete {
|
|
background: none; border: 1px solid var(--cell-border);
|
|
border-radius: 5px; color: var(--text-secondary);
|
|
cursor: pointer; padding: 3px 7px; margin-left: 6px;
|
|
font-size: 9px; transition: border-color 0.2s, color 0.2s;
|
|
}
|
|
.file-item .fi-delete:hover {
|
|
border-color: var(--accent3); color: var(--accent3);
|
|
}
|
|
|
|
.upload-status {
|
|
font-size: 9px; letter-spacing: 1px;
|
|
margin-top: 8px; text-align: center;
|
|
color: var(--text-secondary);
|
|
}
|
|
.upload-status.success { color: var(--accent4); }
|
|
.upload-status.error { color: var(--accent3); }
|
|
|
|
.upload-progress {
|
|
display: none;
|
|
width: 100%;
|
|
height: 6px;
|
|
background: var(--cell-bg);
|
|
border: 1px solid var(--cell-border);
|
|
border-radius: 3px;
|
|
margin-top: 10px;
|
|
overflow: hidden;
|
|
}
|
|
.upload-progress .upload-progress-bar {
|
|
height: 100%;
|
|
width: 0%;
|
|
background: linear-gradient(90deg, var(--accent), var(--accent2));
|
|
border-radius: 3px;
|
|
transition: width 0.15s ease;
|
|
}
|
|
.upload-progress-percent {
|
|
display: none;
|
|
font-size: 8px;
|
|
color: var(--text-secondary);
|
|
letter-spacing: 1px;
|
|
text-align: center;
|
|
margin-top: 4px;
|
|
}
|
|
|
|
.btn {
|
|
font-family: 'Orbitron', sans-serif; font-size: 10px; letter-spacing: 2px;
|
|
padding: 8px 16px; border-radius: 7px; cursor: pointer; font-weight: 600;
|
|
border: none; transition: opacity 0.3s, box-shadow 0.3s;
|
|
}
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, var(--accent), var(--accent2));
|
|
color: #000;
|
|
}
|
|
.btn-primary:hover { opacity: 0.85; box-shadow: 0 0 20px rgba(0, 240, 255, 0.3); }
|
|
.btn-danger {
|
|
background: linear-gradient(135deg, var(--accent3), var(--accent2));
|
|
color: #fff;
|
|
}
|
|
.btn-danger:hover { opacity: 0.85; box-shadow: 0 0 20px rgba(255, 45, 120, 0.4); }
|
|
.btn-ghost {
|
|
background: var(--cell-bg); color: var(--text-secondary);
|
|
border: 1px solid var(--cell-border);
|
|
}
|
|
.btn-ghost:hover { border-color: var(--accent); color: var(--text-primary); }
|
|
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
|
|
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
|
|
|
|
.footer {
|
|
margin-top: 24px; text-align: center;
|
|
font-size: 9px; letter-spacing: 2px; color: var(--text-secondary);
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
::-webkit-scrollbar { width: 5px; }
|
|
::-webkit-scrollbar-track { background: transparent; }
|
|
::-webkit-scrollbar-thumb { background: var(--text-secondary); border-radius: 3px; }
|
|
|
|
@media (max-width: 900px) {
|
|
.counters-row, .bottom-row { grid-template-columns: 1fr; }
|
|
.container { padding: 12px 8px; }
|
|
.header { flex-direction: column; gap: 10px; padding: 14px 16px; }
|
|
.counter-card .counter-val { font-size: 40px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="bg-grid"></div>
|
|
<div class="orb orb-1"></div>
|
|
<div class="orb orb-2"></div>
|
|
|
|
<div class="container">
|
|
<div class="header">
|
|
<div class="header-left">
|
|
<div class="logo-icon">✖</div>
|
|
<div>
|
|
<h1>{{ site_name }} Recounting Upload</h1>
|
|
<div class="header-sub">Upload MP4 & recount</div>
|
|
</div>
|
|
</div>
|
|
<div class="header-right">
|
|
<div class="live-chip live-chip-green">
|
|
<span class="dot"></span>
|
|
<span>LIVE</span>
|
|
</div>
|
|
<div class="live-chip">
|
|
<span class="dot"></span>
|
|
<span>RECOUNT</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="counters-row">
|
|
<div class="panel">
|
|
<span class="section-title" id="live-title">◉ Live Counter</span>
|
|
<div class="counter-card">
|
|
<div class="counter-val" id="live-count">--</div>
|
|
<div class="counter-label" id="live-label">Objects Counted</div>
|
|
<div class="counter-sub">Batch <span class="batch-num" id="live-batch">--</span> · <span id="live-time">--</span></div>
|
|
<div class="counter-status disconnected" id="live-status">
|
|
no file selected
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="panel">
|
|
<span class="section-title">◉ Recount Progress</span>
|
|
<div class="counter-card recount">
|
|
<div class="counter-val" id="recount-count">--</div>
|
|
<div class="counter-label">Objects Recounted</div>
|
|
<div class="counter-sub"><span id="recount-time">--</span></div>
|
|
<div class="counter-status disconnected" id="recount-status">
|
|
waiting...
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bottom-row">
|
|
<div class="video-panel">
|
|
<div class="video-header">
|
|
<span class="section-title" style="margin-bottom:0;">◉ Preview</span>
|
|
<div style="display:flex;align-items:center;gap:10px;">
|
|
<span class="video-status stopped" id="video-status">
|
|
<span style="width:6px;height:6px;border-radius:50%;background:var(--text-secondary);"></span>
|
|
stopped
|
|
</span>
|
|
<button class="video-toggle" id="videoToggle" onclick="togglePreview()">STREAM OFF</button>
|
|
</div>
|
|
</div>
|
|
<div class="video-container" id="video-container">
|
|
<div class="video-placeholder" id="video-placeholder">
|
|
<div class="vp-icon">▶</div>
|
|
<div class="vp-text">Upload an MP4 and start recount</div>
|
|
<div class="vp-hint">Preview via recount node live feed</div>
|
|
</div>
|
|
<img id="stream-img" alt="Stream" style="display:none;" />
|
|
</div>
|
|
</div>
|
|
<div class="file-panel">
|
|
<div class="fp-header">
|
|
<span class="section-title" style="margin-bottom:0;font-size:11px;">◉ Upload MP4</span>
|
|
<button class="btn btn-ghost" onclick="loadUploads()" style="font-size:8px;padding:4px 8px;">
|
|
<i class="fas fa-sync-alt"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<div class="upload-area" id="upload-drop" onclick="document.getElementById('upload-file-input').click()">
|
|
<div class="upload-icon">⇪</div>
|
|
<div class="upload-text">Click or drop .mp4 file here</div>
|
|
<div class="upload-hint">Max 512 MB</div>
|
|
</div>
|
|
|
|
<div class="upload-row">
|
|
<span class="file-name" id="pending-filename">no file chosen</span>
|
|
<button class="btn btn-ghost" id="btn-upload" onclick="uploadFile()">UPLOAD</button>
|
|
</div>
|
|
|
|
<div class="upload-progress" id="upload-progress">
|
|
<div class="upload-progress-bar" id="upload-progress-bar"></div>
|
|
</div>
|
|
<div class="upload-progress-percent" id="upload-progress-percent"></div>
|
|
<div class="upload-status" id="upload-status"></div>
|
|
|
|
<input type="file" id="upload-file-input" accept=".mp4" style="display:none"
|
|
onchange="onFilePicked(event)">
|
|
|
|
<div class="file-list" id="file-list">
|
|
<div style="font-size:10px;color:var(--text-secondary);text-align:center;padding:20px;">
|
|
No uploads yet
|
|
</div>
|
|
</div>
|
|
|
|
<div class="btn-row">
|
|
<button class="btn btn-primary" id="btn-start" onclick="startRecount()" disabled>
|
|
▶ START RECOUNT
|
|
</button>
|
|
<button class="btn btn-danger" id="btn-stop" onclick="stopRecount()" disabled>
|
|
■ STOP
|
|
</button>
|
|
<button class="btn btn-ghost" id="btn-download" onclick="downloadFile()" disabled>
|
|
<i class="fas fa-download"></i>
|
|
</button>
|
|
<button class="btn btn-ghost" id="btn-delete" onclick="deleteUpload()" disabled>
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer">{{ site_name }} Recounting Upload Dashboard</div>
|
|
</div>
|
|
|
|
<script>
|
|
let selectedFile = null;
|
|
let streaming = false;
|
|
let streamUrl = '';
|
|
let pendingUploadFile = null;
|
|
let batchResultLoaded = false;
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
loadRecountProgress();
|
|
loadUploads();
|
|
syncState();
|
|
|
|
setInterval(loadRecountProgress, 500);
|
|
setInterval(loadUploads, 30000);
|
|
setInterval(syncState, 1000);
|
|
|
|
var drop = document.getElementById('upload-drop');
|
|
drop.addEventListener('dragover', function(e) { e.preventDefault(); drop.classList.add('dragover'); });
|
|
drop.addEventListener('dragleave', function() { drop.classList.remove('dragover'); });
|
|
drop.addEventListener('drop', function(e) {
|
|
e.preventDefault();
|
|
drop.classList.remove('dragover');
|
|
if (e.dataTransfer.files.length > 0) {
|
|
setPendingFile(e.dataTransfer.files[0]);
|
|
}
|
|
});
|
|
});
|
|
|
|
function onFilePicked(event) {
|
|
if (event.target.files.length > 0) {
|
|
setPendingFile(event.target.files[0]);
|
|
}
|
|
event.target.value = '';
|
|
}
|
|
|
|
function setPendingFile(file) {
|
|
if (!file.name.toLowerCase().endsWith('.mp4')) {
|
|
showUploadStatus('Only .mp4 files allowed', 'error');
|
|
return;
|
|
}
|
|
pendingUploadFile = file;
|
|
document.getElementById('pending-filename').textContent = file.name;
|
|
document.getElementById('pending-filename').classList.add('has-file');
|
|
document.getElementById('upload-status').textContent = '';
|
|
document.getElementById('upload-status').className = 'upload-status';
|
|
showUploadProgress(false);
|
|
}
|
|
|
|
function showUploadProgress(show) {
|
|
document.getElementById('upload-progress').style.display = show ? 'block' : 'none';
|
|
document.getElementById('upload-progress-percent').style.display = show ? 'block' : 'none';
|
|
document.getElementById('upload-progress-bar').style.width = '0%';
|
|
document.getElementById('upload-progress-percent').textContent = '';
|
|
}
|
|
|
|
function showUploadStatus(msg, cls) {
|
|
var el = document.getElementById('upload-status');
|
|
el.textContent = msg;
|
|
el.className = 'upload-status ' + (cls || '');
|
|
}
|
|
|
|
function uploadFile() {
|
|
if (!pendingUploadFile) {
|
|
showUploadStatus('Pick a file first', 'error');
|
|
return;
|
|
}
|
|
var btn = document.getElementById('btn-upload');
|
|
btn.disabled = true;
|
|
btn.textContent = 'UPLOADING...';
|
|
showUploadStatus('Uploading...', '');
|
|
showUploadProgress(true);
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open('POST', '/api/upload');
|
|
|
|
xhr.upload.onprogress = function(e) {
|
|
if (e.lengthComputable) {
|
|
var pct = Math.round((e.loaded / e.total) * 100);
|
|
document.getElementById('upload-progress-bar').style.width = pct + '%';
|
|
document.getElementById('upload-progress-percent').textContent = pct + '%';
|
|
}
|
|
};
|
|
|
|
xhr.onload = function() {
|
|
showUploadProgress(false);
|
|
try {
|
|
var data = JSON.parse(xhr.responseText);
|
|
if (!data.success) {
|
|
showUploadStatus(data.error || 'Upload failed', 'error');
|
|
btn.disabled = false;
|
|
btn.textContent = 'UPLOAD';
|
|
return;
|
|
}
|
|
showUploadStatus('Upload complete: ' + data.name, 'success');
|
|
selectedFile = data.path;
|
|
document.getElementById('btn-start').disabled = false;
|
|
document.getElementById('btn-download').disabled = false;
|
|
document.getElementById('btn-delete').disabled = false;
|
|
document.getElementById('pending-filename').textContent = 'no file chosen';
|
|
document.getElementById('pending-filename').classList.remove('has-file');
|
|
pendingUploadFile = null;
|
|
loadUploads();
|
|
loadBatchResult(data.path);
|
|
} catch (err) {
|
|
showUploadStatus('Upload error: ' + err.message, 'error');
|
|
}
|
|
btn.disabled = false;
|
|
btn.textContent = 'UPLOAD';
|
|
};
|
|
|
|
xhr.onerror = function() {
|
|
showUploadProgress(false);
|
|
showUploadStatus('Upload error: network error', 'error');
|
|
btn.disabled = false;
|
|
btn.textContent = 'UPLOAD';
|
|
};
|
|
|
|
xhr.onabort = function() {
|
|
showUploadProgress(false);
|
|
showUploadStatus('Upload aborted', '');
|
|
btn.disabled = false;
|
|
btn.textContent = 'UPLOAD';
|
|
};
|
|
|
|
var form = new FormData();
|
|
form.append('file', pendingUploadFile);
|
|
xhr.send(form);
|
|
}
|
|
|
|
function selectFile(path, name) {
|
|
if (selectedFile === path) {
|
|
selectedFile = null;
|
|
batchResultLoaded = false;
|
|
document.getElementById('btn-start').disabled = true;
|
|
document.getElementById('btn-download').disabled = true;
|
|
document.getElementById('btn-delete').disabled = true;
|
|
document.getElementById('live-title').innerHTML = '◉ Live Counter';
|
|
document.getElementById('live-count').textContent = '--';
|
|
document.getElementById('live-label').textContent = 'Objects Counted';
|
|
document.getElementById('live-batch').textContent = '--';
|
|
document.getElementById('live-time').textContent = '--';
|
|
document.getElementById('live-status').textContent = 'no file selected';
|
|
document.getElementById('live-status').className = 'counter-status disconnected';
|
|
updateFileSelection();
|
|
return;
|
|
}
|
|
selectedFile = path;
|
|
document.getElementById('btn-start').disabled = false;
|
|
document.getElementById('btn-download').disabled = false;
|
|
document.getElementById('btn-delete').disabled = false;
|
|
updateFileSelection();
|
|
loadBatchResult(path);
|
|
}
|
|
|
|
function updateFileSelection() {
|
|
document.querySelectorAll('.file-item').forEach(function(el) {
|
|
var p = el.getAttribute('data-path');
|
|
if (p === selectedFile) {
|
|
el.classList.add('selected');
|
|
} else {
|
|
el.classList.remove('selected');
|
|
}
|
|
});
|
|
}
|
|
|
|
async function loadUploads() {
|
|
var container = document.getElementById('file-list');
|
|
try {
|
|
var res = await fetch('/api/uploads');
|
|
var files = await res.json();
|
|
if (!files || files.length === 0) {
|
|
container.innerHTML = '<div style="font-size:10px;color:var(--text-secondary);text-align:center;padding:20px;">No uploads yet</div>';
|
|
return;
|
|
}
|
|
container.innerHTML = files.map(function(f) {
|
|
var sel = selectedFile === f.path;
|
|
var str = streaming && selectedFile === f.path;
|
|
var cls = 'file-item';
|
|
if (str) cls += ' streaming';
|
|
else if (sel) cls += ' selected';
|
|
return '<div class="' + cls + '" onclick="event.stopPropagation(); selectFile(\'' +
|
|
f.path.replace(/'/g, "\\'") + '\', \'' + f.name.replace(/'/g, "\\'") + '\')" data-path="' +
|
|
f.path.replace(/"/g, '"') + '">' +
|
|
'<span class="fi-icon">' + (str ? '◉' : '▶') + '</span>' +
|
|
'<span class="fi-name">' + f.name + '</span>' +
|
|
'<span class="fi-size">' + formatSize(f.size) + '</span>' +
|
|
'<button class="fi-delete" onclick="event.stopPropagation(); deleteUploadRecord(\'' +
|
|
f.path.replace(/'/g, "\\'") + '\')">✕</button>' +
|
|
'</div>';
|
|
}).join('');
|
|
} catch (err) {
|
|
console.error('Failed to load uploads:', err);
|
|
}
|
|
}
|
|
|
|
function formatSize(bytes) {
|
|
if (bytes < 1024) return bytes + ' B';
|
|
if (bytes < 1048576) return (bytes / 1024).toFixed(1) + ' KB';
|
|
if (bytes < 1073741824) return (bytes / 1048576).toFixed(1) + ' MB';
|
|
return (bytes / 1073741824).toFixed(1) + ' GB';
|
|
}
|
|
|
|
async function startRecount() {
|
|
if (!selectedFile) return;
|
|
var btnStart = document.getElementById('btn-start');
|
|
btnStart.disabled = true;
|
|
btnStart.textContent = 'CONNECTING...';
|
|
|
|
lastRecountCount = null;
|
|
lastRecountTime = null;
|
|
document.getElementById('recount-count').textContent = '0';
|
|
document.getElementById('recount-time').textContent = 'resetting...';
|
|
document.getElementById('recount-status').textContent = 'resetting';
|
|
document.getElementById('recount-status').className = 'counter-status disconnected';
|
|
|
|
try {
|
|
var res = await fetch('/api/start-recount', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ path: selectedFile })
|
|
});
|
|
var data = await res.json();
|
|
if (!data.success) {
|
|
alert('Failed: ' + (data.error || 'unknown'));
|
|
btnStart.disabled = false;
|
|
btnStart.textContent = '\u25b6 START RECOUNT';
|
|
return;
|
|
}
|
|
streamUrl = data.stream_url;
|
|
streaming = true;
|
|
selectedFile = data.path;
|
|
|
|
document.getElementById('btn-stop').disabled = false;
|
|
btnStart.textContent = 'STREAMING';
|
|
btnStart.classList.add('btn-ghost');
|
|
document.getElementById('video-status').innerHTML =
|
|
'<span style="width:6px;height:6px;border-radius:50%;background:var(--accent4);box-shadow:0 0 6px var(--accent4);animation:blink 1.5s ease-in-out infinite;"></span> streaming ' + data.file;
|
|
document.getElementById('video-status').className = 'video-status connected';
|
|
} catch (err) {
|
|
alert('Error: ' + err.message);
|
|
btnStart.disabled = false;
|
|
btnStart.textContent = '\u25b6 START RECOUNT';
|
|
}
|
|
}
|
|
|
|
async function stopRecount() {
|
|
try {
|
|
await fetch('/api/stop-recount', { method: 'POST' });
|
|
} catch (err) {
|
|
alert('Failed to stop recount');
|
|
return;
|
|
}
|
|
streaming = false;
|
|
streamUrl = '';
|
|
selectedFile = null;
|
|
batchResultLoaded = false;
|
|
|
|
var img = document.getElementById('stream-img');
|
|
var placeholder = document.getElementById('video-placeholder');
|
|
img.src = '';
|
|
img.style.display = 'none';
|
|
if (placeholder) placeholder.style.display = '';
|
|
|
|
var btnStart = document.getElementById('btn-start');
|
|
var btnStop = document.getElementById('btn-stop');
|
|
btnStart.disabled = true;
|
|
btnStart.textContent = '\u25b6 START RECOUNT';
|
|
btnStart.classList.remove('btn-ghost');
|
|
btnStop.disabled = true;
|
|
|
|
document.getElementById('btn-download').disabled = true;
|
|
document.getElementById('btn-delete').disabled = true;
|
|
|
|
document.getElementById('video-status').innerHTML =
|
|
'<span style="width:6px;height:6px;border-radius:50%;background:var(--text-secondary);"></span> stopped';
|
|
document.getElementById('video-status').className = 'video-status stopped';
|
|
|
|
document.getElementById('live-title').innerHTML = '◉ Live Counter';
|
|
document.getElementById('live-count').textContent = '--';
|
|
document.getElementById('live-label').textContent = 'Objects Counted';
|
|
document.getElementById('live-batch').textContent = '--';
|
|
document.getElementById('live-time').textContent = '--';
|
|
document.getElementById('live-status').textContent = 'no file selected';
|
|
document.getElementById('live-status').className = 'counter-status disconnected';
|
|
|
|
resetVideoToggle();
|
|
loadUploads();
|
|
}
|
|
|
|
function togglePreview() {
|
|
var btn = document.getElementById('videoToggle');
|
|
var img = document.getElementById('stream-img');
|
|
var placeholder = document.getElementById('video-placeholder');
|
|
if (!streamUrl) return;
|
|
if (img.style.display === 'block') {
|
|
img.src = '';
|
|
img.style.display = 'none';
|
|
if (placeholder) placeholder.style.display = '';
|
|
btn.textContent = 'STREAM OFF';
|
|
btn.classList.remove('active');
|
|
} else {
|
|
img.src = streamUrl + '?' + Date.now();
|
|
img.style.display = 'block';
|
|
if (placeholder) placeholder.style.display = 'none';
|
|
btn.textContent = 'STREAM ON';
|
|
btn.classList.add('active');
|
|
}
|
|
}
|
|
|
|
function resetVideoToggle() {
|
|
var btn = document.getElementById('videoToggle');
|
|
var img = document.getElementById('stream-img');
|
|
var placeholder = document.getElementById('video-placeholder');
|
|
img.src = '';
|
|
img.style.display = 'none';
|
|
if (placeholder) placeholder.style.display = '';
|
|
btn.textContent = 'STREAM OFF';
|
|
btn.classList.remove('active');
|
|
}
|
|
|
|
async function syncState() {
|
|
try {
|
|
var res = await fetch('/api/state');
|
|
var data = await res.json();
|
|
applyState(data);
|
|
} catch (err) {}
|
|
}
|
|
|
|
function applyState(data) {
|
|
if (!data) return;
|
|
|
|
if (data.streaming && data.file) {
|
|
streaming = true;
|
|
streamUrl = data.stream_url;
|
|
selectedFile = data.file;
|
|
document.getElementById('btn-stop').disabled = false;
|
|
document.getElementById('btn-start').disabled = true;
|
|
document.getElementById('btn-download').disabled = false;
|
|
document.getElementById('btn-delete').disabled = false;
|
|
document.getElementById('btn-start').textContent = 'STREAMING';
|
|
document.getElementById('btn-start').classList.add('btn-ghost');
|
|
document.getElementById('video-status').innerHTML =
|
|
'<span style="width:6px;height:6px;border-radius:50%;background:var(--accent4);box-shadow:0 0 6px var(--accent4);animation:blink 1.5s ease-in-out infinite;"></span> streaming ' + (data.file_name || '');
|
|
document.getElementById('video-status').className = 'video-status connected';
|
|
|
|
loadBatchResult(data.file);
|
|
} else if (data.file && selectedFile === data.file) {
|
|
loadBatchResult(data.file);
|
|
}
|
|
}
|
|
|
|
async function loadBatchResult(filePath) {
|
|
if (!filePath) {
|
|
batchResultLoaded = false;
|
|
document.getElementById('live-title').innerHTML = '◉ Live Counter';
|
|
document.getElementById('live-label').textContent = 'Objects Counted';
|
|
document.getElementById('live-count').textContent = '--';
|
|
document.getElementById('live-batch').textContent = '--';
|
|
document.getElementById('live-time').textContent = '--';
|
|
document.getElementById('live-status').textContent = 'no file selected';
|
|
document.getElementById('live-status').className = 'counter-status disconnected';
|
|
return;
|
|
}
|
|
try {
|
|
var res = await fetch('/api/batch-result?file=' + encodeURIComponent(filePath));
|
|
var data = await res.json();
|
|
if (!data.success) {
|
|
document.getElementById('live-title').innerHTML = '◉ Live Counter';
|
|
document.getElementById('live-count').textContent = '--';
|
|
document.getElementById('live-label').textContent = 'Objects Counted';
|
|
document.getElementById('live-batch').textContent = '--';
|
|
document.getElementById('live-time').textContent = data.error || 'not found';
|
|
document.getElementById('live-status').textContent = 'not found';
|
|
document.getElementById('live-status').className = 'counter-status disconnected';
|
|
batchResultLoaded = false;
|
|
return;
|
|
}
|
|
batchResultLoaded = true;
|
|
document.getElementById('live-title').innerHTML = '◉ Batch Result';
|
|
document.getElementById('live-count').textContent = data.count.toLocaleString();
|
|
document.getElementById('live-label').textContent = 'Objects Counted';
|
|
document.getElementById('live-batch').textContent = data.batch_number;
|
|
document.getElementById('live-time').textContent = data.date;
|
|
var startStr = data.start_time ? new Date(data.start_time).toLocaleTimeString('en-US', {hour12: false, hour:'2-digit', minute:'2-digit'}) : '--';
|
|
var endStr = data.end_time ? new Date(data.end_time).toLocaleTimeString('en-US', {hour12: false, hour:'2-digit', minute:'2-digit'}) : '--';
|
|
document.getElementById('live-status').textContent = 'recorded \u00b7 ' + startStr + ' \u2013 ' + endStr;
|
|
document.getElementById('live-status').className = 'counter-status connected';
|
|
} catch (err) {
|
|
console.error('Failed to load batch result:', err);
|
|
batchResultLoaded = false;
|
|
}
|
|
}
|
|
|
|
async function deleteUploadRecord(fpath) {
|
|
var ok = confirm('Delete ' + (fpath.split('/').pop()) + '?');
|
|
if (!ok) return;
|
|
try {
|
|
var res = await fetch('/api/delete-upload', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ path: fpath })
|
|
});
|
|
var data = await res.json();
|
|
if (!data.success) {
|
|
alert('Delete failed: ' + (data.error || 'unknown'));
|
|
return;
|
|
}
|
|
if (selectedFile === fpath) {
|
|
selectedFile = null;
|
|
batchResultLoaded = false;
|
|
document.getElementById('btn-start').disabled = true;
|
|
document.getElementById('btn-download').disabled = true;
|
|
document.getElementById('btn-delete').disabled = true;
|
|
document.getElementById('live-title').innerHTML = '◉ Live Counter';
|
|
document.getElementById('live-count').textContent = '--';
|
|
document.getElementById('live-label').textContent = 'Objects Counted';
|
|
document.getElementById('live-batch').textContent = '--';
|
|
document.getElementById('live-time').textContent = '--';
|
|
document.getElementById('live-status').textContent = 'no file selected';
|
|
document.getElementById('live-status').className = 'counter-status disconnected';
|
|
}
|
|
loadUploads();
|
|
} catch (err) {
|
|
alert('Error: ' + err.message);
|
|
}
|
|
}
|
|
|
|
function deleteUpload() {
|
|
if (!selectedFile) return;
|
|
deleteUploadRecord(selectedFile);
|
|
}
|
|
|
|
function downloadFile() {
|
|
if (!selectedFile) return;
|
|
var a = document.createElement('a');
|
|
a.href = '/api/download-mp4?file=' + encodeURIComponent(selectedFile);
|
|
a.download = selectedFile.split('/').pop();
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
}
|
|
|
|
var lastRecountCount = null;
|
|
var lastRecountTime = null;
|
|
|
|
async function loadRecountProgress() {
|
|
var countEl = document.getElementById('recount-count');
|
|
var timeEl = document.getElementById('recount-time');
|
|
var statusEl = document.getElementById('recount-status');
|
|
try {
|
|
var res = await fetch('/api/recount-progress');
|
|
var data = await res.json();
|
|
if (!data.success) {
|
|
if (lastRecountCount === null) {
|
|
countEl.textContent = '--';
|
|
timeEl.textContent = data.error || 'unreachable';
|
|
}
|
|
statusEl.className = 'counter-status disconnected';
|
|
statusEl.textContent = 'completed';
|
|
return;
|
|
}
|
|
lastRecountCount = data.count.toLocaleString();
|
|
countEl.textContent = lastRecountCount;
|
|
if (data.last_detection_time) {
|
|
var d = new Date(data.last_detection_time);
|
|
lastRecountTime = d.toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
timeEl.textContent = lastRecountTime;
|
|
} else if (lastRecountTime) {
|
|
timeEl.textContent = lastRecountTime;
|
|
} else {
|
|
timeEl.textContent = 'waiting...';
|
|
}
|
|
statusEl.className = 'counter-status connected';
|
|
statusEl.textContent = 'connected';
|
|
} catch (err) {
|
|
if (lastRecountCount === null) {
|
|
countEl.textContent = '--';
|
|
timeEl.textContent = 'unreachable';
|
|
}
|
|
statusEl.className = 'counter-status disconnected';
|
|
statusEl.textContent = 'completed';
|
|
}
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|