package com.ard.web.controller.sample.media; import com.ard.sample.common.model.PaginationData; import com.ard.sample.common.model.ResponseResult; import com.ard.sample.media.model.MediaFileDTO; import com.ard.sample.media.service.IFileService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URL; /** * @author sean * @version 0.2 * @date 2021/12/9 */ @Api(tags = "媒体文件管理") @RestController @RequestMapping("/dock/media/files") public class FileController { @Autowired private IFileService fileService; /** * Get information about all the media files in this workspace based on the workspace id. * @return */ @ApiOperation("获取所有媒体文件列表") @GetMapping("/files") public ResponseResult> getFilesList(@RequestParam(defaultValue = "1") Long page, @RequestParam(name = "page_size", defaultValue = "10") Long pageSize) { PaginationData filesList = fileService.getMediaFilesPagination(page, pageSize); return ResponseResult.success(filesList); } /** * Query the download address of the file according to the media file id, * and redirect to this address directly for download. * @param fileId * @param response */ @ApiOperation("根据id获取媒体文件地址") @GetMapping("/file/{file_id}/url") public void getFileUrl(@PathVariable(name = "file_id") String fileId, HttpServletResponse response) { try { URL url = fileService.getObjectUrl(fileId); response.sendRedirect(url.toString()); } catch (IOException e) { e.printStackTrace(); } } /** * 根据任务id获取全部媒体库文件列表 * */ @ApiOperation("获取任务中媒体文件列表") @GetMapping("/jobfiles") public ResponseResult> getJobFiles(@RequestParam(defaultValue = "1") Long page, @RequestParam(name = "page_size", defaultValue = "10") Long pageSize, @RequestParam(name = "job_id") String jobId) { PaginationData filesList = fileService.getJobFiles(page, pageSize, jobId); return ResponseResult.success(filesList); } }