remove debug loggings

This commit is contained in:
2026-03-18 04:41:57 +08:00
parent 8b9fc94874
commit f7e3124797
3 changed files with 26 additions and 23 deletions
+2 -20
View File
@@ -177,7 +177,6 @@ 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();
@@ -190,7 +189,6 @@ function setupUrlInput() {
});
input.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
console.log('[keydown] Enter pressed');
e.preventDefault();
handleEnter();
}
@@ -198,29 +196,23 @@ 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 (e) {
console.error('[lookupUrl] error:', e);
} catch {
clearResult();
}
}
@@ -229,12 +221,8 @@ 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;
@@ -242,20 +230,16 @@ 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) {
@@ -267,11 +251,9 @@ 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 (e) {
console.error('[handleEnter] network error:', e);
} catch {
setStatus('network error', 'err');
}
}