Spaces:
Zeuscloud
/
m
Sleeping

Eluza133 commited on
Commit
0be21c9
·
verified ·
1 Parent(s): 0af4662

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -9
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;
@@ -529,6 +529,17 @@ def logout():
529
  session.pop('username', None)
530
  return redirect(url_for('feed'))
531
 
 
 
 
 
 
 
 
 
 
 
 
532
  # Feed
533
  @app.route('/', methods=['GET', 'POST'])
534
  def feed():
@@ -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,22 @@ 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') {
@@ -1065,7 +1086,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 +1114,22 @@ 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 +1296,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 +1320,22 @@ 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') {
@@ -1620,7 +1661,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 +1678,9 @@ def admin_panel():
1637
  {% endif %}
1638
  </div>
1639
  </div>
 
 
 
1640
  <script>
1641
  function toggleSidebar() {
1642
  document.getElementById('sidebar').classList.toggle('active');
@@ -1645,6 +1689,28 @@ 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');
@@ -1665,4 +1731,4 @@ def admin_panel():
1665
  if __name__ == '__main__':
1666
  backup_thread = threading.Thread(target=periodic_backup, daemon=True)
1667
  backup_thread.start()
1668
- app.run(debug=True, host='0.0.0.0', port=7860)
 
175
  color: white;
176
  }
177
  .logout-btn:hover {
178
+ background: #45b7b0; /* Исправлена синтаксическая ошибка */
179
  }
180
  .menu-btn {
181
  display: none;
 
529
  session.pop('username', None)
530
  return redirect(url_for('feed'))
531
 
532
+ # Новый маршрут для увеличения просмотров
533
+ @app.route('/increment_view/<post_id>', methods=['POST'])
534
+ def increment_view(post_id):
535
+ data = load_data()
536
+ post = next((p for p in data['posts'] if p['id'] == post_id), None)
537
+ if post:
538
+ post['views'] = post.get('views', 0) + 1
539
+ save_data(data)
540
+ return '', 204 # Пустой ответ с кодом 204 (No Content)
541
+ return 'Post not found', 404
542
+
543
  # Feed
544
  @app.route('/', methods=['GET', 'POST'])
545
  def feed():
 
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
+ // Увеличиваем счетчик просмотров
706
+ fetch('/increment_view/' + postId, {
707
+ method: 'POST',
708
+ headers: {
709
+ 'Content-Type': 'application/json',
710
+ }
711
+ }).then(response => {
712
+ if (!response.ok) console.error('Error incrementing view');
713
+ });
714
  }
715
  function closeModal(event) {
716
  if (event.target.tagName !== 'IMG') {
 
1086
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
1087
  </video>
1088
  {% else %}
1089
+ <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'] }}')">
1090
  {% endif %}
1091
  <h3>{{ post['title'] }}</h3>
1092
  </a>
 
1114
  document.body.classList.toggle('dark');
1115
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
1116
  }
1117
+ function openModal(src, event, postId) {
1118
  event.preventDefault();
1119
  const modal = document.getElementById('imageModal');
1120
  const modalImg = document.getElementById('modalImage');
1121
  modal.style.display = 'flex';
1122
  modalImg.src = src;
1123
+
1124
+ // Увеличиваем счетчик просмотров
1125
+ fetch('/increment_view/' + postId, {
1126
+ method: 'POST',
1127
+ headers: {
1128
+ 'Content-Type': 'application/json',
1129
+ }
1130
+ }).then(response => {
1131
+ if (!response.ok) console.error('Error incrementing view');
1132
+ });
1133
  }
1134
  function closeModal(event) {
1135
  if (event.target.tagName !== 'IMG') {
 
1296
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
1297
  </video>
1298
  {% else %}
1299
+ <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'] }}')">
1300
  {% endif %}
1301
  <h3>{{ post['title'] }}</h3>
1302
  </a>
 
1320
  document.body.classList.toggle('dark');
1321
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
1322
  }
1323
+ function openModal(src, event, postId) {
1324
  event.preventDefault();
1325
  const modal = document.getElementById('imageModal');
1326
  const modalImg = document.getElementById('modalImage');
1327
  modal.style.display = 'flex';
1328
  modalImg.src = src;
1329
+
1330
+ // Увеличиваем счетчик просмотров
1331
+ fetch('/increment_view/' + postId, {
1332
+ method: 'POST',
1333
+ headers: {
1334
+ 'Content-Type': 'application/json',
1335
+ }
1336
+ }).then(response => {
1337
+ if (!response.ok) console.error('Error incrementing view');
1338
+ });
1339
  }
1340
  function closeModal(event) {
1341
  if (event.target.tagName !== 'IMG') {
 
1661
  <source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ post['type'] }}s/{{ post['filename'] }}" type="video/mp4">
1662
  </video>
1663
  {% else %}
1664
+ <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'] }}')">
1665
  {% endif %}
1666
  <h2>{{ post['title'] }}</h2>
1667
  </a>
 
1678
  {% endif %}
1679
  </div>
1680
  </div>
1681
+ <div class="modal" id="imageModal" onclick="closeModal(event)">
1682
+ <img id="modalImage" src="">
1683
+ </div>
1684
  <script>
1685
  function toggleSidebar() {
1686
  document.getElementById('sidebar').classList.toggle('active');
 
1689
  document.body.classList.toggle('dark');
1690
  localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
1691
  }
1692
+ function openModal(src, event, postId) {
1693
+ event.preventDefault();
1694
+ const modal = document.getElementById('imageModal');
1695
+ const modalImg = document.getElementById('modalImage');
1696
+ modal.style.display = 'flex';
1697
+ modalImg.src = src;
1698
+
1699
+ // Увеличиваем счетчик просмотров
1700
+ fetch('/increment_view/' + postId, {
1701
+ method: 'POST',
1702
+ headers: {
1703
+ 'Content-Type': 'application/json',
1704
+ }
1705
+ }).then(response => {
1706
+ if (!response.ok) console.error('Error incrementing view');
1707
+ });
1708
+ }
1709
+ function closeModal(event) {
1710
+ if (event.target.tagName !== 'IMG') {
1711
+ document.getElementById('imageModal').style.display = 'none';
1712
+ }
1713
+ }
1714
  window.onload = () => {
1715
  if (localStorage.getItem('theme') === 'dark') document.body.classList.add('dark');
1716
  const videos = document.querySelectorAll('.post-preview');
 
1731
  if __name__ == '__main__':
1732
  backup_thread = threading.Thread(target=periodic_backup, daemon=True)
1733
  backup_thread.start()
1734
+ app.run(debug=True, host='0.0.0.0', port=7860),