Files
Foxel/models/database.py
2025-09-08 12:28:37 +08:00

110 lines
3.4 KiB
Python

from tortoise import fields
from tortoise.models import Model
class StorageAdapter(Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=100, unique=True)
type = fields.CharField(max_length=30)
config = fields.JSONField()
enabled = fields.BooleanField(default=True)
path = fields.CharField(max_length=255, unique=True)
sub_path = fields.CharField(max_length=1024, null=True)
class Meta:
table = "storage_adapters"
class UserAccount(Model):
id = fields.IntField(pk=True)
username = fields.CharField(max_length=50, unique=True)
email = fields.CharField(max_length=100, unique=True, null=True)
full_name = fields.CharField(max_length=100, null=True)
hashed_password = fields.CharField(max_length=128)
disabled = fields.BooleanField(default=False)
class Meta:
table = "user"
class Configuration(Model):
id = fields.IntField(pk=True)
key = fields.CharField(max_length=100, unique=True)
value = fields.TextField()
class Meta:
table = "configurations"
class AutomationTask(Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=100)
event = fields.CharField(max_length=50)
path_pattern = fields.CharField(max_length=1024, null=True)
filename_regex = fields.CharField(max_length=255, null=True)
processor_type = fields.CharField(max_length=100)
processor_config = fields.JSONField()
enabled = fields.BooleanField(default=True)
class Meta:
table = "automation_tasks"
class Log(Model):
id = fields.IntField(pk=True)
timestamp = fields.DatetimeField(auto_now_add=True)
level = fields.CharField(max_length=50)
source = fields.CharField(max_length=100)
message = fields.TextField()
details = fields.JSONField(null=True)
user_id = fields.IntField(null=True)
class Meta:
table = "logs"
class ShareLink(Model):
id = fields.IntField(pk=True)
token = fields.CharField(max_length=100, unique=True, index=True)
name = fields.CharField(max_length=255)
paths = fields.JSONField()
user: fields.ForeignKeyRelation[UserAccount] = fields.ForeignKeyField(
"models.UserAccount", related_name="shares", on_delete=fields.CASCADE
)
created_at = fields.DatetimeField(auto_now_add=True)
expires_at = fields.DatetimeField(null=True)
access_type = fields.CharField(max_length=20, default="public")
hashed_password = fields.CharField(max_length=128, null=True)
class Meta:
table = "share_links"
class Plugin(Model):
id = fields.IntField(pk=True)
url = fields.CharField(max_length=2048)
enabled = fields.BooleanField(default=True)
key = fields.CharField(max_length=100, null=True)
name = fields.CharField(max_length=255, null=True)
version = fields.CharField(max_length=50, null=True)
supported_exts = fields.JSONField(null=True)
default_bounds = fields.JSONField(null=True)
default_maximized = fields.BooleanField(null=True)
icon = fields.CharField(max_length=2048, null=True)
description = fields.TextField(null=True)
author = fields.CharField(max_length=255, null=True)
website = fields.CharField(max_length=2048, null=True)
github = fields.CharField(max_length=2048, null=True)
created_at = fields.DatetimeField(auto_now_add=True)
updated_at = fields.DatetimeField(auto_now=True)
class Meta:
table = "plugins"