Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,162 @@
|
|
| 1 |
from flask import Flask, render_template, request, jsonify, session
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
from datetime import timedelta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
app.secret_key = os.urandom(24)
|
| 7 |
app.permanent_session_lifetime = timedelta(days=7)
|
| 8 |
|
| 9 |
-
# Hugging Face URL ๋ชฉ๋ก
|
| 10 |
-
# 'is_liked'๋ฅผ true๋ก ์ค์ ํ URL์ ํญ์ ์ข์์ ์ํ๋ก ํ์๋จ
|
| 11 |
HUGGINGFACE_URLS = [
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
]
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# URL์ ๋ง์ง๋ง ๋ถ๋ถ์ ์ ๋ชฉ์ผ๋ก ์ถ์ถ
|
| 34 |
def extract_title(url):
|
| 35 |
parts = url.split("/")
|
| 36 |
title = parts[-1] if parts else ""
|
| 37 |
return title.replace("_", " ").replace("-", " ")
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
@app.route('/')
|
| 40 |
def home():
|
| 41 |
return render_template('index.html')
|
|
@@ -47,16 +168,36 @@ def login():
|
|
| 47 |
if not token:
|
| 48 |
return jsonify({'success': False, 'message': 'ํ ํฐ์ ์
๋ ฅํด์ฃผ์ธ์.'})
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
return jsonify({'success': False, 'message': '์ ํจํ์ง ์์ ํ ํฐ์
๋๋ค.'})
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
username =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# ์ธ์
์ ์ ์ฅ
|
|
|
|
| 58 |
session['username'] = username
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
return jsonify({
|
| 61 |
'success': True,
|
| 62 |
'username': username
|
|
@@ -64,20 +205,30 @@ def login():
|
|
| 64 |
|
| 65 |
@app.route('/api/logout', methods=['POST'])
|
| 66 |
def logout():
|
|
|
|
| 67 |
session.pop('username', None)
|
|
|
|
| 68 |
return jsonify({'success': True})
|
| 69 |
|
| 70 |
@app.route('/api/urls', methods=['GET'])
|
| 71 |
def get_urls():
|
|
|
|
|
|
|
| 72 |
results = []
|
| 73 |
-
for
|
| 74 |
-
url = url_item["url"]
|
| 75 |
-
is_liked = url_item["is_liked"]
|
| 76 |
title = extract_title(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
results.append({
|
| 79 |
'url': url,
|
| 80 |
'title': title,
|
|
|
|
| 81 |
'is_liked': is_liked
|
| 82 |
})
|
| 83 |
|
|
@@ -85,7 +236,7 @@ def get_urls():
|
|
| 85 |
|
| 86 |
@app.route('/api/toggle-like', methods=['POST'])
|
| 87 |
def toggle_like():
|
| 88 |
-
if '
|
| 89 |
return jsonify({'success': False, 'message': '๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค.'})
|
| 90 |
|
| 91 |
data = request.json
|
|
@@ -94,19 +245,42 @@ def toggle_like():
|
|
| 94 |
if not url:
|
| 95 |
return jsonify({'success': False, 'message': 'URL์ด ํ์ํฉ๋๋ค.'})
|
| 96 |
|
| 97 |
-
#
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
'is_liked': url_item["is_liked"],
|
| 106 |
-
'message': '์ข์์๋ฅผ ์ถ๊ฐํ์ต๋๋ค.' if url_item["is_liked"] else '์ข์์๋ฅผ ์ทจ์ํ์ต๋๋ค.'
|
| 107 |
-
})
|
| 108 |
|
| 109 |
-
return jsonify({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
@app.route('/api/session-status', methods=['GET'])
|
| 112 |
def session_status():
|
|
@@ -190,6 +364,14 @@ if __name__ == '__main__':
|
|
| 190 |
background-color: #45a049;
|
| 191 |
}
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
button.logout {
|
| 194 |
background-color: #f44336;
|
| 195 |
}
|
|
@@ -387,6 +569,14 @@ if __name__ == '__main__':
|
|
| 387 |
margin-top: 1rem;
|
| 388 |
}
|
| 389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
@media (max-width: 768px) {
|
| 391 |
.user-controls {
|
| 392 |
flex-direction: column;
|
|
@@ -429,11 +619,16 @@ if __name__ == '__main__':
|
|
| 429 |
</div>
|
| 430 |
|
| 431 |
<div id="loggedInSection" class="logged-in-section">
|
|
|
|
| 432 |
<button id="logoutButton" class="logout">๋ก๊ทธ์์</button>
|
| 433 |
</div>
|
| 434 |
</div>
|
| 435 |
</div>
|
| 436 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
<div id="likeStatus" class="like-status">
|
| 438 |
<div id="likeStatsText">์ด <span id="totalUrlCount">0</span>๊ฐ ์ค <strong><span id="likedUrlCount">0</span>๊ฐ</strong>์ URL์ ์ข์์ ํ์ต๋๋ค.</div>
|
| 439 |
</div>
|
|
@@ -463,6 +658,7 @@ if __name__ == '__main__':
|
|
| 463 |
tokenInput: document.getElementById('tokenInput'),
|
| 464 |
loginButton: document.getElementById('loginButton'),
|
| 465 |
logoutButton: document.getElementById('logoutButton'),
|
|
|
|
| 466 |
currentUser: document.getElementById('currentUser'),
|
| 467 |
cardsContainer: document.getElementById('cardsContainer'),
|
| 468 |
loadingIndicator: document.getElementById('loadingIndicator'),
|
|
@@ -619,63 +815,54 @@ if __name__ == '__main__':
|
|
| 619 |
}
|
| 620 |
}
|
| 621 |
|
| 622 |
-
//
|
| 623 |
-
async function
|
| 624 |
setLoading(true);
|
| 625 |
|
| 626 |
try {
|
| 627 |
-
const response = await fetch('/api/
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
// URL ๋ฐ ์ข์์ ์ํ ์ ์ฅ
|
| 631 |
-
state.allURLs = urls;
|
| 632 |
|
| 633 |
-
|
| 634 |
-
filterAndRenderCards();
|
| 635 |
|
| 636 |
-
|
| 637 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 638 |
} catch (error) {
|
| 639 |
-
console.error('
|
| 640 |
-
showMessage(
|
| 641 |
} finally {
|
| 642 |
setLoading(false);
|
| 643 |
}
|
| 644 |
}
|
| 645 |
|
| 646 |
-
//
|
| 647 |
-
function
|
| 648 |
-
|
| 649 |
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
const
|
| 653 |
-
|
| 654 |
-
// ์ข์์ ํํฐ๋ง (์ข์์๋ง ๋ณด๊ธฐ ๋ชจ๋)
|
| 655 |
-
if (state.viewMode === 'liked' && !is_liked) {
|
| 656 |
-
return false;
|
| 657 |
-
}
|
| 658 |
-
|
| 659 |
-
// ๊ฒ์ ํํฐ๋ง
|
| 660 |
-
if (searchText && !url.toLowerCase().includes(searchText) && !title.toLowerCase().includes(searchText)) {
|
| 661 |
-
return false;
|
| 662 |
-
}
|
| 663 |
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 668 |
}
|
| 669 |
|
| 670 |
// ์ข์์ ํ ๊ธ
|
| 671 |
-
async function toggleLike(url
|
| 672 |
-
if (!state.username) {
|
| 673 |
-
showMessage('์ข์์๋ฅผ ํ๋ ค๋ฉด ํ๊น
ํ์ด์ค API ํ ํฐ์ผ๋ก ์ธ์ฆ์ด ํ์ํฉ๋๋ค.', true);
|
| 674 |
-
return;
|
| 675 |
-
}
|
| 676 |
-
|
| 677 |
-
setLoading(true);
|
| 678 |
-
|
| 679 |
try {
|
| 680 |
const response = await fetch('/api/toggle-like', {
|
| 681 |
method: 'POST',
|
|
@@ -688,164 +875,152 @@ if __name__ == '__main__':
|
|
| 688 |
const data = await handleApiResponse(response);
|
| 689 |
|
| 690 |
if (data.success) {
|
| 691 |
-
//
|
| 692 |
-
const
|
| 693 |
-
if (
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
// ์นด๋ UI ์
๋ฐ์ดํธ
|
| 698 |
-
if (data.is_liked) {
|
| 699 |
-
card.classList.add('liked');
|
| 700 |
-
const likeBtn = card.querySelector('.like-button');
|
| 701 |
-
if (likeBtn) likeBtn.classList.add('liked');
|
| 702 |
-
|
| 703 |
-
// ์ข์์ ๋ฐฐ์ง ์ถ๊ฐ
|
| 704 |
-
if (!card.querySelector('.like-badge')) {
|
| 705 |
-
const likeBadge = document.createElement('div');
|
| 706 |
-
likeBadge.className = 'like-badge';
|
| 707 |
-
likeBadge.textContent = '์ข์์';
|
| 708 |
-
card.appendChild(likeBadge);
|
| 709 |
-
}
|
| 710 |
-
} else {
|
| 711 |
-
card.classList.remove('liked');
|
| 712 |
-
const likeBtn = card.querySelector('.like-button');
|
| 713 |
-
if (likeBtn) likeBtn.classList.remove('liked');
|
| 714 |
-
|
| 715 |
-
// ์ข์์ ๋ฐฐ์ง ์ ๊ฑฐ
|
| 716 |
-
const likeBadge = card.querySelector('.like-badge');
|
| 717 |
-
if (likeBadge) card.removeChild(likeBadge);
|
| 718 |
-
}
|
| 719 |
}
|
| 720 |
|
| 721 |
showMessage(data.message);
|
| 722 |
-
|
| 723 |
-
// ์ข์์ ํต๊ณ ์
๋ฐ์ดํธ
|
| 724 |
-
updateLikeStats();
|
| 725 |
-
|
| 726 |
-
// ์ข์์๋ง ๋ณด๊ธฐ ๋ชจ๋์ธ ๊ฒฝ์ฐ ๋ชฉ๋ก ๋ค์ ํํฐ๋ง
|
| 727 |
-
if (state.viewMode === 'liked') {
|
| 728 |
-
filterAndRenderCards();
|
| 729 |
-
}
|
| 730 |
} else {
|
| 731 |
-
showMessage(data.message || '์ข์์
|
| 732 |
}
|
| 733 |
} catch (error) {
|
| 734 |
console.error('์ข์์ ํ ๊ธ ์ค๋ฅ:', error);
|
| 735 |
-
showMessage(`์ข์์
|
| 736 |
-
} finally {
|
| 737 |
-
setLoading(false);
|
| 738 |
}
|
| 739 |
}
|
| 740 |
|
| 741 |
// ์นด๋ ๋ ๋๋ง
|
| 742 |
-
function renderCards(
|
| 743 |
elements.cardsContainer.innerHTML = '';
|
| 744 |
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 751 |
return;
|
| 752 |
}
|
| 753 |
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
// ์นด๋ ์์ฑ
|
| 758 |
const card = document.createElement('div');
|
| 759 |
-
card.className = `card ${is_liked ? 'liked' : ''}`;
|
| 760 |
-
|
| 761 |
-
// ์นด๋ ํค๋
|
| 762 |
-
const cardHeader = document.createElement('div');
|
| 763 |
-
cardHeader.className = 'card-header';
|
| 764 |
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
card.appendChild(cardHeader);
|
| 772 |
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 779 |
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
likeBtn.className = `like-button ${is_liked ? 'liked' : ''}`;
|
| 783 |
-
likeBtn.innerHTML = 'โฅ';
|
| 784 |
-
likeBtn.title = is_liked ? '์ข์์ ์ทจ์' : '์ข์์';
|
| 785 |
|
| 786 |
-
|
|
|
|
|
|
|
| 787 |
e.preventDefault();
|
| 788 |
-
|
|
|
|
| 789 |
});
|
| 790 |
-
|
| 791 |
-
card.appendChild(likeBtn);
|
| 792 |
-
|
| 793 |
-
// ์ข์์ ๋ฐฐ์ง (์ข์์ ์ํ์ผ ๋๋ง)
|
| 794 |
-
if (is_liked) {
|
| 795 |
-
const likeBadge = document.createElement('div');
|
| 796 |
-
likeBadge.className = 'like-badge';
|
| 797 |
-
likeBadge.textContent = '์ข์์';
|
| 798 |
-
card.appendChild(likeBadge);
|
| 799 |
-
}
|
| 800 |
-
|
| 801 |
-
// ์นด๋ ์ถ๊ฐ
|
| 802 |
-
elements.cardsContainer.appendChild(card);
|
| 803 |
});
|
| 804 |
}
|
| 805 |
|
| 806 |
-
//
|
| 807 |
-
function
|
| 808 |
-
|
|
|
|
|
|
|
|
|
|
| 809 |
|
| 810 |
-
//
|
| 811 |
-
elements.
|
| 812 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 813 |
|
| 814 |
-
//
|
| 815 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 816 |
}
|
| 817 |
|
| 818 |
-
//
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
elements.logoutButton.addEventListener('click', logout);
|
| 824 |
-
|
| 825 |
-
// ์ํฐ ํค๋ก ๋ก๊ทธ์ธ ๊ฐ๋ฅํ๊ฒ
|
| 826 |
-
elements.tokenInput.addEventListener('keypress', (event) => {
|
| 827 |
-
if (event.key === 'Enter') {
|
| 828 |
-
login(elements.tokenInput.value);
|
| 829 |
-
}
|
| 830 |
-
});
|
| 831 |
-
|
| 832 |
-
// ๊ฒ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋
|
| 833 |
-
elements.searchInput.addEventListener('input', () => {
|
| 834 |
-
// ๋๋ฐ์ด์ฑ (์
๋ ฅ ์ง์ฐ ์ฒ๋ฆฌ)
|
| 835 |
-
clearTimeout(state.searchTimeout);
|
| 836 |
-
state.searchTimeout = setTimeout(filterAndRenderCards, 300);
|
| 837 |
-
});
|
| 838 |
-
|
| 839 |
-
// ํํฐ ๋ฒํผ ์ด๋ฒคํธ ๋ฆฌ์ค๋
|
| 840 |
-
elements.allUrlsBtn.addEventListener('click', () => changeViewMode('all'));
|
| 841 |
-
elements.likedUrlsBtn.addEventListener('click', () => changeViewMode('liked'));
|
| 842 |
|
| 843 |
-
// ์ด๊ธฐํ
|
| 844 |
-
|
| 845 |
</script>
|
| 846 |
</body>
|
| 847 |
</html>
|
| 848 |
-
'''
|
|
|
|
| 849 |
|
| 850 |
-
|
| 851 |
-
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 1 |
from flask import Flask, render_template, request, jsonify, session
|
| 2 |
+
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
import os
|
| 5 |
from datetime import timedelta
|
| 6 |
+
import logging
|
| 7 |
+
import time
|
| 8 |
+
|
| 9 |
+
# ๋ก๊น
์ค์
|
| 10 |
+
logging.basicConfig(level=logging.INFO,
|
| 11 |
+
format='%(asctime)s - %(levelname)s - %(message)s')
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
app = Flask(__name__)
|
| 15 |
app.secret_key = os.urandom(24)
|
| 16 |
app.permanent_session_lifetime = timedelta(days=7)
|
| 17 |
|
| 18 |
+
# Hugging Face URL ๋ชฉ๋ก
|
|
|
|
| 19 |
HUGGINGFACE_URLS = [
|
| 20 |
+
"https://huggingface.co/spaces/ginipick/Tech_Hangman_Game",
|
| 21 |
+
"https://huggingface.co/spaces/openfree/deepseek_r1_API",
|
| 22 |
+
"https://huggingface.co/spaces/ginipick/open_Deep-Research",
|
| 23 |
+
"https://huggingface.co/spaces/aiqmaster/open-deep-research",
|
| 24 |
+
"https://huggingface.co/spaces/seawolf2357/DeepSeek-R1-32b-search",
|
| 25 |
+
"https://huggingface.co/spaces/ginigen/LLaDA",
|
| 26 |
+
"https://huggingface.co/spaces/VIDraft/PHI4-Multimodal",
|
| 27 |
+
"https://huggingface.co/spaces/ginigen/Ovis2-8B",
|
| 28 |
+
"https://huggingface.co/spaces/ginigen/Graph-Mind",
|
| 29 |
+
"https://huggingface.co/spaces/ginigen/Workflow-Canvas",
|
| 30 |
+
"https://huggingface.co/spaces/ginigen/Design",
|
| 31 |
+
"https://huggingface.co/spaces/ginigen/Diagram",
|
| 32 |
+
"https://huggingface.co/spaces/ginigen/Mockup",
|
| 33 |
+
"https://huggingface.co/spaces/ginigen/Infographic",
|
| 34 |
+
"https://huggingface.co/spaces/ginigen/Flowchart",
|
| 35 |
+
"https://huggingface.co/spaces/aiqcamp/FLUX-Vision",
|
| 36 |
+
"https://huggingface.co/spaces/ginigen/VoiceClone-TTS",
|
| 37 |
+
"https://huggingface.co/spaces/openfree/Perceptron-Network",
|
| 38 |
+
"https://huggingface.co/spaces/openfree/Article-Generator",
|
| 39 |
]
|
| 40 |
|
| 41 |
+
# URL์์ ๋ชจ๋ธ/์คํ์ด์ค ์ ๋ณด ์ถ์ถ
|
| 42 |
+
def extract_model_info(url):
|
| 43 |
+
parts = url.split('/')
|
| 44 |
+
if len(parts) < 6:
|
| 45 |
+
return None
|
| 46 |
+
|
| 47 |
+
if parts[3] == 'spaces' or parts[3] == 'models':
|
| 48 |
+
return {
|
| 49 |
+
'type': parts[3],
|
| 50 |
+
'owner': parts[4],
|
| 51 |
+
'repo': parts[5],
|
| 52 |
+
'full_id': f"{parts[4]}/{parts[5]}"
|
| 53 |
+
}
|
| 54 |
+
elif len(parts) >= 5:
|
| 55 |
+
return {
|
| 56 |
+
'type': 'models',
|
| 57 |
+
'owner': parts[3],
|
| 58 |
+
'repo': parts[4],
|
| 59 |
+
'full_id': f"{parts[3]}/{parts[4]}"
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
return None
|
| 63 |
+
|
| 64 |
# URL์ ๋ง์ง๋ง ๋ถ๋ถ์ ์ ๋ชฉ์ผ๋ก ์ถ์ถ
|
| 65 |
def extract_title(url):
|
| 66 |
parts = url.split("/")
|
| 67 |
title = parts[-1] if parts else ""
|
| 68 |
return title.replace("_", " ").replace("-", " ")
|
| 69 |
|
| 70 |
+
# ํ๊น
ํ์ด์ค ํ ํฐ ๊ฒ์ฆ
|
| 71 |
+
def validate_token(token):
|
| 72 |
+
headers = {"Authorization": f"Bearer {token}"}
|
| 73 |
+
|
| 74 |
+
try:
|
| 75 |
+
response = requests.get("https://huggingface.co/api/whoami-v2", headers=headers)
|
| 76 |
+
if response.ok:
|
| 77 |
+
return True, response.json()
|
| 78 |
+
except Exception as e:
|
| 79 |
+
logger.error(f"ํ ํฐ ๊ฒ์ฆ ์ค๋ฅ: {e}")
|
| 80 |
+
|
| 81 |
+
return False, None
|
| 82 |
+
|
| 83 |
+
# ์น ์คํฌ๋ํ์ผ๋ก ์ข์์ ์ํ ํ์ธ
|
| 84 |
+
def check_like_status_by_scraping(url, token):
|
| 85 |
+
headers = {
|
| 86 |
+
"Authorization": f"Bearer {token}",
|
| 87 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
try:
|
| 91 |
+
# ํ์ด์ง ์์ฒญ
|
| 92 |
+
response = requests.get(url, headers=headers)
|
| 93 |
+
if not response.ok:
|
| 94 |
+
logger.warning(f"ํ์ด์ง ์์ฒญ ์คํจ: {url}, ์ํ ์ฝ๋: {response.status_code}")
|
| 95 |
+
return False
|
| 96 |
+
|
| 97 |
+
# HTML ํ์ฑ
|
| 98 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 99 |
+
|
| 100 |
+
# ์ข์์ ๋ฒํผ ์ฐพ๊ธฐ (๋ค์ํ ์ ํ์ ์๋)
|
| 101 |
+
like_button = None
|
| 102 |
+
selectors = [
|
| 103 |
+
'.like-button-container button',
|
| 104 |
+
'button[aria-label="Like"]',
|
| 105 |
+
'button.like-button',
|
| 106 |
+
'button[data-testid="like-button"]',
|
| 107 |
+
'button.heart-button'
|
| 108 |
+
]
|
| 109 |
+
|
| 110 |
+
for selector in selectors:
|
| 111 |
+
like_button = soup.select_one(selector)
|
| 112 |
+
if like_button:
|
| 113 |
+
break
|
| 114 |
+
|
| 115 |
+
if not like_button:
|
| 116 |
+
logger.warning(f"์ข์์ ๋ฒํผ์ ์ฐพ์ ์ ์์: {url}")
|
| 117 |
+
return False
|
| 118 |
+
|
| 119 |
+
# ์ข์์ ์ํ ํ์ธ (ํด๋์ค, aria-pressed ์์ฑ ๋ฑ์ผ๋ก ํ์ธ)
|
| 120 |
+
is_liked = False
|
| 121 |
+
|
| 122 |
+
# ํด๋์ค๋ก ํ์ธ
|
| 123 |
+
if 'liked' in like_button.get('class', []) or 'active' in like_button.get('class', []):
|
| 124 |
+
is_liked = True
|
| 125 |
+
|
| 126 |
+
# aria-pressed ์์ฑ์ผ๋ก ํ์ธ
|
| 127 |
+
elif like_button.get('aria-pressed') == 'true':
|
| 128 |
+
is_liked = True
|
| 129 |
+
|
| 130 |
+
# ๋ด๋ถ ํ
์คํธ ๋๋ ์์ด์ฝ์ผ๋ก ํ์ธ
|
| 131 |
+
elif like_button.find('span', class_='liked') or like_button.find('svg', class_='liked'):
|
| 132 |
+
is_liked = True
|
| 133 |
+
|
| 134 |
+
logger.info(f"์คํฌ๋ํ ๊ฒฐ๊ณผ: {url} - ์ข์์ {is_liked}")
|
| 135 |
+
return is_liked
|
| 136 |
+
|
| 137 |
+
except Exception as e:
|
| 138 |
+
logger.error(f"์คํฌ๋ํ ์ค๋ฅ ({url}): {e}")
|
| 139 |
+
return False
|
| 140 |
+
|
| 141 |
+
# ์ ์ฒด URL ๋ชฉ๋ก์ ์ข์์ ์ํ ์คํฌ๋ํ
|
| 142 |
+
def scrape_all_like_status(token):
|
| 143 |
+
like_status = {}
|
| 144 |
+
|
| 145 |
+
for url in HUGGINGFACE_URLS:
|
| 146 |
+
try:
|
| 147 |
+
# ๊ณผ๋ํ ์์ฒญ ๋ฐฉ์ง๋ฅผ ์ํ ์ง์ฐ
|
| 148 |
+
time.sleep(1)
|
| 149 |
+
|
| 150 |
+
is_liked = check_like_status_by_scraping(url, token)
|
| 151 |
+
like_status[url] = is_liked
|
| 152 |
+
|
| 153 |
+
logger.info(f"์ข์์ ์ํ ํ์ธ: {url} - {is_liked}")
|
| 154 |
+
except Exception as e:
|
| 155 |
+
logger.error(f"URL ์ฒ๋ฆฌ ์ค ์ค๋ฅ: {url} - {e}")
|
| 156 |
+
like_status[url] = False
|
| 157 |
+
|
| 158 |
+
return like_status
|
| 159 |
+
|
| 160 |
@app.route('/')
|
| 161 |
def home():
|
| 162 |
return render_template('index.html')
|
|
|
|
| 168 |
if not token:
|
| 169 |
return jsonify({'success': False, 'message': 'ํ ํฐ์ ์
๋ ฅํด์ฃผ์ธ์.'})
|
| 170 |
|
| 171 |
+
is_valid, user_info = validate_token(token)
|
| 172 |
+
|
| 173 |
+
if not is_valid or not user_info:
|
| 174 |
return jsonify({'success': False, 'message': '์ ํจํ์ง ์์ ํ ํฐ์
๋๋ค.'})
|
| 175 |
|
| 176 |
+
# ์ฌ์ฉ์ ์ด๋ฆ ์ฐพ๊ธฐ
|
| 177 |
+
username = None
|
| 178 |
+
if 'name' in user_info:
|
| 179 |
+
username = user_info['name']
|
| 180 |
+
elif 'user' in user_info and 'username' in user_info['user']:
|
| 181 |
+
username = user_info['user']['username']
|
| 182 |
+
elif 'username' in user_info:
|
| 183 |
+
username = user_info['username']
|
| 184 |
+
else:
|
| 185 |
+
username = '์ธ์ฆ๋ ์ฌ์ฉ์'
|
| 186 |
|
| 187 |
# ์ธ์
์ ์ ์ฅ
|
| 188 |
+
session['token'] = token
|
| 189 |
session['username'] = username
|
| 190 |
|
| 191 |
+
# ์น ์คํฌ๋ํ์ผ๋ก ์ข์์ ์ํ ํ์ธ
|
| 192 |
+
# ์ฐธ๊ณ : ์ด ์์
์ด ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆด ์ ์์ผ๋ฏ๋ก ๋น๋๊ธฐ๋ก ์ฒ๋ฆฌํ๋ ๊ฒ์ด ์ข์ต๋๋ค
|
| 193 |
+
# ํ์ฌ๋ ์์๋ก ๋๊ธฐ ๋ฐฉ์์ผ๋ก ๊ตฌํํ์ต๋๋ค
|
| 194 |
+
try:
|
| 195 |
+
like_status = scrape_all_like_status(token)
|
| 196 |
+
session['like_status'] = like_status
|
| 197 |
+
except Exception as e:
|
| 198 |
+
logger.error(f"์ข์์ ์ํ ์คํฌ๋ํ ์ค ์ค๋ฅ: {e}")
|
| 199 |
+
session['like_status'] = {}
|
| 200 |
+
|
| 201 |
return jsonify({
|
| 202 |
'success': True,
|
| 203 |
'username': username
|
|
|
|
| 205 |
|
| 206 |
@app.route('/api/logout', methods=['POST'])
|
| 207 |
def logout():
|
| 208 |
+
session.pop('token', None)
|
| 209 |
session.pop('username', None)
|
| 210 |
+
session.pop('like_status', None)
|
| 211 |
return jsonify({'success': True})
|
| 212 |
|
| 213 |
@app.route('/api/urls', methods=['GET'])
|
| 214 |
def get_urls():
|
| 215 |
+
like_status = session.get('like_status', {})
|
| 216 |
+
|
| 217 |
results = []
|
| 218 |
+
for url in HUGGINGFACE_URLS:
|
|
|
|
|
|
|
| 219 |
title = extract_title(url)
|
| 220 |
+
model_info = extract_model_info(url)
|
| 221 |
+
|
| 222 |
+
if not model_info:
|
| 223 |
+
continue
|
| 224 |
+
|
| 225 |
+
# ์ข์์ ์ํ ํ์ธ
|
| 226 |
+
is_liked = like_status.get(url, False)
|
| 227 |
|
| 228 |
results.append({
|
| 229 |
'url': url,
|
| 230 |
'title': title,
|
| 231 |
+
'model_info': model_info,
|
| 232 |
'is_liked': is_liked
|
| 233 |
})
|
| 234 |
|
|
|
|
| 236 |
|
| 237 |
@app.route('/api/toggle-like', methods=['POST'])
|
| 238 |
def toggle_like():
|
| 239 |
+
if 'token' not in session:
|
| 240 |
return jsonify({'success': False, 'message': '๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค.'})
|
| 241 |
|
| 242 |
data = request.json
|
|
|
|
| 245 |
if not url:
|
| 246 |
return jsonify({'success': False, 'message': 'URL์ด ํ์ํฉ๋๋ค.'})
|
| 247 |
|
| 248 |
+
# ํ์ฌ ์ข์์ ์ํ ํ์ธ
|
| 249 |
+
like_status = session.get('like_status', {})
|
| 250 |
+
current_status = like_status.get(url, False)
|
| 251 |
+
|
| 252 |
+
# ์ค์ ๋ก๋ ์ฌ๊ธฐ์ ํ๊น
ํ์ด์ค API๋ฅผ ํธ์ถํ์ฌ ์ข์์ ์ํ๋ฅผ ๋ณ๊ฒฝํด์ผ ํฉ๋๋ค
|
| 253 |
+
# ํ์ฌ๋ ์์๋ก ์ธ์
์๋ง ์ํ๋ฅผ ์ ์ฅํฉ๋๋ค
|
| 254 |
+
like_status[url] = not current_status
|
| 255 |
+
session['like_status'] = like_status
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
+
return jsonify({
|
| 258 |
+
'success': True,
|
| 259 |
+
'is_liked': like_status[url],
|
| 260 |
+
'message': '์ข์์๋ฅผ ์ถ๊ฐํ์ต๋๋ค.' if like_status[url] else '์ข์์๋ฅผ ์ทจ์ํ์ต๋๋ค.'
|
| 261 |
+
})
|
| 262 |
+
|
| 263 |
+
@app.route('/api/refresh-likes', methods=['POST'])
|
| 264 |
+
def refresh_likes():
|
| 265 |
+
if 'token' not in session:
|
| 266 |
+
return jsonify({'success': False, 'message': '๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค.'})
|
| 267 |
+
|
| 268 |
+
try:
|
| 269 |
+
# ์น ์คํฌ๋ํ์ผ๋ก ์ข์์ ์ํ ์๋ก๊ณ ์นจ
|
| 270 |
+
like_status = scrape_all_like_status(session['token'])
|
| 271 |
+
session['like_status'] = like_status
|
| 272 |
+
|
| 273 |
+
return jsonify({
|
| 274 |
+
'success': True,
|
| 275 |
+
'message': '์ข์์ ์ํ๊ฐ ์๋ก๊ณ ์นจ๋์์ต๋๋ค.',
|
| 276 |
+
'like_status': like_status
|
| 277 |
+
})
|
| 278 |
+
except Exception as e:
|
| 279 |
+
logger.error(f"์ข์์ ์ํ ์๋ก๊ณ ์นจ ์ค ์ค๋ฅ: {e}")
|
| 280 |
+
return jsonify({
|
| 281 |
+
'success': False,
|
| 282 |
+
'message': f'์ข์์ ์ํ ์๋ก๊ณ ์นจ ์ค ์ค๋ฅ: {str(e)}'
|
| 283 |
+
})
|
| 284 |
|
| 285 |
@app.route('/api/session-status', methods=['GET'])
|
| 286 |
def session_status():
|
|
|
|
| 364 |
background-color: #45a049;
|
| 365 |
}
|
| 366 |
|
| 367 |
+
button.refresh {
|
| 368 |
+
background-color: #2196F3;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
button.refresh:hover {
|
| 372 |
+
background-color: #0b7dda;
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
button.logout {
|
| 376 |
background-color: #f44336;
|
| 377 |
}
|
|
|
|
| 569 |
margin-top: 1rem;
|
| 570 |
}
|
| 571 |
|
| 572 |
+
.note {
|
| 573 |
+
padding: 0.5rem;
|
| 574 |
+
background-color: #fffde7;
|
| 575 |
+
border-left: 3px solid #ffd600;
|
| 576 |
+
margin-bottom: 1rem;
|
| 577 |
+
font-size: 0.9rem;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
@media (max-width: 768px) {
|
| 581 |
.user-controls {
|
| 582 |
flex-direction: column;
|
|
|
|
| 619 |
</div>
|
| 620 |
|
| 621 |
<div id="loggedInSection" class="logged-in-section">
|
| 622 |
+
<button id="refreshButton" class="refresh">์๋ก๊ณ ์นจ</button>
|
| 623 |
<button id="logoutButton" class="logout">๋ก๊ทธ์์</button>
|
| 624 |
</div>
|
| 625 |
</div>
|
| 626 |
</div>
|
| 627 |
|
| 628 |
+
<div class="note">
|
| 629 |
+
<p><strong>์ฐธ๊ณ :</strong> ์ด ํ์ด์ง๋ ์น ์คํฌ๋ํ ๋ฐฉ์์ผ๋ก ์ข์์ ์ํ๋ฅผ ๊ฐ์ ธ์ต๋๋ค. ์ข์์ ์ํ๊ฐ ์ ํํ์ง ์๊ฑฐ๋ ์ง์ฐ๋ ์ ์์ต๋๋ค. '์๋ก๊ณ ์นจ' ๋ฒํผ์ ํด๋ฆญํ์ฌ ์ต์ ์ํ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.</p>
|
| 630 |
+
</div>
|
| 631 |
+
|
| 632 |
<div id="likeStatus" class="like-status">
|
| 633 |
<div id="likeStatsText">์ด <span id="totalUrlCount">0</span>๊ฐ ์ค <strong><span id="likedUrlCount">0</span>๊ฐ</strong>์ URL์ ์ข์์ ํ์ต๋๋ค.</div>
|
| 634 |
</div>
|
|
|
|
| 658 |
tokenInput: document.getElementById('tokenInput'),
|
| 659 |
loginButton: document.getElementById('loginButton'),
|
| 660 |
logoutButton: document.getElementById('logoutButton'),
|
| 661 |
+
refreshButton: document.getElementById('refreshButton'),
|
| 662 |
currentUser: document.getElementById('currentUser'),
|
| 663 |
cardsContainer: document.getElementById('cardsContainer'),
|
| 664 |
loadingIndicator: document.getElementById('loadingIndicator'),
|
|
|
|
| 815 |
}
|
| 816 |
}
|
| 817 |
|
| 818 |
+
// ์ข์์ ์ํ ์๋ก๊ณ ์นจ
|
| 819 |
+
async function refreshLikes() {
|
| 820 |
setLoading(true);
|
| 821 |
|
| 822 |
try {
|
| 823 |
+
const response = await fetch('/api/refresh-likes', {
|
| 824 |
+
method: 'POST'
|
| 825 |
+
});
|
|
|
|
|
|
|
| 826 |
|
| 827 |
+
const data = await handleApiResponse(response);
|
|
|
|
| 828 |
|
| 829 |
+
|
| 830 |
+
if (data.success) {
|
| 831 |
+
// URL ๋ชฉ๋ก ๋ค์ ๋ก๋
|
| 832 |
+
loadUrls();
|
| 833 |
+
showMessage('์ข์์ ์ํ๊ฐ ์๋ก๊ณ ์นจ๋์์ต๋๋ค.');
|
| 834 |
+
} else {
|
| 835 |
+
showMessage(data.message || '์ข์์ ์ํ ์๋ก๊ณ ์นจ์ ์คํจํ์ต๋๋ค.', true);
|
| 836 |
+
}
|
| 837 |
} catch (error) {
|
| 838 |
+
console.error('์ข์์ ์ํ ์๋ก๊ณ ์นจ ์ค๋ฅ:', error);
|
| 839 |
+
showMessage(`์ข์์ ์ํ ์๋ก๊ณ ์นจ ์ค๋ฅ: ${error.message}`, true);
|
| 840 |
} finally {
|
| 841 |
setLoading(false);
|
| 842 |
}
|
| 843 |
}
|
| 844 |
|
| 845 |
+
// URL ๋ชฉ๋ก ๋ก๋
|
| 846 |
+
async function loadUrls() {
|
| 847 |
+
setLoading(true);
|
| 848 |
|
| 849 |
+
try {
|
| 850 |
+
const response = await fetch('/api/urls');
|
| 851 |
+
const data = await handleApiResponse(response);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 852 |
|
| 853 |
+
state.allURLs = data;
|
| 854 |
+
updateLikeStats();
|
| 855 |
+
renderCards();
|
| 856 |
+
} catch (error) {
|
| 857 |
+
console.error('URL ๋ชฉ๋ก ๋ก๋ ์ค๋ฅ:', error);
|
| 858 |
+
showMessage(`URL ๋ชฉ๋ก ๋ก๋ ์ค๋ฅ: ${error.message}`, true);
|
| 859 |
+
} finally {
|
| 860 |
+
setLoading(false);
|
| 861 |
+
}
|
| 862 |
}
|
| 863 |
|
| 864 |
// ์ข์์ ํ ๊ธ
|
| 865 |
+
async function toggleLike(url) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 866 |
try {
|
| 867 |
const response = await fetch('/api/toggle-like', {
|
| 868 |
method: 'POST',
|
|
|
|
| 875 |
const data = await handleApiResponse(response);
|
| 876 |
|
| 877 |
if (data.success) {
|
| 878 |
+
// URL ๊ฐ์ฒด ์ฐพ๊ธฐ
|
| 879 |
+
const urlObj = state.allURLs.find(item => item.url === url);
|
| 880 |
+
if (urlObj) {
|
| 881 |
+
urlObj.is_liked = data.is_liked;
|
| 882 |
+
updateLikeStats();
|
| 883 |
+
renderCards();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 884 |
}
|
| 885 |
|
| 886 |
showMessage(data.message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 887 |
} else {
|
| 888 |
+
showMessage(data.message || '์ข์์ ์ํ ๋ณ๊ฒฝ์ ์คํจํ์ต๋๋ค.', true);
|
| 889 |
}
|
| 890 |
} catch (error) {
|
| 891 |
console.error('์ข์์ ํ ๊ธ ์ค๋ฅ:', error);
|
| 892 |
+
showMessage(`์ข์์ ํ ๊ธ ์ค๋ฅ: ${error.message}`, true);
|
|
|
|
|
|
|
| 893 |
}
|
| 894 |
}
|
| 895 |
|
| 896 |
// ์นด๋ ๋ ๋๋ง
|
| 897 |
+
function renderCards() {
|
| 898 |
elements.cardsContainer.innerHTML = '';
|
| 899 |
|
| 900 |
+
let urlsToShow = state.allURLs;
|
| 901 |
+
|
| 902 |
+
// ๊ฒ์์ด๋ก ํํฐ๋ง
|
| 903 |
+
const searchTerm = elements.searchInput.value.trim().toLowerCase();
|
| 904 |
+
if (searchTerm) {
|
| 905 |
+
urlsToShow = urlsToShow.filter(item =>
|
| 906 |
+
item.url.toLowerCase().includes(searchTerm) ||
|
| 907 |
+
item.title.toLowerCase().includes(searchTerm)
|
| 908 |
+
);
|
| 909 |
+
}
|
| 910 |
+
|
| 911 |
+
// ๋ณด๊ธฐ ๋ชจ๋๋ก ํํฐ๋ง (์ ์ฒด ๋๋ ์ข์์๋ง)
|
| 912 |
+
if (state.viewMode === 'liked') {
|
| 913 |
+
urlsToShow = urlsToShow.filter(item => item.is_liked);
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
if (urlsToShow.length === 0) {
|
| 917 |
+
const emptyMessage = document.createElement('div');
|
| 918 |
+
emptyMessage.textContent = 'ํ์ํ URL์ด ์์ต๋๋ค.';
|
| 919 |
+
emptyMessage.style.padding = '1rem';
|
| 920 |
+
emptyMessage.style.width = '100%';
|
| 921 |
+
emptyMessage.style.textAlign = 'center';
|
| 922 |
+
elements.cardsContainer.appendChild(emptyMessage);
|
| 923 |
return;
|
| 924 |
}
|
| 925 |
|
| 926 |
+
// ์นด๋ ์์ฑ
|
| 927 |
+
urlsToShow.forEach(item => {
|
|
|
|
|
|
|
| 928 |
const card = document.createElement('div');
|
| 929 |
+
card.className = `card ${item.is_liked ? 'liked' : ''}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 930 |
|
| 931 |
+
if (item.is_liked) {
|
| 932 |
+
const badge = document.createElement('div');
|
| 933 |
+
badge.className = 'like-badge';
|
| 934 |
+
badge.textContent = '์ข์์';
|
| 935 |
+
card.appendChild(badge);
|
| 936 |
+
}
|
|
|
|
| 937 |
|
| 938 |
+
const cardContent = `
|
| 939 |
+
<div class="card-header">
|
| 940 |
+
<h3 class="card-title">${item.title}</h3>
|
| 941 |
+
<button class="like-button ${item.is_liked ? 'liked' : ''}" data-url="${item.url}">
|
| 942 |
+
โค
|
| 943 |
+
</button>
|
| 944 |
+
</div>
|
| 945 |
+
<div class="card-body">
|
| 946 |
+
<a href="${item.url}" target="_blank">${item.url}</a>
|
| 947 |
+
<div style="margin-top: 0.5rem;">
|
| 948 |
+
<span>์์ ์: ${item.model_info.owner}</span>
|
| 949 |
+
</div>
|
| 950 |
+
<div>
|
| 951 |
+
<span>์ ์ฅ์: ${item.model_info.repo}</span>
|
| 952 |
+
</div>
|
| 953 |
+
<div>
|
| 954 |
+
<span>์ ํ: ${item.model_info.type}</span>
|
| 955 |
+
</div>
|
| 956 |
+
</div>
|
| 957 |
+
`;
|
| 958 |
|
| 959 |
+
card.innerHTML = cardContent;
|
| 960 |
+
elements.cardsContainer.appendChild(card);
|
|
|
|
|
|
|
|
|
|
| 961 |
|
| 962 |
+
// ์ข์์ ๋ฒํผ ์ด๋ฒคํธ ์ถ๊ฐ
|
| 963 |
+
const likeButton = card.querySelector('.like-button');
|
| 964 |
+
likeButton.addEventListener('click', (e) => {
|
| 965 |
e.preventDefault();
|
| 966 |
+
const url = e.target.dataset.url;
|
| 967 |
+
toggleLike(url);
|
| 968 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 969 |
});
|
| 970 |
}
|
| 971 |
|
| 972 |
+
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก
|
| 973 |
+
function registerEventListeners() {
|
| 974 |
+
// ๋ก๊ทธ์ธ ๋ฒํผ
|
| 975 |
+
elements.loginButton.addEventListener('click', () => {
|
| 976 |
+
login(elements.tokenInput.value);
|
| 977 |
+
});
|
| 978 |
|
| 979 |
+
// ์ํฐ ํค๋ก ๋ก๊ทธ์ธ
|
| 980 |
+
elements.tokenInput.addEventListener('keydown', (e) => {
|
| 981 |
+
if (e.key === 'Enter') {
|
| 982 |
+
login(elements.tokenInput.value);
|
| 983 |
+
}
|
| 984 |
+
});
|
| 985 |
+
|
| 986 |
+
// ๋ก๊ทธ์์ ๋ฒํผ
|
| 987 |
+
elements.logoutButton.addEventListener('click', logout);
|
| 988 |
+
|
| 989 |
+
// ์๋ก๊ณ ์นจ ๋ฒํผ
|
| 990 |
+
elements.refreshButton.addEventListener('click', refreshLikes);
|
| 991 |
|
| 992 |
+
// ๊ฒ์ ์
๋ ฅ ํ๋
|
| 993 |
+
elements.searchInput.addEventListener('input', renderCards);
|
| 994 |
+
|
| 995 |
+
// ํํฐ ๋ฒํผ - ์ ์ฒด ๋ณด๊ธฐ
|
| 996 |
+
elements.allUrlsBtn.addEventListener('click', () => {
|
| 997 |
+
elements.allUrlsBtn.classList.add('active');
|
| 998 |
+
elements.likedUrlsBtn.classList.remove('active');
|
| 999 |
+
state.viewMode = 'all';
|
| 1000 |
+
renderCards();
|
| 1001 |
+
});
|
| 1002 |
+
|
| 1003 |
+
// ํํฐ ๋ฒํผ - ์ข์์๋ง ๋ณด๊ธฐ
|
| 1004 |
+
elements.likedUrlsBtn.addEventListener('click', () => {
|
| 1005 |
+
elements.likedUrlsBtn.classList.add('active');
|
| 1006 |
+
elements.allUrlsBtn.classList.remove('active');
|
| 1007 |
+
state.viewMode = 'liked';
|
| 1008 |
+
renderCards();
|
| 1009 |
+
});
|
| 1010 |
}
|
| 1011 |
|
| 1012 |
+
// ์ด๊ธฐํ ํจ์
|
| 1013 |
+
function init() {
|
| 1014 |
+
registerEventListeners();
|
| 1015 |
+
checkSessionStatus();
|
| 1016 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1017 |
|
| 1018 |
+
// ์ ํ๋ฆฌ์ผ์ด์
์ด๊ธฐํ
|
| 1019 |
+
init();
|
| 1020 |
</script>
|
| 1021 |
</body>
|
| 1022 |
</html>
|
| 1023 |
+
'''
|
| 1024 |
+
)
|
| 1025 |
|
| 1026 |
+
app.run(debug=True, host='0.0.0.0', port=5000)
|
|
|