file_app.py


Overview

file_app.py is a Flask-based web API module that manages file and folder operations within the InfiniFlow platform. It provides endpoints for uploading, creating, listing, retrieving, renaming, moving, and deleting files and folders, all secured via user authentication (flask_login). This module acts as a controller layer interfacing between HTTP requests and the backend services that handle file metadata (FileService), document associations (DocumentService, File2DocumentService), and storage operations (via STORAGE_IMPL).

The file ensures user access control, enforces business rules (e.g., maximum file counts), maintains file hierarchy integrity, and coordinates consistent state between storage and database layers.


Classes and Functions

This module primarily defines Flask route handler functions; no classes are defined here. Below is a detailed explanation of each route handler.


1. upload()

Parameters

Returns

Behavior and Implementation Details

Usage Example (cURL)

curl -X POST -F "parent_id=<folder_id>" -F "file=@path/to/file1" -F "file=@path/to/file2" https://api.infinitflow.com/upload

2. create()

Parameters (JSON Body)

Returns

Behavior

Usage Example

POST /create
{
  "name": "NewFolder",
  "parent_id": "12345",
  "type": "FOLDER"
}

3. list_files()

Query Parameters

Returns

Behavior


4. get_root_folder()

Returns


5. get_parent_folder()

Query Parameters

Returns


6. get_all_parent_folders()

Query Parameters

Returns


7. rm()

Parameters (JSON Body)

Returns

Behavior


8. rename()

Parameters (JSON Body)

Returns

Behavior


9. get(file_id)

Parameters

Returns

Behavior


10. move()

Parameters (JSON Body)

Returns

Behavior


Important Implementation Details


Interactions with Other Components

This module acts as the REST API layer, coordinating between HTTP requests, business logic, persistent storage, and authentication.


Visual Diagram

classDiagram
    class file_app {
        +upload()
        +create()
        +list_files()
        +get_root_folder()
        +get_parent_folder()
        +get_all_parent_folders()
        +rm()
        +rename()
        +get(file_id)
        +move()
    }
    file_app ..> FileService : Uses for metadata operations
    file_app ..> DocumentService : Uses for document management
    file_app ..> File2DocumentService : Uses for file-document links
    file_app ..> STORAGE_IMPL : Uses for physical file storage
    file_app ..> flask_login : Uses for user authentication
    file_app ..> api.utils.api_utils : Uses for response and validation utilities

Summary

file_app.py is a core API component within InfiniFlow that facilitates comprehensive file and folder management functionalities. It ensures secure, consistent, and user-scoped file handling integrated with document management and physical storage. The module's design promotes modularity by delegating specialized tasks to dedicated services and utilities, enabling maintainable and scalable file management features in the application.