From bee873deb6adebb469c11e0aa30bb7249c0721f5 Mon Sep 17 00:00:00 2001 From: cabbagec Date: Wed, 18 Mar 2026 04:21:46 +0800 Subject: [PATCH] debug: interactive bug --- static/app.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/static/app.js b/static/app.js index e1be7b3..b1659e6 100644 --- a/static/app.js +++ b/static/app.js @@ -177,6 +177,7 @@ function setupUrlInput() { input.addEventListener('input', () => { clearTimeout(_lookupTimer); const val = input.value.trim(); + console.log('[input event] value:', val); if (!val) { clearResult(); if (state.isAdmin) renderAdminPanel(); @@ -189,6 +190,7 @@ function setupUrlInput() { }); input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { + console.log('[keydown] Enter pressed'); e.preventDefault(); handleEnter(); } @@ -196,23 +198,29 @@ function setupUrlInput() { } async function lookupUrl(url) { + console.log('[lookupUrl] called with:', url); if (!isValidUrl(url)) { + console.log('[lookupUrl] invalid URL, clearing'); clearResult(); return; } try { const res = await apiGet('/api/lookup?url=' + encodeURIComponent(url)); + console.log('[lookupUrl] response status:', res.status); if (res.ok) { const data = await res.json(); + console.log('[lookupUrl] found existing:', data); state.currentMeta = data; renderMeta(data); setStatus('exists', 'ok'); } else { + console.log('[lookupUrl] not found, clearing meta'); state.currentMeta = null; clearResult(); setStatus('', ''); } - } catch { + } catch (e) { + console.error('[lookupUrl] error:', e); clearResult(); } } @@ -221,7 +229,12 @@ async function handleEnter() { clearTimeout(_lookupTimer); // cancel any pending debounced lookup const input = document.getElementById('url-input'); const url = input.value.trim(); + console.log('[handleEnter] url:', url); + console.log('[handleEnter] state.apiKey:', state.apiKey ? '(set)' : '(empty)'); + console.log('[handleEnter] state.currentMeta:', state.currentMeta); + if (!url || !isValidUrl(url)) { + console.log('[handleEnter] invalid/empty URL, clearing'); clearResult(); setStatus('', ''); return; @@ -229,16 +242,20 @@ async function handleEnter() { // If the debounced lookup already found this URL exists, just show it if (state.currentMeta && state.currentMeta.original_url === url) { + console.log('[handleEnter] URL already found by lookup, showing existing'); setStatus('exists', 'ok'); return; } // Create a new short URL + console.log('[handleEnter] proceeding to create...'); setStatus('creating…', ''); try { const res = await apiPost('/api/shorten', { url: url }); + console.log('[handleEnter] POST /api/shorten status:', res.status); if (res.status === 201) { const shortUrl = await res.text(); + console.log('[handleEnter] created:', shortUrl); const code = shortUrl.split('/').pop(); const metaRes = await apiGet('/api/urls/' + encodeURIComponent(code)); if (metaRes.ok) { @@ -250,9 +267,11 @@ async function handleEnter() { } } else { const err = await res.json().catch(() => null); + console.log('[handleEnter] create failed:', res.status, err); setStatus(err?.error || 'error', 'err'); } - } catch { + } catch (e) { + console.error('[handleEnter] network error:', e); setStatus('network error', 'err'); } }