Skip to content

System

DeleteTempFileRequest

Bases: BaseModel

Request model for deleting a temporary file.

Attributes:

  • path (str) –

    The path of the temporary file to delete.

Source code in app/api/v1/endpoints/system.py
133
134
135
136
137
138
139
140
141
class DeleteTempFileRequest(BaseModel):
    """
    Request model for deleting a temporary file.

    Attributes:
        path: The path of the temporary file to delete.
    """

    path: str

FilePathResponse

Bases: BaseModel

File path response.

Source code in app/api/v1/endpoints/system.py
26
27
28
29
class FilePathResponse(BaseModel):
    """File path response."""

    path: str

MessageResponse

Bases: BaseModel

Generic message response.

Source code in app/api/v1/endpoints/system.py
19
20
21
22
23
class MessageResponse(BaseModel):
    """Generic message response."""

    message: str
    success: bool = True

OpenFileRequest

Bases: BaseModel

Request model for opening a file.

Attributes:

  • document_id (str) –

    The ID of the document to open.

Source code in app/api/v1/endpoints/system.py
32
33
34
35
36
37
38
39
40
class OpenFileRequest(BaseModel):
    """
    Request model for opening a file.

    Attributes:
        document_id: The ID of the document to open.
    """

    document_id: str

delete_temp_file(request, service, current_admin) async

Delete a temporary uploaded file.

Admin only. Used when user cancels connector creation after uploading.

Parameters:

  • request (DeleteTempFileRequest) –

    The request body containing the file path.

  • service (Annotated[DocumentService, Depends(get_document_service)]) –

    The document service instance.

  • current_admin (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

Raises:

  • Exception

    If there's an error during file deletion.

Source code in app/api/v1/endpoints/system.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
@router.delete("/temp-file", response_model=MessageResponse)
async def delete_temp_file(
    request: DeleteTempFileRequest,
    service: Annotated[DocumentService, Depends(get_document_service)],
    current_admin: Annotated[User, Depends(get_current_admin)],
) -> MessageResponse:
    """
    Delete a temporary uploaded file.

    Admin only.
    Used when user cancels connector creation after uploading.

    Args:
        request: The request body containing the file path.
        service: The document service instance.
        current_admin: The currently authenticated admin user.

    Returns:
        A dictionary containing a success message.

    Raises:
        Exception: If there's an error during file deletion.
    """
    try:
        await service.delete_temp_file(request.path)
        return {"message": "File deleted successfully"}
    except Exception as e:
        logger.error(
            f"❌ FAIL | delete_temp_file | Path: {request.path} | Error: {str(e)}",
            exc_info=True,
        )
        raise e

download_file(document_id, service, current_user) async

Download a file based on document ID. Safety checks are performed by SystemService.

Source code in app/api/v1/endpoints/system.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
@router.get("/download-file/{document_id}")
async def download_file(
    document_id: str,
    service: Annotated[SystemService, Depends(get_system_service)],
    current_user: Annotated[User, Depends(get_current_user)],
):
    """
    Download a file based on document ID.
    Safety checks are performed by SystemService.
    """
    from fastapi.responses import FileResponse
    import os

    try:
        file_path = await service.get_resolved_path_by_document_id(document_id)
        return FileResponse(
            path=file_path,
            filename=os.path.basename(file_path),
            media_type="application/octet-stream",
        )
    except Exception as e:
        logger.error(f"❌ FAIL | download_file | DocumentID: {document_id} | Error: {str(e)}", exc_info=True)
        raise e

open_file_external(request, service, current_user) async

Open a file using the system's default application based on document ID.

Reconstructs the full path using connector configuration. Basic auth required.

Parameters:

  • request (OpenFileRequest) –

    The request body containing document_id.

  • service (Annotated[SystemService, Depends(get_system_service)]) –

    The system service instance.

  • current_user (Annotated[User, Depends(get_current_user)]) –

    The currently authenticated user.

Returns:

Raises:

  • Exception

    If there's an error opening the file.

Source code in app/api/v1/endpoints/system.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@router.post("/open-file", response_model=MessageResponse)
async def open_file_external(
    request: OpenFileRequest,
    service: Annotated[SystemService, Depends(get_system_service)],
    current_user: Annotated[User, Depends(get_current_user)],
) -> MessageResponse:
    """
    Open a file using the system's default application based on document ID.

    Reconstructs the full path using connector configuration.
    Basic auth required.

    Args:
        request: The request body containing document_id.
        service: The system service instance.
        current_user: The currently authenticated user.

    Returns:
        A dictionary containing the status of the operation.

    Raises:
        Exception: If there's an error opening the file.
    """
    try:
        success = await service.open_file_by_document_id(request.document_id)
        return {"message": "File opened", "success": success}
    except Exception as e:
        logger.error(
            f"❌ FAIL | open_file_external | DocumentID: {request.document_id} | Error: {str(e)}",
            exc_info=True,
        )
        raise e

upload_file(service, current_admin, file=File(...)) async

Upload a file to the temporary area.

Admin only.

Parameters:

  • service (Annotated[DocumentService, Depends(get_document_service)]) –

    The document service instance.

  • current_admin (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

  • file (UploadFile, default: File(...) ) –

    The file to be uploaded.

Returns:

Raises:

  • Exception

    If there's an error during file upload.

Source code in app/api/v1/endpoints/system.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
@router.post("/upload", response_model=FilePathResponse)
async def upload_file(
    service: Annotated[DocumentService, Depends(get_document_service)],
    current_admin: Annotated[User, Depends(get_current_admin)],
    file: UploadFile = File(...),
) -> FilePathResponse:
    """
    Upload a file to the temporary area.

    Admin only.

    Args:
        service: The document service instance.
        current_admin: The currently authenticated admin user.
        file: The file to be uploaded.

    Returns:
        A dictionary containing the path of the uploaded file.

    Raises:
        Exception: If there's an error during file upload.
    """
    try:
        # Delegate to Service
        file_path = await service.upload_file(file)
        return {"path": file_path}
    except Exception as e:
        logger.error(f"❌ FAIL | upload_file | Error: {str(e)}", exc_info=True)
        raise e