Update app.py
Browse files25 unmodified lines262728293031323334353659 unmodified lines969798991001012 unmodified lines10410510610710810911011111211311411511611727 unmodified lines14514614714814915015115215315415515615715815916016116216316416516616716816917022 unmodified lines1931941951961971988 unmodified lines20720820921021121221321421521621721821922022122222322422522622722817 unmodified lines24624724824925025114 unmodified lines26626726826927027127227327427527627727827928028128228328428516 unmodified lines30230330430530630715 unmodified lines3233243253263273281 unmodified line33033133233333433533633733833934034134234334434534634734834935035135222 unmodified lines37537637737837938043 unmodified lines4244254264274284296 unmodified lines43643743843944044144244344444544644744844945045145245345445545645745841 unmodified lines50050150250350450525 unmodified lineswith open(DATA_FILE, 'r', encoding='utf-8') as file:data = json.load(file)if not isinstance(data, dict):return {'videos': [], 'users': {}}if 'videos' not in data:data['videos'] = []if 'users' not in data:data['users'] = {}return dataexcept Exception as e:logging.error(f"Ошибка загрузки данных: {e}")59 unmodified lineshashed_password = hashlib.sha256(password.encode('utf-8')).hexdigest()data['users'][username] = {'password': hashed_password}save_data(data)flash('Регистрация успешна! Войдите в систему.')return redirect(url_for('login'))2 unmodified lines<html lang="ru"><head><meta charset="UTF-8"><title>Регистрация</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; }.container { max-width: 400px; margin: 0 auto; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }input { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #e2e8f0; border-radius: 8px; }button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; }.flash { color: red; margin-bottom: 10px; }</style></head><body>27 unmodified linesdata = load_data()hashed_password = hashlib.sha256(password.encode('utf-8')).hexdigest()if username in data['users'] and data['users'][username]['password'] == hashed_password:session['username'] = usernamereturn redirect(url_for('video_feed'))else:flash('Неверный логин или пароль!')return redirect(url_for('login'))html = '''<!DOCTYPE html><html lang="ru"><head><meta charset="UTF-8"><title>Вход</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; }.container { max-width: 400px; margin: 0 auto; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }input { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #e2e8f0; border-radius: 8px; }button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; }.flash { color: red; margin-bottom: 10px; }</style></head><body>22 unmodified lines@app.route('/logout')def logout():session.pop('username', None)return redirect(url_for('video_feed'))# Главная страница - лента видео с превью (доступна всем)8 unmodified lines<html lang="ru"><head><meta charset="UTF-8"><title>Видеохостинг</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.container { max-width: 1200px; margin: 0 auto; padding-left: 250px; }.sidebar { position: fixed; left: 0; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); }.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }.video-item { background: #fff; padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); text-decoration: none; color: #2d3748; }.video-item img { width: 100%; border-radius: 8px; height: 200px; object-fit: cover; }.auth-links, .upload-btn, .logout-btn, .profile-link { display: inline-block; margin: 10px 0; padding: 10px 20px; background: #3b82f6; color: white; text-align: center; text-decoration: none; border-radius: 8px; }.logout-btn { background: #ef4444; }.profile-link { background: #10b981; }</style></head><body><div class="sidebar">{% if is_authenticated %}<a href="{{ url_for('profile') }}" class="profile-link"><span style="font-size: 1.2em;">👤</span> {{ username }}17 unmodified lines{% endfor %}</div></div></body></html>'''14 unmodified lines<html lang="ru"><head><meta charset="UTF-8"><title>{{ video['title'] }}</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.sidebar { position: fixed; left: 0; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); }.container { max-width: 800px; margin: 0 auto; padding-left: 250px; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }video { width: 100%; border-radius: 8px; }.back-btn, .profile-link, .logout-btn { display: inline-block; margin-top: 20px; padding: 10px 20px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; }.profile-link { background: #10b981; }.logout-btn { background: #ef4444; }</style></head><body><div class="sidebar">{% if is_authenticated %}<a href="{{ url_for('profile') }}" class="profile-link"><span style="font-size: 1.2em;">👤</span> {{ username }}16 unmodified lines<p><a href="{{ url_for('login') }}">Войдите</a>, чтобы загрузить свои видео.</p>{% endif %}</div></body></html>'''15 unmodified linesif video_id:data['videos'] = [v for v in data['videos'] if v['id'] != video_id or v['uploader'] != username]save_data(data)return redirect(url_for('profile'))html = '''1 unmodified line<html lang="ru"><head><meta charset="UTF-8"><title>Профиль - {{ username }}</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.sidebar { position: fixed; left: 0; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); }.container { max-width: 800px; margin: 0 auto; padding-left: 250px; }.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }.video-item { background: #fff; padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }.video-item img { width: 100%; border-radius: 8px; height: 200px; object-fit: cover; }.upload-btn, .delete-btn, .profile-link, .logout-btn { display: inline-block; margin: 10px 0; padding: 10px 20px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; }.delete-btn { background: #ef4444; }.profile-link { background: #10b981; }.logout-btn { background: #ef4444; }</style></head><body><div class="sidebar"><a href="{{ url_for('profile') }}" class="profile-link"><span style="font-size: 1.2em;">👤</span> {{ username }}</a>22 unmodified lines{% endif %}</div></div></body></html>'''43 unmodified lines'upload_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S')})save_data(data)if os.path.exists(temp_path):os.remove(temp_path)6 unmodified lines<html lang="ru"><head><meta charset="UTF-8"><title>Загрузка видео</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.sidebar { position: fixed; left: 0; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); }.container { max-width: 600px; margin: 0 auto; padding-left: 250px; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }input, textarea { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #e2e8f0; border-radius: 8px; }button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; }#progress-container { margin-top: 10px; }#progress-bar { width: 0%; height: 20px; background: #3b82f6; border-radius: 8px; transition: width 0.3s; }.profile-link, .logout-btn { display: inline-block; margin: 10px 0; padding: 10px 20px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; }.profile-link { background: #10b981; }.logout-btn { background: #ef4444; }</style></head><body><div class="sidebar"><a href="{{ url_for('profile') }}" class="profile-link"><span style="font-size: 1.2em;">👤</span> {{ username }}</a>41 unmodified linesxhr.send(formData);};</script></body></html>25 unmodified lines2627282930313233343536373859 unmodified lines98991001011021031042 unmodified lines10710810911011111211311411511611711811912012112212312412527 unmodified lines15315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019122 unmodified lines2142152162172182192208 unmodified lines22923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226317 unmodified lines28128228328428528628728828929029114 unmodified lines30630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633716 unmodified lines35435535635735835936036136236336415 unmodified lines3803813823833843853861 unmodified line38838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342422 unmodified lines44744844945045145245345445545645743 unmodified lines5015025035045055065076 unmodified lines51451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654741 unmodified lines58959059159259359459559659725 unmodified lineswith open(DATA_FILE, 'r', encoding='utf-8') as file:data = json.load(file)if not isinstance(data, dict):logging.warning("Данные не в формате dict, инициализация пустой базы")return {'videos': [], 'users': {}}if 'videos' not in data:data['videos'] = []if 'users' not in data:data['users'] = {}logging.info("Данные успешно загружены")return dataexcept Exception as e:logging.error(f"Ошибка загрузки данных: {e}")59 unmodified lineshashed_password = hashlib.sha256(password.encode('utf-8')).hexdigest()data['users'][username] = {'password': hashed_password}save_data(data)logging.info(f"Пользователь {username} зарегистрирован")flash('Регистрация успешна! Войдите в систему.')return redirect(url_for('login'))2 unmodified lines<html lang="ru"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Регистрация</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.container { max-width: 400px; margin: 0 auto; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }input { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #e2e8f0; border-radius: 8px; box-sizing: border-box; }button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; width: 100%; }.flash { color: red; margin-bottom: 10px; }@media (max-width: 600px) {.container { padding: 15px; }input, button { font-size: 14px; padding: 8px; }}</style></head><body>27 unmodified linesdata = load_data()hashed_password = hashlib.sha256(password.encode('utf-8')).hexdigest()logging.debug(f"Попытка входа: {username}, введённый хеш: {hashed_password}")if username in data['users']:stored_hash = data['users'][username]['password']logging.debug(f"Сохранённый хеш для {username}: {stored_hash}")if stored_hash == hashed_password:session['username'] = usernamelogging.info(f"Успешный вход: {username}")return redirect(url_for('video_feed'))else:logging.warning(f"Неверный пароль для {username}")else:logging.warning(f"Пользователь {username} не найден")flash('Неверный логин или пароль!')return redirect(url_for('login'))html = '''<!DOCTYPE html><html lang="ru"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Вход</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.container { max-width: 400px; margin: 0 auto; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }input { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #e2e8f0; border-radius: 8px; box-sizing: border-box; }button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; width: 100%; }.flash { color: red; margin-bottom: 10px; }@media (max-width: 600px) {.container { padding: 15px; }input, button { font-size: 14px; padding: 8px; }}</style></head><body>22 unmodified lines@app.route('/logout')def logout():session.pop('username', None)logging.info("Пользователь вышел из системы")return redirect(url_for('video_feed'))# Главная страница - лента видео с превью (доступна всем)8 unmodified lines<html lang="ru"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Видеохостинг</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.container { max-width: 1200px; margin: 0 auto; padding-left: 220px; transition: padding-left 0.3s; }.sidebar { position: fixed; left: -220px; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); transition: left 0.3s; }.sidebar.active { left: 0; }.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }.video-item { background: #fff; padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); text-decoration: none; color: #2d3748; }.video-item img { width: 100%; border-radius: 8px; height: 200px; object-fit: cover; }.auth-links, .upload-btn, .logout-btn, .profile-link { display: block; margin: 10px 0; padding: 10px; background: #3b82f6; color: white; text-align: center; text-decoration: none; border-radius: 8px; }.logout-btn { background: #ef4444; }.profile-link { background: #10b981; }.menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1000; }@media (max-width: 768px) {.container { padding-left: 20px; }.sidebar { left: -220px; }.sidebar.active { left: 0; }.menu-btn { display: block; }.video-grid { grid-template-columns: 1fr; }.video-item { padding: 10px; }.video-item img { height: 150px; }}</style></head><body><button class="menu-btn" onclick="toggleSidebar()">☰</button><div class="sidebar" id="sidebar">{% if is_authenticated %}<a href="{{ url_for('profile') }}" class="profile-link"><span style="font-size: 1.2em;">👤</span> {{ username }}17 unmodified lines{% endfor %}</div></div><script>function toggleSidebar() {document.getElementById('sidebar').classList.toggle('active');}</script></body></html>'''14 unmodified lines<html lang="ru"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>{{ video['title'] }}</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.sidebar { position: fixed; left: -220px; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); transition: left 0.3s; }.sidebar.active { left: 0; }.container { max-width: 800px; margin: 0 auto; padding-left: 220px; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); transition: padding-left 0.3s; }video { width: 100%; border-radius: 8px; }.back-btn, .profile-link, .logout-btn { display: inline-block; margin-top: 10px; padding: 10px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; }.profile-link { background: #10b981; }.logout-btn { background: #ef4444; }.menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1000; }@media (max-width: 768px) {.container { padding-left: 20px; padding: 15px; }.sidebar { left: -220px; }.sidebar.active { left: 0; }.menu-btn { display: block; }video { height: auto; }.back-btn { width: 100%; text-align: center; }}</style></head><body><button class="menu-btn" onclick="toggleSidebar()">☰</button><div class="sidebar" id="sidebar">{% if is_authenticated %}<a href="{{ url_for('profile') }}" class="profile-link"><span style="font-size: 1.2em;">👤</span> {{ username }}16 unmodified lines<p><a href="{{ url_for('login') }}">Войдите</a>, чтобы загрузить свои видео.</p>{% endif %}</div><script>function toggleSidebar() {document.getElementById('sidebar').classList.toggle('active');}</script></body></html>'''15 unmodified linesif video_id:data['videos'] = [v for v in data['videos'] if v['id'] != video_id or v['uploader'] != username]save_data(data)logging.info(f"Видео {video_id} удалено пользователем {username}")return redirect(url_for('profile'))html = '''1 unmodified line<html lang="ru"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Профиль - {{ username }}</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.sidebar { position: fixed; left: -220px; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); transition: left 0.3s; }.sidebar.active { left: 0; }.container { max-width: 800px; margin: 0 auto; padding-left: 220px; transition: padding-left 0.3s; }.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }.video-item { background: #fff; padding: 15px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }.video-item img { width: 100%; border-radius: 8px; height: 200px; object-fit: cover; }.upload-btn, .delete-btn, .profile-link, .logout-btn { display: block; margin: 10px 0; padding: 10px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; }.delete-btn { background: #ef4444; border: none; cursor: pointer; }.profile-link { background: #10b981; }.logout-btn { background: #ef4444; }.menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1000; }@media (max-width: 768px) {.container { padding-left: 20px; }.sidebar { left: -220px; }.sidebar.active { left: 0; }.menu-btn { display: block; }.video-grid { grid-template-columns: 1fr; }.video-item { padding: 10px; }.video-item img { height: 150px; }.upload-btn, .delete-btn { font-size: 14px; padding: 8px; }}</style></head><body><button class="menu-btn" onclick="toggleSidebar()">☰</button><div class="sidebar" id="sidebar"><a href="{{ url_for('profile') }}" class="profile-link"><span style="font-size: 1.2em;">👤</span> {{ username }}</a>22 unmodified lines{% endif %}</div></div><script>function toggleSidebar() {document.getElementById('sidebar').classList.toggle('active');}</script></body></html>'''43 unmodified lines'upload_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S')})save_data(data)logging.info(f"Видео {title} загружено пользователем {uploader}")if os.path.exists(temp_path):os.remove(temp_path)6 unmodified lines<html lang="ru"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Загрузка видео</title><link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"><style>body { font-family: 'Poppins', sans-serif; background: #f0f2f5; padding: 20px; margin: 0; }.sidebar { position: fixed; left: -220px; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); transition: left 0.3s; }.sidebar.active { left: 0; }.container { max-width: 600px; margin: 0 auto; padding-left: 220px; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); transition: padding-left 0.3s; }input, textarea { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #e2e8f0; border-radius: 8px; box-sizing: border-box; }button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; width: 100%; }#progress-container { margin-top: 10px; }#progress-bar { width: 0%; height: 20px; background: #3b82f6; border-radius: 8px; transition: width 0.3s; }.profile-link, .logout-btn { display: block; margin: 10px 0; padding: 10px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; }.profile-link { background: #10b981; }.logout-btn { background: #ef4444; }.menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1000; }@media (max-width: 768px) {.container { padding-left: 20px; padding: 15px; }.sidebar { left: -220px; }.sidebar.active { left: 0; }.menu-btn { display: block; }input, textarea, button { font-size: 14px; padding: 8px; }}</style></head><body><button class="menu-btn" onclick="toggleSidebar()">☰</button><div class="sidebar" id="sidebar"><a href="{{ url_for('profile') }}" class="profile-link"><span style="font-size: 1.2em;">👤</span> {{ username }}</a>41 unmodified linesxhr.send(formData);};function toggleSidebar() {document.getElementById('sidebar').classList.toggle('active');}</script></body></html>
app.py+122-30