Eluza133 commited on
Commit
09f87ea
·
verified ·
1 Parent(s): 3119e94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -13
app.py CHANGED
@@ -175,7 +175,7 @@ BASE_STYLE = '''
175
  color: white;
176
  }
177
  .logout-btn:hover {
178
- background %s: #45b7b0;
179
  }
180
  .menu-btn {
181
  display: none;
@@ -312,6 +312,17 @@ NAV_HTML = '''
312
  </aside>
313
  '''
314
 
 
 
 
 
 
 
 
 
 
 
 
315
  # Registration
316
  @app.route('/register', methods=['GET', 'POST'])
317
  def register():
@@ -521,7 +532,7 @@ def login():
521
  </body>
522
  </html>
523
  '''
524
- return render_template_string(html, is_authenticated=is_authenticated, username=username)
525
 
526
  # Logout
527
  @app.route('/logout')
@@ -663,7 +674,7 @@ def feed():
663
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
664
  </video>
665
  {% else %}
666
- <img class="post-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}" onclick="openModal(this.src, event)">
667
  {% endif %}
668
  <h2>{{ post['title'] }}</h2>
669
  <p>{{ post['description'] }}</p>
@@ -684,12 +695,28 @@ def feed():
684
  document.body.classList.toggle('dark');
685
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
686
  }
687
- function openModal(src, event) {
688
  event.preventDefault();
689
  const modal = document.getElementById('imageModal');
690
  const modalImg = document.getElementById('modalImage');
691
  modal.style.display = 'flex';
692
  modalImg.src = src;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
693
  }
694
  function closeModal(event) {
695
  if (event.target.tagName !== 'IMG') {
@@ -818,7 +845,7 @@ def post_page(post_id):
818
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
819
  </video>
820
  {% else %}
821
- <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}" onclick="openModal(this.src)">
822
  {% endif %}
823
  <p>{{ post['description'] }}</p>
824
  <p>Uploaded by: <a href="{{ url_for('user_profile', username=post['uploader']) }}" class="username-link">{{ post['uploader'] }}</a> | {{ post['upload_date'] }}</p>
@@ -831,7 +858,7 @@ def post_page(post_id):
831
  </form>
832
  <form method="POST" class="comment-section">
833
  <textarea name="comment" placeholder="Leave a comment" rows="4"></textarea>
834
- <button type="submit" class="btn">Submit</button>
835
  </form>
836
  {% endif %}
837
  <h3 style="margin-top: 40px; font-size: 1.8em;">Comments</h3>
@@ -856,11 +883,26 @@ def post_page(post_id):
856
  document.body.classList.toggle('dark');
857
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
858
  }
859
- function openModal(src) {
860
  const modal = document.getElementById('imageModal');
861
  const modalImg = document.getElementById('modalImage');
862
  modal.style.display = 'flex';
863
  modalImg.src = src;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
864
  }
