Add fotos.carloselugo.com photo-upload service
Event photo upload app with OAuth2 (Google Drive), Caddy route, and env-var-driven compose config. Refresh token persists to token.json so re-auth isn't needed after container restarts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,345 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin · Fotos del Evento</title>
|
||||
|
||||
<!--
|
||||
============================================================
|
||||
VISTA DE ADMINISTRACIÓN
|
||||
Permite activar/desactivar la subida de fotos sin tocar el
|
||||
servidor. Protegida por password (ADMIN_PASSWORD en .env).
|
||||
No hay sesión persistente: la contraseña se envía en cada
|
||||
toggle, igual de simple que el host password de NI Quiz.
|
||||
============================================================
|
||||
-->
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--accent: #ec3013;
|
||||
--bg: #faf9f5;
|
||||
--text: #1a1a1a;
|
||||
--muted: #6b6b6b;
|
||||
--success: #1e8e3e;
|
||||
--error: #d93025;
|
||||
--radius: 16px;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.card {
|
||||
width: 100%;
|
||||
max-width: 380px;
|
||||
background: #fff;
|
||||
border-radius: var(--radius);
|
||||
padding: 28px 24px;
|
||||
box-shadow: 0 4px 24px rgba(0,0,0,0.08);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1.2rem;
|
||||
margin: 0 0 4px 0;
|
||||
}
|
||||
|
||||
input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
border: 1.5px solid #e0e0e0;
|
||||
border-radius: 10px;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#loginBtn {
|
||||
background: var(--text);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.toggle-row {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.toggle-row.active { display: flex; }
|
||||
|
||||
.switch {
|
||||
position: relative;
|
||||
width: 72px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.switch input { display: none; }
|
||||
|
||||
.slider {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: #d93025;
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
transition: background 0.25s ease;
|
||||
}
|
||||
|
||||
.slider::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
left: 4px;
|
||||
top: 4px;
|
||||
background: #fff;
|
||||
border-radius: 50%;
|
||||
transition: transform 0.25s ease;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background: var(--success);
|
||||
}
|
||||
|
||||
input:checked + .slider::before {
|
||||
transform: translateX(32px);
|
||||
}
|
||||
|
||||
.state-label {
|
||||
font-weight: 700;
|
||||
font-size: 1rem;
|
||||
}
|
||||
.state-label.on { color: var(--success); }
|
||||
.state-label.off { color: var(--error); }
|
||||
|
||||
#msg {
|
||||
font-size: 0.85rem;
|
||||
min-height: 18px;
|
||||
text-align: center;
|
||||
}
|
||||
#msg.error { color: var(--error); }
|
||||
#msg.success { color: var(--success); }
|
||||
|
||||
.hint {
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.divider {
|
||||
border: none;
|
||||
border-top: 1px solid #eee;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.token-section {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
.token-section.active { display: flex; }
|
||||
|
||||
#tokenBtn {
|
||||
background: #fff;
|
||||
color: var(--text);
|
||||
border: 1.5px solid var(--text);
|
||||
}
|
||||
|
||||
#tokenInfo {
|
||||
font-size: 0.78rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="card">
|
||||
<h1>🔐 Panel de administración</h1>
|
||||
|
||||
<div id="loginView">
|
||||
<input type="password" id="passwordInput" placeholder="Contraseña" autocomplete="off">
|
||||
<button id="loginBtn" style="margin-top:10px;">Entrar</button>
|
||||
</div>
|
||||
|
||||
<div class="toggle-row" id="toggleRow">
|
||||
<p class="hint">Controla si los asistentes pueden subir fotos ahora mismo.</p>
|
||||
<label class="switch">
|
||||
<input type="checkbox" id="toggleInput">
|
||||
<span class="slider"></span>
|
||||
</label>
|
||||
<div class="state-label" id="stateLabel"></div>
|
||||
|
||||
<hr class="divider">
|
||||
|
||||
<div class="token-section active" id="tokenSection">
|
||||
<p class="hint">Si las subidas empiezan a fallar por autenticación con Google, genera un token nuevo.</p>
|
||||
<button id="tokenBtn">🔄 Generar nuevo token de Google</button>
|
||||
<div id="tokenInfo">Verificando estado del token...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="msg"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
const loginView = document.getElementById('loginView');
|
||||
const passwordInput = document.getElementById('passwordInput');
|
||||
const loginBtn = document.getElementById('loginBtn');
|
||||
const toggleRow = document.getElementById('toggleRow');
|
||||
const toggleInput = document.getElementById('toggleInput');
|
||||
const stateLabel = document.getElementById('stateLabel');
|
||||
const msgEl = document.getElementById('msg');
|
||||
const tokenBtn = document.getElementById('tokenBtn');
|
||||
const tokenInfo = document.getElementById('tokenInfo');
|
||||
|
||||
let currentPassword = '';
|
||||
|
||||
function setMsg(type, text) {
|
||||
msgEl.className = type;
|
||||
msgEl.textContent = text;
|
||||
}
|
||||
|
||||
function renderState(enabled) {
|
||||
toggleInput.checked = enabled;
|
||||
stateLabel.textContent = enabled ? '✅ Subidas ACTIVADAS' : '⛔ Subidas DESACTIVADAS';
|
||||
stateLabel.className = 'state-label ' + (enabled ? 'on' : 'off');
|
||||
}
|
||||
|
||||
function formatDate(iso) {
|
||||
if (!iso) return null;
|
||||
try {
|
||||
return new Date(iso).toLocaleString('es-PR', { dateStyle: 'medium', timeStyle: 'short' });
|
||||
} catch (e) {
|
||||
return iso;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadTokenInfo() {
|
||||
try {
|
||||
const res = await fetch('/admin/oauth/token-info', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password: currentPassword })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (!res.ok || !data.success) {
|
||||
tokenInfo.textContent = 'No se pudo verificar el estado del token.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.hasToken) {
|
||||
tokenInfo.textContent = '⚠️ No hay ningún token configurado todavía.';
|
||||
} else if (data.updatedAt) {
|
||||
tokenInfo.textContent = 'Último generado desde este panel: ' + formatDate(data.updatedAt);
|
||||
} else {
|
||||
tokenInfo.textContent = 'Usando el token inicial configurado en el servidor (.env).';
|
||||
}
|
||||
} catch (err) {
|
||||
tokenInfo.textContent = 'No se pudo verificar el estado del token.';
|
||||
}
|
||||
}
|
||||
|
||||
loginBtn.addEventListener('click', async () => {
|
||||
const password = passwordInput.value.trim();
|
||||
if (!password) return;
|
||||
|
||||
setMsg('', '');
|
||||
loginBtn.disabled = true;
|
||||
loginBtn.textContent = 'Verificando...';
|
||||
|
||||
try {
|
||||
const res = await fetch('/admin/status-check', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (!res.ok || !data.success) {
|
||||
setMsg('error', '❌ ' + (data.error || 'Contraseña incorrecta.'));
|
||||
loginBtn.disabled = false;
|
||||
loginBtn.textContent = 'Entrar';
|
||||
return;
|
||||
}
|
||||
|
||||
currentPassword = password;
|
||||
loginView.style.display = 'none';
|
||||
toggleRow.classList.add('active');
|
||||
renderState(data.enabled);
|
||||
loadTokenInfo();
|
||||
} catch (err) {
|
||||
setMsg('error', '❌ Error de conexión.');
|
||||
loginBtn.disabled = false;
|
||||
loginBtn.textContent = 'Entrar';
|
||||
}
|
||||
});
|
||||
|
||||
passwordInput.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter') loginBtn.click();
|
||||
});
|
||||
|
||||
toggleInput.addEventListener('change', async () => {
|
||||
const desired = toggleInput.checked;
|
||||
toggleInput.disabled = true;
|
||||
setMsg('', '');
|
||||
|
||||
try {
|
||||
const res = await fetch('/admin/toggle', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password: currentPassword, enabled: desired })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (!res.ok || !data.success) {
|
||||
setMsg('error', '❌ ' + (data.error || 'No se pudo actualizar.'));
|
||||
toggleInput.checked = !desired; // revertir visualmente
|
||||
} else {
|
||||
renderState(data.enabled);
|
||||
setMsg('success', '✅ Estado actualizado.');
|
||||
}
|
||||
} catch (err) {
|
||||
setMsg('error', '❌ Error de conexión.');
|
||||
toggleInput.checked = !desired;
|
||||
} finally {
|
||||
toggleInput.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Redirige a Google para reautorizar. El servidor valida la contraseña
|
||||
// antes de generar la URL de consentimiento (ver /admin/oauth/start).
|
||||
tokenBtn.addEventListener('click', () => {
|
||||
window.location.href = '/admin/oauth/start?password=' + encodeURIComponent(currentPassword);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user