Skip to content

Commit 2bd7a14

Browse files
committed
fix: 修复.gitignore导致models目录被忽略的问题
1 parent d0af550 commit 2bd7a14

11 files changed

Lines changed: 652 additions & 1 deletion

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dist/
2424
*.egg-info/
2525

2626
# Models directory (large binary files - use git-lfs or separate download)
27-
models/
27+
/models/
2828

2929
# Output directories
3030
result/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Data models for user resource management system.
3+
"""
4+
5+
from manga_translator.server.models.resource_models import PromptResource, FontResource
6+
from manga_translator.server.models.translation_models import TranslationResult
7+
from manga_translator.server.models.permission_models import UserPermission
8+
from manga_translator.server.models.cleanup_models import CleanupRule
9+
from manga_translator.server.models.config_models import ConfigPreset, UserConfig
10+
from manga_translator.server.models.quota_models import QuotaLimit, QuotaStats
11+
from manga_translator.server.models.log_models import LogEntry
12+
from manga_translator.server.models.group_models import UserGroup
13+
14+
__all__ = [
15+
'PromptResource',
16+
'FontResource',
17+
'TranslationResult',
18+
'UserPermission',
19+
'CleanupRule',
20+
'ConfigPreset',
21+
'UserConfig',
22+
'QuotaLimit',
23+
'QuotaStats',
24+
'LogEntry',
25+
'UserGroup',
26+
]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Cleanup rule data models.
3+
"""
4+
5+
from dataclasses import dataclass, asdict
6+
from datetime import datetime, UTC
7+
from typing import Optional
8+
import uuid
9+
10+
11+
@dataclass
12+
class CleanupRule:
13+
"""Model for cleanup rules."""
14+
15+
id: str
16+
level: str # global, user_group, user
17+
target_id: Optional[str] # user_group_id or user_id
18+
retention_days: int
19+
enabled: bool = True
20+
created_at: Optional[str] = None
21+
created_by: Optional[str] = None
22+
23+
@classmethod
24+
def create(cls, level: str, retention_days: int,
25+
target_id: Optional[str] = None, created_by: Optional[str] = None,
26+
enabled: bool = True) -> 'CleanupRule':
27+
"""Create a new CleanupRule instance."""
28+
return cls(
29+
id=str(uuid.uuid4()),
30+
level=level,
31+
target_id=target_id,
32+
retention_days=retention_days,
33+
enabled=enabled,
34+
created_at=datetime.now(UTC).isoformat(),
35+
created_by=created_by
36+
)
37+
38+
def to_dict(self) -> dict:
39+
"""Convert to dictionary for JSON serialization."""
40+
return asdict(self)
41+
42+
@classmethod
43+
def from_dict(cls, data: dict) -> 'CleanupRule':
44+
"""Create instance from dictionary."""
45+
return cls(**data)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
"""
2+
Configuration data models.
3+
"""
4+
5+
from dataclasses import dataclass, asdict, field
6+
from datetime import datetime, timezone
7+
from typing import Optional, List
8+
import uuid
9+
10+
11+
@dataclass
12+
class ConfigPreset:
13+
"""Model for configuration presets."""
14+
15+
id: str
16+
name: str
17+
description: str
18+
config: dict
19+
visible_to_groups: List[str] = field(default_factory=list)
20+
created_at: Optional[str] = None
21+
created_by: Optional[str] = None
22+
updated_at: Optional[str] = None
23+
24+
@classmethod
25+
def create(cls, name: str, description: str, config: dict,
26+
created_by: Optional[str] = None,
27+
visible_to_groups: Optional[List[str]] = None) -> 'ConfigPreset':
28+
"""Create a new ConfigPreset instance."""
29+
now = datetime.now(timezone.utc).isoformat()
30+
return cls(
31+
id=str(uuid.uuid4()),
32+
name=name,
33+
description=description,
34+
config=config,
35+
visible_to_groups=visible_to_groups or [],
36+
created_at=now,
37+
created_by=created_by,
38+
updated_at=now
39+
)
40+
41+
def to_dict(self) -> dict:
42+
"""Convert to dictionary for JSON serialization."""
43+
return asdict(self)
44+
45+
@classmethod
46+
def from_dict(cls, data: dict) -> 'ConfigPreset':
47+
"""Create instance from dictionary."""
48+
return cls(**data)
49+
50+
def update(self, **kwargs) -> None:
51+
"""Update preset fields."""
52+
for key, value in kwargs.items():
53+
if hasattr(self, key) and key not in ['id', 'created_at', 'created_by']:
54+
setattr(self, key, value)
55+
self.updated_at = datetime.now(timezone.utc).isoformat()
56+
57+
58+
@dataclass
59+
class UserConfig:
60+
"""Model for user configurations."""
61+
62+
user_id: str
63+
api_keys: dict = field(default_factory=dict)
64+
selected_preset_id: Optional[str] = None
65+
custom_settings: dict = field(default_factory=dict)
66+
config_mode: str = "server" # server or custom
67+
updated_at: Optional[str] = None
68+
69+
@classmethod
70+
def create(cls, user_id: str, **kwargs) -> 'UserConfig':
71+
"""Create a new UserConfig instance."""
72+
return cls(
73+
user_id=user_id,
74+
updated_at=datetime.now(timezone.utc).isoformat(),
75+
**kwargs
76+
)
77+
78+
def to_dict(self) -> dict:
79+
"""Convert to dictionary for JSON serialization."""
80+
return asdict(self)
81+
82+
@classmethod
83+
def from_dict(cls, data: dict) -> 'UserConfig':
84+
"""Create instance from dictionary."""
85+
return cls(**data)
86+
87+
def update(self, **kwargs) -> None:
88+
"""Update config fields."""
89+
for key, value in kwargs.items():
90+
if hasattr(self, key) and key != 'user_id':
91+
setattr(self, key, value)
92+
self.updated_at = datetime.now(timezone.utc).isoformat()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
User group data models.
3+
"""
4+
5+
from dataclasses import dataclass, asdict, field
6+
from datetime import datetime, timezone
7+
from typing import Optional, List
8+
import uuid
9+
10+
11+
@dataclass
12+
class UserGroup:
13+
"""Model for user groups."""
14+
15+
id: str
16+
name: str
17+
description: str
18+
permissions: dict = field(default_factory=dict)
19+
quota_limits: dict = field(default_factory=dict)
20+
visible_presets: List[str] = field(default_factory=list)
21+
created_at: Optional[str] = None
22+
created_by: Optional[str] = None
23+
is_system: bool = False
24+
25+
@classmethod
26+
def create(cls, name: str, description: str,
27+
created_by: Optional[str] = None,
28+
is_system: bool = False,
29+
permissions: Optional[dict] = None,
30+
quota_limits: Optional[dict] = None,
31+
visible_presets: Optional[List[str]] = None) -> 'UserGroup':
32+
"""Create a new UserGroup instance."""
33+
return cls(
34+
id=str(uuid.uuid4()),
35+
name=name,
36+
description=description,
37+
permissions=permissions or {},
38+
quota_limits=quota_limits or {},
39+
visible_presets=visible_presets or [],
40+
created_at=datetime.now(timezone.utc).isoformat(),
41+
created_by=created_by,
42+
is_system=is_system
43+
)
44+
45+
def to_dict(self) -> dict:
46+
"""Convert to dictionary for JSON serialization."""
47+
return asdict(self)
48+
49+
@classmethod
50+
def from_dict(cls, data: dict) -> 'UserGroup':
51+
"""Create instance from dictionary."""
52+
return cls(**data)
53+
54+
def update(self, **kwargs) -> None:
55+
"""Update group fields."""
56+
for key, value in kwargs.items():
57+
if hasattr(self, key) and key not in ['id', 'created_at', 'created_by', 'is_system']:
58+
setattr(self, key, value)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Log data models.
3+
"""
4+
5+
from dataclasses import dataclass, asdict, field
6+
from datetime import datetime, timezone
7+
from typing import Optional
8+
import uuid
9+
10+
11+
@dataclass
12+
class LogEntry:
13+
"""Model for log entries."""
14+
15+
id: str
16+
session_token: str
17+
user_id: str
18+
timestamp: str
19+
level: str # info, warning, error
20+
event_type: str
21+
message: str
22+
details: dict = field(default_factory=dict)
23+
24+
@classmethod
25+
def create(cls, session_token: str, user_id: str, level: str,
26+
event_type: str, message: str,
27+
details: Optional[dict] = None) -> 'LogEntry':
28+
"""Create a new LogEntry instance."""
29+
return cls(
30+
id=str(uuid.uuid4()),
31+
session_token=session_token,
32+
user_id=user_id,
33+
timestamp=datetime.now(timezone.utc).isoformat(),
34+
level=level,
35+
event_type=event_type,
36+
message=message,
37+
details=details or {}
38+
)
39+
40+
def to_dict(self) -> dict:
41+
"""Convert to dictionary for JSON serialization."""
42+
return asdict(self)
43+
44+
@classmethod
45+
def from_dict(cls, data: dict) -> 'LogEntry':
46+
"""Create instance from dictionary."""
47+
return cls(**data)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Permission data models.
3+
"""
4+
5+
from dataclasses import dataclass, asdict
6+
from datetime import datetime, timezone
7+
from typing import Optional
8+
9+
10+
@dataclass
11+
class UserPermission:
12+
"""Model for user permissions."""
13+
14+
user_id: str
15+
can_upload_prompt: bool = False
16+
can_upload_font: bool = False
17+
view_permission: str = "own" # own, none, all
18+
save_enabled: bool = True
19+
can_delete_own_files: bool = True
20+
can_delete_all_files: bool = False
21+
can_edit_own_env: bool = False
22+
can_edit_server_env: bool = False
23+
can_view_own_logs: bool = True
24+
can_view_all_logs: bool = False
25+
can_view_system_logs: bool = False
26+
updated_at: Optional[str] = None
27+
updated_by: Optional[str] = None
28+
29+
@classmethod
30+
def create(cls, user_id: str, updated_by: Optional[str] = None,
31+
**permissions) -> 'UserPermission':
32+
"""Create a new UserPermission instance."""
33+
return cls(
34+
user_id=user_id,
35+
updated_at=datetime.now(timezone.utc).isoformat(),
36+
updated_by=updated_by,
37+
**permissions
38+
)
39+
40+
def to_dict(self) -> dict:
41+
"""Convert to dictionary for JSON serialization."""
42+
return asdict(self)
43+
44+
@classmethod
45+
def from_dict(cls, data: dict) -> 'UserPermission':
46+
"""Create instance from dictionary."""
47+
return cls(**data)
48+
49+
def update(self, updated_by: str, **permissions) -> None:
50+
"""Update permissions."""
51+
for key, value in permissions.items():
52+
if hasattr(self, key):
53+
setattr(self, key, value)
54+
self.updated_at = datetime.now(timezone.utc).isoformat()
55+
self.updated_by = updated_by

0 commit comments

Comments
 (0)