Initial commit

This commit is contained in:
shiyu
2025-08-24 18:49:00 +08:00
parent 99866befe1
commit 6b0f2bd4fa
129 changed files with 11587 additions and 0 deletions

3
models/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
from .database import StorageAdapter, Mount
__all__ = ["StorageAdapter", "Mount"]

95
models/database.py Normal file
View File

@@ -0,0 +1,95 @@
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)
mounts: fields.ReverseRelation["Mount"]
class Meta:
table = "storage_adapters"
class Mount(Model):
id = fields.IntField(pk=True)
path = fields.CharField(max_length=255, unique=True)
sub_path = fields.CharField(max_length=1024, null=True)
adapter: fields.ForeignKeyRelation[StorageAdapter] = fields.ForeignKeyField(
"models.StorageAdapter", related_name="mounts", on_delete=fields.CASCADE
)
enabled = fields.BooleanField(default=True)
class Meta:
table = "mounts"
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"