system_app.py


Overview

system_app.py is a Flask-based backend API module that provides system-level endpoints for the InfiniFlow application. It includes routes for retrieving system version and status, managing API tokens for authentication, and fetching system configuration settings.

The file primarily serves the following purposes:

This module interacts heavily with database services, Redis cache, storage engine implementations, and authentication utilities to consolidate and expose relevant system information.


Detailed Description of Endpoints and Functions

1. version()

Route: /version
Method: GET
Authentication: Required (login_required decorator)

Description:
Returns the current version of the InfiniFlow application.

Returns:

Usage Example:

GET /version
Authorization: Bearer <token>

Response:

{
  "version": "1.2.3"
}

Implementation Details:
Uses get_ragflow_version() from api.versions to retrieve the version string and wraps the result with get_json_result() for standardized JSON response formatting.


2. status()

Route: /status
Method: GET
Authentication: Required

Description:
Performs a comprehensive health check on core system components:

Returns:

Implementation Details:

Usage Example:

GET /status
Authorization: Bearer <token>

Response Example:

{
  "doc_engine": {
    "status": "green",
    "elapsed": "12.3"
  },
  "storage": {
    "storage": "filesystem",
    "status": "green",
    "elapsed": "5.0"
  },
  "database": {
    "database": "postgresql",
    "status": "green",
    "elapsed": "8.7"
  },
  "redis": {
    "status": "green",
    "elapsed": "2.1"
  },
  "task_executor_heartbeats": {
    "executor_1": [
      {"timestamp": 1685858400, "status": "alive"}
    ]
  }
}

3. new_token()

Route: /new_token
Method: POST
Authentication: Required

Description:
Generates a new API token for the current user’s tenant with the 'owner' role.

Parameters:

Returns:

Token Data Fields:

Implementation Details:

Usage Example:

POST /new_token
Authorization: Bearer <token>

Response Example:

{
  "tenant_id": "tenant-123",
  "token": "ragflow-abcdef123456",
  "beta": "bcdef1234567890abcdef1234567890",
  "create_time": 1685858400,
  "create_date": "2024-06-04 12:00:00",
  "update_time": null,
  "update_date": null
}

4. token_list()

Route: /token_list
Method: GET
Authentication: Required

Description:
Lists all API tokens associated with the current user's tenant that has 'owner' role.

Returns:

Token Object Fields:

Implementation Details:

Usage Example:

GET /token_list
Authorization: Bearer <token>

Response Example:

[
  {
    "token": "ragflow-abcdef123456",
    "name": "My Token",
    "create_time": 1685858400,
    "beta": "bcdef1234567890abcdef1234567890"
  },
  ...
]

5. rm(token)

Route: /token/<token>
Method: DELETE
Authentication: Required

Description:
Removes (deletes) the specified API token belonging to the current user.

Parameters:

Returns:

Implementation Details:

Usage Example:

DELETE /token/ragflow-abcdef123456
Authorization: Bearer <token>

Response Example:

true

6. get_config()

Route: /config
Method: GET
Authentication: None (public endpoint)

Description:
Returns system configuration flags, currently exposing whether user registration is enabled.

Returns:

Returned Fields:

Usage Example:

GET /config

Response Example:

{
  "registerEnabled": 1
}

Important Implementation Details and Algorithms


Interaction with Other Components


Mermaid Class Diagram

classDiagram
    class system_app {
        +version()
        +status()
        +new_token()
        +token_list()
        +rm(token)
        +get_config()
    }

Note: This module is primarily a collection of Flask route functions, not classes. The diagram shows the module as a container of these endpoint functions.


Summary

system_app.py is a crucial system API module that provides endpoints for:

Its design emphasizes robust component health monitoring, secure API token lifecycle management, and consistent JSON-based API responses. It integrates tightly with core services, databases, Redis cache, and authentication mechanisms to deliver system-level insights and controls to authorized users.