865
  function closeModal(event) {
866
  if (event.target.tagName !== 'IMG') {
@@ -1065,7 +1107,7 @@ def profile():
1065
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
1066
  </video>
1067
  {% else %}
1068
- <img class="post-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}" onclick="openModal(this.src, event)">
1069
  {% endif %}
1070
  <h3>{{ post['title'] }}</h3>
1071
  </a>
@@ -1093,12 +1135,30 @@ def profile():
1093
  document.body.classList.toggle('dark');
1094
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
1095
  }
1096
- function openModal(src, event) {
1097
  event.preventDefault();
1098
  const modal = document.getElementById('imageModal');
1099
  const modalImg = document.getElementById('modalImage');
1100
  modal.style.display = 'flex';
1101
  modalImg.src = src;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1102
  }
1103
  function closeModal(event) {
1104
  if (event.target.tagName !== 'IMG') {
@@ -1265,7 +1325,7 @@ def user_profile(username):
1265
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
1266
  </video>
1267
  {% else %}
1268
- <img class="post-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}" onclick="openModal(this.src, event)">
1269
  {% endif %}
1270
  <h3>{{ post['title'] }}</h3>
1271
  </a>
@@ -1289,12 +1349,30 @@ def user_profile(username):
1289
  document.body.classList.toggle('dark');
1290
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
1291
  }
1292
- function openModal(src, event) {
1293
  event.preventDefault();
1294
  const modal = document.getElementById('imageModal');
1295
  const modalImg = document.getElementById('modalImage');
1296
  modal.style.display = 'flex';
1297
  modalImg.src = src;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1298
  }
1299
  function closeModal(event) {
1300
  if (event.target.tagName !== 'IMG') {
@@ -1385,7 +1463,7 @@ def upload():
1385
  <head>
1386
  <meta charset="UTF-8">
1387
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
1388
- <meta name="keywords" content="interracial porn, bbc porn, qos, queen of spades, big black cock">
1389
  <title>Upload Content - Content Hub</title>
1390
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap" rel="stylesheet">
1391
  <style>
@@ -1620,7 +1698,7 @@ def admin_panel():
1620
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
1621
  </video>
1622
  {% else %}
1623
- <img class="post-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}">
1624
  {% endif %}
1625
  <h2>{{ post['title'] }}</h2>
1626
  </a>
@@ -1637,6 +1715,9 @@ def admin_panel():
1637
  {% endif %}
1638
  </div>
1639
  </div>
 
 
 
1640
  <script>
1641
  function toggleSidebar() {
1642
  document.getElementById('sidebar').classList.toggle('active');
@@ -1645,6 +1726,33 @@ def admin_panel():
1645
  document.body.classList.toggle('dark');
1646
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
1647
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1648
  window.onload = () => {
1649
  if (localStorage.getItem('theme') === 'dark') document.body.classList.add('dark');
1650
  const videos = document.querySelectorAll('.post-preview');
 
175
  color: white;
176
  }
177
  .logout-btn:hover {
178
+ background: #45b7b0;
179
  }
180
  .menu-btn {
181
  display: none;
 
312
  </aside>
313
  '''
314
 
315
+ # Новый маршрут для увеличения счётчика просмотров
316
+ @app.route('/increment_view/<post_id>', methods=['POST'])
317
+ def increment_view(post_id):
318
+ data = load_data()
319
+ post = next((p for p in data['posts'] if p['id'] == post_id), None)
320
+ if post:
321
+ post['views'] = post.get('views', 0) + 1
322
+ save_data(data)
323
+ return {"status": "success", "views": post['views']}, 200
324
+ return {"status": "error", "message": "Post not found"}, 404
325
+
326
  # Registration
327
  @app.route('/register', methods=['GET', 'POST'])
328
  def register():
 
532
  </body>
533
  </html>
534
  '''
535
+ return render_template_string(html, is_authenticated=isAuthenticated, username=username)
536
 
537
  # Logout
538
  @app.route('/logout')
 
674
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
675
  </video>
676
  {% else %}
677
+ <img class="post-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}" onclick="openModal(this.src, event, '{{ post['id'] }}')">
678
  {% endif %}
679
  <h2>{{ post['title'] }}</h2>
680
  <p>{{ post['description'] }}</p>
 
695
  document.body.classList.toggle('dark');
696
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
697
  }
698
+ function openModal(src, event, postId) {
699
  event.preventDefault();
700
  const modal = document.getElementById('imageModal');
701
  const modalImg = document.getElementById('modalImage');
702
  modal.style.display = 'flex';
703
  modalImg.src = src;
704
+
705
+ // Увеличиваем счётчик просмотров через AJAX
706
+ fetch(`/increment_view/${postId}`, {
707
+ method: 'POST',
708
+ headers: {
709
+ 'Content-Type': 'application/json',
710
+ }
711
+ })
712
+ .then(response => response.json())
713
+ .then(data => {
714
+ if (data.status === 'success') {
715
+ const statsElement = event.target.closest('.post-item').querySelector('.stats');
716
+ statsElement.textContent = `Views: ${data.views} | Likes: ${statsElement.textContent.split('|')[1].trim()}`;
717
+ }
718
+ })
719
+ .catch(error => console.error('Error incrementing view:', error));
720
  }
721
  function closeModal(event) {
722
  if (event.target.tagName !== 'IMG') {
 
845
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
846
  </video>
847
  {% else %}
848
+ <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}" onclick="openModal(this.src, '{{ post['id'] }}')">
849
  {% endif %}
850
  <p>{{ post['description'] }}</p>
851
  <p>Uploaded by: <a href="{{ url_for('user_profile', username=post['uploader']) }}" class="username-link">{{ post['uploader'] }}</a> | {{ post['upload_date'] }}</p>
 
858
  </form>
859
  <form method="POST" class="comment-section">
860
  <textarea name="comment" placeholder="Leave a comment" rows="4"></textarea>
861
+ <button type="submitNC" class="btn">Submit</button>
862
  </form>
863
  {% endif %}
864
  <h3 style="margin-top: 40px; font-size: 1.8em;">Comments</h3>
 
883
  document.body.classList.toggle('dark');
884
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
885
  }
886
+ function openModal(src, postId) {
887
  const modal = document.getElementById('imageModal');
888
  const modalImg = document.getElementById('modalImage');
889
  modal.style.display = 'flex';
890
  modalImg.src = src;
891
+
892
+ // Увеличиваем счётчик просмотров через AJAX
893
+ fetch(`/increment_view/${postId}`, {
894
+ method: 'POST',
895
+ headers: {
896
+ 'Content-Type': 'application/json',
897
+ }
898
+ })
899
+ .then(response => response.json())
900
+ .then(data => {
901
+ if (data.status === 'success') {
902
+ document.querySelector('p:contains("Views:")').textContent = `Views: ${data.views} | Likes: {{ post['likes']|length }}`;
903
+ }
904
+ })
905
+ .catch(error => console.error('Error incrementing view:', error));
906
  }
907
  function closeModal(event) {
908
  if (event.target.tagName !== 'IMG') {
 
1107
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
1108
  </video>
1109
  {% else %}
1110
+ <img class="post-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}" onclick="openModal(this.src, event, '{{ post['id'] }}')">
1111
  {% endif %}
1112
  <h3>{{ post['title'] }}</h3>
1113
  </a>
 
1135
  document.body.classList.toggle('dark');
1136
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
1137
  }
1138
+ function openModal(src, event, postId) {
1139
  event.preventDefault();
1140
  const modal = document.getElementById('imageModal');
1141
  const modalImg = document.getElementById('modalImage');
1142
  modal.style.display = 'flex';
1143
  modalImg.src = src;
1144
+
1145
+ // Увеличиваем счётчик просмотров через AJAX
1146
+ fetch(`/increment_view/${postId}`, {
1147
+ method: 'POST',
1148
+ headers: {
1149
+ 'Content-Type': 'application/json',
1150
+ }
1151
+ })
1152
+ .then(response => response.json())
1153
+ .then(data => {
1154
+ if (data.status === 'success') {
1155
+ // Обновляем общее количество просмотров на странице профиля
1156
+ const totalViewsElement = document.querySelector('.profile-info p:contains("Views:")');
1157
+ const currentLikes = totalViewsElement.textContent.split('|')[1].trim();
1158
+ totalViewsElement.textContent = `Views: ${parseInt(totalViewsElement.textContent.split(' ')[1]) + 1} | ${currentLikes}`;
1159
+ }
1160
+ })
1161
+ .catch(error => console.error('Error incrementing view:', error));
1162
  }
1163
  function closeModal(event) {
1164
  if (event.target.tagName !== 'IMG') {
 
1325
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
1326
  </video>
1327
  {% else %}
1328
+ <img class="post-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}" onclick="openModal(this.src, event, '{{ post['id'] }}')">
1329
  {% endif %}
1330
  <h3>{{ post['title'] }}</h3>
1331
  </a>
 
1349
  document.body.classList.toggle('dark');
1350
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
1351
  }
1352
+ function openModal(src, event, postId) {
1353
  event.preventDefault();
1354
  const modal = document.getElementById('imageModal');
1355
  const modalImg = document.getElementById('modalImage');
1356
  modal.style.display = 'flex';
1357
  modalImg.src = src;
1358
+
1359
+ // Увеличиваем счётчик просмотров через AJAX
1360
+ fetch(`/increment_view/${postId}`, {
1361
+ method: 'POST',
1362
+ headers: {
1363
+ 'Content-Type': 'application/json',
1364
+ }
1365
+ })
1366
+ .then(response => response.json())
1367
+ .then(data => {
1368
+ if (data.status === 'success') {
1369
+ // Обновляем общее количество просмотров на странице профиля
1370
+ const totalViewsElement = document.querySelector('.profile-info p:contains("Views:")');
1371
+ const currentLikes = totalViewsElement.textContent.split('|')[1].trim();
1372
+ totalViewsElement.textContent = `Views: ${parseInt(totalViewsElement.textContent.split(' ')[1]) + 1} | ${currentLikes}`;
1373
+ }
1374
+ })
1375
+ .catch(error => console.error('Error incrementing view:', error));
1376
  }
1377
  function closeModal(event) {
1378
  if (event.target.tagName !== 'IMG') {
 
1463
  <head>
1464
  <meta charset="UTF-8">
1465
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
1466
+ (groups porn, bbc porn, qos, queen of spades, big black cock">
1467
  <title>Upload Content - Content Hub</title>
1468
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap" rel="stylesheet">
1469
  <style>
 
1698
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
1699
  </video>
1700
  {% else %}
1701
+ <img class="post-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" alt="{{ post['title'] }}" onclick="openModal(this.src, event, '{{ post['id'] }}')">
1702
  {% endif %}
1703
  <h2>{{ post['title'] }}</h2>
1704
  </a>
 
1715
  {% endif %}
1716
  </div>
1717
  </div>
1718
+ <div class="modal" id="imageModal" onclick="closeModal(event)">
1719
+ <img id="modalImage" src="">
1720
+ </div>
1721
  <script>
1722
  function toggleSidebar() {
1723
  document.getElementById('sidebar').classList.toggle('active');
 
1726
  document.body.classList.toggle('dark');
1727
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
1728
  }
1729
+ function openModal(src, event, postId) {
1730
+ event.preventDefault();
1731
+ const modal = document.getElementById('imageModal');
1732
+ const modalImg = document.getElementById('modalImage');
1733
+ modal.style.display = 'flex';
1734
+ modalImg.src = src;
1735
+
1736
+ // Увеличиваем счётчик просмотров через AJAX
1737
+ fetch(`/increment_view/${postId}`, {
1738
+ method: 'POST',
1739
+ headers: {
1740
+ 'Content-Type': 'application/json',
1741
+ }
1742
+ })
1743
+ .then(response => response.json())
1744
+ .then(data => {
1745
+ if (data.status === 'success') {
1746
+ alert('View incremented! New count: ' + data.views); // Временное уведомление для проверки
1747
+ }
1748
+ })
1749
+ .catch(error => console.error('Error incrementing view:', error));
1750
+ }
1751
+ function closeModal(event) {
1752
+ if (event.target.tagName !== 'IMG') {
1753
+ document.getElementById('imageModal').style.display = 'none';
1754
+ }
1755
+ }
1756
  window.onload = () => {
1757
  if (localStorage.getItem('theme') === 'dark') document.body.classList.add('dark');
1758
  const videos = document.querySelectorAll('.post-preview');