debug: interactive bug
This commit is contained in:
+21
-2
@@ -177,6 +177,7 @@ function setupUrlInput() {
|
|||||||
input.addEventListener('input', () => {
|
input.addEventListener('input', () => {
|
||||||
clearTimeout(_lookupTimer);
|
clearTimeout(_lookupTimer);
|
||||||
const val = input.value.trim();
|
const val = input.value.trim();
|
||||||
|
console.log('[input event] value:', val);
|
||||||
if (!val) {
|
if (!val) {
|
||||||
clearResult();
|
clearResult();
|
||||||
if (state.isAdmin) renderAdminPanel();
|
if (state.isAdmin) renderAdminPanel();
|
||||||
@@ -189,6 +190,7 @@ function setupUrlInput() {
|
|||||||
});
|
});
|
||||||
input.addEventListener('keydown', (e) => {
|
input.addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
|
console.log('[keydown] Enter pressed');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
handleEnter();
|
handleEnter();
|
||||||
}
|
}
|
||||||
@@ -196,23 +198,29 @@ function setupUrlInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function lookupUrl(url) {
|
async function lookupUrl(url) {
|
||||||
|
console.log('[lookupUrl] called with:', url);
|
||||||
if (!isValidUrl(url)) {
|
if (!isValidUrl(url)) {
|
||||||
|
console.log('[lookupUrl] invalid URL, clearing');
|
||||||
clearResult();
|
clearResult();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const res = await apiGet('/api/lookup?url=' + encodeURIComponent(url));
|
const res = await apiGet('/api/lookup?url=' + encodeURIComponent(url));
|
||||||
|
console.log('[lookupUrl] response status:', res.status);
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
console.log('[lookupUrl] found existing:', data);
|
||||||
state.currentMeta = data;
|
state.currentMeta = data;
|
||||||
renderMeta(data);
|
renderMeta(data);
|
||||||
setStatus('exists', 'ok');
|
setStatus('exists', 'ok');
|
||||||
} else {
|
} else {
|
||||||
|
console.log('[lookupUrl] not found, clearing meta');
|
||||||
state.currentMeta = null;
|
state.currentMeta = null;
|
||||||
clearResult();
|
clearResult();
|
||||||
setStatus('', '');
|
setStatus('', '');
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
console.error('[lookupUrl] error:', e);
|
||||||
clearResult();
|
clearResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +229,12 @@ async function handleEnter() {
|
|||||||
clearTimeout(_lookupTimer); // cancel any pending debounced lookup
|
clearTimeout(_lookupTimer); // cancel any pending debounced lookup
|
||||||
const input = document.getElementById('url-input');
|
const input = document.getElementById('url-input');
|
||||||
const url = input.value.trim();
|
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)) {
|
if (!url || !isValidUrl(url)) {
|
||||||
|
console.log('[handleEnter] invalid/empty URL, clearing');
|
||||||
clearResult();
|
clearResult();
|
||||||
setStatus('', '');
|
setStatus('', '');
|
||||||
return;
|
return;
|
||||||
@@ -229,16 +242,20 @@ async function handleEnter() {
|
|||||||
|
|
||||||
// If the debounced lookup already found this URL exists, just show it
|
// If the debounced lookup already found this URL exists, just show it
|
||||||
if (state.currentMeta && state.currentMeta.original_url === url) {
|
if (state.currentMeta && state.currentMeta.original_url === url) {
|
||||||
|
console.log('[handleEnter] URL already found by lookup, showing existing');
|
||||||
setStatus('exists', 'ok');
|
setStatus('exists', 'ok');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new short URL
|
// Create a new short URL
|
||||||
|
console.log('[handleEnter] proceeding to create...');
|
||||||
setStatus('creating…', '');
|
setStatus('creating…', '');
|
||||||
try {
|
try {
|
||||||
const res = await apiPost('/api/shorten', { url: url });
|
const res = await apiPost('/api/shorten', { url: url });
|
||||||
|
console.log('[handleEnter] POST /api/shorten status:', res.status);
|
||||||
if (res.status === 201) {
|
if (res.status === 201) {
|
||||||
const shortUrl = await res.text();
|
const shortUrl = await res.text();
|
||||||
|
console.log('[handleEnter] created:', shortUrl);
|
||||||
const code = shortUrl.split('/').pop();
|
const code = shortUrl.split('/').pop();
|
||||||
const metaRes = await apiGet('/api/urls/' + encodeURIComponent(code));
|
const metaRes = await apiGet('/api/urls/' + encodeURIComponent(code));
|
||||||
if (metaRes.ok) {
|
if (metaRes.ok) {
|
||||||
@@ -250,9 +267,11 @@ async function handleEnter() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const err = await res.json().catch(() => null);
|
const err = await res.json().catch(() => null);
|
||||||
|
console.log('[handleEnter] create failed:', res.status, err);
|
||||||
setStatus(err?.error || 'error', 'err');
|
setStatus(err?.error || 'error', 'err');
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
console.error('[handleEnter] network error:', e);
|
||||||
setStatus('network error', 'err');
|
setStatus('network error', 'err');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user