zyc 92826dec14 feat(core/backend): pipeline continuity + threaded ffmpeg burn-in export + upload/save-timeline
Video pipeline (script→assets→storyboard→video→stitch):
- robust split_script_into_segments (4 non-empty scenes), scene-aware storyboard/video prompts
- link VideoSegment→ScriptSegment + storyboard-frame reference image (graceful text fallback)
- idempotent poll_video_segment (no double-charge on repeated polling)
- threaded export (no Celery worker needed) + poll-export endpoint
- run_export_job rewritten to filter_complex: per-clip trim, xfade transitions,
  subtitle burn-in (Pillow PNG overlay; this ffmpeg lacks libass), BGM mix
- upload-video-segment / upload-bgm / save-timeline endpoints
- serializers embed asset preview URLs (beat assets pagination); Pillow added to requirements

Also includes prior uncommitted backend work: account preferences/sessions,
billing trend, product/asset endpoints, accounts 0002 migration.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 14:46:16 +08:00

98 lines
3.5 KiB
Python

import uuid
from django.contrib.auth.models import AbstractUser
from django.db import models
from apps.common.models import TimeStampedModel
class User(AbstractUser):
class Status(models.TextChoices):
ACTIVE = "active", "Active"
DISABLED = "disabled", "Disabled"
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
status = models.CharField(max_length=24, choices=Status.choices, default=Status.ACTIVE)
phone = models.CharField(max_length=32, blank=True)
avatar_url = models.URLField(blank=True)
@property
def is_disabled(self) -> bool:
return self.status == self.Status.DISABLED
class Team(TimeStampedModel):
class Status(models.TextChoices):
ACTIVE = "active", "Active"
DISABLED = "disabled", "Disabled"
name = models.CharField(max_length=128)
status = models.CharField(max_length=24, choices=Status.choices, default=Status.ACTIVE)
owner = models.ForeignKey(User, on_delete=models.PROTECT, related_name="owned_teams")
def __str__(self) -> str:
return self.name
def _default_notify() -> dict:
return {"n-export": True, "n-fail": True, "n-quota": True, "n-login": True}
def _default_creation() -> dict:
return {"template": "pain", "duration": "60", "subtitle": "big-variety", "bgm": "kapian", "transition": "fade"}
def _default_display() -> dict:
return {"appearance": "system", "language": "zh", "density": "standard"}
class UserPreference(TimeStampedModel):
"""用户设置:通知策略 / 两步验证 / 创作默认 / 显示偏好。服务端持久化(替代前端 localStorage)。"""
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="preference")
notify = models.JSONField(default=_default_notify, blank=True)
two_factor_enabled = models.BooleanField(default=False)
creation_defaults = models.JSONField(default=_default_creation, blank=True)
display = models.JSONField(default=_default_display, blank=True)
def __str__(self) -> str:
return f"prefs/{self.user}"
class LoginSession(TimeStampedModel):
"""登录会话记录:每次登录写一条(设备 UA / IP / 时间),供设置页「在用设备」展示与下线。"""
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="login_sessions")
user_agent = models.CharField(max_length=400, blank=True)
ip_address = models.GenericIPAddressField(null=True, blank=True)
last_seen_at = models.DateTimeField(auto_now=True)
revoked_at = models.DateTimeField(null=True, blank=True)
class Meta:
ordering = ["-last_seen_at"]
class TeamMember(TimeStampedModel):
class Role(models.TextChoices):
OWNER = "owner", "Owner"
ADMIN = "admin", "Admin"
MEMBER = "member", "Member"
VIEWER = "viewer", "Viewer"
class Status(models.TextChoices):
ACTIVE = "active", "Active"
INVITED = "invited", "Invited"
DISABLED = "disabled", "Disabled"
team = models.ForeignKey(Team, on_delete=models.CASCADE, related_name="members")
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="team_memberships")
role = models.CharField(max_length=24, choices=Role.choices, default=Role.MEMBER)
status = models.CharField(max_length=24, choices=Status.choices, default=Status.ACTIVE)
monthly_credit_limit = models.DecimalField(max_digits=12, decimal_places=2, default=0)
class Meta:
unique_together = [("team", "user")]
def __str__(self) -> str:
return f"{self.team} / {self.user} / {self.role}"