|
|
|
|
@ -12,6 +12,7 @@ from app.services.image_service import ImageService
|
|
|
|
|
from app.services.image.image_serializer import get_image_serializer
|
|
|
|
|
from app.services.image.task_image_strategy import TaskImageStrategy
|
|
|
|
|
from app.database import Image, ImageType
|
|
|
|
|
from app import db
|
|
|
|
|
|
|
|
|
|
image_bp = Blueprint('image', __name__)
|
|
|
|
|
|
|
|
|
|
@ -252,6 +253,57 @@ def get_flow_images_binary(flow_id, current_user_id):
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# ==================== 用户图库接口 ====================
|
|
|
|
|
|
|
|
|
|
@image_bp.route('/gallery/perturbed', methods=['GET'])
|
|
|
|
|
@int_jwt_required
|
|
|
|
|
def get_user_perturbed_gallery(current_user_id):
|
|
|
|
|
"""
|
|
|
|
|
获取用户所有的加噪图片(图库接口)
|
|
|
|
|
|
|
|
|
|
Query参数:
|
|
|
|
|
page: 页码,默认1
|
|
|
|
|
per_page: 每页数量,默认20,最大100
|
|
|
|
|
|
|
|
|
|
返回:
|
|
|
|
|
- images: 加噪图片列表
|
|
|
|
|
- total: 总数量
|
|
|
|
|
- page: 当前页码
|
|
|
|
|
- per_page: 每页数量
|
|
|
|
|
- pages: 总页数
|
|
|
|
|
"""
|
|
|
|
|
from app.database import Task
|
|
|
|
|
|
|
|
|
|
page = request.args.get('page', 1, type=int)
|
|
|
|
|
per_page = min(request.args.get('per_page', 20, type=int), 100)
|
|
|
|
|
|
|
|
|
|
# 获取加噪图片类型
|
|
|
|
|
perturbed_type = ImageType.query.filter_by(image_code='perturbed').first()
|
|
|
|
|
if not perturbed_type:
|
|
|
|
|
return ImageService.json_error('图片类型配置错误', 500)
|
|
|
|
|
|
|
|
|
|
# 查询用户所有任务的加噪图片
|
|
|
|
|
user_task_ids = db.session.query(Task.tasks_id).filter_by(user_id=current_user_id).subquery()
|
|
|
|
|
|
|
|
|
|
query = Image.query.filter(
|
|
|
|
|
Image.task_id.in_(user_task_ids),
|
|
|
|
|
Image.image_types_id == perturbed_type.image_types_id
|
|
|
|
|
).order_by(Image.images_id.desc())
|
|
|
|
|
|
|
|
|
|
# 分页
|
|
|
|
|
pagination = query.paginate(page=page, per_page=per_page, error_out=False)
|
|
|
|
|
|
|
|
|
|
serializer = get_image_serializer()
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
'images': [serializer.to_dict(img) for img in pagination.items],
|
|
|
|
|
'total': pagination.total,
|
|
|
|
|
'page': pagination.page,
|
|
|
|
|
'per_page': pagination.per_page,
|
|
|
|
|
'pages': pagination.pages
|
|
|
|
|
}), 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" 前端解析预览图片方式
|
|
|
|
|
const response = await fetch(`/api/image/binary/task/${taskId}`);
|
|
|
|
|
const contentType = response.headers.get('content-type');
|
|
|
|
|
|