-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
49 lines (38 loc) · 1.75 KB
/
Copy pathmodels.py
File metadata and controls
49 lines (38 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from datetime import datetime
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import generate_password_hash, check_password_hash
db = SQLAlchemy()
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password_hash = db.Column(db.String(128))
profile_photo = db.Column(db.String(255)) # Path ke foto profil
created_at = db.Column(db.DateTime, default=datetime.utcnow)
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password_hash, password)
def __repr__(self):
return f'<User {self.username}>'
class Video(db.Model):
__tablename__ = 'videos'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), nullable=False)
file_path = db.Column(db.String(255), nullable=False)
file_size = db.Column(db.Integer) # Ukuran dalam bytes
download_date = db.Column(db.DateTime, default=datetime.utcnow)
# Status streaming
is_streaming = db.Column(db.Boolean, default=False)
stream_platform = db.Column(db.String(50)) # 'facebook' atau 'youtube'
stream_start_time = db.Column(db.DateTime)
def __repr__(self):
return f'<Video {self.name}>'
def get_size_display(self):
"""Mengembalikan ukuran file dalam format yang mudah dibaca"""
for unit in ['B', 'KB', 'MB', 'GB']:
if self.file_size < 1024:
return f"{self.file_size:.1f} {unit}"
self.file_size /= 1024
return f"{self.file_size:.1f} TB"