Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 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
|
|
@@ -13,15 +12,14 @@ import requests
|
|
| 13 |
from io import BytesIO
|
| 14 |
|
| 15 |
app = Flask(__name__)
|
| 16 |
-
|
|
|
|
| 17 |
DATA_FILE = 'cloud_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 |
-
# REGISTRATION_CODE is removed as requested
|
| 22 |
-
|
| 23 |
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
|
| 24 |
-
logging.basicConfig(level=logging.INFO
|
| 25 |
|
| 26 |
@cache.memoize(timeout=300)
|
| 27 |
def load_data():
|
|
@@ -30,41 +28,28 @@ def load_data():
|
|
| 30 |
with open(DATA_FILE, 'r', encoding='utf-8') as file:
|
| 31 |
data = json.load(file)
|
| 32 |
if not isinstance(data, dict):
|
| 33 |
-
logging.warning("
|
| 34 |
return {'users': {}, 'files': {}}
|
| 35 |
data.setdefault('users', {})
|
| 36 |
data.setdefault('files', {})
|
| 37 |
-
logging.info("
|
| 38 |
return data
|
| 39 |
-
except FileNotFoundError:
|
| 40 |
-
logging.warning(f"{DATA_FILE} not found. Initializing empty structure.")
|
| 41 |
-
return {'users': {}, 'files': {}}
|
| 42 |
-
except json.JSONDecodeError:
|
| 43 |
-
logging.error(f"Error decoding JSON from {DATA_FILE}. Initializing empty structure.")
|
| 44 |
-
return {'users': {}, 'files': {}}
|
| 45 |
except Exception as e:
|
| 46 |
-
logging.error(f"
|
| 47 |
return {'users': {}, 'files': {}}
|
| 48 |
|
| 49 |
def save_data(data):
|
| 50 |
-
temp_file = DATA_FILE + '.tmp'
|
| 51 |
try:
|
| 52 |
-
with open(
|
| 53 |
json.dump(data, file, ensure_ascii=False, indent=4)
|
| 54 |
-
os.replace(temp_file, DATA_FILE)
|
| 55 |
upload_db_to_hf()
|
| 56 |
cache.clear()
|
| 57 |
-
logging.info("
|
| 58 |
except Exception as e:
|
| 59 |
-
logging.error(f"
|
| 60 |
-
if os.path.exists(temp_file):
|
| 61 |
-
os.remove(temp_file)
|
| 62 |
raise
|
| 63 |
|
| 64 |
def upload_db_to_hf():
|
| 65 |
-
if not HF_TOKEN_WRITE:
|
| 66 |
-
logging.warning("HF_TOKEN_WRITE not set. Skipping Hugging Face upload.")
|
| 67 |
-
return
|
| 68 |
try:
|
| 69 |
api = HfApi()
|
| 70 |
api.upload_file(
|
|
@@ -73,19 +58,13 @@ def upload_db_to_hf():
|
|
| 73 |
repo_id=REPO_ID,
|
| 74 |
repo_type="dataset",
|
| 75 |
token=HF_TOKEN_WRITE,
|
| 76 |
-
commit_message=f"
|
| 77 |
)
|
| 78 |
-
logging.info("
|
| 79 |
except Exception as e:
|
| 80 |
-
logging.error(f"
|
| 81 |
|
| 82 |
def download_db_from_hf():
|
| 83 |
-
if not HF_TOKEN_READ:
|
| 84 |
-
logging.warning("HF_TOKEN_READ not set. Skipping Hugging Face download.")
|
| 85 |
-
if not os.path.exists(DATA_FILE):
|
| 86 |
-
with open(DATA_FILE, 'w', encoding='utf-8') as f:
|
| 87 |
-
json.dump({'users': {}, 'files': {}}, f)
|
| 88 |
-
return
|
| 89 |
try:
|
| 90 |
hf_hub_download(
|
| 91 |
repo_id=REPO_ID,
|
|
@@ -93,442 +72,257 @@ def download_db_from_hf():
|
|
| 93 |
repo_type="dataset",
|
| 94 |
token=HF_TOKEN_READ,
|
| 95 |
local_dir=".",
|
| 96 |
-
local_dir_use_symlinks=False
|
| 97 |
-
force_download=True # Ensure we get the latest version
|
| 98 |
)
|
| 99 |
-
logging.info("
|
| 100 |
except Exception as e:
|
| 101 |
-
logging.error(f"
|
| 102 |
if not os.path.exists(DATA_FILE):
|
| 103 |
-
logging.info("Creating empty database file as download failed and file doesn't exist.")
|
| 104 |
with open(DATA_FILE, 'w', encoding='utf-8') as f:
|
| 105 |
json.dump({'users': {}, 'files': {}}, f)
|
| 106 |
|
| 107 |
def periodic_backup():
|
| 108 |
while True:
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
try:
|
| 112 |
-
data = load_data.sync() # Use sync version if available or handle async appropriately
|
| 113 |
-
save_data(data) # This already includes the HF upload
|
| 114 |
-
except Exception as e:
|
| 115 |
-
logging.error(f"Error during periodic backup: {e}")
|
| 116 |
-
|
| 117 |
|
| 118 |
def get_file_type(filename):
|
| 119 |
-
video_extensions = ('.mp4', '.mov', '.avi'
|
| 120 |
-
image_extensions = ('.jpg', '.jpeg', '.png', '.gif'
|
| 121 |
-
|
| 122 |
-
if filename_lower.endswith(video_extensions):
|
| 123 |
return 'video'
|
| 124 |
-
elif
|
| 125 |
return 'image'
|
| 126 |
return 'other'
|
| 127 |
|
| 128 |
BASE_STYLE = '''
|
| 129 |
-
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap');
|
| 130 |
-
|
| 131 |
:root {
|
| 132 |
-
--primary
|
| 133 |
-
--secondary
|
| 134 |
-
--accent
|
| 135 |
-
|
| 136 |
-
--
|
| 137 |
-
--
|
| 138 |
-
--
|
| 139 |
-
|
| 140 |
-
--
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
--text-light: #212529;
|
| 145 |
-
--text-dark: #e4e6eb;
|
| 146 |
-
--border-light: rgba(0, 0, 0, 0.1);
|
| 147 |
-
--border-dark: rgba(255, 255, 255, 0.15);
|
| 148 |
-
|
| 149 |
-
--shadow-light: 0 10px 30px rgba(0, 0, 0, 0.1);
|
| 150 |
-
--shadow-dark: 0 10px 30px rgba(0, 0, 0, 0.4);
|
| 151 |
-
--glass-bg-light: rgba(255, 255, 255, 0.2);
|
| 152 |
-
--glass-bg-dark: rgba(50, 50, 50, 0.3);
|
| 153 |
-
|
| 154 |
-
--delete-color: hsl(0, 80%, 60%);
|
| 155 |
-
--download-color: hsl(145, 63%, 49%);
|
| 156 |
-
|
| 157 |
-
--transition-fast: all 0.2s ease-out;
|
| 158 |
-
--transition-medium: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
|
| 159 |
-
--border-radius-sm: 8px;
|
| 160 |
-
--border-radius-md: 16px;
|
| 161 |
-
--border-radius-lg: 24px;
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
*, *::before, *::after {
|
| 165 |
margin: 0;
|
| 166 |
padding: 0;
|
| 167 |
box-sizing: border-box;
|
| 168 |
}
|
| 169 |
|
| 170 |
body {
|
| 171 |
-
font-family: '
|
| 172 |
-
background:
|
| 173 |
-
color: var(--text
|
| 174 |
-
line-height: 1.
|
| 175 |
-
transition: background 0.3s ease, color 0.3s ease;
|
| 176 |
min-height: 100vh;
|
| 177 |
-
|
| 178 |
-
padding-bottom: 50px;
|
| 179 |
-
}
|
| 180 |
-
|
| 181 |
-
body.dark {
|
| 182 |
-
background: var(--bg-dark);
|
| 183 |
-
color: var(--text-dark);
|
| 184 |
-
}
|
| 185 |
-
|
| 186 |
-
.theme-toggle {
|
| 187 |
-
position: fixed;
|
| 188 |
-
top: 15px;
|
| 189 |
-
right: 15px;
|
| 190 |
-
background: var(--card-bg-light);
|
| 191 |
-
border: 1px solid var(--border-light);
|
| 192 |
-
color: var(--text-light);
|
| 193 |
-
padding: 8px 12px;
|
| 194 |
-
border-radius: var(--border-radius-sm);
|
| 195 |
-
cursor: pointer;
|
| 196 |
-
z-index: 1001;
|
| 197 |
-
transition: var(--transition-medium);
|
| 198 |
-
box-shadow: var(--shadow-light);
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
body.dark .theme-toggle {
|
| 202 |
-
background: var(--card-bg-dark);
|
| 203 |
-
border-color: var(--border-dark);
|
| 204 |
-
color: var(--text-dark);
|
| 205 |
-
box-shadow: var(--shadow-dark);
|
| 206 |
-
}
|
| 207 |
-
|
| 208 |
-
.theme-toggle:hover {
|
| 209 |
-
transform: scale(1.05);
|
| 210 |
-
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
|
| 211 |
-
}
|
| 212 |
-
|
| 213 |
-
body.dark .theme-toggle:hover {
|
| 214 |
-
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
|
| 215 |
}
|
| 216 |
|
| 217 |
-
|
| 218 |
.container {
|
| 219 |
-
margin:
|
| 220 |
-
max-width:
|
| 221 |
-
padding: 30px
|
| 222 |
-
background: var(--card-bg
|
| 223 |
-
border-radius:
|
| 224 |
-
box-shadow: var(--shadow
|
| 225 |
backdrop-filter: blur(10px);
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
body.dark .container {
|
| 231 |
-
background: var(--card-bg-dark);
|
| 232 |
-
box-shadow: var(--shadow-dark);
|
| 233 |
-
border: 1px solid var(--border-dark);
|
| 234 |
}
|
| 235 |
|
| 236 |
h1 {
|
| 237 |
-
font-size:
|
| 238 |
-
font-weight:
|
| 239 |
text-align: center;
|
| 240 |
-
margin-bottom:
|
| 241 |
-
background: linear-gradient(135deg, var(--primary
|
| 242 |
-webkit-background-clip: text;
|
| 243 |
color: transparent;
|
| 244 |
-
|
| 245 |
}
|
| 246 |
|
| 247 |
h2 {
|
| 248 |
-
font-size:
|
| 249 |
-
margin
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
padding-bottom: 5px;
|
| 253 |
-
border-bottom: 2px solid hsla(var(--primary-hue), 100%, 60%, 0.3);
|
| 254 |
-
}
|
| 255 |
-
|
| 256 |
-
body.dark h2 {
|
| 257 |
-
color: var(--primary-color);
|
| 258 |
-
border-bottom-color: hsla(var(--primary-hue), 100%, 60%, 0.5);
|
| 259 |
}
|
| 260 |
|
| 261 |
-
input
|
| 262 |
width: 100%;
|
| 263 |
-
padding: 16px
|
| 264 |
-
margin:
|
| 265 |
-
border:
|
| 266 |
-
border-radius:
|
| 267 |
-
background: var(--glass-bg
|
| 268 |
-
color: var(--text
|
| 269 |
-
font-size: 1.
|
| 270 |
-
transition: var(--transition
|
| 271 |
-
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
body.dark input[type="text"],
|
| 275 |
-
body.dark input[type="password"],
|
| 276 |
-
body.dark input[type="file"],
|
| 277 |
-
body.dark textarea {
|
| 278 |
-
background: var(--glass-bg-dark);
|
| 279 |
-
color: var(--text-dark);
|
| 280 |
-
border-color: var(--border-dark);
|
| 281 |
-
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 282 |
}
|
| 283 |
|
| 284 |
input:focus, textarea:focus {
|
| 285 |
outline: none;
|
| 286 |
-
border-color: var(--primary
|
| 287 |
-
box-shadow: 0 0
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
input[type="file"] {
|
| 291 |
-
padding: 12px 18px;
|
| 292 |
-
cursor: pointer;
|
| 293 |
-
}
|
| 294 |
-
|
| 295 |
-
input[type="file"]::file-selector-button {
|
| 296 |
-
margin-right: 15px;
|
| 297 |
-
border: none;
|
| 298 |
-
background: linear-gradient(135deg, var(--secondary-color), var(--accent-color));
|
| 299 |
-
padding: 10px 18px;
|
| 300 |
-
border-radius: var(--border-radius-sm);
|
| 301 |
-
color: white;
|
| 302 |
-
cursor: pointer;
|
| 303 |
-
transition: var(--transition-fast);
|
| 304 |
-
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
-
input[type="file"]::file-selector-button:hover {
|
| 308 |
-
transform: translateY(-1px);
|
| 309 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
| 310 |
}
|
| 311 |
|
| 312 |
.btn {
|
| 313 |
-
padding:
|
| 314 |
-
background:
|
| 315 |
-
color:
|
| 316 |
border: none;
|
| 317 |
-
border-radius:
|
| 318 |
cursor: pointer;
|
| 319 |
-
font-size: 1.
|
| 320 |
-
font-weight:
|
| 321 |
-
transition: var(--transition
|
| 322 |
-
box-shadow:
|
| 323 |
display: inline-block;
|
| 324 |
text-decoration: none;
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
margin-right: 10px;
|
| 328 |
}
|
| 329 |
|
| 330 |
-
.btn:
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
}
|
| 334 |
|
| 335 |
-
.btn:
|
| 336 |
-
|
| 337 |
-
box-shadow: 0 4px 15px hsla(var(--primary-hue), 100%, 50%, 0.3);
|
| 338 |
}
|
| 339 |
|
| 340 |
-
.
|
| 341 |
-
|
| 342 |
-
|
|
|
|
| 343 |
}
|
| 344 |
-
.download-btn:hover { box-shadow: 0 8px 25px hsla(145, 63%, 49%, 0.4); }
|
| 345 |
-
.download-btn:active { box-shadow: 0 4px 15px hsla(145, 63%, 49%, 0.3); }
|
| 346 |
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
background: linear-gradient(135deg, var(--delete-color), hsl(0, 80%, 50%));
|
| 350 |
-
box-shadow: 0 4px 15px hsla(0, 80%, 60%, 0.3);
|
| 351 |
}
|
| 352 |
-
.delete-btn:hover { box-shadow: 0 8px 25px hsla(0, 80%, 60%, 0.4); }
|
| 353 |
-
.delete-btn:active { box-shadow: 0 4px 15px hsla(0, 80%, 60%, 0.3); }
|
| 354 |
|
| 355 |
-
.
|
| 356 |
-
|
| 357 |
-
margin-bottom: 20px;
|
| 358 |
-
border-radius: var(--border-radius-md);
|
| 359 |
-
text-align: center;
|
| 360 |
-
font-weight: 600;
|
| 361 |
-
background-color: hsla(var(--secondary-hue), 80%, 85%, 0.8);
|
| 362 |
-
color: hsl(var(--secondary-hue), 100%, 25%);
|
| 363 |
-
border: 1px solid hsla(var(--secondary-hue), 100%, 45%, 0.3);
|
| 364 |
}
|
| 365 |
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
color: hsl(var(--secondary-hue), 100%, 85%);
|
| 369 |
-
border-color: hsla(var(--secondary-hue), 100%, 45%, 0.5);
|
| 370 |
}
|
| 371 |
|
| 372 |
-
.
|
| 373 |
-
background
|
| 374 |
-
color: hsl(var(--primary-hue), 100%, 25%);
|
| 375 |
-
border: 1px solid hsla(var(--primary-hue), 100%, 60%, 0.3);
|
| 376 |
-
}
|
| 377 |
-
body.dark .flash.error {
|
| 378 |
-
background-color: hsla(var(--primary-hue), 50%, 30%, 0.7);
|
| 379 |
-
color: hsl(var(--primary-hue), 100%, 85%);
|
| 380 |
-
border-color: hsla(var(--primary-hue), 100%, 60%, 0.5);
|
| 381 |
}
|
| 382 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
|
| 384 |
.file-grid {
|
| 385 |
display: grid;
|
| 386 |
-
grid-template-columns: repeat(auto-fill, minmax(
|
| 387 |
gap: 25px;
|
| 388 |
margin-top: 30px;
|
| 389 |
}
|
| 390 |
|
| 391 |
.user-list {
|
| 392 |
-
margin-top:
|
| 393 |
-
display: grid;
|
| 394 |
-
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
| 395 |
-
gap: 20px;
|
| 396 |
}
|
| 397 |
|
| 398 |
.user-item {
|
| 399 |
-
padding: 20px
|
| 400 |
-
background: var(--
|
| 401 |
-
border-radius:
|
| 402 |
-
margin-bottom:
|
| 403 |
-
box-shadow: var(--shadow
|
| 404 |
-
transition: var(--transition
|
| 405 |
-
border: 1px solid var(--border-light);
|
| 406 |
-
}
|
| 407 |
-
|
| 408 |
-
body.dark .user-item {
|
| 409 |
-
background: var(--card-bg-dark);
|
| 410 |
-
border-color: var(--border-dark);
|
| 411 |
-
box-shadow: var(--shadow-dark);
|
| 412 |
}
|
| 413 |
|
| 414 |
.user-item:hover {
|
| 415 |
-
transform: translateY(-
|
| 416 |
-
box-shadow: 0
|
| 417 |
-
}
|
| 418 |
-
|
| 419 |
-
body.dark .user-item:hover {
|
| 420 |
-
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
|
| 421 |
}
|
| 422 |
|
| 423 |
-
|
| 424 |
.user-item a {
|
| 425 |
-
color: var(--primary
|
| 426 |
text-decoration: none;
|
| 427 |
font-weight: 600;
|
| 428 |
-
font-size: 1.
|
| 429 |
-
display: block;
|
| 430 |
-
margin-bottom: 8px;
|
| 431 |
}
|
| 432 |
|
| 433 |
.user-item a:hover {
|
| 434 |
-
color: var(--
|
| 435 |
}
|
| 436 |
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
}
|
| 442 |
-
|
| 443 |
-
|
|
|
|
|
|
|
|
|
|
| 444 |
}
|
| 445 |
|
| 446 |
.file-item {
|
| 447 |
-
background: var(--
|
| 448 |
-
padding:
|
| 449 |
-
border-radius:
|
| 450 |
-
box-shadow: var(--shadow
|
| 451 |
text-align: center;
|
| 452 |
-
transition: var(--transition
|
| 453 |
-
|
| 454 |
-
flex-direction: column;
|
| 455 |
-
justify-content: space-between;
|
| 456 |
-
overflow: hidden;
|
| 457 |
-
border: 1px solid var(--border-light);
|
| 458 |
-
}
|
| 459 |
-
|
| 460 |
-
body.dark .file-item {
|
| 461 |
-
background: var(--card-bg-dark);
|
| 462 |
-
border-color: var(--border-dark);
|
| 463 |
-
box-shadow: var(--shadow-dark);
|
| 464 |
}
|
| 465 |
|
| 466 |
.file-item:hover {
|
| 467 |
-
transform: translateY(-
|
| 468 |
-
box-shadow: 0
|
| 469 |
-
}
|
| 470 |
-
body.dark .file-item:hover {
|
| 471 |
-
box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
|
| 472 |
-
}
|
| 473 |
-
|
| 474 |
-
.file-preview-container {
|
| 475 |
-
width: 100%;
|
| 476 |
-
height: 200px; /* Fixed height container */
|
| 477 |
-
margin-bottom: 15px;
|
| 478 |
-
border-radius: var(--border-radius-sm);
|
| 479 |
-
overflow: hidden;
|
| 480 |
-
background-color: rgba(0,0,0,0.05); /* Placeholder bg */
|
| 481 |
-
display: flex;
|
| 482 |
-
align-items: center;
|
| 483 |
-
justify-content: center;
|
| 484 |
-
}
|
| 485 |
-
body.dark .file-preview-container {
|
| 486 |
-
background-color: rgba(255,255,255,0.05);
|
| 487 |
}
|
| 488 |
|
| 489 |
.file-preview {
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
|
|
|
|
|
|
| 494 |
cursor: pointer;
|
| 495 |
-
transition: transform 0.3s ease;
|
| 496 |
}
|
| 497 |
|
| 498 |
-
.file-
|
| 499 |
transform: scale(1.05);
|
| 500 |
}
|
| 501 |
|
| 502 |
-
|
| 503 |
.file-item p {
|
| 504 |
-
font-size:
|
| 505 |
margin: 8px 0;
|
| 506 |
-
word-wrap: break-word;
|
| 507 |
-
}
|
| 508 |
-
.file-item p.filename {
|
| 509 |
-
font-weight: 600;
|
| 510 |
-
color: var(--text-light);
|
| 511 |
-
}
|
| 512 |
-
body.dark .file-item p.filename {
|
| 513 |
-
color: var(--text-dark);
|
| 514 |
-
}
|
| 515 |
-
|
| 516 |
-
.file-item p.date {
|
| 517 |
-
font-size: 0.8em;
|
| 518 |
-
opacity: 0.7;
|
| 519 |
}
|
| 520 |
|
| 521 |
-
.file-item
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
justify-content: space-around;
|
| 525 |
-
gap: 10px;
|
| 526 |
}
|
| 527 |
|
| 528 |
-
.file-item
|
| 529 |
-
|
| 530 |
-
font-size: 0.9em;
|
| 531 |
-
flex-grow: 1;
|
| 532 |
}
|
| 533 |
|
| 534 |
.modal {
|
|
@@ -542,889 +336,687 @@ body.dark .file-item p.filename {
|
|
| 542 |
z-index: 2000;
|
| 543 |
justify-content: center;
|
| 544 |
align-items: center;
|
| 545 |
-
|
| 546 |
-
cursor: pointer;
|
| 547 |
-
}
|
| 548 |
-
|
| 549 |
-
.modal-content {
|
| 550 |
-
position: relative;
|
| 551 |
-
max-width: 95%;
|
| 552 |
-
max-height: 95%;
|
| 553 |
-
display: flex;
|
| 554 |
-
justify-content: center;
|
| 555 |
-
align-items: center;
|
| 556 |
-
cursor: default;
|
| 557 |
}
|
| 558 |
|
| 559 |
.modal img, .modal video {
|
| 560 |
-
|
| 561 |
-
max-
|
| 562 |
-
max-height: 100%;
|
| 563 |
object-fit: contain;
|
| 564 |
-
border-radius:
|
| 565 |
-
box-shadow:
|
|
|
|
| 566 |
}
|
| 567 |
|
| 568 |
-
.modal-close {
|
| 569 |
-
position: absolute;
|
| 570 |
-
top: -35px;
|
| 571 |
-
right: -25px;
|
| 572 |
-
color: #fff;
|
| 573 |
-
font-size: 2.5em;
|
| 574 |
-
font-weight: bold;
|
| 575 |
-
cursor: pointer;
|
| 576 |
-
transition: transform 0.2s ease;
|
| 577 |
-
line-height: 1;
|
| 578 |
-
}
|
| 579 |
-
.modal-close:hover {
|
| 580 |
-
transform: scale(1.1);
|
| 581 |
-
color: var(--primary-color);
|
| 582 |
-
}
|
| 583 |
-
|
| 584 |
-
|
| 585 |
#progress-container {
|
| 586 |
width: 100%;
|
| 587 |
-
background: var(--glass-bg
|
| 588 |
-
border-radius:
|
| 589 |
margin: 20px 0;
|
| 590 |
-
overflow: hidden;
|
| 591 |
display: none;
|
| 592 |
-
border: 1px solid var(--border-light);
|
| 593 |
-
}
|
| 594 |
-
body.dark #progress-container {
|
| 595 |
-
background: var(--glass-bg-dark);
|
| 596 |
-
border: 1px solid var(--border-dark);
|
| 597 |
}
|
| 598 |
|
| 599 |
#progress-bar {
|
| 600 |
width: 0%;
|
| 601 |
height: 25px;
|
| 602 |
-
background: linear-gradient(90deg, var(--
|
| 603 |
-
border-radius:
|
| 604 |
-
transition: width 0.
|
| 605 |
-
text-align: center;
|
| 606 |
-
line-height: 25px;
|
| 607 |
-
color: white;
|
| 608 |
-
font-weight: 600;
|
| 609 |
-
font-size: 0.9em;
|
| 610 |
}
|
| 611 |
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
padding: 30px;
|
| 616 |
-
background: var(--card-bg-light);
|
| 617 |
-
border-radius: var(--border-radius-lg);
|
| 618 |
-
box-shadow: var(--shadow-light);
|
| 619 |
-
border: 1px solid var(--border-light);
|
| 620 |
-
}
|
| 621 |
-
body.dark form#login-form, body.dark form#register-form {
|
| 622 |
-
background: var(--card-bg-dark);
|
| 623 |
-
box-shadow: var(--shadow-dark);
|
| 624 |
-
border: 1px solid var(--border-dark);
|
| 625 |
}
|
| 626 |
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
}
|
| 631 |
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
}
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
@media (max-width: 768px) {
|
| 644 |
-
.container { padding: 20px; }
|
| 645 |
-
h1 { font-size: 2.2em; margin-bottom: 25px;}
|
| 646 |
-
h2 { font-size: 1.5em; }
|
| 647 |
-
.file-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 15px;}
|
| 648 |
-
.file-item { padding: 10px; }
|
| 649 |
-
.file-preview-container { height: 160px; }
|
| 650 |
-
.btn { padding: 12px 25px; font-size: 1em; }
|
| 651 |
-
.file-item .actions .btn { font-size: 0.8em; padding: 6px 10px;}
|
| 652 |
-
.theme-toggle { padding: 6px 10px; font-size: 0.9em;}
|
| 653 |
-
}
|
| 654 |
-
|
| 655 |
-
@media (max-width: 480px) {
|
| 656 |
-
h1 { font-size: 1.8em; }
|
| 657 |
-
.file-grid { grid-template-columns: 1fr; gap: 20px;}
|
| 658 |
-
.file-item { padding: 15px; }
|
| 659 |
-
.file-preview-container { height: 180px; }
|
| 660 |
-
.btn { width: 100%; margin-right: 0; margin-bottom: 10px; }
|
| 661 |
-
.file-item .actions { flex-direction: column; }
|
| 662 |
-
.file-item .actions .btn { width: auto;}
|
| 663 |
-
form#login-form, form#register-form { padding: 20px; }
|
| 664 |
-
.modal-close { top: 5px; right: 5px; font-size: 2em; }
|
| 665 |
}
|
| 666 |
'''
|
| 667 |
|
| 668 |
-
GLOBAL_JAVASCRIPT = '''
|
| 669 |
-
<script>
|
| 670 |
-
const themeToggle = document.getElementById('themeToggle');
|
| 671 |
-
const body = document.body;
|
| 672 |
-
|
| 673 |
-
function applyTheme(theme) {
|
| 674 |
-
if (theme === 'dark') {
|
| 675 |
-
body.classList.add('dark');
|
| 676 |
-
if(themeToggle) themeToggle.textContent = 'Light Mode';
|
| 677 |
-
localStorage.setItem('theme', 'dark');
|
| 678 |
-
} else {
|
| 679 |
-
body.classList.remove('dark');
|
| 680 |
-
if(themeToggle) themeToggle.textContent = 'Dark Mode';
|
| 681 |
-
localStorage.setItem('theme', 'light');
|
| 682 |
-
}
|
| 683 |
-
}
|
| 684 |
-
|
| 685 |
-
if (themeToggle) {
|
| 686 |
-
themeToggle.addEventListener('click', () => {
|
| 687 |
-
const currentTheme = localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
| 688 |
-
applyTheme(currentTheme === 'dark' ? 'light' : 'dark');
|
| 689 |
-
});
|
| 690 |
-
}
|
| 691 |
-
|
| 692 |
-
// Apply saved theme or system preference on initial load
|
| 693 |
-
const savedTheme = localStorage.getItem('theme');
|
| 694 |
-
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
| 695 |
-
applyTheme(savedTheme || (prefersDark ? 'dark' : 'light'));
|
| 696 |
-
|
| 697 |
-
function openModal(src, isVideo) {
|
| 698 |
-
const modal = document.getElementById('mediaModal');
|
| 699 |
-
if (!modal) return;
|
| 700 |
-
const modalContent = document.getElementById('modalContent');
|
| 701 |
-
let contentHTML = '';
|
| 702 |
-
if (isVideo) {
|
| 703 |
-
contentHTML = `<video controls autoplay playsinline><source src="${src}" type="video/mp4">Your browser does not support the video tag.</video>`;
|
| 704 |
-
} else {
|
| 705 |
-
contentHTML = `<img src="${src}" alt="Preview">`;
|
| 706 |
-
}
|
| 707 |
-
modalContent.innerHTML = contentHTML + '<span class="modal-close" onclick="closeModal(event)">×</span>';
|
| 708 |
-
modal.style.display = 'flex';
|
| 709 |
-
// Add event listener to close modal on Escape key press
|
| 710 |
-
document.addEventListener('keydown', handleEscKey);
|
| 711 |
-
}
|
| 712 |
-
|
| 713 |
-
function closeModal(event) {
|
| 714 |
-
// Check if the click was directly on the modal backdrop or the close button
|
| 715 |
-
if (event.target.id === 'mediaModal' || event.target.classList.contains('modal-close')) {
|
| 716 |
-
const modal = document.getElementById('mediaModal');
|
| 717 |
-
if (!modal) return;
|
| 718 |
-
modal.style.display = 'none';
|
| 719 |
-
// Stop video playback if any
|
| 720 |
-
const video = modal.querySelector('video');
|
| 721 |
-
if (video) {
|
| 722 |
-
video.pause();
|
| 723 |
-
video.removeAttribute('src'); // detach the source
|
| 724 |
-
video.load();
|
| 725 |
-
}
|
| 726 |
-
modal.querySelector('#modalContent').innerHTML = ''; // Clear content
|
| 727 |
-
document.removeEventListener('keydown', handleEscKey); // Remove listener
|
| 728 |
-
event.stopPropagation(); // Prevent event bubbling if needed
|
| 729 |
-
}
|
| 730 |
-
}
|
| 731 |
-
|
| 732 |
-
function handleEscKey(event) {
|
| 733 |
-
if (event.key === 'Escape') {
|
| 734 |
-
closeModal({ target: document.getElementById('mediaModal') }); // Simulate click on backdrop
|
| 735 |
-
}
|
| 736 |
-
}
|
| 737 |
-
|
| 738 |
-
// Add event listener for clicks outside the modal content but within the modal area
|
| 739 |
-
const modalElement = document.getElementById('mediaModal');
|
| 740 |
-
if(modalElement) {
|
| 741 |
-
modalElement.addEventListener('click', closeModal);
|
| 742 |
-
}
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
</script>
|
| 746 |
-
'''
|
| 747 |
-
|
| 748 |
@app.route('/register', methods=['GET', 'POST'])
|
| 749 |
def register():
|
| 750 |
if request.method == 'POST':
|
| 751 |
-
username = request.form.get('username'
|
| 752 |
password = request.form.get('password')
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
if not username or not password:
|
| 756 |
-
flash('Логин и пароль обязательны!', 'error')
|
| 757 |
-
return redirect(url_for('register'))
|
| 758 |
-
|
| 759 |
-
if len(username) < 3 or len(password) < 6:
|
| 760 |
-
flash('Логин должен быть не менее 3 символов, пароль не менее 6 символов.', 'error')
|
| 761 |
-
return redirect(url_for('register'))
|
| 762 |
-
|
| 763 |
data = load_data()
|
| 764 |
-
|
| 765 |
if username in data['users']:
|
| 766 |
-
flash('Пользователь с таким логином уже существует!'
|
| 767 |
return redirect(url_for('register'))
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
data['users'][username] = {
|
| 775 |
-
'password': password,
|
| 776 |
'created_at': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
| 777 |
'files': []
|
| 778 |
}
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
except Exception as e:
|
| 785 |
-
flash('Ошибка при сохранении данных регистрации.', 'error')
|
| 786 |
-
logging.error(f"Registration save error for {username}: {e}")
|
| 787 |
-
return redirect(url_for('register'))
|
| 788 |
-
|
| 789 |
html = '''
|
| 790 |
<!DOCTYPE html>
|
| 791 |
-
<html lang="
|
| 792 |
<head>
|
| 793 |
<meta charset="UTF-8">
|
| 794 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 795 |
<title>Регистрация - Zeus Cloud</title>
|
| 796 |
-
<
|
|
|
|
| 797 |
</head>
|
| 798 |
<body>
|
| 799 |
-
<
|
| 800 |
<div class="container">
|
| 801 |
-
<h1>
|
| 802 |
-
{
|
| 803 |
-
{
|
| 804 |
-
{
|
| 805 |
-
<div class="flash
|
| 806 |
-
{
|
| 807 |
-
{
|
| 808 |
-
{
|
| 809 |
<form method="POST" id="register-form">
|
| 810 |
-
<input type="text" name="username" placeholder="
|
| 811 |
-
<input type="password" name="password" placeholder="П
|
| 812 |
-
<!-- Removed registration code input -->
|
| 813 |
<button type="submit" class="btn">Зарегистрироваться</button>
|
| 814 |
</form>
|
| 815 |
-
<p>Уже есть аккаунт? <a href="{{
|
| 816 |
</div>
|
| 817 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 818 |
</body>
|
| 819 |
</html>
|
| 820 |
-
'''
|
| 821 |
return render_template_string(html)
|
| 822 |
|
| 823 |
@app.route('/', methods=['GET', 'POST'])
|
| 824 |
def login():
|
| 825 |
-
if 'username' in session:
|
| 826 |
-
return redirect(url_for('dashboard')) # Redirect if already logged in
|
| 827 |
-
|
| 828 |
if request.method == 'POST':
|
| 829 |
username = request.form.get('username')
|
| 830 |
password = request.form.get('password')
|
| 831 |
data = load_data()
|
| 832 |
-
|
| 833 |
-
# IMPORTANT: Use password hashing in a real application!
|
| 834 |
-
# Example: from werkzeug.security import check_password_hash
|
| 835 |
-
# if username in data['users'] and check_password_hash(data['users'][username]['password_hash'], password):
|
| 836 |
if username in data['users'] and data['users'][username]['password'] == password:
|
| 837 |
session['username'] = username
|
| 838 |
-
session.permanent = True # Make session persistent
|
| 839 |
-
app.permanent_session_lifetime = timedelta(days=30) # Example: 30 days
|
| 840 |
return jsonify({'status': 'success', 'redirect': url_for('dashboard')})
|
| 841 |
else:
|
| 842 |
return jsonify({'status': 'error', 'message': 'Неверный логин или пароль!'})
|
| 843 |
-
|
| 844 |
html = '''
|
| 845 |
<!DOCTYPE html>
|
| 846 |
-
<html lang="
|
| 847 |
<head>
|
| 848 |
<meta charset="UTF-8">
|
| 849 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 850 |
-
<title>
|
| 851 |
-
<
|
|
|
|
| 852 |
</head>
|
| 853 |
<body>
|
| 854 |
-
<
|
| 855 |
<div class="container">
|
| 856 |
<h1>Zeus Cloud</h1>
|
| 857 |
<div id="flash-messages">
|
| 858 |
-
{
|
| 859 |
-
{
|
| 860 |
-
{
|
| 861 |
-
<div class="flash
|
| 862 |
-
{
|
| 863 |
-
{
|
| 864 |
-
{
|
| 865 |
</div>
|
| 866 |
<form method="POST" id="login-form">
|
| 867 |
-
<input type="text" name="username" placeholder="
|
| 868 |
-
<input type="password" name="password" placeholder="
|
| 869 |
<button type="submit" class="btn">Войти</button>
|
| 870 |
</form>
|
| 871 |
-
<p>Нет аккаунта? <a href="{{
|
| 872 |
</div>
|
| 873 |
-
|
| 874 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 875 |
const savedCredentials = JSON.parse(localStorage.getItem('zeusCredentials'));
|
| 876 |
if (savedCredentials) {
|
| 877 |
-
fetch('/', {
|
| 878 |
method: 'POST',
|
| 879 |
-
headers: {
|
| 880 |
'Content-Type': 'application/x-www-form-urlencoded',
|
| 881 |
-
}
|
| 882 |
-
body: `username=${
|
| 883 |
-
}
|
| 884 |
.then(response => response.json())
|
| 885 |
-
.then(data => {
|
| 886 |
-
if (data.status === 'success') {
|
| 887 |
window.location.href = data.redirect;
|
| 888 |
-
}
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
}}
|
| 892 |
-
}})
|
| 893 |
-
.catch(error => {{
|
| 894 |
-
console.error('Ошибка автоматического входа:', error);
|
| 895 |
-
localStorage.removeItem('zeusCredentials');
|
| 896 |
-
}});
|
| 897 |
}
|
| 898 |
|
| 899 |
-
document.getElementById('login-form').addEventListener('submit', function(e) {
|
| 900 |
e.preventDefault();
|
| 901 |
const formData = new FormData(this);
|
| 902 |
-
|
| 903 |
-
flashContainer.innerHTML = ''; // Clear previous messages
|
| 904 |
-
|
| 905 |
-
fetch('/', {{
|
| 906 |
method: 'POST',
|
| 907 |
body: formData
|
| 908 |
-
}
|
| 909 |
.then(response => response.json())
|
| 910 |
-
.then(data => {
|
| 911 |
-
if (data.status === 'success') {
|
| 912 |
const username = formData.get('username');
|
| 913 |
const password = formData.get('password');
|
| 914 |
-
|
| 915 |
-
// localStorage.setItem('zeusCredentials', JSON.stringify({{ username, password }}));
|
| 916 |
window.location.href = data.redirect;
|
| 917 |
-
}
|
| 918 |
-
|
| 919 |
-
}
|
| 920 |
-
}
|
| 921 |
-
.catch(error => {
|
| 922 |
-
|
| 923 |
-
}
|
| 924 |
-
}
|
| 925 |
</script>
|
| 926 |
</body>
|
| 927 |
</html>
|
| 928 |
-
'''
|
| 929 |
return render_template_string(html)
|
| 930 |
|
| 931 |
@app.route('/dashboard', methods=['GET', 'POST'])
|
| 932 |
def dashboard():
|
| 933 |
if 'username' not in session:
|
| 934 |
-
flash('Пожалуйста, войдите!'
|
| 935 |
return redirect(url_for('login'))
|
| 936 |
-
|
| 937 |
username = session['username']
|
| 938 |
data = load_data()
|
| 939 |
if username not in data['users']:
|
| 940 |
session.pop('username', None)
|
| 941 |
-
flash('Пользователь не найден!
|
| 942 |
return redirect(url_for('login'))
|
|
|
|
|
|
|
| 943 |
|
| 944 |
if request.method == 'POST':
|
| 945 |
files = request.files.getlist('files')
|
| 946 |
-
if
|
| 947 |
-
|
| 948 |
-
return redirect(url_for('dashboard'))
|
| 949 |
-
|
| 950 |
-
if len(files) > 20:
|
| 951 |
-
flash('Можно загрузить не более 20 файлов за раз!', 'error')
|
| 952 |
-
return redirect(url_for('dashboard'))
|
| 953 |
-
|
| 954 |
-
if not HF_TOKEN_WRITE:
|
| 955 |
-
flash('Ошибка конфигурации сервера: загрузка файлов невозможна.', 'error')
|
| 956 |
-
logging.error("HF_TOKEN_WRITE is not configured for file upload.")
|
| 957 |
return redirect(url_for('dashboard'))
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
# Create a unique filename to avoid conflicts (e.g., user_timestamp_filename)
|
| 969 |
-
timestamp = datetime.now().strftime("%Y%m%d%H%M%S%f")
|
| 970 |
-
unique_filename = f"{timestamp}_{original_filename}"
|
| 971 |
-
temp_path = os.path.join(upload_dir, unique_filename)
|
| 972 |
-
|
| 973 |
-
try:
|
| 974 |
file.save(temp_path)
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
-
|
| 981 |
-
|
| 982 |
-
|
| 983 |
-
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
-
|
| 989 |
-
|
| 990 |
-
|
| 991 |
-
)
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
files_uploaded_info.append(file_info)
|
| 1003 |
-
|
| 1004 |
-
except Exception as e:
|
| 1005 |
-
logging.error(f"Error uploading file {original_filename} for {username}: {e}")
|
| 1006 |
-
errors_occurred = True
|
| 1007 |
-
flash(f'Ошибка при загрузке файла: {original_filename}', 'error')
|
| 1008 |
-
finally:
|
| 1009 |
-
if os.path.exists(temp_path):
|
| 1010 |
-
try:
|
| 1011 |
-
os.remove(temp_path)
|
| 1012 |
-
except OSError as e:
|
| 1013 |
-
logging.error(f"Error removing temporary file {temp_path}: {e}")
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
-
if files_uploaded_info:
|
| 1017 |
-
data['users'][username]['files'].extend(files_uploaded_info)
|
| 1018 |
-
try:
|
| 1019 |
-
save_data(data)
|
| 1020 |
-
if not errors_occurred:
|
| 1021 |
-
flash('Файлы успешно загружены!', 'success')
|
| 1022 |
-
else:
|
| 1023 |
-
flash('Часть файлов загружена, но произошли ошибки.', 'warning')
|
| 1024 |
-
except Exception as e:
|
| 1025 |
-
flash('Ошибка при сохранении информации о файлах.', 'error')
|
| 1026 |
-
logging.error(f"Error saving file metadata after upload for {username}: {e}")
|
| 1027 |
-
|
| 1028 |
return redirect(url_for('dashboard'))
|
| 1029 |
|
| 1030 |
-
|
| 1031 |
-
user_files = sorted(data['users'][username].get('files', []), key=lambda x: x['upload_date'], reverse=True)
|
| 1032 |
-
|
| 1033 |
html = '''
|
| 1034 |
<!DOCTYPE html>
|
| 1035 |
-
<html lang="
|
| 1036 |
<head>
|
| 1037 |
<meta charset="UTF-8">
|
| 1038 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 1039 |
-
<title>
|
| 1040 |
-
<
|
|
|
|
| 1041 |
</head>
|
| 1042 |
<body>
|
| 1043 |
-
<
|
| 1044 |
<div class="container">
|
| 1045 |
-
<h1>Zeus Cloud</h1>
|
| 1046 |
-
<p style="
|
| 1047 |
-
{
|
| 1048 |
-
{
|
| 1049 |
-
{
|
| 1050 |
-
<div class="flash
|
| 1051 |
-
{
|
| 1052 |
-
{
|
| 1053 |
-
{
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
<
|
| 1057 |
-
<button type="submit" class="btn" id="upload-btn">Загрузить файлы (макс 20)</button>
|
| 1058 |
</form>
|
| 1059 |
<div id="progress-container">
|
| 1060 |
-
<div id="progress-bar">
|
| 1061 |
</div>
|
| 1062 |
-
|
| 1063 |
<h2>Ваши файлы</h2>
|
| 1064 |
<div class="file-grid">
|
| 1065 |
-
{
|
| 1066 |
<div class="file-item">
|
| 1067 |
-
|
| 1068 |
-
|
| 1069 |
-
|
| 1070 |
-
<video class="file-preview" preload="metadata" muted loading="lazy" onclick="openModal('{file_url}', true)">
|
| 1071 |
-
<source src="{file_url}" type="video/mp4">
|
| 1072 |
</video>
|
| 1073 |
-
{
|
| 1074 |
-
<img class="file-preview" src="{
|
| 1075 |
-
{
|
| 1076 |
-
|
| 1077 |
-
{
|
| 1078 |
-
</
|
| 1079 |
-
<
|
| 1080 |
-
<
|
| 1081 |
-
<div class="actions">
|
| 1082 |
-
<a href="{{{{ url_for('download_file', file_path=file.path, filename=file.filename) }}}}" class="btn download-btn">Скачать</a>
|
| 1083 |
-
<a href="{{{{ url_for('delete_file', file_path=file.path) }}}}" class="btn delete-btn" onclick="return confirm('Вы уверены, что хотите удалить файл \\'{{{{ file.filename }}}}\\'? Это действие необратимо.');">Удалить</a>
|
| 1084 |
-
</div>
|
| 1085 |
</div>
|
| 1086 |
-
{
|
| 1087 |
-
{
|
| 1088 |
-
<p
|
| 1089 |
-
{
|
| 1090 |
</div>
|
| 1091 |
-
<a href="
|
| 1092 |
</div>
|
| 1093 |
-
|
| 1094 |
-
|
| 1095 |
-
<div id="modalContent" class="modal-content"></div>
|
| 1096 |
</div>
|
| 1097 |
-
|
| 1098 |
-
{global_js}
|
| 1099 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1100 |
const form = document.getElementById('upload-form');
|
| 1101 |
const progressBar = document.getElementById('progress-bar');
|
| 1102 |
const progressContainer = document.getElementById('progress-container');
|
| 1103 |
const uploadBtn = document.getElementById('upload-btn');
|
| 1104 |
-
const fileInput = form.querySelector('input[type="file"]');
|
| 1105 |
|
| 1106 |
-
form.addEventListener('submit', function(e) {
|
| 1107 |
e.preventDefault();
|
| 1108 |
-
const files =
|
| 1109 |
-
if (files.length
|
| 1110 |
-
alert('Пожалуйста, выберите файлы для загрузки.');
|
| 1111 |
-
return;
|
| 1112 |
-
}}
|
| 1113 |
-
if (files.length > 20) {{
|
| 1114 |
alert('Максимум 20 файлов за раз!');
|
| 1115 |
return;
|
| 1116 |
-
}
|
| 1117 |
|
| 1118 |
const formData = new FormData(form);
|
| 1119 |
progressContainer.style.display = 'block';
|
| 1120 |
progressBar.style.width = '0%';
|
| 1121 |
-
progressBar.textContent = '0%';
|
| 1122 |
uploadBtn.disabled = true;
|
| 1123 |
-
uploadBtn.textContent = 'Загрузка...';
|
| 1124 |
-
|
| 1125 |
|
| 1126 |
const xhr = new XMLHttpRequest();
|
| 1127 |
xhr.open('POST', '/dashboard', true);
|
| 1128 |
|
| 1129 |
-
xhr.upload.onprogress = function(event) {
|
| 1130 |
-
if (event.lengthComputable) {
|
| 1131 |
-
const percent =
|
| 1132 |
progressBar.style.width = percent + '%';
|
| 1133 |
-
|
| 1134 |
-
|
| 1135 |
-
|
| 1136 |
-
|
| 1137 |
-
|
| 1138 |
-
|
| 1139 |
-
|
| 1140 |
-
|
| 1141 |
-
|
| 1142 |
-
|
| 1143 |
-
|
| 1144 |
-
|
| 1145 |
-
|
| 1146 |
-
|
|
|
|
| 1147 |
progressContainer.style.display = 'none';
|
| 1148 |
uploadBtn.disabled = false;
|
| 1149 |
-
|
| 1150 |
-
}};
|
| 1151 |
|
| 1152 |
xhr.send(formData);
|
| 1153 |
-
}
|
| 1154 |
|
| 1155 |
-
document.getElementById('logout-btn').addEventListener('click', function(e) {
|
| 1156 |
e.preventDefault();
|
| 1157 |
-
localStorage.removeItem('zeusCredentials');
|
| 1158 |
-
window.location.href = '
|
| 1159 |
-
}
|
| 1160 |
</script>
|
| 1161 |
</body>
|
| 1162 |
</html>
|
| 1163 |
-
'''
|
| 1164 |
return render_template_string(html, username=username, user_files=user_files, repo_id=REPO_ID)
|
| 1165 |
|
| 1166 |
-
|
| 1167 |
@app.route('/download/<path:file_path>/<filename>')
|
| 1168 |
def download_file(file_path, filename):
|
| 1169 |
if 'username' not in session:
|
| 1170 |
-
flash('Пожалуйста, войдите!'
|
| 1171 |
return redirect(url_for('login'))
|
| 1172 |
-
|
| 1173 |
username = session['username']
|
| 1174 |
data = load_data()
|
| 1175 |
if username not in data['users']:
|
| 1176 |
session.pop('username', None)
|
| 1177 |
-
flash('Пользователь не найден!'
|
| 1178 |
return redirect(url_for('login'))
|
| 1179 |
-
|
| 1180 |
-
|
| 1181 |
-
|
| 1182 |
-
|
| 1183 |
-
# is_admin = session.get('is_admin', False) # Placeholder for admin logic
|
| 1184 |
-
|
| 1185 |
-
if not is_owner: # and not is_admin: # Add admin check here if needed
|
| 1186 |
-
flash('У вас нет доступа к этому файлу!', 'error')
|
| 1187 |
return redirect(url_for('dashboard'))
|
| 1188 |
-
|
| 1189 |
-
|
| 1190 |
-
|
| 1191 |
-
|
| 1192 |
-
|
| 1193 |
-
|
| 1194 |
-
|
| 1195 |
-
# Use hf_hub_download to get the file content
|
| 1196 |
-
try:
|
| 1197 |
-
logging.info(f"Attempting to download {file_path} for user {username}")
|
| 1198 |
-
downloaded_file_path = hf_hub_download(
|
| 1199 |
-
repo_id=REPO_ID,
|
| 1200 |
-
filename=file_path,
|
| 1201 |
-
repo_type="dataset",
|
| 1202 |
-
token=HF_TOKEN_READ
|
| 1203 |
-
)
|
| 1204 |
-
logging.info(f"File {file_path} downloaded to {downloaded_file_path}")
|
| 1205 |
-
|
| 1206 |
-
# It's generally safer to send the file from the downloaded path
|
| 1207 |
-
# rather than reading it all into memory if files can be large.
|
| 1208 |
return send_file(
|
| 1209 |
-
|
| 1210 |
as_attachment=True,
|
| 1211 |
-
download_name=filename
|
| 1212 |
-
|
| 1213 |
)
|
| 1214 |
-
|
| 1215 |
-
|
| 1216 |
-
|
| 1217 |
-
flash('Ошибка при скачивании файла с сервера.', 'error')
|
| 1218 |
-
# Redirect back to where the user came from, or dashboard as fallback
|
| 1219 |
-
return redirect(request.referrer or url_for('dashboard'))
|
| 1220 |
-
|
| 1221 |
|
| 1222 |
@app.route('/delete/<path:file_path>')
|
| 1223 |
def delete_file(file_path):
|
| 1224 |
if 'username' not in session:
|
| 1225 |
-
flash('Пожалуйста, войдите!'
|
| 1226 |
return redirect(url_for('login'))
|
| 1227 |
-
|
| 1228 |
username = session['username']
|
| 1229 |
data = load_data()
|
| 1230 |
if username not in data['users']:
|
| 1231 |
session.pop('username', None)
|
| 1232 |
-
flash('Пользователь не найден!'
|
| 1233 |
return redirect(url_for('login'))
|
| 1234 |
-
|
| 1235 |
-
user_files = data['users'][username]
|
| 1236 |
-
file_to_delete = next((
|
| 1237 |
-
|
| 1238 |
if not file_to_delete:
|
| 1239 |
-
flash('Файл не найден
|
| 1240 |
-
return redirect(url_for('dashboard'))
|
| 1241 |
-
|
| 1242 |
-
if not HF_TOKEN_WRITE:
|
| 1243 |
-
flash('Ошибка конфигурации сервера: удаление файлов невозможно.', 'error')
|
| 1244 |
-
logging.error("HF_TOKEN_WRITE is not configured for file deletion.")
|
| 1245 |
return redirect(url_for('dashboard'))
|
| 1246 |
-
|
| 1247 |
try:
|
| 1248 |
-
logging.info(f"Attempting to delete file {file_path} for user {username}")
|
| 1249 |
api = HfApi()
|
| 1250 |
api.delete_file(
|
| 1251 |
path_in_repo=file_path,
|
| 1252 |
repo_id=REPO_ID,
|
| 1253 |
repo_type="dataset",
|
| 1254 |
-
token=HF_TOKEN_WRITE
|
| 1255 |
-
|
| 1256 |
)
|
| 1257 |
-
logging.info(f"Successfully deleted file {file_path} from HF.")
|
| 1258 |
-
|
| 1259 |
-
# Update the local data file
|
| 1260 |
data['users'][username]['files'] = [f for f in user_files if f['path'] != file_path]
|
| 1261 |
save_data(data)
|
| 1262 |
-
flash(
|
| 1263 |
-
|
| 1264 |
except Exception as e:
|
| 1265 |
-
logging.error(f"
|
| 1266 |
-
|
| 1267 |
-
|
| 1268 |
-
logging.warning(f"File {file_path} not found on HF during deletion attempt, possibly already deleted. Removing from local data.")
|
| 1269 |
-
# Still try to remove from local data if it exists there
|
| 1270 |
-
if any(f['path'] == file_path for f in data['users'][username]['files']):
|
| 1271 |
-
data['users'][username]['files'] = [f for f in user_files if f['path'] != file_path]
|
| 1272 |
-
try:
|
| 1273 |
-
save_data(data)
|
| 1274 |
-
flash(f'Файл "{file_to_delete["filename"]}" удален (возможно, уже был удален с хранилища).', 'warning')
|
| 1275 |
-
except Exception as save_err:
|
| 1276 |
-
logging.error(f"Error saving data after confirming HF deletion failed for {file_path}: {save_err}")
|
| 1277 |
-
flash('Ошибка при обновлении списка файлов после удаления.', 'error')
|
| 1278 |
-
else:
|
| 1279 |
-
flash('Файл не найден.', 'error')
|
| 1280 |
-
|
| 1281 |
-
else:
|
| 1282 |
-
flash('Ошибка при удалении файла.', 'error')
|
| 1283 |
-
|
| 1284 |
return redirect(url_for('dashboard'))
|
| 1285 |
|
| 1286 |
@app.route('/logout')
|
| 1287 |
def logout():
|
| 1288 |
session.pop('username', None)
|
| 1289 |
-
# session.pop('is_admin', None) # Clear admin status if used
|
| 1290 |
-
flash('Вы успешно вышли из системы.', 'success')
|
| 1291 |
return redirect(url_for('login'))
|
| 1292 |
|
| 1293 |
@app.route('/admhosto')
|
| 1294 |
def admin_panel():
|
| 1295 |
-
# Add authentication/authorization check here!
|
| 1296 |
-
# Example: if not session.get('is_admin'): abort(403)
|
| 1297 |
-
# For now, it's open, which is insecure.
|
| 1298 |
-
|
| 1299 |
data = load_data()
|
| 1300 |
-
users = data
|
| 1301 |
-
|
| 1302 |
html = '''
|
| 1303 |
<!DOCTYPE html>
|
| 1304 |
-
<html lang="
|
| 1305 |
<head>
|
| 1306 |
<meta charset="UTF-8">
|
| 1307 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 1308 |
<title>Админ-панель - Zeus Cloud</title>
|
| 1309 |
-
<
|
|
|
|
| 1310 |
</head>
|
| 1311 |
<body>
|
| 1312 |
-
|
| 1313 |
<div class="container">
|
| 1314 |
<h1>Админ-панель Zeus Cloud</h1>
|
| 1315 |
-
<h2>
|
| 1316 |
<div class="user-list">
|
| 1317 |
-
{
|
| 1318 |
<div class="user-item">
|
| 1319 |
-
<a href="{{
|
| 1320 |
-
<p>Дата регистрации: {{ user_data
|
| 1321 |
-
<p>
|
| 1322 |
-
{# Add more user info or actions here if needed #}
|
| 1323 |
</div>
|
| 1324 |
-
{
|
| 1325 |
-
{
|
| 1326 |
-
<p
|
| 1327 |
-
{
|
| 1328 |
</div>
|
| 1329 |
-
{# Add more admin features here: server status, settings, etc. #}
|
| 1330 |
</div>
|
| 1331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1332 |
</body>
|
| 1333 |
</html>
|
| 1334 |
-
'''
|
| 1335 |
return render_template_string(html, users=users)
|
| 1336 |
|
| 1337 |
@app.route('/admhosto/user/<username>')
|
| 1338 |
def admin_user_files(username):
|
| 1339 |
-
# Add authentication/authorization check here!
|
| 1340 |
-
# Example: if not session.get('is_admin'): abort(403)
|
| 1341 |
-
|
| 1342 |
data = load_data()
|
| 1343 |
-
if username not in data
|
| 1344 |
-
flash('Пользователь не найден!'
|
| 1345 |
return redirect(url_for('admin_panel'))
|
| 1346 |
-
|
| 1347 |
-
user_files = sorted(data['users'][username]
|
| 1348 |
-
|
| 1349 |
html = '''
|
| 1350 |
<!DOCTYPE html>
|
| 1351 |
-
<html lang="
|
| 1352 |
<head>
|
| 1353 |
<meta charset="UTF-8">
|
| 1354 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 1355 |
<title>Файлы пользователя {{ username }} - Zeus Cloud</title>
|
| 1356 |
-
|
|
|
|
| 1357 |
</head>
|
| 1358 |
<body>
|
| 1359 |
-
<
|
| 1360 |
<div class="container">
|
| 1361 |
<h1>Файлы пользователя: {{ username }}</h1>
|
| 1362 |
-
{
|
| 1363 |
-
{
|
| 1364 |
-
{
|
| 1365 |
-
<div class="flash
|
| 1366 |
-
{
|
| 1367 |
-
{
|
| 1368 |
-
{
|
| 1369 |
<div class="file-grid">
|
| 1370 |
-
|
| 1371 |
<div class="file-item">
|
| 1372 |
-
|
| 1373 |
-
|
| 1374 |
-
|
| 1375 |
-
<video class="file-preview" preload="metadata" muted loading="lazy" onclick="openModal('{file_url}', true)">
|
| 1376 |
-
<source src="{file_url}" type="video/mp4">
|
| 1377 |
</video>
|
| 1378 |
-
{
|
| 1379 |
-
<img class="file-preview" src="{
|
| 1380 |
-
{
|
| 1381 |
-
|
| 1382 |
-
{
|
| 1383 |
-
</
|
| 1384 |
-
<
|
| 1385 |
-
<p class="date">{{{{ file.upload_date }}}}</p>
|
| 1386 |
-
<div class="actions">
|
| 1387 |
-
{# Admin might have different actions, e.g., only download or delete with confirmation #}
|
| 1388 |
-
<a href="{{{{ url_for('download_file', file_path=file.path, filename=file.filename) }}}}" class="btn download-btn">Скачать</a>
|
| 1389 |
-
{# Maybe add admin-specific delete here, possibly requiring extra confirmation #}
|
| 1390 |
-
{# <a href="{{ url_for('admin_delete_file', username=username, file_path=file['path']) }}" class="btn delete-btn" onclick="return confirm('ADMIN: Удалить файл пользователя {{ username }}?');">Удалить (Админ)</a> #}
|
| 1391 |
-
</div>
|
| 1392 |
</div>
|
| 1393 |
-
{
|
| 1394 |
-
{
|
| 1395 |
-
<p
|
| 1396 |
-
{
|
| 1397 |
</div>
|
| 1398 |
-
<a href="{{
|
| 1399 |
</div>
|
| 1400 |
-
|
| 1401 |
-
|
| 1402 |
</div>
|
| 1403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1404 |
</body>
|
| 1405 |
</html>
|
| 1406 |
-
'''
|
| 1407 |
return render_template_string(html, username=username, user_files=user_files, repo_id=REPO_ID)
|
| 1408 |
|
| 1409 |
-
|
| 1410 |
if __name__ == '__main__':
|
| 1411 |
-
|
| 1412 |
-
if not HF_TOKEN_WRITE or not HF_TOKEN_READ:
|
| 1413 |
-
logging.warning("HF_TOKEN_WRITE or HF_TOKEN_READ environment variables are not set. File operations might fail.")
|
| 1414 |
-
|
| 1415 |
-
# Initial download of the database on startup
|
| 1416 |
-
logging.info("Performing initial database download...")
|
| 1417 |
-
download_db_from_hf()
|
| 1418 |
-
|
| 1419 |
-
# Start periodic backup in a background thread
|
| 1420 |
-
backup_thread = threading.Thread(target=periodic_backup, daemon=True)
|
| 1421 |
-
backup_thread.start()
|
| 1422 |
-
logging.info("Periodic backup thread started.")
|
| 1423 |
-
|
| 1424 |
-
# Use waitress or gunicorn for production instead of Flask's built-in server
|
| 1425 |
-
# Example using waitress:
|
| 1426 |
-
# from waitress import serve
|
| 1427 |
-
# serve(app, host='0.0.0.0', port=7860)
|
| 1428 |
-
|
| 1429 |
-
# For development/testing:
|
| 1430 |
app.run(debug=False, host='0.0.0.0', port=7860)
|
|
|
|
|
|
|
| 1 |
from flask import Flask, render_template_string, request, redirect, url_for, session, flash, send_file, jsonify
|
| 2 |
from flask_caching import Cache
|
| 3 |
import json
|
|
|
|
| 12 |
from io import BytesIO
|
| 13 |
|
| 14 |
app = Flask(__name__)
|
| 15 |
+
|
| 16 |
+
app.secret_key = os.getenv("FLASK_SECRET_KEY", "supersecretkey")
|
| 17 |
DATA_FILE = 'cloud_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 |
cache = Cache(app, config={'CACHE_TYPE': 'simple'})
|
| 22 |
+
logging.basicConfig(level=logging.INFO)
|
| 23 |
|
| 24 |
@cache.memoize(timeout=300)
|
| 25 |
def load_data():
|
|
|
|
| 28 |
with open(DATA_FILE, 'r', encoding='utf-8') as file:
|
| 29 |
data = json.load(file)
|
| 30 |
if not isinstance(data, dict):
|
| 31 |
+
logging.warning("Данные не в формате dict, инициализация пустой базы")
|
| 32 |
return {'users': {}, 'files': {}}
|
| 33 |
data.setdefault('users', {})
|
| 34 |
data.setdefault('files', {})
|
| 35 |
+
logging.info("Данные успешно загружены")
|
| 36 |
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
except Exception as e:
|
| 38 |
+
logging.error(f"Ошибка при загрузке данных: {e}")
|
| 39 |
return {'users': {}, 'files': {}}
|
| 40 |
|
| 41 |
def save_data(data):
|
|
|
|
| 42 |
try:
|
| 43 |
+
with open(DATA_FILE, 'w', encoding='utf-8') as file:
|
| 44 |
json.dump(data, file, ensure_ascii=False, indent=4)
|
|
|
|
| 45 |
upload_db_to_hf()
|
| 46 |
cache.clear()
|
| 47 |
+
logging.info("Данные сохранены и загружены на HF")
|
| 48 |
except Exception as e:
|
| 49 |
+
logging.error(f"Ошибка при сохранении данных: {e}")
|
|
|
|
|
|
|
| 50 |
raise
|
| 51 |
|
| 52 |
def upload_db_to_hf():
|
|
|
|
|
|
|
|
|
|
| 53 |
try:
|
| 54 |
api = HfApi()
|
| 55 |
api.upload_file(
|
|
|
|
| 58 |
repo_id=REPO_ID,
|
| 59 |
repo_type="dataset",
|
| 60 |
token=HF_TOKEN_WRITE,
|
| 61 |
+
commit_message=f"Бэкап {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
|
| 62 |
)
|
| 63 |
+
logging.info("База данных загружена на Hugging Face")
|
| 64 |
except Exception as e:
|
| 65 |
+
logging.error(f"Ошибка при загрузке базы данных: {e}")
|
| 66 |
|
| 67 |
def download_db_from_hf():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
try:
|
| 69 |
hf_hub_download(
|
| 70 |
repo_id=REPO_ID,
|
|
|
|
| 72 |
repo_type="dataset",
|
| 73 |
token=HF_TOKEN_READ,
|
| 74 |
local_dir=".",
|
| 75 |
+
local_dir_use_symlinks=False
|
|
|
|
| 76 |
)
|
| 77 |
+
logging.info("База данных скачана с Hugging Face")
|
| 78 |
except Exception as e:
|
| 79 |
+
logging.error(f"Ошибка при скачивании базы данных: {e}")
|
| 80 |
if not os.path.exists(DATA_FILE):
|
|
|
|
| 81 |
with open(DATA_FILE, 'w', encoding='utf-8') as f:
|
| 82 |
json.dump({'users': {}, 'files': {}}, f)
|
| 83 |
|
| 84 |
def periodic_backup():
|
| 85 |
while True:
|
| 86 |
+
upload_db_to_hf()
|
| 87 |
+
time.sleep(1800)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
def get_file_type(filename):
|
| 90 |
+
video_extensions = ('.mp4', '.mov', '.avi')
|
| 91 |
+
image_extensions = ('.jpg', '.jpeg', '.png', '.gif')
|
| 92 |
+
if filename.lower().endswith(video_extensions):
|
|
|
|
| 93 |
return 'video'
|
| 94 |
+
elif filename.lower().endswith(image_extensions):
|
| 95 |
return 'image'
|
| 96 |
return 'other'
|
| 97 |
|
| 98 |
BASE_STYLE = '''
|
|
|
|
|
|
|
| 99 |
:root {
|
| 100 |
+
--primary: #6C63FF;
|
| 101 |
+
--secondary: #00E1D4;
|
| 102 |
+
--accent: #FF6B6B;
|
| 103 |
+
--background: #0F0C29;
|
| 104 |
+
--card-bg: rgba(30, 27, 75, 0.95);
|
| 105 |
+
--text: #E0E7FF;
|
| 106 |
+
--shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
|
| 107 |
+
--glass-bg: rgba(255, 255, 255, 0.1);
|
| 108 |
+
--transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
* {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
margin: 0;
|
| 113 |
padding: 0;
|
| 114 |
box-sizing: border-box;
|
| 115 |
}
|
| 116 |
|
| 117 |
body {
|
| 118 |
+
font-family: 'Poppins', sans-serif;
|
| 119 |
+
background: linear-gradient(135deg, #0F0C29, #302B63);
|
| 120 |
+
color: var(--text);
|
| 121 |
+
line-height: 1.8;
|
|
|
|
| 122 |
min-height: 100vh;
|
| 123 |
+
overflow-x: hidden;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
}
|
| 125 |
|
|
|
|
| 126 |
.container {
|
| 127 |
+
margin: 40px auto;
|
| 128 |
+
max-width: 1400px;
|
| 129 |
+
padding: 30px;
|
| 130 |
+
background: var(--card-bg);
|
| 131 |
+
border-radius: 25px;
|
| 132 |
+
box-shadow: var(--shadow);
|
| 133 |
backdrop-filter: blur(10px);
|
| 134 |
+
position: relative;
|
| 135 |
+
z-index: 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
}
|
| 137 |
|
| 138 |
h1 {
|
| 139 |
+
font-size: 3em;
|
| 140 |
+
font-weight: 900;
|
| 141 |
text-align: center;
|
| 142 |
+
margin-bottom: 30px;
|
| 143 |
+
background: linear-gradient(135deg, var(--primary), var(--secondary));
|
| 144 |
-webkit-background-clip: text;
|
| 145 |
color: transparent;
|
| 146 |
+
text-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
|
| 147 |
}
|
| 148 |
|
| 149 |
h2 {
|
| 150 |
+
font-size: 2em;
|
| 151 |
+
margin: 40px 0 20px;
|
| 152 |
+
color: var(--text);
|
| 153 |
+
font-weight: 600;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
}
|
| 155 |
|
| 156 |
+
input, textarea {
|
| 157 |
width: 100%;
|
| 158 |
+
padding: 16px;
|
| 159 |
+
margin: 15px 0;
|
| 160 |
+
border: 2px solid transparent;
|
| 161 |
+
border-radius: 15px;
|
| 162 |
+
background: var(--glass-bg);
|
| 163 |
+
color: var(--text);
|
| 164 |
+
font-size: 1.2em;
|
| 165 |
+
transition: var(--transition);
|
| 166 |
+
backdrop-filter: blur(5px);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
}
|
| 168 |
|
| 169 |
input:focus, textarea:focus {
|
| 170 |
outline: none;
|
| 171 |
+
border-color: var(--primary);
|
| 172 |
+
box-shadow: 0 0 15px var(--primary);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
}
|
| 174 |
|
| 175 |
.btn {
|
| 176 |
+
padding: 16px 32px;
|
| 177 |
+
background: var(--primary);
|
| 178 |
+
color: var(--text);
|
| 179 |
border: none;
|
| 180 |
+
border-radius: 15px;
|
| 181 |
cursor: pointer;
|
| 182 |
+
font-size: 1.2em;
|
| 183 |
+
font-weight: 700;
|
| 184 |
+
transition: var(--transition);
|
| 185 |
+
box-shadow: var(--shadow);
|
| 186 |
display: inline-block;
|
| 187 |
text-decoration: none;
|
| 188 |
+
position: relative;
|
| 189 |
+
overflow: hidden;
|
|
|
|
| 190 |
}
|
| 191 |
|
| 192 |
+
.btn::before {
|
| 193 |
+
content: '';
|
| 194 |
+
position: absolute;
|
| 195 |
+
top: 0;
|
| 196 |
+
left: -100%;
|
| 197 |
+
width: 100%;
|
| 198 |
+
height: 100%;
|
| 199 |
+
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
|
| 200 |
+
transition: var(--transition);
|
| 201 |
}
|
| 202 |
|
| 203 |
+
.btn:hover::before {
|
| 204 |
+
left: 100%;
|
|
|
|
| 205 |
}
|
| 206 |
|
| 207 |
+
.btn:hover {
|
| 208 |
+
transform: translateY(-5px);
|
| 209 |
+
background: var(--secondary);
|
| 210 |
+
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
|
| 211 |
}
|
|
|
|
|
|
|
| 212 |
|
| 213 |
+
.download-btn {
|
| 214 |
+
background: var(--secondary);
|
|
|
|
|
|
|
| 215 |
}
|
|
|
|
|
|
|
| 216 |
|
| 217 |
+
.download-btn:hover {
|
| 218 |
+
background: var(--accent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
}
|
| 220 |
|
| 221 |
+
.delete-btn {
|
| 222 |
+
background: var(--accent);
|
|
|
|
|
|
|
| 223 |
}
|
| 224 |
|
| 225 |
+
.delete-btn:hover {
|
| 226 |
+
background: #FF4B4B;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
}
|
| 228 |
|
| 229 |
+
.flash {
|
| 230 |
+
color: var(--secondary);
|
| 231 |
+
text-align: center;
|
| 232 |
+
margin-bottom: 20px;
|
| 233 |
+
font-size: 1.2em;
|
| 234 |
+
animation: fadeIn 0.5s ease;
|
| 235 |
+
}
|
| 236 |
|
| 237 |
.file-grid {
|
| 238 |
display: grid;
|
| 239 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
| 240 |
gap: 25px;
|
| 241 |
margin-top: 30px;
|
| 242 |
}
|
| 243 |
|
| 244 |
.user-list {
|
| 245 |
+
margin-top: 30px;
|
|
|
|
|
|
|
|
|
|
| 246 |
}
|
| 247 |
|
| 248 |
.user-item {
|
| 249 |
+
padding: 20px;
|
| 250 |
+
background: var(--glass-bg);
|
| 251 |
+
border-radius: 20px;
|
| 252 |
+
margin-bottom: 15px;
|
| 253 |
+
box-shadow: var(--shadow);
|
| 254 |
+
transition: var(--transition);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
}
|
| 256 |
|
| 257 |
.user-item:hover {
|
| 258 |
+
transform: translateY(-10px);
|
| 259 |
+
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
}
|
| 261 |
|
|
|
|
| 262 |
.user-item a {
|
| 263 |
+
color: var(--primary);
|
| 264 |
text-decoration: none;
|
| 265 |
font-weight: 600;
|
| 266 |
+
font-size: 1.3em;
|
|
|
|
|
|
|
| 267 |
}
|
| 268 |
|
| 269 |
.user-item a:hover {
|
| 270 |
+
color: var(--secondary);
|
| 271 |
}
|
| 272 |
|
| 273 |
+
@media (max-width: 768px) {
|
| 274 |
+
.file-grid {
|
| 275 |
+
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
| 276 |
+
}
|
| 277 |
}
|
| 278 |
+
|
| 279 |
+
@media (max-width: 480px) {
|
| 280 |
+
.file-grid {
|
| 281 |
+
grid-template-columns: 1fr;
|
| 282 |
+
}
|
| 283 |
}
|
| 284 |
|
| 285 |
.file-item {
|
| 286 |
+
background: var(--glass-bg);
|
| 287 |
+
padding: 20px;
|
| 288 |
+
border-radius: 20px;
|
| 289 |
+
box-shadow: var(--shadow);
|
| 290 |
text-align: center;
|
| 291 |
+
transition: var(--transition);
|
| 292 |
+
backdrop-filter: blur(8px);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
}
|
| 294 |
|
| 295 |
.file-item:hover {
|
| 296 |
+
transform: translateY(-10px);
|
| 297 |
+
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
}
|
| 299 |
|
| 300 |
.file-preview {
|
| 301 |
+
max-width: 100%;
|
| 302 |
+
max-height: 250px;
|
| 303 |
+
object-fit: cover;
|
| 304 |
+
border-radius: 15px;
|
| 305 |
+
margin-bottom: 15px;
|
| 306 |
+
transition: var(--transition);
|
| 307 |
cursor: pointer;
|
|
|
|
| 308 |
}
|
| 309 |
|
| 310 |
+
.file-preview:hover {
|
| 311 |
transform: scale(1.05);
|
| 312 |
}
|
| 313 |
|
|
|
|
| 314 |
.file-item p {
|
| 315 |
+
font-size: 1em;
|
| 316 |
margin: 8px 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
}
|
| 318 |
|
| 319 |
+
.file-item a {
|
| 320 |
+
color: var(--primary);
|
| 321 |
+
text-decoration: none;
|
|
|
|
|
|
|
| 322 |
}
|
| 323 |
|
| 324 |
+
.file-item a:hover {
|
| 325 |
+
color: var(--secondary);
|
|
|
|
|
|
|
| 326 |
}
|
| 327 |
|
| 328 |
.modal {
|
|
|
|
| 336 |
z-index: 2000;
|
| 337 |
justify-content: center;
|
| 338 |
align-items: center;
|
| 339 |
+
backdrop-filter: blur(5px);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
}
|
| 341 |
|
| 342 |
.modal img, .modal video {
|
| 343 |
+
max-width: 90%;
|
| 344 |
+
max-height: 90%;
|
|
|
|
| 345 |
object-fit: contain;
|
| 346 |
+
border-radius: 25px;
|
| 347 |
+
box-shadow: var(--shadow);
|
| 348 |
+
animation: zoomIn 0.5s ease;
|
| 349 |
}
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
#progress-container {
|
| 352 |
width: 100%;
|
| 353 |
+
background: var(--glass-bg);
|
| 354 |
+
border-radius: 15px;
|
| 355 |
margin: 20px 0;
|
|
|
|
| 356 |
display: none;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
}
|
| 358 |
|
| 359 |
#progress-bar {
|
| 360 |
width: 0%;
|
| 361 |
height: 25px;
|
| 362 |
+
background: linear-gradient(90deg, var(--primary), var(--secondary));
|
| 363 |
+
border-radius: 15px;
|
| 364 |
+
transition: width 0.5s ease;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
}
|
| 366 |
|
| 367 |
+
@keyframes fadeIn {
|
| 368 |
+
from { opacity: 0; }
|
| 369 |
+
to { opacity: 1; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
}
|
| 371 |
|
| 372 |
+
@keyframes zoomIn {
|
| 373 |
+
from { transform: scale(0.8); opacity: 0; }
|
| 374 |
+
to { transform: scale(1); opacity: 1; }
|
| 375 |
}
|
| 376 |
|
| 377 |
+
.particles {
|
| 378 |
+
position: fixed;
|
| 379 |
+
top: 0;
|
| 380 |
+
left: 0;
|
| 381 |
+
width: 100%;
|
| 382 |
+
height: 100%;
|
| 383 |
+
pointer-events: none;
|
| 384 |
+
z-index: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
}
|
| 386 |
'''
|
| 387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
@app.route('/register', methods=['GET', 'POST'])
|
| 389 |
def register():
|
| 390 |
if request.method == 'POST':
|
| 391 |
+
username = request.form.get('username')
|
| 392 |
password = request.form.get('password')
|
| 393 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
data = load_data()
|
| 395 |
+
|
| 396 |
if username in data['users']:
|
| 397 |
+
flash('Пользователь с таким логином уже существует!')
|
| 398 |
return redirect(url_for('register'))
|
| 399 |
+
|
| 400 |
+
if not username or not password:
|
| 401 |
+
flash('Логин и пароль обязательны!')
|
| 402 |
+
return redirect(url_for('register'))
|
| 403 |
+
|
|
|
|
| 404 |
data['users'][username] = {
|
| 405 |
+
'password': password,
|
| 406 |
'created_at': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
| 407 |
'files': []
|
| 408 |
}
|
| 409 |
+
save_data(data)
|
| 410 |
+
session['username'] = username
|
| 411 |
+
flash('Регистрация успешна!')
|
| 412 |
+
return redirect(url_for('dashboard'))
|
| 413 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
html = '''
|
| 415 |
<!DOCTYPE html>
|
| 416 |
+
<html lang="en">
|
| 417 |
<head>
|
| 418 |
<meta charset="UTF-8">
|
| 419 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 420 |
<title>Регистрация - Zeus Cloud</title>
|
| 421 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;800&display=swap" rel="stylesheet">
|
| 422 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 423 |
</head>
|
| 424 |
<body>
|
| 425 |
+
<div class="particles" id="particles-js"></div>
|
| 426 |
<div class="container">
|
| 427 |
+
<h1>Создать аккаунт</h1>
|
| 428 |
+
{% with messages = get_flashed_messages() %}
|
| 429 |
+
{% if messages %}
|
| 430 |
+
{% for message in messages %}
|
| 431 |
+
<div class="flash">{{ message }}</div>
|
| 432 |
+
{% endfor %}
|
| 433 |
+
{% endif %}
|
| 434 |
+
{% endwith %}
|
| 435 |
<form method="POST" id="register-form">
|
| 436 |
+
<input type="text" name="username" placeholder="Логин" required>
|
| 437 |
+
<input type="password" name="password" placeholder="Пароль" required>
|
|
|
|
| 438 |
<button type="submit" class="btn">Зарегистрироваться</button>
|
| 439 |
</form>
|
| 440 |
+
<p style="margin-top: 25px; text-align: center;">Уже есть аккаунт? <a href="{{ url_for('login') }}">Войти</a></p>
|
| 441 |
</div>
|
| 442 |
+
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
|
| 443 |
+
<script>
|
| 444 |
+
particlesJS("particles-js", {
|
| 445 |
+
particles: {
|
| 446 |
+
number: { value: 80, density: { enable: true, value_area: 800 } },
|
| 447 |
+
color: { value: "#6C63FF" },
|
| 448 |
+
shape: { type: "circle" },
|
| 449 |
+
opacity: { value: 0.5, random: true },
|
| 450 |
+
size: { value: 3, random: true },
|
| 451 |
+
line_linked: { enable: true, distance: 150, color: "#00E1D4", opacity: 0.4, width: 1 },
|
| 452 |
+
move: { enable: true, speed: 2, direction: "none", random: true }
|
| 453 |
+
},
|
| 454 |
+
interactivity: {
|
| 455 |
+
detect_on: "canvas",
|
| 456 |
+
events: { onhover: { enable: true, mode: "grab" }, onclick: { enable: true, mode: "push" } },
|
| 457 |
+
modes: { grab: { distance: 200, line_linked: { opacity: 1 } }, push: { particles_nb: 4 } }
|
| 458 |
+
},
|
| 459 |
+
retina_detect: true
|
| 460 |
+
});
|
| 461 |
+
</script>
|
| 462 |
</body>
|
| 463 |
</html>
|
| 464 |
+
'''
|
| 465 |
return render_template_string(html)
|
| 466 |
|
| 467 |
@app.route('/', methods=['GET', 'POST'])
|
| 468 |
def login():
|
|
|
|
|
|
|
|
|
|
| 469 |
if request.method == 'POST':
|
| 470 |
username = request.form.get('username')
|
| 471 |
password = request.form.get('password')
|
| 472 |
data = load_data()
|
| 473 |
+
|
|
|
|
|
|
|
|
|
|
| 474 |
if username in data['users'] and data['users'][username]['password'] == password:
|
| 475 |
session['username'] = username
|
|
|
|
|
|
|
| 476 |
return jsonify({'status': 'success', 'redirect': url_for('dashboard')})
|
| 477 |
else:
|
| 478 |
return jsonify({'status': 'error', 'message': 'Неверный логин или пароль!'})
|
| 479 |
+
|
| 480 |
html = '''
|
| 481 |
<!DOCTYPE html>
|
| 482 |
+
<html lang="en">
|
| 483 |
<head>
|
| 484 |
<meta charset="UTF-8">
|
| 485 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 486 |
+
<title>Zeus Cloud</title>
|
| 487 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;800&display=swap" rel="stylesheet">
|
| 488 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 489 |
</head>
|
| 490 |
<body>
|
| 491 |
+
<div class="particles" id="particles-js"></div>
|
| 492 |
<div class="container">
|
| 493 |
<h1>Zeus Cloud</h1>
|
| 494 |
<div id="flash-messages">
|
| 495 |
+
{% with messages = get_flashed_messages() %}
|
| 496 |
+
{% if messages %}
|
| 497 |
+
{% for message in messages %}
|
| 498 |
+
<div class="flash">{{ message }}</div>
|
| 499 |
+
{% endfor %}
|
| 500 |
+
{% endif %}
|
| 501 |
+
{% endwith %}
|
| 502 |
</div>
|
| 503 |
<form method="POST" id="login-form">
|
| 504 |
+
<input type="text" name="username" placeholder="Логин" required>
|
| 505 |
+
<input type="password" name="password" placeholder="Пароль" required>
|
| 506 |
<button type="submit" class="btn">Войти</button>
|
| 507 |
</form>
|
| 508 |
+
<p style="margin-top: 25px; text-align: center;">Нет аккаунта? <a href="{{ url_for('register') }}">Зарегистрироваться</a></p>
|
| 509 |
</div>
|
| 510 |
+
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
|
| 511 |
<script>
|
| 512 |
+
particlesJS("particles-js", {
|
| 513 |
+
particles: {
|
| 514 |
+
number: { value: 80, density: { enable: true, value_area: 800 } },
|
| 515 |
+
color: { value: "#6C63FF" },
|
| 516 |
+
shape: { type: "circle" },
|
| 517 |
+
opacity: { value: 0.5, random: true },
|
| 518 |
+
size: { value: 3, random: true },
|
| 519 |
+
line_linked: { enable: true, distance: 150, color: "#00E1D4", opacity: 0.4, width: 1 },
|
| 520 |
+
move: { enable: true, speed: 2, direction: "none", random: true }
|
| 521 |
+
},
|
| 522 |
+
interactivity: {
|
| 523 |
+
detect_on: "canvas",
|
| 524 |
+
events: { onhover: { enable: true, mode: "grab" }, onclick: { enable: true, mode: "push" } },
|
| 525 |
+
modes: { grab: { distance: 200, line_linked: { opacity: 1 } }, push: { particles_nb: 4 } }
|
| 526 |
+
},
|
| 527 |
+
retina_detect: true
|
| 528 |
+
});
|
| 529 |
+
|
| 530 |
const savedCredentials = JSON.parse(localStorage.getItem('zeusCredentials'));
|
| 531 |
if (savedCredentials) {
|
| 532 |
+
fetch('/', {
|
| 533 |
method: 'POST',
|
| 534 |
+
headers: {
|
| 535 |
'Content-Type': 'application/x-www-form-urlencoded',
|
| 536 |
+
},
|
| 537 |
+
body: `username=${encodeURIComponent(savedCredentials.username)}&password=${encodeURIComponent(savedCredentials.password)}`
|
| 538 |
+
})
|
| 539 |
.then(response => response.json())
|
| 540 |
+
.then(data => {
|
| 541 |
+
if (data.status === 'success') {
|
| 542 |
window.location.href = data.redirect;
|
| 543 |
+
}
|
| 544 |
+
})
|
| 545 |
+
.catch(error => console.error('Ошибка автоматического входа:', error));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 546 |
}
|
| 547 |
|
| 548 |
+
document.getElementById('login-form').addEventListener('submit', function(e) {
|
| 549 |
e.preventDefault();
|
| 550 |
const formData = new FormData(this);
|
| 551 |
+
fetch('/', {
|
|
|
|
|
|
|
|
|
|
| 552 |
method: 'POST',
|
| 553 |
body: formData
|
| 554 |
+
})
|
| 555 |
.then(response => response.json())
|
| 556 |
+
.then(data => {
|
| 557 |
+
if (data.status === 'success') {
|
| 558 |
const username = formData.get('username');
|
| 559 |
const password = formData.get('password');
|
| 560 |
+
localStorage.setItem('zeusCredentials', JSON.stringify({ username, password }));
|
|
|
|
| 561 |
window.location.href = data.redirect;
|
| 562 |
+
} else {
|
| 563 |
+
document.getElementById('flash-messages').innerHTML = `<div class="flash">${data.message}</div>`;
|
| 564 |
+
}
|
| 565 |
+
})
|
| 566 |
+
.catch(error => {
|
| 567 |
+
document.getElementById('flash-messages').innerHTML = `<div class="flash">Ошибка соединения!</div>`;
|
| 568 |
+
});
|
| 569 |
+
});
|
| 570 |
</script>
|
| 571 |
</body>
|
| 572 |
</html>
|
| 573 |
+
'''
|
| 574 |
return render_template_string(html)
|
| 575 |
|
| 576 |
@app.route('/dashboard', methods=['GET', 'POST'])
|
| 577 |
def dashboard():
|
| 578 |
if 'username' not in session:
|
| 579 |
+
flash('Пожалуйста, войдите!')
|
| 580 |
return redirect(url_for('login'))
|
| 581 |
+
|
| 582 |
username = session['username']
|
| 583 |
data = load_data()
|
| 584 |
if username not in data['users']:
|
| 585 |
session.pop('username', None)
|
| 586 |
+
flash('Пользователь не найден!')
|
| 587 |
return redirect(url_for('login'))
|
| 588 |
+
|
| 589 |
+
user_files = sorted(data['users'][username]['files'], key=lambda x: x['upload_date'], reverse=True)
|
| 590 |
|
| 591 |
if request.method == 'POST':
|
| 592 |
files = request.files.getlist('files')
|
| 593 |
+
if files and len(files) > 20:
|
| 594 |
+
flash('Максимум 20 файлов за раз!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
return redirect(url_for('dashboard'))
|
| 596 |
+
|
| 597 |
+
if files:
|
| 598 |
+
os.makedirs('uploads', exist_ok=True)
|
| 599 |
+
api = HfApi()
|
| 600 |
+
temp_files = []
|
| 601 |
+
|
| 602 |
+
for file in files:
|
| 603 |
+
if file and file.filename:
|
| 604 |
+
filename = secure_filename(file.filename)
|
| 605 |
+
temp_path = os.path.join('uploads', filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 606 |
file.save(temp_path)
|
| 607 |
+
temp_files.append((temp_path, filename))
|
| 608 |
+
|
| 609 |
+
for temp_path, filename in temp_files:
|
| 610 |
+
file_path = f"cloud_files/{username}/{filename}"
|
| 611 |
+
api.upload_file(
|
| 612 |
+
path_or_fileobj=temp_path,
|
| 613 |
+
path_in_repo=file_path,
|
| 614 |
+
repo_id=REPO_ID,
|
| 615 |
+
repo_type="dataset",
|
| 616 |
+
token=HF_TOKEN_WRITE,
|
| 617 |
+
commit_message=f"Загружен файл для {username}"
|
| 618 |
+
)
|
| 619 |
+
|
| 620 |
+
file_info = {
|
| 621 |
+
'filename': filename,
|
| 622 |
+
'path': file_path,
|
| 623 |
+
'type': get_file_type(filename),
|
| 624 |
+
'upload_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
| 625 |
+
}
|
| 626 |
+
data['users'][username]['files'].append(file_info)
|
| 627 |
+
|
| 628 |
+
if os.path.exists(temp_path):
|
| 629 |
+
os.remove(temp_path)
|
| 630 |
+
|
| 631 |
+
save_data(data)
|
| 632 |
+
flash('Файлы успешно загружены!')
|
| 633 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
return redirect(url_for('dashboard'))
|
| 635 |
|
|
|
|
|
|
|
|
|
|
| 636 |
html = '''
|
| 637 |
<!DOCTYPE html>
|
| 638 |
+
<html lang="en">
|
| 639 |
<head>
|
| 640 |
<meta charset="UTF-8">
|
| 641 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 642 |
+
<title>Dashboard - Zeus Cloud</title>
|
| 643 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;800&display=swap" rel="stylesheet">
|
| 644 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 645 |
</head>
|
| 646 |
<body>
|
| 647 |
+
<div class="particles" id="particles-js"></div>
|
| 648 |
<div class="container">
|
| 649 |
+
<h1>Zeus Cloud Dashboard</h1>
|
| 650 |
+
<p style="font-size: 1.2em;">Добро пожаловать, {{ username }}</p>
|
| 651 |
+
{% with messages = get_flashed_messages() %}
|
| 652 |
+
{% if messages %}
|
| 653 |
+
{% for message in messages %}
|
| 654 |
+
<div class="flash">{{ message }}</div>
|
| 655 |
+
{% endfor %}
|
| 656 |
+
{% endif %}
|
| 657 |
+
{% endwith %}
|
| 658 |
+
<form id="upload-form" method="POST" enctype="multipart/form-data">
|
| 659 |
+
<input type="file" name="files" multiple required accept="image/*,video/*">
|
| 660 |
+
<button type="submit" class="btn" id="upload-btn">Загрузить файлы</button>
|
|
|
|
| 661 |
</form>
|
| 662 |
<div id="progress-container">
|
| 663 |
+
<div id="progress-bar"></div>
|
| 664 |
</div>
|
|
|
|
| 665 |
<h2>Ваши файлы</h2>
|
| 666 |
<div class="file-grid">
|
| 667 |
+
{% for file in user_files %}
|
| 668 |
<div class="file-item">
|
| 669 |
+
{% if file['type'] == 'video' %}
|
| 670 |
+
<video class="file-preview" preload="metadata" muted loading="lazy" onclick="openModal('https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}', true)">
|
| 671 |
+
<source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}" type="video/mp4">
|
|
|
|
|
|
|
| 672 |
</video>
|
| 673 |
+
{% elif file['type'] == 'image' %}
|
| 674 |
+
<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)">
|
| 675 |
+
{% else %}
|
| 676 |
+
<p>{{ file['filename'] }}</p>
|
| 677 |
+
{% endif %}
|
| 678 |
+
<p>{{ file['upload_date'] }}</p>
|
| 679 |
+
<a href="{{ url_for('download_file', file_path=file['path'], filename=file['filename']) }}" class="btn download-btn">Скачать</a>
|
| 680 |
+
<a href="{{ url_for('delete_file', file_path=file['path']) }}" class="btn delete-btn" onclick="return confirm('Вы уверены, что хотите удалить этот файл?');">Удалить</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
</div>
|
| 682 |
+
{% endfor %}
|
| 683 |
+
{% if not user_files %}
|
| 684 |
+
<p>У вас пока нет загруженных файлов.</p>
|
| 685 |
+
{% endif %}
|
| 686 |
</div>
|
| 687 |
+
<a href="{{ url_for('logout') }}" class="btn" style="margin-top: 30px;" id="logout-btn">Выйти</a>
|
| 688 |
</div>
|
| 689 |
+
<div class="modal" id="mediaModal" onclick="closeModal(event)">
|
| 690 |
+
<div id="modalContent"></div>
|
|
|
|
| 691 |
</div>
|
| 692 |
+
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
|
|
|
|
| 693 |
<script>
|
| 694 |
+
particlesJS("particles-js", {
|
| 695 |
+
particles: {
|
| 696 |
+
number: { value: 80, density: { enable: true, value_area: 800 } },
|
| 697 |
+
color: { value: "#6C63FF" },
|
| 698 |
+
shape: { type: "circle" },
|
| 699 |
+
opacity: { value: 0.5, random: true },
|
| 700 |
+
size: { value: 3, random: true },
|
| 701 |
+
line_linked: { enable: true, distance: 150, color: "#00E1D4", opacity: 0.4, width: 1 },
|
| 702 |
+
move: { enable: true, speed: 2, direction: "none", random: true }
|
| 703 |
+
},
|
| 704 |
+
interactivity: {
|
| 705 |
+
detect_on: "canvas",
|
| 706 |
+
events: { onhover: { enable: true, mode: "grab" }, onclick: { enable: true, mode: "push" } },
|
| 707 |
+
modes: { grab: { distance: 200, line_linked: { opacity: 1 } }, push: { particles_nb: 4 } }
|
| 708 |
+
},
|
| 709 |
+
retina_detect: true
|
| 710 |
+
});
|
| 711 |
+
|
| 712 |
+
function openModal(src, isVideo) {
|
| 713 |
+
const modal = document.getElementById('mediaModal');
|
| 714 |
+
const modalContent = document.getElementById('modalContent');
|
| 715 |
+
if (isVideo) {
|
| 716 |
+
modalContent.innerHTML = `<video controls><source src="${src}" type="video/mp4"></video>`;
|
| 717 |
+
} else {
|
| 718 |
+
modalContent.innerHTML = `<img src="${src}">`;
|
| 719 |
+
}
|
| 720 |
+
modal.style.display = 'flex';
|
| 721 |
+
}
|
| 722 |
+
function closeModal(event) {
|
| 723 |
+
if (event.target.tagName !== 'IMG' && event.target.tagName !== 'VIDEO') {
|
| 724 |
+
const modal = document.getElementById('mediaModal');
|
| 725 |
+
modal.style.display = 'none';
|
| 726 |
+
modal.innerHTML = '<div id="modalContent"></div>';
|
| 727 |
+
}
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
const form = document.getElementById('upload-form');
|
| 731 |
const progressBar = document.getElementById('progress-bar');
|
| 732 |
const progressContainer = document.getElementById('progress-container');
|
| 733 |
const uploadBtn = document.getElementById('upload-btn');
|
|
|
|
| 734 |
|
| 735 |
+
form.addEventListener('submit', function(e) {
|
| 736 |
e.preventDefault();
|
| 737 |
+
const files = form.querySelector('input[type="file"]').files;
|
| 738 |
+
if (files.length > 20) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
alert('Максимум 20 файлов за раз!');
|
| 740 |
return;
|
| 741 |
+
}
|
| 742 |
|
| 743 |
const formData = new FormData(form);
|
| 744 |
progressContainer.style.display = 'block';
|
| 745 |
progressBar.style.width = '0%';
|
|
|
|
| 746 |
uploadBtn.disabled = true;
|
|
|
|
|
|
|
| 747 |
|
| 748 |
const xhr = new XMLHttpRequest();
|
| 749 |
xhr.open('POST', '/dashboard', true);
|
| 750 |
|
| 751 |
+
xhr.upload.onprogress = function(event) {
|
| 752 |
+
if (event.lengthComputable) {
|
| 753 |
+
const percent = (event.loaded / event.total) * 100;
|
| 754 |
progressBar.style.width = percent + '%';
|
| 755 |
+
}
|
| 756 |
+
};
|
| 757 |
+
|
| 758 |
+
xhr.onload = function() {
|
| 759 |
+
if (xhr.status === 200) {
|
| 760 |
+
location.reload();
|
| 761 |
+
} else {
|
| 762 |
+
alert('Ошибка загрузки!');
|
| 763 |
+
progressContainer.style.display = 'none';
|
| 764 |
+
uploadBtn.disabled = false;
|
| 765 |
+
}
|
| 766 |
+
};
|
| 767 |
+
|
| 768 |
+
xhr.onerror = function() {
|
| 769 |
+
alert('Ошибка соединения!');
|
| 770 |
progressContainer.style.display = 'none';
|
| 771 |
uploadBtn.disabled = false;
|
| 772 |
+
};
|
|
|
|
| 773 |
|
| 774 |
xhr.send(formData);
|
| 775 |
+
});
|
| 776 |
|
| 777 |
+
document.getElementById('logout-btn').addEventListener('click', function(e) {
|
| 778 |
e.preventDefault();
|
| 779 |
+
localStorage.removeItem('zeusCredentials');
|
| 780 |
+
window.location.href = '/logout';
|
| 781 |
+
});
|
| 782 |
</script>
|
| 783 |
</body>
|
| 784 |
</html>
|
| 785 |
+
'''
|
| 786 |
return render_template_string(html, username=username, user_files=user_files, repo_id=REPO_ID)
|
| 787 |
|
|
|
|
| 788 |
@app.route('/download/<path:file_path>/<filename>')
|
| 789 |
def download_file(file_path, filename):
|
| 790 |
if 'username' not in session:
|
| 791 |
+
flash('Пожалуйста, войдите!')
|
| 792 |
return redirect(url_for('login'))
|
| 793 |
+
|
| 794 |
username = session['username']
|
| 795 |
data = load_data()
|
| 796 |
if username not in data['users']:
|
| 797 |
session.pop('username', None)
|
| 798 |
+
flash('Пользователь не найден!')
|
| 799 |
return redirect(url_for('login'))
|
| 800 |
+
|
| 801 |
+
user_files = data['users'][username]['files']
|
| 802 |
+
if not any(file['path'] == file_path for file in user_files):
|
| 803 |
+
flash('У вас нет доступа к этому файлу!')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 804 |
return redirect(url_for('dashboard'))
|
| 805 |
+
|
| 806 |
+
file_url = f"https://huggingface.co/datasets/{REPO_ID}/resolve/main/{file_path}"
|
| 807 |
+
response = requests.get(file_url)
|
| 808 |
+
|
| 809 |
+
if response.status_code == 200:
|
| 810 |
+
file_content = BytesIO(response.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 811 |
return send_file(
|
| 812 |
+
file_content,
|
| 813 |
as_attachment=True,
|
| 814 |
+
download_name=filename,
|
| 815 |
+
mimetype='application/octet-stream'
|
| 816 |
)
|
| 817 |
+
else:
|
| 818 |
+
flash('Ошибка при скачивании файла!')
|
| 819 |
+
return redirect(url_for('dashboard'))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 820 |
|
| 821 |
@app.route('/delete/<path:file_path>')
|
| 822 |
def delete_file(file_path):
|
| 823 |
if 'username' not in session:
|
| 824 |
+
flash('Пожалуйста, войдите!')
|
| 825 |
return redirect(url_for('login'))
|
| 826 |
+
|
| 827 |
username = session['username']
|
| 828 |
data = load_data()
|
| 829 |
if username not in data['users']:
|
| 830 |
session.pop('username', None)
|
| 831 |
+
flash('Пользователь не найден!')
|
| 832 |
return redirect(url_for('login'))
|
| 833 |
+
|
| 834 |
+
user_files = data['users'][username]['files']
|
| 835 |
+
file_to_delete = next((file for file in user_files if file['path'] == file_path), None)
|
| 836 |
+
|
| 837 |
if not file_to_delete:
|
| 838 |
+
flash('Файл не найден!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 839 |
return redirect(url_for('dashboard'))
|
| 840 |
+
|
| 841 |
try:
|
|
|
|
| 842 |
api = HfApi()
|
| 843 |
api.delete_file(
|
| 844 |
path_in_repo=file_path,
|
| 845 |
repo_id=REPO_ID,
|
| 846 |
repo_type="dataset",
|
| 847 |
+
token=HF_TOKEN_WRITE,
|
| 848 |
+
commit_message=f"Удален файл {file_path} для {username}"
|
| 849 |
)
|
|
|
|
|
|
|
|
|
|
| 850 |
data['users'][username]['files'] = [f for f in user_files if f['path'] != file_path]
|
| 851 |
save_data(data)
|
| 852 |
+
flash('Файл успешно удален!')
|
|
|
|
| 853 |
except Exception as e:
|
| 854 |
+
logging.error(f"Ошибка при удалении файла: {e}")
|
| 855 |
+
flash('Ошибка при удалении файла!')
|
| 856 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 857 |
return redirect(url_for('dashboard'))
|
| 858 |
|
| 859 |
@app.route('/logout')
|
| 860 |
def logout():
|
| 861 |
session.pop('username', None)
|
|
|
|
|
|
|
| 862 |
return redirect(url_for('login'))
|
| 863 |
|
| 864 |
@app.route('/admhosto')
|
| 865 |
def admin_panel():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 866 |
data = load_data()
|
| 867 |
+
users = data['users']
|
| 868 |
+
|
| 869 |
html = '''
|
| 870 |
<!DOCTYPE html>
|
| 871 |
+
<html lang="en">
|
| 872 |
<head>
|
| 873 |
<meta charset="UTF-8">
|
| 874 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 875 |
<title>Админ-панель - Zeus Cloud</title>
|
| 876 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;800&display=swap" rel="stylesheet">
|
| 877 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 878 |
</head>
|
| 879 |
<body>
|
| 880 |
+
<div class="particles" id="particles-js"></div>
|
| 881 |
<div class="container">
|
| 882 |
<h1>Админ-панель Zeus Cloud</h1>
|
| 883 |
+
<h2>Пользователи</h2>
|
| 884 |
<div class="user-list">
|
| 885 |
+
{% for username, user_data in users.items() %}
|
| 886 |
<div class="user-item">
|
| 887 |
+
<a href="{{ url_for('admin_user_files', username=username) }}">{{ username }}</a>
|
| 888 |
+
<p>Дата регистрации: {{ user_data['created_at'] }}</p>
|
| 889 |
+
<p>Файлов: {{ user_data['files'] | length }}</p>
|
|
|
|
| 890 |
</div>
|
| 891 |
+
{% endfor %}
|
| 892 |
+
{% if not users %}
|
| 893 |
+
<p>Пользователей пока нет.</p>
|
| 894 |
+
{% endif %}
|
| 895 |
</div>
|
|
|
|
| 896 |
</div>
|
| 897 |
+
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
|
| 898 |
+
<script>
|
| 899 |
+
particlesJS("particles-js", {
|
| 900 |
+
particles: {
|
| 901 |
+
number: { value: 80, density: { enable: true, value_area: 800 } },
|
| 902 |
+
color: { value: "#6C63FF" },
|
| 903 |
+
shape: { type: "circle" },
|
| 904 |
+
opacity: { value: 0.5, random: true },
|
| 905 |
+
size: { value: 3, random: true },
|
| 906 |
+
line_linked: { enable: true, distance: 150, color: "#00E1D4", opacity: 0.4, width: 1 },
|
| 907 |
+
move: { enable: true, speed: 2, direction: "none", random: true }
|
| 908 |
+
},
|
| 909 |
+
interactivity: {
|
| 910 |
+
detect_on: "canvas",
|
| 911 |
+
events: { onhover: { enable: true, mode: "grab" }, onclick: { enable: true, mode: "push" } },
|
| 912 |
+
modes: { grab: { distance: 200, line_linked: { opacity: 1 } }, push: { particles_nb: 4 } }
|
| 913 |
+
},
|
| 914 |
+
retina_detect: true
|
| 915 |
+
});
|
| 916 |
+
</script>
|
| 917 |
</body>
|
| 918 |
</html>
|
| 919 |
+
'''
|
| 920 |
return render_template_string(html, users=users)
|
| 921 |
|
| 922 |
@app.route('/admhosto/user/<username>')
|
| 923 |
def admin_user_files(username):
|
|
|
|
|
|
|
|
|
|
| 924 |
data = load_data()
|
| 925 |
+
if username not in data['users']:
|
| 926 |
+
flash('Пользователь не найден!')
|
| 927 |
return redirect(url_for('admin_panel'))
|
| 928 |
+
|
| 929 |
+
user_files = sorted(data['users'][username]['files'], key=lambda x: x['upload_date'], reverse=True)
|
| 930 |
+
|
| 931 |
html = '''
|
| 932 |
<!DOCTYPE html>
|
| 933 |
+
<html lang="en">
|
| 934 |
<head>
|
| 935 |
<meta charset="UTF-8">
|
| 936 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 937 |
<title>Файлы пользователя {{ username }} - Zeus Cloud</title>
|
| 938 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;800&display=swap" rel="stylesheet">
|
| 939 |
+
<style>''' + BASE_STYLE + '''</style>
|
| 940 |
</head>
|
| 941 |
<body>
|
| 942 |
+
<div class="particles" id="particles-js"></div>
|
| 943 |
<div class="container">
|
| 944 |
<h1>Файлы пользователя: {{ username }}</h1>
|
| 945 |
+
{% with messages = get_flashed_messages() %}
|
| 946 |
+
{% if messages %}
|
| 947 |
+
{% for message in messages %}
|
| 948 |
+
<div class="flash">{{ message }}</div>
|
| 949 |
+
{% endfor %}
|
| 950 |
+
{% endif %}
|
| 951 |
+
{% endwith %}
|
| 952 |
<div class="file-grid">
|
| 953 |
+
{% for file in user_files %}
|
| 954 |
<div class="file-item">
|
| 955 |
+
{% if file['type'] == 'video' %}
|
| 956 |
+
<video class="file-preview" preload="metadata" muted loading="lazy" onclick="openModal('https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}', true)">
|
| 957 |
+
<source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ file['path'] }}" type="video/mp4">
|
|
|
|
|
|
|
| 958 |
</video>
|
| 959 |
+
{% elif file['type'] == 'image' %}
|
| 960 |
+
<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)">
|
| 961 |
+
{% else %}
|
| 962 |
+
<p>{{ file['filename'] }}</p>
|
| 963 |
+
{% endif %}
|
| 964 |
+
<p>{{ file['upload_date'] }}</p>
|
| 965 |
+
<a href="{{ url_for('download_file', file_path=file['path'], filename=file['filename']) }}" class="btn download-btn">Скачать</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 966 |
</div>
|
| 967 |
+
{% endfor %}
|
| 968 |
+
{% if not user_files %}
|
| 969 |
+
<p>У пользователя пока нет файлов.</p>
|
| 970 |
+
{% endif %}
|
| 971 |
</div>
|
| 972 |
+
<a href="{{ url_for('admin_panel') }}" class="btn" style="margin-top: 30px;">Назад</a>
|
| 973 |
</div>
|
| 974 |
+
<div class="modal" id="mediaModal" onclick="closeModal(event)">
|
| 975 |
+
<div id="modalContent"></div>
|
| 976 |
</div>
|
| 977 |
+
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
|
| 978 |
+
<script>
|
| 979 |
+
particlesJS("particles-js", {
|
| 980 |
+
particles: {
|
| 981 |
+
number: { value: 80, density: { enable: true, value_area: 800 } },
|
| 982 |
+
color: { value: "#6C63FF" },
|
| 983 |
+
shape: { type: "circle" },
|
| 984 |
+
opacity: { value: 0.5, random: true },
|
| 985 |
+
size: { value: 3, random: true },
|
| 986 |
+
line_linked: { enable: true, distance: 150, color: "#00E1D4", opacity: 0.4, width: 1 },
|
| 987 |
+
move: { enable: true, speed: 2, direction: "none", random: true }
|
| 988 |
+
},
|
| 989 |
+
interactivity: {
|
| 990 |
+
detect_on: "canvas",
|
| 991 |
+
events: { onhover: { enable: true, mode: "grab" }, onclick: { enable: true, mode: "push" } },
|
| 992 |
+
modes: { grab: { distance: 200, line_linked: { opacity: 1 } }, push: { particles_nb: 4 } }
|
| 993 |
+
},
|
| 994 |
+
retina_detect: true
|
| 995 |
+
});
|
| 996 |
+
|
| 997 |
+
function openModal(src, isVideo) {
|
| 998 |
+
const modal = document.getElementById('mediaModal');
|
| 999 |
+
const modalContent = document.getElementById('modalContent');
|
| 1000 |
+
if (isVideo) {
|
| 1001 |
+
modalContent.innerHTML = `<video controls><source src="${src}" type="video/mp4"></video>`;
|
| 1002 |
+
} else {
|
| 1003 |
+
modalContent.innerHTML = `<img src="${src}">`;
|
| 1004 |
+
}
|
| 1005 |
+
modal.style.display = 'flex';
|
| 1006 |
+
}
|
| 1007 |
+
function closeModal(event) {
|
| 1008 |
+
if (event.target.tagName !== 'IMG' && event.target.tagName !== 'VIDEO') {
|
| 1009 |
+
const modal = document.getElementById('mediaModal');
|
| 1010 |
+
modal.style.display = 'none';
|
| 1011 |
+
modal.innerHTML = '<div id="modalContent"></div>';
|
| 1012 |
+
}
|
| 1013 |
+
}
|
| 1014 |
+
</script>
|
| 1015 |
</body>
|
| 1016 |
</html>
|
| 1017 |
+
'''
|
| 1018 |
return render_template_string(html, username=username, user_files=user_files, repo_id=REPO_ID)
|
| 1019 |
|
|
|
|
| 1020 |
if __name__ == '__main__':
|
| 1021 |
+
threading.Thread(target=periodic_backup, daemon=True).start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1022 |
app.run(debug=False, host='0.0.0.0', port=7860)
|