2025-08-25 09:26:54 +08:00
|
|
|
from flask_restx import Api, Namespace, fields
|
2024-02-06 13:21:13 +08:00
|
|
|
|
2023-09-27 16:06:32 +08:00
|
|
|
from libs.helper import TimestampField
|
|
|
|
|
|
|
|
|
|
upload_config_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"file_size_limit": fields.Integer,
|
|
|
|
|
"batch_count_limit": fields.Integer,
|
|
|
|
|
"image_file_size_limit": fields.Integer,
|
2024-10-23 15:23:30 +08:00
|
|
|
"video_file_size_limit": fields.Integer,
|
|
|
|
|
"audio_file_size_limit": fields.Integer,
|
2024-11-04 15:55:34 +08:00
|
|
|
"workflow_file_upload_limit": fields.Integer,
|
2023-09-27 16:06:32 +08:00
|
|
|
}
|
|
|
|
|
|
2025-08-25 09:26:54 +08:00
|
|
|
|
|
|
|
|
def build_upload_config_model(api_or_ns: Api | Namespace):
|
|
|
|
|
"""Build the upload config model for the API or Namespace.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
api_or_ns: Flask-RestX Api or Namespace instance
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
The registered model
|
|
|
|
|
"""
|
|
|
|
|
return api_or_ns.model("UploadConfig", upload_config_fields)
|
|
|
|
|
|
|
|
|
|
|
2023-09-27 16:06:32 +08:00
|
|
|
file_fields = {
|
2024-08-15 12:54:05 +08:00
|
|
|
"id": fields.String,
|
|
|
|
|
"name": fields.String,
|
|
|
|
|
"size": fields.Integer,
|
|
|
|
|
"extension": fields.String,
|
|
|
|
|
"mime_type": fields.String,
|
|
|
|
|
"created_by": fields.String,
|
|
|
|
|
"created_at": TimestampField,
|
2025-04-22 13:05:42 +08:00
|
|
|
"preview_url": fields.String,
|
2024-08-15 12:54:05 +08:00
|
|
|
}
|
2024-10-21 10:43:49 +08:00
|
|
|
|
2025-08-25 09:26:54 +08:00
|
|
|
|
|
|
|
|
def build_file_model(api_or_ns: Api | Namespace):
|
|
|
|
|
"""Build the file model for the API or Namespace.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
api_or_ns: Flask-RestX Api or Namespace instance
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
The registered model
|
|
|
|
|
"""
|
|
|
|
|
return api_or_ns.model("File", file_fields)
|
|
|
|
|
|
|
|
|
|
|
2024-10-21 10:43:49 +08:00
|
|
|
remote_file_info_fields = {
|
|
|
|
|
"file_type": fields.String(attribute="file_type"),
|
|
|
|
|
"file_length": fields.Integer(attribute="file_length"),
|
|
|
|
|
}
|
2024-11-01 15:51:22 +08:00
|
|
|
|
|
|
|
|
|
2025-08-25 09:26:54 +08:00
|
|
|
def build_remote_file_info_model(api_or_ns: Api | Namespace):
|
|
|
|
|
"""Build the remote file info model for the API or Namespace.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
api_or_ns: Flask-RestX Api or Namespace instance
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
The registered model
|
|
|
|
|
"""
|
|
|
|
|
return api_or_ns.model("RemoteFileInfo", remote_file_info_fields)
|
|
|
|
|
|
|
|
|
|
|
2024-11-01 15:51:22 +08:00
|
|
|
file_fields_with_signed_url = {
|
|
|
|
|
"id": fields.String,
|
|
|
|
|
"name": fields.String,
|
|
|
|
|
"size": fields.Integer,
|
|
|
|
|
"extension": fields.String,
|
|
|
|
|
"url": fields.String,
|
|
|
|
|
"mime_type": fields.String,
|
|
|
|
|
"created_by": fields.String,
|
|
|
|
|
"created_at": TimestampField,
|
|
|
|
|
}
|
2025-08-25 09:26:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_file_with_signed_url_model(api_or_ns: Api | Namespace):
|
|
|
|
|
"""Build the file with signed URL model for the API or Namespace.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
api_or_ns: Flask-RestX Api or Namespace instance
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
The registered model
|
|
|
|
|
"""
|
|
|
|
|
return api_or_ns.model("FileWithSignedUrl", file_fields_with_signed_url)
|