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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from flask import Flask, render_template_string, request, redirect, url_for, session, flash, send_file, jsonify
|
| 3 |
+
from flask_caching import Cache
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import logging
|
| 7 |
+
import threading
|
| 8 |
+
import time
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 11 |
+
from werkzeug.utils import secure_filename
|
| 12 |
+
import requests
|
| 13 |
+
from io import BytesIO
|
| 14 |
+
|
| 15 |
+
app = Flask(__name__)
|
| 16 |
+
app.secret_key = os.getenv("FLASK_SECRET_KEY", "supersecretkey")
|
| 17 |
+
DATA_FILE = 'cloudeng_data.json'
|
| 18 |
+
REPO_ID = "Eluza133/Z1e1u"
|
| 19 |
+
HF_TOKEN_WRITE = os.getenv("HF_TOKEN")
|
| 20 |
+
HF_TOKEN_READ = os.getenv("HF_TOKEN_READ") or HF_TOKEN_WRITE
|
| 21 |
+
|
| 22 |
+
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
|
| 23 |
+
logging.basicConfig(level=logging.INFO)
|
| 24 |
+
|
| 25 |
+
@cache.memoize(timeout=300)
|
| 26 |
+
def load_data():
|
| 27 |
+
try:
|
| 28 |
+
download_db_from_hf()
|
| 29 |
+
with open(DATA_FILE, 'r', encoding='utf-8') as file:
|
| 30 |
+
data = json.load(file)
|
| 31 |
+
if not isinstance(data, dict):
|
| 32 |
+
logging.warning("Data is not in dict format, initializing empty database")
|
| 33 |
+
return {'users': {}, 'files': {}}
|
| 34 |
+
data.setdefault('users', {})
|
| 35 |
+
data.setdefault('files', {})
|
| 36 |
+
logging.info("Data successfully loaded")
|
| 37 |
+
return data
|
| 38 |
+
except Exception as e:
|
| 39 |
+
logging.error(f"Error loading data: {e}")
|
| 40 |
+
return {'users': {}, 'files': {}}
|
| 41 |
+
|
| 42 |
+
def save_data(data):
|
| 43 |
+
try:
|
| 44 |
+
with open(DATA_FILE, 'w', encoding='utf-8') as file:
|
| 45 |
+
json.dump(data, file, ensure_ascii=False, indent=4)
|
| 46 |
+
upload_db_to_hf()
|
| 47 |
+
cache.clear()
|
| 48 |
+
logging.info("Data saved and uploaded to HF")
|
| 49 |
+
except Exception as e:
|
| 50 |
+
logging.error(f"Error saving data: {e}")
|
| 51 |
+
raise
|
| 52 |
+
|
| 53 |
+
def upload_db_to_hf():
|
| 54 |
+
try:
|
| 55 |
+
api = HfApi()
|
| 56 |
+
api.upload_file(
|
| 57 |
+
path_or_fileobj=DATA_FILE,
|
| 58 |
+
path_in_repo=DATA_FILE,
|
| 59 |
+
repo_id=REPO_ID,
|
| 60 |
+
repo_type="dataset",
|
| 61 |
+
token=HF_TOKEN_WRITE,
|
| 62 |
+
commit_message=f"Backup {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
|
| 63 |
+
)
|
| 64 |
+
logging.info("Database uploaded to Hugging Face")
|
| 65 |
+
except Exception as e:
|
| 66 |
+
logging.error(f"Error uploading database: {e}")
|
| 67 |
+
|
| 68 |
+
def download_db_from_hf():
|
| 69 |
+
try:
|
| 70 |
+
hf_hub_download(
|
| 71 |
+
repo_id=REPO_ID,
|
| 72 |
+
filename=DATA_FILE,
|
| 73 |
+
repo_type="dataset",
|
| 74 |
+
token=HF_TOKEN_READ,
|
| 75 |
+
local_dir=".",
|
| 76 |
+
local_dir_use_symlinks=False
|
| 77 |
+
)
|
| 78 |
+
logging.info("Database downloaded from Hugging Face")
|
| 79 |
+
except Exception as e:
|
| 80 |
+
logging.error(f"Error downloading database: {e}")
|
| 81 |
+
if not os.path.exists(DATA_FILE):
|
| 82 |
+
with open(DATA_FILE, 'w', encoding='utf-8') as f:
|
| 83 |
+
json.dump({'users': {}, 'files': {}}, f)
|
| 84 |
+
|
| 85 |
+
def periodic_backup():
|
| 86 |
+
while True:
|
| 87 |
+
upload_db_to_hf()
|
| 88 |
+
time.sleep(1800)
|
| 89 |
+
|
| 90 |
+
def get_file_type(filename):
|
| 91 |
+
video_extensions = ('.mp4', '.mov', '.avi')
|
| 92 |
+
image_extensions = ('.jpg', '.jpeg', '.png', '.gif')
|
| 93 |
+
if filename.lower().endswith(video_extensions):
|
| 94 |
+
return 'video'
|
| 95 |
+
elif filename.lower().endswith(image_extensions):
|
| 96 |
+
return 'image'
|
| 97 |
+
return 'other'
|
| 98 |
+
|
| 99 |
+
BASE_STYLE = '''
|
| 100 |
+
:root {
|
| 101 |
+
--primary: #ff4d6d;
|
| 102 |
+
--secondary: #00ddeb;
|
| 103 |
+
--accent: #8b5cf6;
|
| 104 |
+
--background-light: #f5f6fa;
|
| 105 |
+
--background-dark: #1a1625;
|
| 106 |
+
--card-bg: rgba(255, 255, 255, 0.95);
|
| 107 |
+
--card-bg-dark: rgba(40, 35, 60, 0.95);
|
| 108 |
+
--text-light: #2a1e5a;
|
| 109 |
+
--text-dark: #e8e1ff;
|
| 110 |
+
--shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
| 111 |
+
--glass-bg: rgba(255, 255, 255, 0.15);
|
| 112 |
+
--transition: all 0.3s ease;
|
| 113 |
+
--delete-color: #ff4444;
|
| 114 |
+
}
|
| 115 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 116 |
+
body {
|
| 117 |
+
font-family: 'Inter', sans-serif;
|
| 118 |
+
background: var(--background-light);
|
| 119 |
+
color: var(--text-light);
|
| 120 |
+
line-height: 1.6;
|
| 121 |
+
}
|
| 122 |
+
body.dark {
|
| 123 |
+
background: var(--background-dark);
|
| 124 |
+
color: var(--text-dark);
|
| 125 |
+
}
|
| 126 |
+
.container {
|
| 127 |
+
margin: 20px auto;
|
| 128 |
+
max-width: 1200px;
|
| 129 |
+
padding: 25px;
|
| 130 |
+
background: var(--card-bg);
|
| 131 |
+
border-radius: 20px;
|
| 132 |
+
box-shadow: var(--shadow);
|
| 133 |
+
}
|
| 134 |
+
body.dark .container {
|
| 135 |
+
background: var(--card-bg-dark);
|
| 136 |
+
}
|
| 137 |
+
h1 {
|
| 138 |
+
font-size: 2em;
|
| 139 |
+
font-weight: 800;
|
| 140 |
+
text-align: center;
|
| 141 |
+
margin-bottom: 25px;
|
| 142 |
+
background: linear-gradient(135deg, var(--primary), var(--accent));
|
| 143 |
+
-webkit-background-clip: text;
|
| 144 |
+
color: transparent;
|
| 145 |
+
}
|
| 146 |
+
h2 {
|
| 147 |
+
font-size: 1.5em;
|
| 148 |
+
margin-top: 30px;
|
| 149 |
+
color: var(--text-light);
|
| 150 |
+
}
|
| 151 |
+
body.dark h2 {
|
| 152 |
+
color: var(--text-dark);
|
| 153 |
+
}
|
| 154 |
+
input, textarea {
|
| 155 |
+
width: 100%;
|
| 156 |
+
padding: 14px;
|
| 157 |
+
margin: 12px 0;
|
| 158 |
+
border: none;
|
| 159 |
+
border-radius: 14px;
|
| 160 |
+
background: var(--glass-bg);
|
| 161 |
+
color: var(--text-light);
|
| 162 |
+
font-size: 1.1em;
|
| 163 |
+
box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.1);
|
| 164 |
+
}
|
| 165 |
+
body.dark input, body.dark textarea {
|
| 166 |
+
color: var(--text-dark);
|
| 167 |
+
}
|
| 168 |
+
input:focus, textarea:focus {
|
| 169 |
+
outline: none;
|
| 170 |
+
box-shadow: 0 0 0 4px var(--primary);
|
| 171 |
+
}
|
| 172 |
+
.btn {
|
| 173 |
+
padding: 14px 28px;
|
| 174 |
+
background: var(--primary);
|
| 175 |
+
color: white;
|
| 176 |
+
border: none;
|
| 177 |
+
border-radius: 14px;
|
| 178 |
+
cursor: pointer;
|
| 179 |
+
font-size: 1.1em;
|
| 180 |
+
font-weight: 600;
|
| 181 |
+
transition: var(--transition);
|
| 182 |
+
box-shadow: var(--shadow);
|
| 183 |
+
display: inline-block;
|
| 184 |
+
text-decoration: none;
|
| 185 |
+
}
|
| 186 |
+
.btn:hover {
|
| 187 |
+
transform: scale(1.05);
|
| 188 |
+
background: #e6415f;
|
| 189 |
+
}
|
| 190 |
+
.download-btn {
|
| 191 |
+
background: var(--secondary);
|
| 192 |
+
margin-top: 10px;
|
| 193 |
+
}
|
| 194 |
+
.download-btn:hover {
|
| 195 |
+
background: #00b8c5;
|
| 196 |
+
}
|
| 197 |
+
.delete-btn {
|
| 198 |
+
background: var(--delete-color);
|
| 199 |
+
margin-top: 10px;
|
| 200 |
+
}
|
| 201 |
+
.delete-btn:hover {
|
| 202 |
+
background: #cc3333;
|
| 203 |
+
}
|
| 204 |
+
.flash {
|
| 205 |
+
color: var(--secondary);
|
| 206 |
+
text-align: center;
|
| 207 |
+
margin-bottom: 15px;
|
| 208 |
+
}
|
| 209 |
+
.file-grid {
|
| 210 |
+
display: grid;
|
| 211 |
+
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
| 212 |
+
gap: 20px;
|
| 213 |
+
margin-top: 20px;
|
| 214 |
+
}
|
| 215 |
+
.user-list {
|
| 216 |
+
margin-top: 20px;
|
| 217 |
+
}
|
| 218 |
+
.user-item {
|
| 219 |
+
padding: 15px;
|
| 220 |
+
background: var(--card-bg);
|
| 221 |
+
border-radius: 16px;
|
| 222 |
+
margin-bottom: 10px;
|
| 223 |
+
box-shadow: var(--shadow);
|
| 224 |
+
transition: var(--transition);
|
| 225 |
+
}
|
| 226 |
+
body.dark .user-item {
|
| 227 |
+
background: var(--card-bg-dark);
|
| 228 |
+
}
|
| 229 |
+
.user-item:hover {
|
| 230 |
+
transform: translateY(-5px);
|
| 231 |
+
}
|
| 232 |
+
.user-item a {
|
| 233 |
+
color: var(--primary);
|
| 234 |
+
text-decoration: none;
|
| 235 |
+
font-weight: 600;
|
| 236 |
+
}
|
| 237 |
+
.user-item a:hover {
|
| 238 |
+
color: var(--accent);
|
| 239 |
+
}
|
| 240 |
+
@media (max-width: 768px) {
|
| 241 |
+
.file-grid {
|
| 242 |
+
grid-template-columns: repeat(2, 1fr);
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
@media (max-width: 480px) {
|
| 246 |
+
.file-grid {
|
| 247 |
+
grid-template-columns: 1fr;
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
.file-item {
|
| 251 |
+
background: var(--card-bg);
|
| 252 |
+
padding: 15px;
|
| 253 |
+
border-radius: 16px;
|
| 254 |
+
box-shadow: var(--shadow);
|
| 255 |
+
text-align: center;
|
| 256 |
+
transition: var(--transition);
|
| 257 |
+
}
|
| 258 |
+
body.dark .file-item {
|
| 259 |
+
background: var(--card-bg-dark);
|
| 260 |
+
}
|
| 261 |
+
.file-item:hover {
|
| 262 |
+
transform: translateY(-5px);
|
| 263 |
+
}
|
| 264 |
+
.file-preview {
|
| 265 |
+
max-width: 100%;
|
| 266 |
+
max-height: 200px;
|
| 267 |
+
object-fit: cover;
|
| 268 |
+
border-radius: 10px;
|
| 269 |
+
margin-bottom: 10px;
|
| 270 |
+
loading: lazy;
|
| 271 |
+
}
|
| 272 |
+
.file-item p {
|
| 273 |
+
font-size: 0.9em;
|
| 274 |
+
margin: 5px 0;
|
| 275 |
+
}
|
| 276 |
+
.file-item a {
|
| 277 |
+
color: var(--primary);
|
| 278 |
+
text-decoration: none;
|
| 279 |
+
}
|
| 280 |
+
.file-item a:hover {
|
| 281 |
+
color: var(--accent);
|
| 282 |
+
}
|
| 283 |
+
.modal {
|
| 284 |
+
display: none;
|
| 285 |
+
position: fixed;
|
| 286 |
+
top: 0;
|
| 287 |
+
left: 0;
|
| 288 |
+
width: 100%;
|
| 289 |
+
height: 100%;
|
| 290 |
+
background: rgba(0, 0, 0, 0.85);
|
| 291 |
+
z-index: 2000;
|
| 292 |
+
justify-content: center;
|
| 293 |
+
align-items: center;
|
| 294 |
+
}
|
| 295 |
+
.modal img, .modal video {
|
| 296 |
+
max-width: 95%;
|
| 297 |
+
max-height: 95%;
|
| 298 |
+
object-fit: contain;
|
| 299 |
+
border-radius: 20px;
|
| 300 |
+
box-shadow: var(--shadow);
|
| 301 |
+
}
|
| 302 |
+
#progress-container {
|
| 303 |
+
width: 100%;
|
| 304 |
+
background: var(--glass-bg);
|
| 305 |
+
border-radius: 10px;
|
| 306 |
+
margin: 15px 0;
|
| 307 |
+
display: none;
|
| 308 |
+
}
|
| 309 |
+
#progress-bar {
|
| 310 |
+
width: 0%;
|
| 311 |
+
height: 20px;
|
| 312 |
+
background: var(--primary);
|
| 313 |
+
border-radius: 10px;
|
| 314 |
+
transition: width 0.3s ease;
|
| 315 |
+
}
|
| 316 |
+
'''
|
| 317 |
+
|
| 318 |
+
@app.route('/register', methods=['GET', 'POST'])
|
| 319 |
+
def register():
|
| 320 |
+
if request.method == 'POST':
|
| 321 |
+
username = request.form.get('username')
|
| 322 |
+
password = request.form.get('password')
|
| 323 |
+
|
| 324 |
+
data = load_data()
|
| 325 |
+
|
| 326 |
+
if username in data['users']:
|
| 327 |
+
flash('Пользователь с таким именем уже существует!')
|
| 328 |
+
return redirect(url_for('register'))
|
| 329 |
+
|
| 330 |
+
if not username or not password:
|
| 331 |
+
flash('Имя пользователя и пароль обязательны!')
|
| 332 |
+
return redirect(url_for('register'))
|
| 333 |
+
|
| 334 |
+
data['users'][username] = {
|
| 335 |
+
'password': password,
|
| 336 |
+
'created_at': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
| 337 |
+
'files': []
|
| 338 |
+
}
|
| 339 |
+
save_data(data)
|
| 340 |
+
session['username'] = username
|
| 341 |
+
flash('Регистрация прошла успешно!')
|
| 342 |
+
return redirect(url_for('dashboard'))
|
| 343 |
+
|
| 344 |
+
html = '''
|
| 345 |
+
<!DOCTYPE html>
|
| 346 |
+
<html lang="ru">
|
| 347 |
+
<head>
|
| 348 |
+
<meta charset="UTF-8">
|
| 349 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 350 |
+
<title>Регистрация - Zeus Cloud</title>
|
| 351 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
|
| 352 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 353 |
+
</head>
|
| 354 |
+
<body>
|
| 355 |
+
<div class="container">
|
| 356 |
+
<h1>Регистрация в Zeus Cloud</h1>
|
| 357 |
+
{% with messages = get_flashed_messages() %}
|
| 358 |
+
{% if messages %}
|
| 359 |
+
{% for message in messages %}
|
| 360 |
+
<div class="flash">{{ message }}</div>
|
| 361 |
+
{% endfor %}
|
| 362 |
+
{% endif %}
|
| 363 |
+
{% endwith %}
|
| 364 |
+
<form method="POST" id="register-form">
|
| 365 |
+
<input type="text" name="username" placeholder="Введите имя пользователя" required>
|
| 366 |
+
<input type="password" name="password" placeholder="Введите пароль" required>
|
| 367 |
+
<button type="submit" class="btn">Зарегистрироваться</button>
|
| 368 |
+
</form>
|
| 369 |
+
<p style="margin-top: 20px;">Уже есть аккаунт? <a href="{{ url_for('login') }}">Войти</a></p>
|
| 370 |
+
</div>
|
| 371 |
+
</body>
|
| 372 |
+
</html>
|
| 373 |
+
'''
|
| 374 |
+
return render_template_string(html)
|
| 375 |
+
|
| 376 |
+
@app.route('/', methods=['GET', 'POST'])
|
| 377 |
+
def login():
|
| 378 |
+
if request.method == 'POST':
|
| 379 |
+
username = request.form.get('username')
|
| 380 |
+
password = request.form.get('password')
|
| 381 |
+
data = load_data()
|
| 382 |
+
|
| 383 |
+
if username in data['users'] and data['users'][username]['password'] == password:
|
| 384 |
+
session['username'] = username
|
| 385 |
+
return jsonify({'status': 'success', 'redirect': url_for('dashboard')})
|
| 386 |
+
else:
|
| 387 |
+
return jsonify({'status': 'error', 'message': 'Неверное имя пользователя или пароль!'})
|
| 388 |
+
|
| 389 |
+
html = '''
|
| 390 |
+
<!DOCTYPE html>
|
| 391 |
+
<html lang="ru">
|
| 392 |
+
<head>
|
| 393 |
+
<meta charset="UTF-8">
|
| 394 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 395 |
+
<title>Zeus Cloud</title>
|
| 396 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
|
| 397 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 398 |
+
</head>
|
| 399 |
+
<body>
|
| 400 |
+
<div class="container">
|
| 401 |
+
<h1>Zeus Cloud</h1>
|
| 402 |
+
<div id="flash-messages">
|
| 403 |
+
{% with messages = get_flashed_messages() %}
|
| 404 |
+
{% if messages %}
|
| 405 |
+
{% for message in messages %}
|
| 406 |
+
<div class="flash">{{ message }}</div>
|
| 407 |
+
{% endfor %}
|
| 408 |
+
{% endif %}
|
| 409 |
+
{% endwith %}
|
| 410 |
+
</div>
|
| 411 |
+
<form method="POST" id="login-form">
|
| 412 |
+
<input type="text" name="username" placeholder="Введите имя пользователя" required>
|
| 413 |
+
<input type="password" name="password" placeholder="Введите пароль" required>
|
| 414 |
+
<button type="submit" class="btn">Войти</button>
|
| 415 |
+
</form>
|
| 416 |
+
<p style="margin-top: 20px;">Нет аккаунта? <a href="{{ url_for('register') }}">Зарегистрируйтесь</a></p>
|
| 417 |
+
</div>
|
| 418 |
+
<script>
|
| 419 |
+
const savedCredentials = JSON.parse(localStorage.getItem('zeusCredentials'));
|
| 420 |
+
if (savedCredentials) {
|
| 421 |
+
fetch('/', {
|
| 422 |
+
method: 'POST',
|
| 423 |
+
headers: {
|
| 424 |
+
'Content-Type': 'application/x-www-form-urlencoded',
|
| 425 |
+
},
|
| 426 |
+
body: `username=${encodeURIComponent(savedCredentials.username)}&password=${encodeURIComponent(savedCredentials.password)}`
|
| 427 |
+
})
|
| 428 |
+
.then(response => response.json())
|
| 429 |
+
.then(data => {
|
| 430 |
+
if (data.status === 'success') {
|
| 431 |
+
window.location.href = data.redirect;
|
| 432 |
+
}
|
| 433 |
+
})
|
| 434 |
+
.catch(error => console.error('Ошибка автовхода:', error));
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
document.getElementById('login-form').addEventListener('submit', function(e) {
|
| 438 |
+
e.preventDefault();
|
| 439 |
+
const formData = new FormData(this);
|
| 440 |
+
fetch('/', {
|
| 441 |
+
method: 'POST',
|
| 442 |
+
body: formData
|
| 443 |
+
})
|
| 444 |
+
.then(response => response.json())
|
| 445 |
+
.then(data => {
|
| 446 |
+
if (data.status === 'success') {
|
| 447 |
+
const username = formData.get('username');
|
| 448 |
+
const password = formData.get('password');
|
| 449 |
+
localStorage.setItem('zeusCredentials', JSON.stringify({ username, password }));
|
| 450 |
+
window.location.href = data.redirect;
|
| 451 |
+
} else {
|
| 452 |
+
document.getElementById('flash-messages').innerHTML = `<div class="flash">${data.message}</div>`;
|
| 453 |
+
}
|
| 454 |
+
})
|
| 455 |
+
.catch(error => {
|
| 456 |
+
document.getElementById('flash-messages').innerHTML = `<div class="flash">Ошибка соединения!</div>`;
|
| 457 |
+
});
|
| 458 |
+
});
|
| 459 |
+
</script>
|
| 460 |
+
</body>
|
| 461 |
+
</html>
|
| 462 |
+
'''
|
| 463 |
+
return render_template_string(html)
|
| 464 |
+
|
| 465 |
+
@app.route('/dashboard', methods=['GET', 'POST'])
|
| 466 |
+
def dashboard():
|
| 467 |
+
if 'username' not in session:
|
| 468 |
+
flash('Пожалуйста, войдите в систему!')
|
| 469 |
+
return redirect(url_for('login'))
|
| 470 |
+
|
| 471 |
+
username = session['username']
|
| 472 |
+
data = load_data()
|
| 473 |
+
if username not in data['users']:
|
| 474 |
+
session.pop('username', None)
|
| 475 |
+
flash('Пользователь не найден!')
|
| 476 |
+
return redirect(url_for('login'))
|
| 477 |
+
|
| 478 |
+
user_files = sorted(data['users'][username]['files'], key=lambda x: x['upload_date'], reverse=True)
|
| 479 |
+
|
| 480 |
+
if request.method == 'POST':
|
| 481 |
+
files = request.files.getlist('files')
|
| 482 |
+
if files and len(files) > 20:
|
| 483 |
+
flash('Максимум 20 файлов за раз!')
|
| 484 |
+
return redirect(url_for('dashboard'))
|
| 485 |
+
|
| 486 |
+
if files:
|
| 487 |
+
os.makedirs('uploads', exist_ok=True)
|
| 488 |
+
api = HfApi()
|
| 489 |
+
temp_files = []
|
| 490 |
+
|
| 491 |
+
for file in files:
|
| 492 |
+
if file and file.filename:
|
| 493 |
+
filename = secure_filename(file.filename)
|
| 494 |
+
temp_path = os.path.join('uploads', filename)
|
| 495 |
+
file.save(temp_path)
|
| 496 |
+
temp_files.append((temp_path, filename))
|
| 497 |
+
|
| 498 |
+
for temp_path, filename in temp_files:
|
| 499 |
+
file_path = f"cloud_files/{username}/{filename}"
|
| 500 |
+
api.upload_file(
|
| 501 |
+
path_or_fileobj=temp_path,
|
| 502 |
+
path_in_repo=file_path,
|
| 503 |
+
repo_id=REPO_ID,
|
| 504 |
+
repo_type="dataset",
|
| 505 |
+
token=HF_TOKEN_WRITE,
|
| 506 |
+
commit_message=f"Uploaded file for {username}"
|
| 507 |
+
)
|
| 508 |
+
|
| 509 |
+
file_info = {
|
| 510 |
+
'filename': filename,
|
| 511 |
+
'path': file_path,
|
| 512 |
+
'type': get_file_type(filename),
|
| 513 |
+
'upload_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
| 514 |
+
}
|
| 515 |
+
data['users'][username]['files'].append(file_info)
|
| 516 |
+
|
| 517 |
+
if os.path.exists(temp_path):
|
| 518 |
+
os.remove(temp_path)
|
| 519 |
+
|
| 520 |
+
save_data(data)
|
| 521 |
+
flash('Файлы успешно загружены!')
|
| 522 |
+
|
| 523 |
+
return redirect(url_for('dashboard'))
|
| 524 |
+
|
| 525 |
+
html = '''
|
| 526 |
+
<!DOCTYPE html>
|
| 527 |
+
<html lang="ru">
|
| 528 |
+
<head>
|
| 529 |
+
<meta charset="UTF-8">
|
| 530 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 531 |
+
<title>Панель управления - Zeus Cloud</title>
|
| 532 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
|
| 533 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 534 |
+
</head>
|
| 535 |
+
<body>
|
| 536 |
+
<div class="container">
|
| 537 |
+
<h1>Панель управления Zeus Cloud</h1>
|
| 538 |
+
<p>Пользователь: {{ username }}</p>
|
| 539 |
+
{% with messages = get_flashed_messages() %}
|
| 540 |
+
{% if messages %}
|
| 541 |
+
{% for message in messages %}
|
| 542 |
+
<div class="flash">{{ message }}</div>
|
| 543 |
+
{% endfor %}
|
| 544 |
+
{% endif %}
|
| 545 |
+
{% endwith %}
|
| 546 |
+
<form id="upload-form" method="POST" enctype="multipart/form-data">
|
| 547 |
+
<input type="file" name="files" multiple required accept="image/*,video/*">
|
| 548 |
+
<button type="submit" class="btn" id="upload-btn">Загрузить файлы</button>
|
| 549 |
+
</form>
|
| 550 |
+
<div id="progress-container">
|
| 551 |
+
<div id="progress-bar"></div>
|
| 552 |
+
</div>
|
| 553 |
+
<h2 style="margin-top: 30px;">Ваши файлы</h2>
|
| 554 |
+
<p style="text-align: center; margin-top: 10px; color: var(--accent);">Ваши файлы под надежной защитой квантовой криптографии</p>
|
| 555 |
+
<div class="file-grid">
|
| 556 |
+
{% for file in user_files %}
|
| 557 |
+
<div class="file-item">
|
| 558 |
+
{% if file['type'] == 'video' %}
|
| 559 |
+
<video class="file-preview" preload="metadata" muted loading="lazy" onclick="openModal('https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}', true)">
|
| 560 |
+
<source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}" type="video/mp4">
|
| 561 |
+
</video>
|
| 562 |
+
{% elif file['type'] == 'image' %}
|
| 563 |
+
<img class="file-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}" alt="{{ file['filename'] }}" loading="lazy" onclick="openModal(this.src, false)">
|
| 564 |
+
{% else %}
|
| 565 |
+
<p>{{ file['filename'] }}</p>
|
| 566 |
+
{% endif %}
|
| 567 |
+
<p>{{ file['upload_date'] }}</p>
|
| 568 |
+
<a href="{{ url_for('download_file', file_path=file['path'], filename=file['filename']) }}" class="btn download-btn">Скачать</a>
|
| 569 |
+
<a href="{{ url_for('delete_file', file_path=file['path']) }}" class="btn delete-btn" onclick="return confirm('Вы уверены, что хотите удалить этот файл?');">Удалить</a>
|
| 570 |
+
</div>
|
| 571 |
+
{% endfor %}
|
| 572 |
+
{% if not user_files %}
|
| 573 |
+
<p>Вы еще не загрузили ни одного файла.</p>
|
| 574 |
+
{% endif %}
|
| 575 |
+
</div>
|
| 576 |
+
<h2 style="margin-top: 30px;">Добавить на главный экран</h2>
|
| 577 |
+
<p>Для быстрого доступа к Zeus Cloud, вы можете добавить это приложение на главный экран вашего телефона:</p>
|
| 578 |
+
<div style="margin-top: 10px;">
|
| 579 |
+
<h3>Для пользователей Android:</h3>
|
| 580 |
+
<ol>
|
| 581 |
+
<li>Откройте Zeus Cloud в браузере Chrome.</li>
|
| 582 |
+
<li>Нажмите на меню браузера (обычно три точки вверху справа).</li>
|
| 583 |
+
<li>Выберите <strong>"Добавить на главный экран"</strong>.</li>
|
| 584 |
+
<li>Подтвердите добавление, и иконка приложения появится на вашем главном экране.</li>
|
| 585 |
+
</ol>
|
| 586 |
+
</div>
|
| 587 |
+
<div style="margin-top: 10px;">
|
| 588 |
+
<h3>Для пользователей iOS (iPhone/iPad):</h3>
|
| 589 |
+
<ol>
|
| 590 |
+
<li>Откройте Zeus Cloud в браузере Safari.</li>
|
| 591 |
+
<li>Нажмите кнопку <strong>"Поделиться"</strong> (квадрат со стрелкой вверх) в нижней части экрана.</li>
|
| 592 |
+
<li>Прокрутите список опций вниз и выберите <strong>"Добавить на экран «Домой»"</strong>.</li>
|
| 593 |
+
<li>В правом верхнем углу нажмите <strong>"Добавить"</strong>. Иконка приложения появится на вашем главном экране.</li>
|
| 594 |
+
</ol>
|
| 595 |
+
</div>
|
| 596 |
+
<a href="{{ url_for('logout') }}" class="btn" style="margin-top: 20px;" id="logout-btn">Выйти</a>
|
| 597 |
+
</div>
|
| 598 |
+
<div class="modal" id="mediaModal" onclick="closeModal(event)">
|
| 599 |
+
<div id="modalContent"></div>
|
| 600 |
+
</div>
|
| 601 |
+
<script>
|
| 602 |
+
function openModal(src, isVideo) {
|
| 603 |
+
const modal = document.getElementById('mediaModal');
|
| 604 |
+
const modalContent = document.getElementById('modalContent');
|
| 605 |
+
if (isVideo) {
|
| 606 |
+
modalContent.innerHTML = `<video controls autoplay><source src="${src}" type="video/mp4"></video>`;
|
| 607 |
+
} else {
|
| 608 |
+
modalContent.innerHTML = `<img src="${src}">`;
|
| 609 |
+
}
|
| 610 |
+
modal.style.display = 'flex';
|
| 611 |
+
}
|
| 612 |
+
function closeModal(event) {
|
| 613 |
+
const modal = document.getElementById('mediaModal');
|
| 614 |
+
if (event.target === modal) { // Закрывать только при клике на фон
|
| 615 |
+
modal.style.display = 'none';
|
| 616 |
+
const video = modal.querySelector('video');
|
| 617 |
+
if (video) {
|
| 618 |
+
video.pause();
|
| 619 |
+
}
|
| 620 |
+
modalContent.innerHTML = ''; // Очистить содержимое
|
| 621 |
+
}
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
const form = document.getElementById('upload-form');
|
| 625 |
+
const progressBar = document.getElementById('progress-bar');
|
| 626 |
+
const progressContainer = document.getElementById('progress-container');
|
| 627 |
+
const uploadBtn = document.getElementById('upload-btn');
|
| 628 |
+
|
| 629 |
+
form.addEventListener('submit', function(e) {
|
| 630 |
+
e.preventDefault();
|
| 631 |
+
const files = form.querySelector('input[type="file"]').files;
|
| 632 |
+
if (files.length > 20) {
|
| 633 |
+
alert('Максимум 20 файлов за раз!');
|
| 634 |
+
return;
|
| 635 |
+
}
|
| 636 |
+
if (files.length === 0) {
|
| 637 |
+
alert('Пожалуйста, выберите файлы для загрузки.');
|
| 638 |
+
return;
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
const formData = new FormData(form);
|
| 642 |
+
progressContainer.style.display = 'block';
|
| 643 |
+
progressBar.style.width = '0%';
|
| 644 |
+
uploadBtn.disabled = true;
|
| 645 |
+
|
| 646 |
+
const xhr = new XMLHttpRequest();
|
| 647 |
+
xhr.open('POST', '/dashboard', true);
|
| 648 |
+
|
| 649 |
+
xhr.upload.onprogress = function(event) {
|
| 650 |
+
if (event.lengthComputable) {
|
| 651 |
+
const percent = (event.loaded / event.total) * 100;
|
| 652 |
+
progressBar.style.width = percent + '%';
|
| 653 |
+
}
|
| 654 |
+
};
|
| 655 |
+
|
| 656 |
+
xhr.onload = function() {
|
| 657 |
+
uploadBtn.disabled = false;
|
| 658 |
+
progressContainer.style.display = 'none';
|
| 659 |
+
progressBar.style.width = '0%';
|
| 660 |
+
if (xhr.status === 200) {
|
| 661 |
+
// Не перезагружаем страницу, а обновляем флеш-сообщения или список файлов динамически, если возможно
|
| 662 |
+
// Для простоты пока оставим перезагрузку
|
| 663 |
+
location.reload();
|
| 664 |
+
} else {
|
| 665 |
+
alert('Ошибка загрузки!');
|
| 666 |
+
}
|
| 667 |
+
};
|
| 668 |
+
|
| 669 |
+
xhr.onerror = function() {
|
| 670 |
+
alert('Ошибка соединения!');
|
| 671 |
+
progressContainer.style.display = 'none';
|
| 672 |
+
progressBar.style.width = '0%';
|
| 673 |
+
uploadBtn.disabled = false;
|
| 674 |
+
};
|
| 675 |
+
|
| 676 |
+
xhr.send(formData);
|
| 677 |
+
});
|
| 678 |
+
|
| 679 |
+
document.getElementById('logout-btn').addEventListener('click', function(e) {
|
| 680 |
+
e.preventDefault();
|
| 681 |
+
localStorage.removeItem('zeusCredentials');
|
| 682 |
+
window.location.href = '/logout';
|
| 683 |
+
});
|
| 684 |
+
</script>
|
| 685 |
+
</body>
|
| 686 |
+
</html>
|
| 687 |
+
'''
|
| 688 |
+
return render_template_string(html, username=username, user_files=user_files, repo_id=REPO_ID)
|
| 689 |
+
|
| 690 |
+
@app.route('/download/<path:file_path>/<filename>')
|
| 691 |
+
def download_file(file_path, filename):
|
| 692 |
+
if 'username' not in session:
|
| 693 |
+
flash('Пожалуйста, войдите в систему!')
|
| 694 |
+
return redirect(url_for('login'))
|
| 695 |
+
|
| 696 |
+
username = session['username']
|
| 697 |
+
data = load_data()
|
| 698 |
+
if username not in data['users']:
|
| 699 |
+
session.pop('username', None)
|
| 700 |
+
flash('Пользователь не найден!')
|
| 701 |
+
return redirect(url_for('login'))
|
| 702 |
+
|
| 703 |
+
# Проверка доступа для обычного пользователя
|
| 704 |
+
user_files = data['users'][username]['files']
|
| 705 |
+
if not any(file['path'] == file_path for file in user_files):
|
| 706 |
+
# Разрешаем скачивание админу, если он залогинен (проверка в админ панели)
|
| 707 |
+
# Но здесь обычный пользователь, ему нельзя
|
| 708 |
+
is_admin_route = request.referrer and 'admhosto' in request.referrer
|
| 709 |
+
if not is_admin_route: # Если это не админ пытается скачать со своей страницы
|
| 710 |
+
flash('У вас нет доступа к этому файлу!')
|
| 711 |
+
return redirect(url_for('dashboard'))
|
| 712 |
+
# Если это админ, доступ разрешен (неявно, т.к. проверка выше не сработает)
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
file_url = f"https://huggingface.co/datasets/{REPO_ID}/resolve/main/{file_path}?download=true"
|
| 716 |
+
try:
|
| 717 |
+
api = HfApi()
|
| 718 |
+
# Использование токена для скачивания, если репозиторий приватный
|
| 719 |
+
headers = {}
|
| 720 |
+
if HF_TOKEN_READ:
|
| 721 |
+
headers["authorization"] = f"Bearer {HF_TOKEN_READ}"
|
| 722 |
+
|
| 723 |
+
response = requests.get(file_url, headers=headers, stream=True)
|
| 724 |
+
response.raise_for_status() # Проверка на ошибки HTTP
|
| 725 |
+
|
| 726 |
+
file_content = BytesIO(response.content)
|
| 727 |
+
return send_file(
|
| 728 |
+
file_content,
|
| 729 |
+
as_attachment=True,
|
| 730 |
+
download_name=filename,
|
| 731 |
+
mimetype='application/octet-stream' # Общий тип для скачивания
|
| 732 |
+
)
|
| 733 |
+
except requests.exceptions.RequestException as e:
|
| 734 |
+
logging.error(f"Error downloading file from HF: {e}")
|
| 735 |
+
flash('Ошибка скачивания файла!')
|
| 736 |
+
# Определяем, куда редиректить: на дашборд или админку
|
| 737 |
+
if request.referrer and 'admhosto' in request.referrer:
|
| 738 |
+
return redirect(url_for('admin_user_files', username=file_path.split('/')[1])) # Получаем username из пути
|
| 739 |
+
else:
|
| 740 |
+
return redirect(url_for('dashboard'))
|
| 741 |
+
except Exception as e:
|
| 742 |
+
logging.error(f"Unexpected error during download: {e}")
|
| 743 |
+
flash('Произошла непредвиденная ошибка при скачивании файла.')
|
| 744 |
+
if request.referrer and 'admhosto' in request.referrer:
|
| 745 |
+
return redirect(url_for('admin_user_files', username=file_path.split('/')[1]))
|
| 746 |
+
else:
|
| 747 |
+
return redirect(url_for('dashboard'))
|
| 748 |
+
|
| 749 |
+
|
| 750 |
+
@app.route('/delete/<path:file_path>')
|
| 751 |
+
def delete_file(file_path):
|
| 752 |
+
if 'username' not in session:
|
| 753 |
+
flash('Пожалуйста, войдите в систему!')
|
| 754 |
+
return redirect(url_for('login'))
|
| 755 |
+
|
| 756 |
+
username = session['username']
|
| 757 |
+
data = load_data()
|
| 758 |
+
if username not in data['users']:
|
| 759 |
+
session.pop('username', None)
|
| 760 |
+
flash('Пользователь не найден!')
|
| 761 |
+
return redirect(url_for('login'))
|
| 762 |
+
|
| 763 |
+
user_files = data['users'][username]['files']
|
| 764 |
+
file_to_delete = next((file for file in user_files if file['path'] == file_path), None)
|
| 765 |
+
|
| 766 |
+
if not file_to_delete:
|
| 767 |
+
flash('Файл не найден!')
|
| 768 |
+
return redirect(url_for('dashboard'))
|
| 769 |
+
|
| 770 |
+
try:
|
| 771 |
+
api = HfApi()
|
| 772 |
+
api.delete_file(
|
| 773 |
+
path_in_repo=file_path,
|
| 774 |
+
repo_id=REPO_ID,
|
| 775 |
+
repo_type="dataset",
|
| 776 |
+
token=HF_TOKEN_WRITE,
|
| 777 |
+
commit_message=f"Deleted file {file_path} for {username}"
|
| 778 |
+
)
|
| 779 |
+
data['users'][username]['files'] = [f for f in user_files if f['path'] != file_path]
|
| 780 |
+
save_data(data)
|
| 781 |
+
flash('Файл успешно удален!')
|
| 782 |
+
except Exception as e:
|
| 783 |
+
logging.error(f"Error deleting file: {e}")
|
| 784 |
+
flash('Ошибка удаления файла!')
|
| 785 |
+
|
| 786 |
+
return redirect(url_for('dashboard'))
|
| 787 |
+
|
| 788 |
+
@app.route('/logout')
|
| 789 |
+
def logout():
|
| 790 |
+
session.pop('username', None)
|
| 791 |
+
# Дополнительно очищаем localStorage на клиенте через редирект
|
| 792 |
+
# Простой редирект, JS на странице логина уже обрабатывает выход
|
| 793 |
+
return redirect(url_for('login'))
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
@app.route('/admhosto')
|
| 797 |
+
def admin_panel():
|
| 798 |
+
# Здесь можно добавить проверку админского пароля или сессии
|
| 799 |
+
data = load_data()
|
| 800 |
+
users = data['users']
|
| 801 |
+
|
| 802 |
+
html = '''
|
| 803 |
+
<!DOCTYPE html>
|
| 804 |
+
<html lang="ru">
|
| 805 |
+
<head>
|
| 806 |
+
<meta charset="UTF-8">
|
| 807 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 808 |
+
<title>Админ-панель - Zeus Cloud</title>
|
| 809 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
|
| 810 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 811 |
+
</head>
|
| 812 |
+
<body>
|
| 813 |
+
<div class="container">
|
| 814 |
+
<h1>Админ-панель Zeus Cloud</h1>
|
| 815 |
+
<h2>Список пользователей</h2>
|
| 816 |
+
<div class="user-list">
|
| 817 |
+
{% for username, user_data in users.items() %}
|
| 818 |
+
<div class="user-item">
|
| 819 |
+
<a href="{{ url_for('admin_user_files', username=username) }}">{{ username }}</a>
|
| 820 |
+
<p>Дата регистрации: {{ user_data.get('created_at', 'N/A') }}</p>
|
| 821 |
+
<p>Количество файлов: {{ user_data.get('files', []) | length }}</p>
|
| 822 |
+
<!-- Добавить кнопку удаления пользователя -->
|
| 823 |
+
<form method="POST" action="{{ url_for('admin_delete_user', username=username) }}" style="display: inline; margin-left: 10px;" onsubmit="return confirm('Вы уверены, что хотите удалить пользователя {{ username }} и все его файлы? Это действие необратимо!');">
|
| 824 |
+
<button type="submit" class="btn delete-btn" style="padding: 5px 10px; font-size: 0.9em;">Удалить</button>
|
| 825 |
+
</form>
|
| 826 |
+
</div>
|
| 827 |
+
{% endfor %}
|
| 828 |
+
{% if not users %}
|
| 829 |
+
<p>Пользователей пока нет.</p>
|
| 830 |
+
{% endif %}
|
| 831 |
+
</div>
|
| 832 |
+
{% with messages = get_flashed_messages() %}
|
| 833 |
+
{% if messages %}
|
| 834 |
+
<div style="margin-top: 20px;">
|
| 835 |
+
{% for message in messages %}
|
| 836 |
+
<div class="flash">{{ message }}</div>
|
| 837 |
+
{% endfor %}
|
| 838 |
+
</div>
|
| 839 |
+
{% endif %}
|
| 840 |
+
{% endwith %}
|
| 841 |
+
</div>
|
| 842 |
+
</body>
|
| 843 |
+
</html>
|
| 844 |
+
'''
|
| 845 |
+
return render_template_string(html, users=users)
|
| 846 |
+
|
| 847 |
+
@app.route('/admhosto/user/<username>')
|
| 848 |
+
def admin_user_files(username):
|
| 849 |
+
# Здесь можно добавить проверку админского пароля или сессии
|
| 850 |
+
data = load_data()
|
| 851 |
+
if username not in data['users']:
|
| 852 |
+
flash('Пользователь не найден!')
|
| 853 |
+
return redirect(url_for('admin_panel'))
|
| 854 |
+
|
| 855 |
+
user_files = sorted(data['users'][username].get('files', []), key=lambda x: x.get('upload_date', ''), reverse=True)
|
| 856 |
+
|
| 857 |
+
html = '''
|
| 858 |
+
<!DOCTYPE html>
|
| 859 |
+
<html lang="ru">
|
| 860 |
+
<head>
|
| 861 |
+
<meta charset="UTF-8">
|
| 862 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 863 |
+
<title>Файлы пользователя {{ username }} - Zeus Cloud</title>
|
| 864 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">
|
| 865 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 866 |
+
</head>
|
| 867 |
+
<body>
|
| 868 |
+
<div class="container">
|
| 869 |
+
<h1>Файлы пользователя: {{ username }}</h1>
|
| 870 |
+
{% with messages = get_flashed_messages() %}
|
| 871 |
+
{% if messages %}
|
| 872 |
+
{% for message in messages %}
|
| 873 |
+
<div class="flash">{{ message }}</div>
|
| 874 |
+
{% endfor %}
|
| 875 |
+
{% endif %}
|
| 876 |
+
{% endwith %}
|
| 877 |
+
<div class="file-grid">
|
| 878 |
+
{% for file in user_files %}
|
| 879 |
+
<div class="file-item">
|
| 880 |
+
{% if file.get('type') == 'video' %}
|
| 881 |
+
<video class="file-preview" preload="metadata" muted loading="lazy" onclick="openModal('https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}?download=true', true)">
|
| 882 |
+
<source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}?download=true" type="video/mp4">
|
| 883 |
+
</video>
|
| 884 |
+
{% elif file.get('type') == 'image' %}
|
| 885 |
+
<img class="file-preview" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}?download=true" alt="{{ file['filename'] }}" loading="lazy" onclick="openModal(this.src, false)">
|
| 886 |
+
{% else %}
|
| 887 |
+
<p>{{ file.get('filename', 'N/A') }}</p>
|
| 888 |
+
{% endif %}
|
| 889 |
+
<p>{{ file.get('upload_date', 'N/A') }}</p>
|
| 890 |
+
<a href="{{ url_for('download_file', file_path=file['path'], filename=file['filename']) }}" class="btn download-btn">Скачать</a>
|
| 891 |
+
<!-- Добавить кнопку удаления файла для админа -->
|
| 892 |
+
<form method="POST" action="{{ url_for('admin_delete_file', username=username, file_path=file['path']) }}" style="display: inline; margin-left: 5px;" onsubmit="return confirm('Вы уверены, что хотите удалить этот файл?');">
|
| 893 |
+
<button type="submit" class="btn delete-btn" style="padding: 5px 10px; font-size: 0.9em;">Удалить</button>
|
| 894 |
+
</form>
|
| 895 |
+
</div>
|
| 896 |
+
{% endfor %}
|
| 897 |
+
{% if not user_files %}
|
| 898 |
+
<p>У это��о пользователя пока нет файлов.</p>
|
| 899 |
+
{% endif %}
|
| 900 |
+
</div>
|
| 901 |
+
<a href="{{ url_for('admin_panel') }}" class="btn" style="margin-top: 20px;">Назад к списку пользователей</a>
|
| 902 |
+
</div>
|
| 903 |
+
<div class="modal" id="mediaModal" onclick="closeModal(event)">
|
| 904 |
+
<div id="modalContent"></div>
|
| 905 |
+
</div>
|
| 906 |
+
<script>
|
| 907 |
+
function openModal(src, isVideo) {
|
| 908 |
+
const modal = document.getElementById('mediaModal');
|
| 909 |
+
const modalContent = document.getElementById('modalContent');
|
| 910 |
+
// Добавляем токен, если он есть, для приватных репо
|
| 911 |
+
const tokenParam = HF_TOKEN_READ ? `?token=${HF_TOKEN_READ}` : "";
|
| 912 |
+
const finalSrc = src + tokenParam; // Добавляем параметр токена, если он есть
|
| 913 |
+
|
| 914 |
+
if (isVideo) {
|
| 915 |
+
// Добавляем download=true, если это еще не сделано
|
| 916 |
+
const videoSrc = finalSrc.includes('?download=true') ? finalSrc : finalSrc.replace('?', '?download=true&');
|
| 917 |
+
modalContent.innerHTML = `<video controls autoplay style='max-width: 95%; max-height: 95vh;'><source src="${videoSrc}" type="video/mp4"></video>`;
|
| 918 |
+
} else {
|
| 919 |
+
// Для изображений download=true обычно не нужен для отображения
|
| 920 |
+
const img_src = finalSrc.includes('?download=true') ? finalSrc : finalSrc.replace('?', '?download=true&');
|
| 921 |
+
modalContent.innerHTML = `<img src="${img_src}" style='max-width: 95%; max-height: 95vh;'>`;
|
| 922 |
+
}
|
| 923 |
+
modal.style.display = 'flex';
|
| 924 |
+
}
|
| 925 |
+
function closeModal(event) {
|
| 926 |
+
const modal = document.getElementById('mediaModal');
|
| 927 |
+
if (event.target === modal) { // Закрывать только при клике на фон
|
| 928 |
+
modal.style.display = 'none';
|
| 929 |
+
const video = modal.querySelector('video');
|
| 930 |
+
if (video) {
|
| 931 |
+
video.pause();
|
| 932 |
+
}
|
| 933 |
+
document.getElementById('modalContent').innerHTML = ''; // Очистить содержимое
|
| 934 |
+
}
|
| 935 |
+
}
|
| 936 |
+
// Переменная для токена чтения, если он нужен для прямого доступа к файлам
|
| 937 |
+
const HF_TOKEN_READ = "{{ os.getenv('HF_TOKEN_READ') or os.getenv('HF_TOKEN') }}";
|
| 938 |
+
</script>
|
| 939 |
+
</body>
|
| 940 |
+
</html>
|
| 941 |
+
'''
|
| 942 |
+
# Передаем переменные окружения в шаблон безопасным способом
|
| 943 |
+
# (Хотя в данном случае это лишь маркер для JS)
|
| 944 |
+
return render_template_string(html, username=username, user_files=user_files, repo_id=REPO_ID, os=os)
|
| 945 |
+
|
| 946 |
+
|
| 947 |
+
@app.route('/admhosto/delete_user/<username>', methods=['POST'])
|
| 948 |
+
def admin_delete_user(username):
|
| 949 |
+
# Добавить проверку админа
|
| 950 |
+
data = load_data()
|
| 951 |
+
if username not in data['users']:
|
| 952 |
+
flash('Пользователь не найден!')
|
| 953 |
+
return redirect(url_for('admin_panel'))
|
| 954 |
+
|
| 955 |
+
user_files_to_delete = data['users'][username].get('files', [])
|
| 956 |
+
|
| 957 |
+
try:
|
| 958 |
+
api = HfApi()
|
| 959 |
+
# Сначала удаляем файлы пользователя из HF Hub
|
| 960 |
+
paths_to_delete = [file['path'] for file in user_files_to_delete]
|
| 961 |
+
if paths_to_delete:
|
| 962 |
+
# Удаление папки целиком, если API поддерживает (или удалять файлы по одному)
|
| 963 |
+
# HfApi может не иметь прямого delete_folder, удаляем по одному или папку если возможно
|
| 964 |
+
# Попробуем удалить папку пользователя
|
| 965 |
+
try:
|
| 966 |
+
api.delete_folder(
|
| 967 |
+
folder_path=f"cloud_files/{username}",
|
| 968 |
+
repo_id=REPO_ID,
|
| 969 |
+
repo_type="dataset",
|
| 970 |
+
token=HF_TOKEN_WRITE,
|
| 971 |
+
commit_message=f"Deleted all files for user {username} by admin"
|
| 972 |
+
)
|
| 973 |
+
logging.info(f"Successfully deleted folder for user {username}")
|
| 974 |
+
except Exception as folder_delete_error:
|
| 975 |
+
logging.warning(f"Could not delete folder for {username}, attempting individual file deletion: {folder_delete_error}")
|
| 976 |
+
# Если удаление папки не удалось, удаляем файлы по одному
|
| 977 |
+
for file_path in paths_to_delete:
|
| 978 |
+
try:
|
| 979 |
+
api.delete_file(
|
| 980 |
+
path_in_repo=file_path,
|
| 981 |
+
repo_id=REPO_ID,
|
| 982 |
+
repo_type="dataset",
|
| 983 |
+
token=HF_TOKEN_WRITE
|
| 984 |
+
)
|
| 985 |
+
except Exception as file_delete_error:
|
| 986 |
+
logging.error(f"Error deleting file {file_path} for user {username}: {file_delete_error}")
|
| 987 |
+
# Продолжаем удаление других файлов
|
| 988 |
+
|
| 989 |
+
# Затем удаляем пользователя из базы данных
|
| 990 |
+
del data['users'][username]
|
| 991 |
+
save_data(data)
|
| 992 |
+
flash(f'Пользователь {username} и его файлы успешно удалены!')
|
| 993 |
+
logging.info(f"Admin deleted user {username} and their files.")
|
| 994 |
+
|
| 995 |
+
except Exception as e:
|
| 996 |
+
logging.error(f"Error deleting user {username}: {e}")
|
| 997 |
+
flash(f'Ошибка при удалении пользователя {username}!')
|
| 998 |
+
|
| 999 |
+
return redirect(url_for('admin_panel'))
|
| 1000 |
+
|
| 1001 |
+
|
| 1002 |
+
@app.route('/admhosto/delete_file/<username>/<path:file_path>', methods=['POST'])
|
| 1003 |
+
def admin_delete_file(username, file_path):
|
| 1004 |
+
# Добавить проверку админа
|
| 1005 |
+
data = load_data()
|
| 1006 |
+
if username not in data['users']:
|
| 1007 |
+
flash('Пользователь не найден!')
|
| 1008 |
+
return redirect(url_for('admin_panel'))
|
| 1009 |
+
|
| 1010 |
+
user_files = data['users'][username].get('files', [])
|
| 1011 |
+
file_exists_in_db = any(f['path'] == file_path for f in user_files)
|
| 1012 |
+
|
| 1013 |
+
if not file_exists_in_db:
|
| 1014 |
+
flash('Файл не найден в базе данных пользователя!')
|
| 1015 |
+
# Все равно попытаться удалить из HF на случай рассинхронизации
|
| 1016 |
+
# или просто редирект
|
| 1017 |
+
|
| 1018 |
+
try:
|
| 1019 |
+
api = HfApi()
|
| 1020 |
+
api.delete_file(
|
| 1021 |
+
path_in_repo=file_path,
|
| 1022 |
+
repo_id=REPO_ID,
|
| 1023 |
+
repo_type="dataset",
|
| 1024 |
+
token=HF_TOKEN_WRITE,
|
| 1025 |
+
commit_message=f"Admin deleted file {file_path} for user {username}"
|
| 1026 |
+
)
|
| 1027 |
+
|
| 1028 |
+
# Обновляем базу данных, даже если файла там не было (на всякий случай)
|
| 1029 |
+
data['users'][username]['files'] = [f for f in user_files if f['path'] != file_path]
|
| 1030 |
+
save_data(data)
|
| 1031 |
+
flash('Файл успешно удален!')
|
| 1032 |
+
logging.info(f"Admin deleted file {file_path} for user {username}")
|
| 1033 |
+
|
| 1034 |
+
except Exception as e:
|
| 1035 |
+
logging.error(f"Error deleting file {file_path} by admin: {e}")
|
| 1036 |
+
# Проверить тип ошибки, возможно файл уже удален на HF
|
| 1037 |
+
flash('Ошибка удаления файла!')
|
| 1038 |
+
|
| 1039 |
+
return redirect(url_for('admin_user_files', username=username))
|
| 1040 |
+
|
| 1041 |
+
|
| 1042 |
+
if __name__ == '__main__':
|
| 1043 |
+
# Проверка наличия токенов при старте
|
| 1044 |
+
if not HF_TOKEN_WRITE:
|
| 1045 |
+
logging.warning("HF_TOKEN (write access) is not set. File uploads and deletions will fail.")
|
| 1046 |
+
if not HF_TOKEN_READ:
|
| 1047 |
+
logging.warning("HF_TOKEN_READ is not set. Falling back to HF_TOKEN. File downloads might fail for private repos if HF_TOKEN is not set.")
|
| 1048 |
+
|
| 1049 |
+
# Запуск периодического бэкапа в отдельном потоке
|
| 1050 |
+
# Убедимся, что бэкап запускается только если есть токен для записи
|
| 1051 |
+
if HF_TOKEN_WRITE:
|
| 1052 |
+
threading.Thread(target=periodic_backup, daemon=True).start()
|
| 1053 |
+
else:
|
| 1054 |
+
logging.warning("Periodic backup disabled because HF_TOKEN (write access) is not set.")
|
| 1055 |
+
|
| 1056 |
+
# Запуск Flask приложения
|
| 1057 |
+
app.run(debug=False, host='0.0.0.0', port=7860)
|