fix(core): use CreatedByRole enum for role consistency (#9607)

This commit is contained in:
-LAN- 2024-10-22 13:03:50 +08:00 committed by GitHub
parent d170d78530
commit 5f12c17355
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 5 deletions

View File

@ -18,6 +18,7 @@ from core.rag.extractor.extractor_base import BaseExtractor
from core.rag.models.document import Document
from extensions.ext_database import db
from extensions.ext_storage import storage
from models.enums import CreatedByRole
from models.model import UploadFile
logger = logging.getLogger(__name__)
@ -109,9 +110,10 @@ class WordExtractor(BaseExtractor):
key=file_key,
name=file_key,
size=0,
extension=image_ext,
mime_type=mime_type,
extension=str(image_ext),
mime_type=mime_type or "",
created_by=self.user_id,
created_by_role=CreatedByRole.ACCOUNT,
created_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),
used=True,
used_by=self.user_id,

View File

@ -1391,7 +1391,7 @@ class UploadFile(db.Model):
size: int,
extension: str,
mime_type: str,
created_by_role: str,
created_by_role: CreatedByRole,
created_by: str,
created_at: datetime,
used: bool,
@ -1406,7 +1406,7 @@ class UploadFile(db.Model):
self.size = size
self.extension = extension
self.mime_type = mime_type
self.created_by_role = created_by_role
self.created_by_role = created_by_role.value
self.created_by = created_by
self.created_at = created_at
self.used = used

View File

@ -20,6 +20,7 @@ from core.rag.extractor.extract_processor import ExtractProcessor
from extensions.ext_database import db
from extensions.ext_storage import storage
from models.account import Account
from models.enums import CreatedByRole
from models.model import EndUser, UploadFile
from services.errors.file import FileNotExistsError, FileTooLargeError, UnsupportedFileTypeError
@ -85,7 +86,7 @@ class FileService:
size=file_size,
extension=extension,
mime_type=file.mimetype,
created_by_role=("account" if isinstance(user, Account) else "end_user"),
created_by_role=(CreatedByRole.ACCOUNT if isinstance(user, Account) else CreatedByRole.END_USER),
created_by=user.id,
created_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),
used=False,
@ -118,6 +119,7 @@ class FileService:
extension="txt",
mime_type="text/plain",
created_by=current_user.id,
created_by_role=CreatedByRole.ACCOUNT,
created_at=datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),
used=True,
used_by=current_user.id,