feat: add file export
This commit is contained in:
@@ -61,3 +61,31 @@ func (h *TaskEndpoint) GetTaskList(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, common.SuccessResponse(c, resp))
|
||||
}
|
||||
|
||||
func (h *TaskEndpoint) ExportTask(c *gin.Context) {
|
||||
var req task.ExportTaskRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
log.Error(c, "func", "ExportTask", "msg", "Invalid parameters", "error", err)
|
||||
c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeParamError, "Invalid parameters"))
|
||||
return
|
||||
}
|
||||
fileData, contentType, err := h.taskService.ExportTask(c, &req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeSystemError, "导出任务失败"))
|
||||
return
|
||||
}
|
||||
|
||||
// set filename based on export type
|
||||
var filename string
|
||||
switch req.Type {
|
||||
case "pdf":
|
||||
filename = "texpixel_export.pdf"
|
||||
case "docx":
|
||||
filename = "texpixel_export.docx"
|
||||
default:
|
||||
filename = "texpixel_export"
|
||||
}
|
||||
|
||||
c.Header("Content-Disposition", "attachment; filename="+filename)
|
||||
c.Data(http.StatusOK, contentType, fileData)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user