seawolf2357's picture
Update app.py
907dfcf verified
raw
history blame
25 kB
from flask import Flask, render_template, request, jsonify, session
import os
from datetime import timedelta
app = Flask(__name__)
app.secret_key = os.urandom(24)
app.permanent_session_lifetime = timedelta(days=7)
# Hugging Face URL λͺ©λ‘ - 일뢀 URL은 미리 μ’‹μ•„μš” μƒνƒœλ‘œ μ„€μ •
# 'is_liked'λ₯Ό true둜 μ„€μ •ν•œ URL은 항상 μ’‹μ•„μš” μƒνƒœλ‘œ ν‘œμ‹œλ¨
HUGGINGFACE_URLS = [
{"url": "https://huggingface.co/spaces/ginipick/Tech_Hangman_Game", "is_liked": True},
{"url": "https://huggingface.co/spaces/openfree/deepseek_r1_API", "is_liked": False},
{"url": "https://huggingface.co/spaces/ginipick/open_Deep-Research", "is_liked": True},
{"url": "https://huggingface.co/spaces/aiqmaster/open-deep-research", "is_liked": False},
{"url": "https://huggingface.co/spaces/seawolf2357/DeepSeek-R1-32b-search", "is_liked": True},
{"url": "https://huggingface.co/spaces/ginigen/LLaDA", "is_liked": False},
{"url": "https://huggingface.co/spaces/VIDraft/PHI4-Multimodal", "is_liked": True},
{"url": "https://huggingface.co/spaces/ginigen/Ovis2-8B", "is_liked": False},
{"url": "https://huggingface.co/spaces/ginigen/Graph-Mind", "is_liked": True},
{"url": "https://huggingface.co/spaces/ginigen/Workflow-Canvas", "is_liked": False},
{"url": "https://huggingface.co/spaces/ginigen/Design", "is_liked": True},
{"url": "https://huggingface.co/spaces/ginigen/Diagram", "is_liked": False},
{"url": "https://huggingface.co/spaces/ginigen/Mockup", "is_liked": True},
{"url": "https://huggingface.co/spaces/ginigen/Infographic", "is_liked": False},
{"url": "https://huggingface.co/spaces/ginigen/Flowchart", "is_liked": True},
{"url": "https://huggingface.co/spaces/aiqcamp/FLUX-Vision", "is_liked": False},
{"url": "https://huggingface.co/spaces/ginigen/VoiceClone-TTS", "is_liked": True},
{"url": "https://huggingface.co/spaces/openfree/Perceptron-Network", "is_liked": False},
{"url": "https://huggingface.co/spaces/openfree/Article-Generator", "is_liked": True},
]
# URL의 λ§ˆμ§€λ§‰ 뢀뢄을 제λͺ©μœΌλ‘œ μΆ”μΆœ
def extract_title(url):
parts = url.split("/")
title = parts[-1] if parts else ""
return title.replace("_", " ").replace("-", " ")
@app.route('/')
def home():
return render_template('index.html')
@app.route('/api/login', methods=['POST'])
def login():
token = request.form.get('token', '')
if not token:
return jsonify({'success': False, 'message': '토큰을 μž…λ ₯ν•΄μ£Όμ„Έμš”.'})
# κ°„λ‹¨νžˆ 토큰 길이만 검사 (μ‹€μ œλ‘œλŠ” 더 λ³΅μž‘ν•œ 검증 ν•„μš”)
if len(token) < 5:
return jsonify({'success': False, 'message': 'μœ νš¨ν•˜μ§€ μ•Šμ€ ν† ν°μž…λ‹ˆλ‹€.'})
# ν† ν°μ˜ 첫 κΈ€μžλ₯Ό μ‚¬μš©μž μ΄λ¦„μœΌλ‘œ μ„€μ • (ν…ŒμŠ€νŠΈμš©)
username = f"μ‚¬μš©μž_{token[:3]}"
# μ„Έμ…˜μ— μ €μž₯
session['username'] = username
return jsonify({
'success': True,
'username': username
})
@app.route('/api/logout', methods=['POST'])
def logout():
session.pop('username', None)
return jsonify({'success': True})
@app.route('/api/urls', methods=['GET'])
def get_urls():
results = []
for url_item in HUGGINGFACE_URLS:
url = url_item["url"]
is_liked = url_item["is_liked"]
title = extract_title(url)
results.append({
'url': url,
'title': title,
'is_liked': is_liked
})
return jsonify(results)
@app.route('/api/toggle-like', methods=['POST'])
def toggle_like():
if 'username' not in session:
return jsonify({'success': False, 'message': '둜그인이 ν•„μš”ν•©λ‹ˆλ‹€.'})
data = request.json
url = data.get('url')
if not url:
return jsonify({'success': False, 'message': 'URL이 ν•„μš”ν•©λ‹ˆλ‹€.'})
# URL λͺ©λ‘μ—μ„œ ν•΄λ‹Ή URL μ°ΎκΈ°
for url_item in HUGGINGFACE_URLS:
if url_item["url"] == url:
# μ’‹μ•„μš” μƒνƒœ ν† κΈ€
url_item["is_liked"] = not url_item["is_liked"]
return jsonify({
'success': True,
'is_liked': url_item["is_liked"],
'message': 'μ’‹μ•„μš”λ₯Ό μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.' if url_item["is_liked"] else 'μ’‹μ•„μš”λ₯Ό μ·¨μ†Œν–ˆμŠ΅λ‹ˆλ‹€.'
})
return jsonify({'success': False, 'message': 'ν•΄λ‹Ή URL을 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.'})
@app.route('/api/session-status', methods=['GET'])
def session_status():
return jsonify({
'logged_in': 'username' in session,
'username': session.get('username')
})
if __name__ == '__main__':
os.makedirs('templates', exist_ok=True)
with open('templates/index.html', 'w', encoding='utf-8') as f:
f.write('''
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hugging Face URL μΉ΄λ“œ 리슀트</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
color: #333;
background-color: #f4f5f7;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 1rem;
}
.header {
background-color: #fff;
padding: 1rem;
border-radius: 8px;
margin-bottom: 1rem;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.user-controls {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
.filter-controls {
background-color: #fff;
padding: 1rem;
border-radius: 8px;
margin-bottom: 1rem;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
display: flex;
justify-content: space-between;
align-items: center;
}
input[type="password"],
input[type="text"] {
padding: 0.5rem;
border: 1px solid #ddd;
border-radius: 4px;
margin-right: 5px;
}
button {
padding: 0.5rem 1rem;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s;
}
button:hover {
background-color: #45a049;
}
button.logout {
background-color: #f44336;
}
button.logout:hover {
background-color: #d32f2f;
}
.token-help {
margin-top: 0.5rem;
font-size: 0.8rem;
color: #666;
}
.token-help a {
color: #4CAF50;
text-decoration: none;
}
.token-help a:hover {
text-decoration: underline;
}
.cards-container {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.card {
border: 1px solid #ddd;
border-radius: 8px;
padding: 1rem;
width: 300px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
position: relative;
background-color: #fff;
transition: all 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.card.liked {
border-color: #ff4757;
background-color: #ffebee;
}
.card-header {
margin-bottom: 0.5rem;
padding-right: 40px; /* μ’‹μ•„μš” λ²„νŠΌ 곡간 */
}
.card-title {
font-size: 1.2rem;
margin: 0 0 0.5rem 0;
color: #333;
}
.card a {
text-decoration: none;
color: #2980b9;
word-break: break-all;
display: block;
font-size: 0.9rem;
}
.card a:hover {
text-decoration: underline;
}
.like-button {
position: absolute;
top: 1rem;
right: 1rem;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
border: none;
background: transparent;
font-size: 1.5rem;
cursor: pointer;
transition: all 0.3s ease;
color: #ddd;
}
.like-button:hover {
transform: scale(1.2);
}
.like-button.liked {
color: #ff4757;
}
.like-badge {
position: absolute;
top: -5px;
left: -5px;
background-color: #ff4757;
color: white;
padding: 0.2rem 0.5rem;
border-radius: 4px;
font-size: 0.7rem;
font-weight: bold;
}
.like-status {
background-color: #fff;
padding: 1rem;
border-radius: 8px;
margin-bottom: 1rem;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
display: none;
}
.like-status strong {
color: #ff4757;
}
.status-message {
position: fixed;
bottom: 20px;
right: 20px;
padding: 1rem;
border-radius: 8px;
display: none;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
z-index: 1000;
max-width: 300px;
}
.success {
background-color: #4CAF50;
color: white;
}
.error {
background-color: #f44336;
color: white;
}
.loading {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(255, 255, 255, 0.8);
display: none;
justify-content: center;
align-items: center;
z-index: 1000;
}
.spinner {
width: 40px;
height: 40px;
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.filter-toggle {
display: flex;
}
.filter-toggle button {
margin-right: 0.5rem;
background-color: #f0f0f0;
color: #333;
}
.filter-toggle button.active {
background-color: #4CAF50;
color: white;
}
.login-section {
margin-top: 1rem;
}
.logged-in-section {
display: none;
margin-top: 1rem;
}
@media (max-width: 768px) {
.user-controls {
flex-direction: column;
align-items: flex-start;
}
.user-controls > div {
margin-bottom: 1rem;
}
.filter-controls {
flex-direction: column;
}
.filter-controls > div {
margin-bottom: 0.5rem;
}
.card {
width: 100%;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<div class="user-controls">
<div>
<span>ν—ˆκΉ…νŽ˜μ΄μŠ€ 계정: </span>
<span id="currentUser">λ‘œκ·ΈμΈλ˜μ§€ μ•ŠμŒ</span>
</div>
<div id="loginSection" class="login-section">
<input type="password" id="tokenInput" placeholder="ν—ˆκΉ…νŽ˜μ΄μŠ€ API 토큰 μž…λ ₯" />
<button id="loginButton">μΈμ¦ν•˜κΈ°</button>
<div class="token-help">
API 토큰은 <a href="https://huggingface.co/settings/tokens" target="_blank">ν—ˆκΉ…νŽ˜μ΄μŠ€ 토큰 νŽ˜μ΄μ§€</a>μ—μ„œ 생성할 수 μžˆμŠ΅λ‹ˆλ‹€.
</div>
</div>
<div id="loggedInSection" class="logged-in-section">
<button id="logoutButton" class="logout">λ‘œκ·Έμ•„μ›ƒ</button>
</div>
</div>
</div>
<div id="likeStatus" class="like-status">
<div id="likeStatsText">총 <span id="totalUrlCount">0</span>개 쀑 <strong><span id="likedUrlCount">0</span>개</strong>의 URL을 μ’‹μ•„μš” ν–ˆμŠ΅λ‹ˆλ‹€.</div>
</div>
<div class="filter-controls">
<div>
<input type="text" id="searchInput" placeholder="URL λ˜λŠ” 제λͺ©μœΌλ‘œ 검색" style="width: 300px;" />
</div>
<div class="filter-toggle">
<button id="allUrlsBtn" class="active">전체 보기</button>
<button id="likedUrlsBtn">μ’‹μ•„μš”λ§Œ 보기</button>
</div>
</div>
<div id="statusMessage" class="status-message"></div>
<div id="loadingIndicator" class="loading">
<div class="spinner"></div>
</div>
<div id="cardsContainer" class="cards-container"></div>
</div>
<script>
// DOM μš”μ†Œ μ°Έμ‘°
const elements = {
tokenInput: document.getElementById('tokenInput'),
loginButton: document.getElementById('loginButton'),
logoutButton: document.getElementById('logoutButton'),
currentUser: document.getElementById('currentUser'),
cardsContainer: document.getElementById('cardsContainer'),
loadingIndicator: document.getElementById('loadingIndicator'),
statusMessage: document.getElementById('statusMessage'),
searchInput: document.getElementById('searchInput'),
loginSection: document.getElementById('loginSection'),
loggedInSection: document.getElementById('loggedInSection'),
likeStatus: document.getElementById('likeStatus'),
totalUrlCount: document.getElementById('totalUrlCount'),
likedUrlCount: document.getElementById('likedUrlCount'),
allUrlsBtn: document.getElementById('allUrlsBtn'),
likedUrlsBtn: document.getElementById('likedUrlsBtn')
};
// μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μƒνƒœ
const state = {
username: null,
allURLs: [],
isLoading: false,
viewMode: 'all' // 'all' λ˜λŠ” 'liked'
};
// λ‘œλ”© μƒνƒœ ν‘œμ‹œ ν•¨μˆ˜
function setLoading(isLoading) {
state.isLoading = isLoading;
elements.loadingIndicator.style.display = isLoading ? 'flex' : 'none';
}
// μƒνƒœ λ©”μ‹œμ§€ ν‘œμ‹œ ν•¨μˆ˜
function showMessage(message, isError = false) {
elements.statusMessage.textContent = message;
elements.statusMessage.className = `status-message ${isError ? 'error' : 'success'}`;
elements.statusMessage.style.display = 'block';
// 3초 ν›„ λ©”μ‹œμ§€ 사라짐
setTimeout(() => {
elements.statusMessage.style.display = 'none';
}, 3000);
}
// API 였λ₯˜ 처리 ν•¨μˆ˜
async function handleApiResponse(response) {
if (!response.ok) {
const errorText = await response.text();
throw new Error(`API 였λ₯˜ (${response.status}): ${errorText}`);
}
return response.json();
}
// μ’‹μ•„μš” 톡계 μ—…λ°μ΄νŠΈ
function updateLikeStats() {
const totalCount = state.allURLs.length;
const likedCount = state.allURLs.filter(item => item.is_liked).length;
elements.totalUrlCount.textContent = totalCount;
elements.likedUrlCount.textContent = likedCount;
}
// μ„Έμ…˜ μƒνƒœ 확인
async function checkSessionStatus() {
try {
const response = await fetch('/api/session-status');
const data = await handleApiResponse(response);
if (data.logged_in) {
state.username = data.username;
elements.currentUser.textContent = data.username;
elements.loginSection.style.display = 'none';
elements.loggedInSection.style.display = 'block';
elements.likeStatus.style.display = 'block';
// URL λͺ©λ‘ λ‘œλ“œ
loadUrls();
}
} catch (error) {
console.error('μ„Έμ…˜ μƒνƒœ 확인 였λ₯˜:', error);
}
}
// 둜그인 처리
async function login(token) {
if (!token.trim()) {
showMessage('토큰을 μž…λ ₯ν•΄μ£Όμ„Έμš”.', true);
return;
}
setLoading(true);
try {
const formData = new FormData();
formData.append('token', token);
const response = await fetch('/api/login', {
method: 'POST',
body: formData
});
const data = await handleApiResponse(response);
if (data.success) {
state.username = data.username;
elements.currentUser.textContent = state.username;
elements.loginSection.style.display = 'none';
elements.loggedInSection.style.display = 'block';
elements.likeStatus.style.display = 'block';
showMessage(`${state.username}λ‹˜μœΌλ‘œ λ‘œκ·ΈμΈλ˜μ—ˆμŠ΅λ‹ˆλ‹€.`);
// URL λͺ©λ‘ λ‘œλ“œ
loadUrls();
} else {
showMessage(data.message || 'λ‘œκ·ΈμΈμ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.', true);
}
} catch (error) {
console.error('둜그인 였λ₯˜:', error);
showMessage(`둜그인 였λ₯˜: ${error.message}`, true);
} finally {
setLoading(false);
}
}
// λ‘œκ·Έμ•„μ›ƒ 처리
async function logout() {
setLoading(true);
try {
const response = await fetch('/api/logout', {
method: 'POST'
});
const data = await handleApiResponse(response);
if (data.success) {
state.username = null;
state.allURLs = [];
elements.currentUser.textContent = 'λ‘œκ·ΈμΈλ˜μ§€ μ•ŠμŒ';
elements.tokenInput.value = '';
elements.loginSection.style.display = 'block';
elements.loggedInSection.style.display = 'none';
elements.likeStatus.style.display = 'none';
showMessage('λ‘œκ·Έμ•„μ›ƒλ˜μ—ˆμŠ΅λ‹ˆλ‹€.');
// μΉ΄λ“œ μ΄ˆκΈ°ν™”
elements.cardsContainer.innerHTML = '';
}
} catch (error) {
console.error('λ‘œκ·Έμ•„μ›ƒ 였λ₯˜:', error);
showMessage(`λ‘œκ·Έμ•„μ›ƒ 였λ₯˜: ${error.message}`, true);
} finally {
setLoading(false);
}
}
// URL λͺ©λ‘ λ‘œλ“œ
async function loadUrls() {
setLoading(true);
try {
const response = await fetch('/api/urls');
const urls = await handleApiResponse(response);
// URL 및 μ’‹μ•„μš” μƒνƒœ μ €μž₯
state.allURLs = urls;
// 필터링 및 λ Œλ”λ§
filterAndRenderCards();
// μ’‹μ•„μš” 톡계 μ—…λ°μ΄νŠΈ
updateLikeStats();
} catch (error) {
console.error('URL λͺ©λ‘ λ‘œλ“œ 였λ₯˜:', error);
showMessage(`URL λ‘œλ“œ 였λ₯˜: ${error.message}`, true);
} finally {
setLoading(false);
}
}
// 필터링 및 μΉ΄λ“œ λ Œλ”λ§
function filterAndRenderCards() {
const searchText = elements.searchInput.value.toLowerCase();
// 필터링 적용
const filteredUrls = state.allURLs.filter(item => {
const { url, title, is_liked } = item;
// μ’‹μ•„μš” 필터링 (μ’‹μ•„μš”λ§Œ 보기 λͺ¨λ“œ)
if (state.viewMode === 'liked' && !is_liked) {
return false;
}
// 검색 필터링
if (searchText && !url.toLowerCase().includes(searchText) && !title.toLowerCase().includes(searchText)) {
return false;
}
return true;
});
renderCards(filteredUrls);
}
// μ’‹μ•„μš” ν† κΈ€
async function toggleLike(url, card) {
if (!state.username) {
showMessage('μ’‹μ•„μš”λ₯Ό ν•˜λ €λ©΄ ν—ˆκΉ…νŽ˜μ΄μŠ€ API ν† ν°μœΌλ‘œ 인증이 ν•„μš”ν•©λ‹ˆλ‹€.', true);
return;
}
setLoading(true);
try {
const response = await fetch('/api/toggle-like', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ url })
});
const data = await handleApiResponse(response);
if (data.success) {
// μƒνƒœ κ°μ²΄μ—μ„œ URL μ°ΎκΈ°
const urlItem = state.allURLs.find(item => item.url === url);
if (urlItem) {
// μ’‹μ•„μš” μƒνƒœ μ—…λ°μ΄νŠΈ
urlItem.is_liked = data.is_liked;
// μΉ΄λ“œ UI μ—…λ°μ΄νŠΈ
if (data.is_liked) {
card.classList.add('liked');
const likeBtn = card.querySelector('.like-button');
if (likeBtn) likeBtn.classList.add('liked');
// μ’‹μ•„μš” λ°°μ§€ μΆ”κ°€
if (!card.querySelector('.like-badge')) {
const likeBadge = document.createElement('div');
likeBadge.className = 'like-badge';
likeBadge.textContent = 'μ’‹μ•„μš”';
card.appendChild(likeBadge);
}
} else {
card.classList.remove('liked');
const likeBtn = card.querySelector('.like-button');
if (likeBtn) likeBtn.classList.remove('liked');
// μ’‹μ•„μš” λ°°μ§€ 제거
const likeBadge = card.querySelector('.like-badge');
if (likeBadge) card.removeChild(likeBadge);
}
}
showMessage(data.message);
// μ’‹μ•„μš” 톡계 μ—…λ°μ΄νŠΈ
updateLikeStats();
// μ’‹μ•„μš”λ§Œ 보기 λͺ¨λ“œμΈ 경우 λͺ©λ‘ λ‹€μ‹œ 필터링
if (state.viewMode === 'liked') {
filterAndRenderCards();
}
} else {
showMessage(data.message || 'μ’‹μ•„μš” μ²˜λ¦¬μ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.', true);
}
} catch (error) {
console.error('μ’‹μ•„μš” ν† κΈ€ 였λ₯˜:', error);
showMessage(`μ’‹μ•„μš” 처리 였λ₯˜: ${error.message}`, true);
} finally {
setLoading(false);
}
}
// μΉ΄λ“œ λ Œλ”λ§
function renderCards(urls) {
elements.cardsContainer.innerHTML = '';
if (!urls || urls.length === 0) {
const noResultsMsg = document.createElement('p');
noResultsMsg.textContent = 'ν‘œμ‹œν•  URL이 μ—†μŠ΅λ‹ˆλ‹€.';
noResultsMsg.style.padding = '1rem';
noResultsMsg.style.fontStyle = 'italic';
elements.cardsContainer.appendChild(noResultsMsg);
return;
}
urls.forEach(item => {
const { url, title, is_liked } = item;
// μΉ΄λ“œ 생성
const card = document.createElement('div');
card.className = `card ${is_liked ? 'liked' : ''}`;
// μΉ΄λ“œ 헀더
const cardHeader = document.createElement('div');
cardHeader.className = 'card-header';
// 제λͺ©
const titleEl = document.createElement('h3');
titleEl.className = 'card-title';
titleEl.textContent = title;
cardHeader.appendChild(titleEl);
card.appendChild(cardHeader);
// URL 링크
const linkEl = document.createElement('a');
linkEl.href = url;
linkEl.textContent = url;
linkEl.target = '_blank';
card.appendChild(linkEl);
// μ’‹μ•„μš” λ²„νŠΌ
const likeBtn = document.createElement('button');
likeBtn.className = `like-button ${is_liked ? 'liked' : ''}`;
likeBtn.innerHTML = 'β™₯';
likeBtn.title = is_liked ? 'μ’‹μ•„μš” μ·¨μ†Œ' : 'μ’‹μ•„μš”';
likeBtn.addEventListener('click', (e) => {
e.preventDefault();
toggleLike(url, card);
});
card.appendChild(likeBtn);
// μ’‹μ•„μš” λ°°μ§€ (μ’‹μ•„μš” μƒνƒœμΌ λ•Œλ§Œ)
if (is_liked) {
const likeBadge = document.createElement('div');
likeBadge.className = 'like-badge';
likeBadge.textContent = 'μ’‹μ•„μš”';
card.appendChild(likeBadge);
}
// μΉ΄λ“œ μΆ”κ°€
elements.cardsContainer.appendChild(card);
});
}
// λ·° λͺ¨λ“œ λ³€κ²½
function changeViewMode(mode) {
state.viewMode = mode;
// λ²„νŠΌ ν™œμ„±ν™” μƒνƒœ μ—…λ°μ΄νŠΈ
elements.allUrlsBtn.classList.toggle('active', mode === 'all');
elements.likedUrlsBtn.classList.toggle('active', mode === 'liked');
// μΉ΄λ“œ λ‹€μ‹œ λ Œλ”λ§
filterAndRenderCards();
}
// 이벀트 λ¦¬μŠ€λ„ˆ μ„€μ •
elements.loginButton.addEventListener('click', () => {
login(elements.tokenInput.value);
});
elements.logoutButton.addEventListener('click', logout);
// μ—”ν„° ν‚€λ‘œ 둜그인 κ°€λŠ₯ν•˜κ²Œ
elements.tokenInput.addEventListener('keypress', (event) => {
if (event.key === 'Enter') {
login(elements.tokenInput.value);
}
});
// 검색 이벀트 λ¦¬μŠ€λ„ˆ
elements.searchInput.addEventListener('input', () => {
// λ””λ°”μš΄μ‹± (μž…λ ₯ μ§€μ—° 처리)
clearTimeout(state.searchTimeout);
state.searchTimeout = setTimeout(filterAndRenderCards, 300);
});
// ν•„ν„° λ²„νŠΌ 이벀트 λ¦¬μŠ€λ„ˆ
elements.allUrlsBtn.addEventListener('click', () => changeViewMode('all'));
elements.likedUrlsBtn.addEventListener('click', () => changeViewMode('liked'));
// μ΄ˆκΈ°ν™”
checkSessionStatus();
</script>
</body>
</html>
''')
# ν—ˆκΉ…νŽ˜μ΄μŠ€ μŠ€νŽ˜μ΄μŠ€μ—μ„œλŠ” 7860 포트 μ‚¬μš©
app.run(host='0.0.0.0', port=7860)