Eluza133 commited on
Commit
42f7f99
·
verified ·
1 Parent(s): 213b5da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -9
app.py CHANGED
@@ -111,6 +111,7 @@ BASE_STYLE = '''
111
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
112
  --glass-bg: rgba(255, 255, 255, 0.15);
113
  --transition: all 0.3s ease;
 
114
  }
115
  * { margin: 0; padding: 0; box-sizing: border-box; }
116
  body {
@@ -186,6 +187,13 @@ input:focus, textarea:focus {
186
  .download-btn:hover {
187
  background: #00b8c5;
188
  }
 
 
 
 
 
 
 
189
  .flash {
190
  color: var(--secondary);
191
  text-align: center;
@@ -312,13 +320,13 @@ def register():
312
  <head>
313
  <meta charset="UTF-8">
314
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
315
- <title>Регистрация - Zues Cloud</title>
316
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
317
  <style>''' + BASE_STYLE + '''</style>
318
  </head>
319
  <body>
320
  <div class="container">
321
- <h1>Регистрация в Zues Cloud</h1>
322
  {% with messages = get_flashed_messages() %}
323
  {% if messages %}
324
  {% for message in messages %}
@@ -358,13 +366,13 @@ def login():
358
  <head>
359
  <meta charset="UTF-8">
360
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
361
- <title>Zues Cloud</title>
362
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
363
  <style>''' + BASE_STYLE + '''</style>
364
  </head>
365
  <body>
366
  <div class="container">
367
- <h1>Zues Cloud</h1>
368
  <div id="flash-messages">
369
  {% with messages = get_flashed_messages() %}
370
  {% if messages %}
@@ -383,7 +391,7 @@ def login():
383
  </div>
384
  <script>
385
  // Проверка localStorage и автоматический вход
386
- const savedCredentials = JSON.parse(localStorage.getItem('zuesCredentials'));
387
  if (savedCredentials) {
388
  fetch('/', {
389
  method: 'POST',
@@ -414,7 +422,7 @@ def login():
414
  if (data.status === 'success') {
415
  const username = formData.get('username');
416
  const password = formData.get('password');
417
- localStorage.setItem('zuesCredentials', JSON.stringify({ username, password }));
418
  window.location.href = data.redirect;
419
  } else {
420
  document.getElementById('flash-messages').innerHTML = `<div class="flash">${data.message}</div>`;
@@ -496,13 +504,13 @@ def dashboard():
496
  <head>
497
  <meta charset="UTF-8">
498
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
499
- <title>Dashboard - Zues Cloud</title>
500
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
501
  <style>''' + BASE_STYLE + '''</style>
502
  </head>
503
  <body>
504
  <div class="container">
505
- <h1>Zues Cloud Dashboard</h1>
506
  <p>Пользователь: {{ username }}</p>
507
  {% with messages = get_flashed_messages() %}
508
  {% if messages %}
@@ -533,6 +541,7 @@ def dashboard():
533
  {% endif %}
534
  <p>{{ file['upload_date'] }}</p>
535
  <a href="{{ url_for('download_file', file_path=file['path'], filename=file['filename']) }}" class="btn download-btn">Скачать</a>
 
536
  </div>
537
  {% endfor %}
538
  {% if not user_files %}
@@ -613,7 +622,7 @@ def dashboard():
613
  // Обработка выхода
614
  document.getElementById('logout-btn').addEventListener('click', function(e) {
615
  e.preventDefault();
616
- localStorage.removeItem('zuesCredentials');
617
  window.location.href = '/logout';
618
  });
619
  </script>
@@ -655,6 +664,44 @@ def download_file(file_path, filename):
655
  flash('Ошибка при скачивании файла!')
656
  return redirect(url_for('dashboard'))
657
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
  @app.route('/logout')
659
  def logout():
660
  session.pop('username', None)
 
111
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
112
  --glass-bg: rgba(255, 255, 255, 0.15);
113
  --transition: all 0.3s ease;
114
+ --delete-color: #ff4444;
115
  }
116
  * { margin: 0; padding: 0; box-sizing: border-box; }
117
  body {
 
187
  .download-btn:hover {
188
  background: #00b8c5;
189
  }
190
+ .delete-btn {
191
+ background: var(--delete-color);
192
+ margin-top: 10px;
193
+ }
194
+ .delete-btn:hover {
195
+ background: #cc3333;
196
+ }
197
  .flash {
198
  color: var(--secondary);
199
  text-align: center;
 
320
  <head>
321
  <meta charset="UTF-8">
322
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
323
+ <title>Регистрация - Zeus Cloud</title>
324
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
325
  <style>''' + BASE_STYLE + '''</style>
326
  </head>
327
  <body>
328
  <div class="container">
329
+ <h1>Регистрация в Zeus Cloud</h1>
330
  {% with messages = get_flashed_messages() %}
331
  {% if messages %}
332
  {% for message in messages %}
 
366
  <head>
367
  <meta charset="UTF-8">
368
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
369
+ <title>Zeus Cloud</title>
370
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
371
  <style>''' + BASE_STYLE + '''</style>
372
  </head>
373
  <body>
374
  <div class="container">
375
+ <h1>Zeus Cloud</h1>
376
  <div id="flash-messages">
377
  {% with messages = get_flashed_messages() %}
378
  {% if messages %}
 
391
  </div>
392
  <script>
393
  // Проверка localStorage и автоматический вход
394
+ const savedCredentials = JSON.parse(localStorage.getItem('zeusCredentials'));
395
  if (savedCredentials) {
396
  fetch('/', {
397
  method: 'POST',
 
422
  if (data.status === 'success') {
423
  const username = formData.get('username');
424
  const password = formData.get('password');
425
+ localStorage.setItem('zeusCredentials', JSON.stringify({ username, password }));
426
  window.location.href = data.redirect;
427
  } else {
428
  document.getElementById('flash-messages').innerHTML = `<div class="flash">${data.message}</div>`;
 
504
  <head>
505
  <meta charset="UTF-8">
506
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
507
+ <title>Dashboard - Zeus Cloud</title>
508
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
509
  <style>''' + BASE_STYLE + '''</style>
510
  </head>
511
  <body>
512
  <div class="container">
513
+ <h1>Zeus Cloud Dashboard</h1>
514
  <p>Пользователь: {{ username }}</p>
515
  {% with messages = get_flashed_messages() %}
516
  {% if messages %}
 
541
  {% endif %}
542
  <p>{{ file['upload_date'] }}</p>
543
  <a href="{{ url_for('download_file', file_path=file['path'], filename=file['filename']) }}" class="btn download-btn">Скачать</a>
544
+ <a href="{{ url_for('delete_file', file_path=file['path']) }}" class="btn delete-btn" onclick="return confirm('Вы уверены, что хотите удалить этот файл?');">Удалить</a>
545
  </div>
546
  {% endfor %}
547
  {% if not user_files %}
 
622
  // Обработка выхода
623
  document.getElementById('logout-btn').addEventListener('click', function(e) {
624
  e.preventDefault();
625
+ localStorage.removeItem('zeusCredentials');
626
  window.location.href = '/logout';
627
  });
628
  </script>
 
664
  flash('Ошибка при скачивании файла!')
665
  return redirect(url_for('dashboard'))
666
 
667
+ @app.route('/delete/<path:file_path>')
668
+ def delete_file(file_path):
669
+ if 'username' not in session:
670
+ flash('Пожалуйста, войдите!')
671
+ return redirect(url_for('login'))
672
+
673
+ username = session['username']
674
+ data = load_data()
675
+ if username not in data['users']:
676
+ session.pop('username', None)
677
+ flash('Пользователь не найден!')
678
+ return redirect(url_for('login'))
679
+
680
+ user_files = data['users'][username]['files']
681
+ file_to_delete = next((file for file in user_files if file['path'] == file_path), None)
682
+
683
+ if not file_to_delete:
684
+ flash('Файл не найден!')
685
+ return redirect(url_for('dashboard'))
686
+
687
+ try:
688
+ api = HfApi()
689
+ api.delete_file(
690
+ path_in_repo=file_path,
691
+ repo_id=REPO_ID,
692
+ repo_type="dataset",
693
+ token=HF_TOKEN_WRITE,
694
+ commit_message=f"Удален файл {file_path} для {username}"
695
+ )
696
+ data['users'][username]['files'] = [f for f in user_files if f['path'] != file_path]
697
+ save_data(data)
698
+ flash('Файл успешно удален!')
699
+ except Exception as e:
700
+ logging.error(f"Ошибка при удалении файла: {e}")
701
+ flash('Ошибка при удалении файла!')
702
+
703
+ return redirect(url_for('dashboard'))
704
+
705
  @app.route('/logout')
706
  def logout():
707
  session.pop('username', None)