Spaces:
Running
Running
from flask import Flask, render_template, request, redirect, url_for, jsonify, session | |
import requests | |
import os | |
import json | |
from datetime import timedelta | |
app = Flask(__name__) | |
app.secret_key = os.urandom(24) # ์ธ์ ์ํธํ๋ฅผ ์ํ ๋น๋ฐ ํค | |
app.permanent_session_lifetime = timedelta(days=7) # ์ธ์ ์ ์ง ๊ธฐ๊ฐ ์ค์ | |
# ํ๊น ํ์ด์ค URL ๋ชฉ๋ก | |
HUGGINGFACE_URLS = [ | |
"https://huggingface.co/spaces/ginipick/Tech_Hangman_Game", | |
"https://huggingface.co/spaces/openfree/deepseek_r1_API", | |
"https://huggingface.co/spaces/ginipick/open_Deep-Research", | |
"https://huggingface.co/spaces/aiqmaster/open-deep-research", | |
"https://huggingface.co/spaces/seawolf2357/DeepSeek-R1-32b-search", | |
"https://huggingface.co/spaces/ginigen/LLaDA", | |
"https://huggingface.co/spaces/VIDraft/PHI4-Multimodal", | |
"https://huggingface.co/spaces/ginigen/Ovis2-8B", | |
"https://huggingface.co/spaces/ginigen/Graph-Mind", | |
"https://huggingface.co/spaces/ginigen/Workflow-Canvas", | |
"https://huggingface.co/spaces/ginigen/Design", | |
"https://huggingface.co/spaces/ginigen/Diagram", | |
"https://huggingface.co/spaces/ginigen/Mockup", | |
"https://huggingface.co/spaces/ginigen/Infographic", | |
"https://huggingface.co/spaces/ginigen/Flowchart", | |
"https://huggingface.co/spaces/aiqcamp/FLUX-Vision", | |
"https://huggingface.co/spaces/ginigen/VoiceClone-TTS", | |
"https://huggingface.co/spaces/openfree/Perceptron-Network", | |
"https://huggingface.co/spaces/openfree/Article-Generator", | |
] | |
# URL์์ ๋ชจ๋ธ/์คํ์ด์ค ์ ๋ณด ์ถ์ถ | |
def extract_model_info(url): | |
parts = url.split('/') | |
if len(parts) < 6: | |
return None | |
if parts[3] == 'spaces' or parts[3] == 'models': | |
return { | |
'type': parts[3], | |
'owner': parts[4], | |
'repo': parts[5], | |
'full_id': f"{parts[4]}/{parts[5]}" | |
} | |
elif len(parts) >= 5: | |
# ๋ค๋ฅธ ํ์์ URL | |
return { | |
'type': 'models', # ๊ธฐ๋ณธ๊ฐ | |
'owner': parts[3], | |
'repo': parts[4], | |
'full_id': f"{parts[3]}/{parts[4]}" | |
} | |
return None | |
# URL์ ๋ง์ง๋ง ๋ถ๋ถ์ ์ ๋ชฉ์ผ๋ก ์ถ์ถ | |
def extract_title(url): | |
parts = url.split("/") | |
title = parts[-1] if parts else "" | |
return title.replace("_", " ").replace("-", " ") | |
# ํ๊น ํ์ด์ค ์ธ์ฆ ํ์ธ | |
def validate_token(token): | |
headers = {"Authorization": f"Bearer {token}"} | |
try: | |
response = requests.get("https://huggingface.co/api/whoami", headers=headers) | |
return response.ok, response.json() if response.ok else None | |
except Exception as e: | |
print(f"ํ ํฐ ๊ฒ์ฆ ์ค๋ฅ: {e}") | |
return False, None | |
# ์ข์์ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ | |
def get_liked_repos(token): | |
headers = {"Authorization": f"Bearer {token}"} | |
endpoints = [ | |
"/api/me/likes", | |
"/api/me/liked-repos", | |
"/api/me/favorites" | |
] | |
liked_models = {} | |
for endpoint in endpoints: | |
try: | |
response = requests.get(f"https://huggingface.co{endpoint}", headers=headers) | |
if response.ok: | |
data = response.json() | |
if isinstance(data, list): | |
for model in data: | |
if isinstance(model, dict): | |
if 'owner' in model and 'name' in model: | |
liked_models[f"{model['owner']}/{model['name']}"] = True | |
elif 'id' in model: | |
liked_models[model['id']] = True | |
elif isinstance(data, dict): | |
for key in data: | |
liked_models[key] = True | |
print(f"์ข์์ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ ์ฑ๊ณต (์๋ํฌ์ธํธ: {endpoint})") | |
return liked_models | |
except Exception as e: | |
print(f"์ข์์ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ ์ค๋ฅ (์๋ํฌ์ธํธ: {endpoint}): {e}") | |
return liked_models | |
# ์ข์์ ํ ๊ธ API ํธ์ถ | |
def toggle_like(token, type_name, owner, repo, is_liked): | |
headers = {"Authorization": f"Bearer {token}"} | |
normalized_type = "spaces" if type_name == "spaces" else "models" | |
method = "DELETE" if is_liked else "POST" | |
url = f"https://huggingface.co/api/{normalized_type}/{owner}/{repo}/like" | |
try: | |
if method == "DELETE": | |
response = requests.delete(url, headers=headers) | |
else: | |
response = requests.post(url, headers=headers) | |
return response.ok, response.status_code | |
except Exception as e: | |
print(f"์ข์์ ํ ๊ธ ์ค๋ฅ: {e}") | |
return False, 500 | |
# ํํ์ด์ง ๋ผ์ฐํธ | |
def home(): | |
return render_template('index.html') | |
# ๋ก๊ทธ์ธ ์ฒ๋ฆฌ API | |
def login(): | |
token = request.form.get('token', '') | |
if not token: | |
return jsonify({'success': False, 'message': 'ํ ํฐ์ ์ ๋ ฅํด์ฃผ์ธ์.'}) | |
is_valid, user_info = validate_token(token) | |
if not is_valid or not user_info: | |
return jsonify({'success': False, 'message': '์ ํจํ์ง ์์ ํ ํฐ์ ๋๋ค.'}) | |
# ์ฌ์ฉ์ ์ด๋ฆ ์ฐพ๊ธฐ | |
username = None | |
if 'name' in user_info: | |
username = user_info['name'] | |
elif 'user' in user_info and 'username' in user_info['user']: | |
username = user_info['user']['username'] | |
elif 'username' in user_info: | |
username = user_info['username'] | |
else: | |
username = '์ธ์ฆ๋ ์ฌ์ฉ์' | |
# ์ข์์ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ | |
liked_models = get_liked_repos(token) | |
# ์ธ์ ์ ์ ์ฅ | |
session['token'] = token | |
session['username'] = username | |
session['liked_models'] = liked_models | |
return jsonify({ | |
'success': True, | |
'username': username, | |
'liked_models': liked_models | |
}) | |
# ๋ก๊ทธ์์ ์ฒ๋ฆฌ API | |
def logout(): | |
session.pop('token', None) | |
session.pop('username', None) | |
session.pop('liked_models', None) | |
return jsonify({'success': True}) | |
# URL ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ API | |
def get_urls(): | |
search_query = request.args.get('search', '').lower() | |
show_only_liked = request.args.get('liked', 'false').lower() == 'true' | |
liked_models = session.get('liked_models', {}) | |
results = [] | |
for url in HUGGINGFACE_URLS: | |
title = extract_title(url) | |
model_info = extract_model_info(url) | |
if not model_info: | |
continue | |
is_liked = model_info['full_id'] in liked_models | |
# ํํฐ๋ง ์ ์ฉ | |
if show_only_liked and not is_liked: | |
continue | |
if search_query and search_query not in url.lower() and search_query not in title.lower(): | |
continue | |
results.append({ | |
'url': url, | |
'title': title, | |
'model_info': model_info, | |
'is_liked': is_liked | |
}) | |
return jsonify(results) | |
# ์ข์์ ํ ๊ธ API | |
def api_toggle_like(): | |
if 'token' not in session: | |
return jsonify({'success': False, 'message': '๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค.'}) | |
data = request.json | |
url = data.get('url') | |
current_liked = data.get('currentLiked', False) | |
if not url: | |
return jsonify({'success': False, 'message': 'URL์ด ํ์ํฉ๋๋ค.'}) | |
model_info = extract_model_info(url) | |
if not model_info: | |
return jsonify({'success': False, 'message': '์ ํจํ์ง ์์ URL์ ๋๋ค.'}) | |
success, status_code = toggle_like( | |
session['token'], | |
model_info['type'], | |
model_info['owner'], | |
model_info['repo'], | |
current_liked | |
) | |
liked_models = session.get('liked_models', {}) | |
if success: | |
# ์ธ์ ์ ์ข์์ ์ํ ์ ๋ฐ์ดํธ | |
if current_liked: | |
if model_info['full_id'] in liked_models: | |
del liked_models[model_info['full_id']] | |
else: | |
liked_models[model_info['full_id']] = True | |
session['liked_models'] = liked_models | |
return jsonify({ | |
'success': True, | |
'new_state': not current_liked, | |
'message': f"{'์ข์์ ์ทจ์' if current_liked else '์ข์์'} ์ฑ๊ณต" | |
}) | |
else: | |
return jsonify({ | |
'success': False, | |
'message': f"API ์ค๋ฅ (์ํ ์ฝ๋: {status_code})" | |
}) | |
# ์ธ์ ์ํ ํ์ธ API | |
def session_status(): | |
return jsonify({ | |
'logged_in': 'token' in session, | |
'username': session.get('username'), | |
'liked_count': len(session.get('liked_models', {})) | |
}) | |
if __name__ == '__main__': | |
# templates ํด๋ ์์ฑ | |
os.makedirs('templates', exist_ok=True) | |
# index.html ํ์ผ ์์ฑ | |
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; | |
} | |
.container { | |
max-width: 1200px; | |
margin: 0 auto; | |
padding: 1rem; | |
} | |
.header { | |
background-color: #f0f0f0; | |
padding: 1rem; | |
border-radius: 5px; | |
margin-bottom: 1rem; | |
} | |
.user-controls { | |
display: flex; | |
justify-content: space-between; | |
align-items: center; | |
flex-wrap: wrap; | |
} | |
.filter-controls { | |
background-color: #f8f9fa; | |
padding: 1rem; | |
border-radius: 5px; | |
margin-bottom: 1rem; | |
} | |
input[type="password"], | |
input[type="text"] { | |
padding: 0.5rem; | |
border: 1px solid #ccc; | |
border-radius: 4px; | |
margin-right: 5px; | |
} | |
button { | |
padding: 0.5rem 1rem; | |
background-color: #4CAF50; | |
color: white; | |
border: none; | |
border-radius: 4px; | |
cursor: pointer; | |
} | |
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 #ccc; | |
border-radius: 5px; | |
padding: 1rem; | |
width: 300px; | |
box-shadow: 2px 2px 8px rgba(0,0,0,0.1); | |
position: relative; | |
background-color: #f9f9f9; | |
} | |
.card a { | |
text-decoration: none; | |
color: #333; | |
word-break: break-all; | |
} | |
.like-button { | |
position: absolute; | |
top: 1rem; | |
right: 1rem; | |
border: none; | |
background: transparent; | |
font-size: 1.5rem; | |
cursor: pointer; | |
transition: color 0.2s; | |
} | |
.like-button.liked { | |
color: red; | |
} | |
.like-button.not-liked { | |
color: white; | |
-webkit-text-stroke: 1px #333; | |
} | |
.status-message { | |
padding: 1rem; | |
border-radius: 4px; | |
margin-bottom: 1rem; | |
display: none; | |
} | |
.success { | |
background-color: #dff0d8; | |
color: #3c763d; | |
} | |
.error { | |
background-color: #f2dede; | |
color: #a94442; | |
} | |
.loading { | |
position: fixed; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
background-color: rgba(255, 255, 255, 0.7); | |
display: none; | |
justify-content: center; | |
align-items: center; | |
z-index: 1000; | |
font-size: 1.5rem; | |
} | |
.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; | |
} | |
.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 class="filter-controls"> | |
<label> | |
<input type="checkbox" id="showOnlyLiked" /> | |
๋ด๊ฐ ์ข์์ํ URL๋ง ๋ณด๊ธฐ | |
</label> | |
<label style="margin-left: 1rem;"> | |
<input type="text" id="searchInput" placeholder="URL ๋๋ ์ ๋ชฉ์ผ๋ก ๊ฒ์" style="width: 250px;" /> | |
</label> | |
</div> | |
<div id="statusMessage" class="status-message"></div> | |
<div id="loadingIndicator" class="loading">์ฒ๋ฆฌ ์ค...</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'), | |
showOnlyLiked: document.getElementById('showOnlyLiked'), | |
searchInput: document.getElementById('searchInput'), | |
loginSection: document.getElementById('loginSection'), | |
loggedInSection: document.getElementById('loggedInSection') | |
}; | |
// ์ ํ๋ฆฌ์ผ์ด์ ์ํ | |
const state = { | |
username: null, | |
likedModels: {}, | |
isLoading: false | |
}; | |
// ๋ก๋ฉ ์ํ ํ์ ํจ์ | |
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(); | |
} | |
// ์ธ์ ์ํ ํ์ธ | |
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'; | |
// 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; | |
state.likedModels = data.liked_models || {}; | |
elements.currentUser.textContent = state.username; | |
elements.loginSection.style.display = 'none'; | |
elements.loggedInSection.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.likedModels = {}; | |
elements.currentUser.textContent = '๋ก๊ทธ์ธ๋์ง ์์'; | |
elements.tokenInput.value = ''; | |
elements.loginSection.style.display = 'block'; | |
elements.loggedInSection.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 showOnlyLiked = elements.showOnlyLiked.checked; | |
const searchText = elements.searchInput.value; | |
const response = await fetch(`/api/urls?liked=${showOnlyLiked}&search=${encodeURIComponent(searchText)}`); | |
const urls = await handleApiResponse(response); | |
renderCards(urls); | |
} catch (error) { | |
console.error('URL ๋ชฉ๋ก ๋ก๋ ์ค๋ฅ:', error); | |
showMessage(`URL ๋ก๋ ์ค๋ฅ: ${error.message}`, true); | |
} finally { | |
setLoading(false); | |
} | |
} | |
// ์ข์์ ํ ๊ธ | |
async function toggleLike(url, button, currentLiked) { | |
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: url, | |
currentLiked: currentLiked | |
}) | |
}); | |
const data = await handleApiResponse(response); | |
if (data.success) { | |
if (currentLiked) { | |
button.classList.remove('liked'); | |
button.classList.add('not-liked'); | |
} else { | |
button.classList.add('liked'); | |
button.classList.remove('not-liked'); | |
} | |
showMessage(data.message); | |
// ํํฐ๋ง๋ ๊ฒฝ์ฐ ๋ชฉ๋ก ๋ค์ ๋ก๋ | |
if (elements.showOnlyLiked.checked) { | |
loadUrls(); | |
} | |
} 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'; | |
// ์ ๋ชฉ | |
const titleEl = document.createElement('h3'); | |
titleEl.textContent = title; | |
card.appendChild(titleEl); | |
// 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' : 'not-liked'}`; | |
likeBtn.textContent = 'โฅ'; | |
likeBtn.addEventListener('click', function(e) { | |
e.preventDefault(); | |
toggleLike(url, likeBtn, is_liked); | |
}); | |
card.appendChild(likeBtn); | |
// ์นด๋ ์ถ๊ฐ | |
elements.cardsContainer.appendChild(card); | |
}); | |
} | |
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ค์ | |
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.showOnlyLiked.addEventListener('change', loadUrls); | |
elements.searchInput.addEventListener('input', () => { | |
// ์ ๋ ฅ ์ง์ฐ ์ฒ๋ฆฌ (ํ์ดํํ ๋๋ง๋ค API ํธ์ถ ๋ฐฉ์ง) | |
clearTimeout(state.searchTimeout); | |
state.searchTimeout = setTimeout(loadUrls, 300); | |
}); | |
// ์ด๊ธฐํ | |
checkSessionStatus(); | |
</script> | |
</body> | |
</html> | |
''') | |
# ์๋ฒ ์คํ | |
app.run(debug=True) |