From 40934da83d6c4e2ecbabb521b8bb54a903070e7c Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Sat, 23 Sep 2023 16:48:12 +0800
Subject: [PATCH] 媒体文件添加条件查询
---
src/main/java/com/dji/sample/media/controller/FileController.java | 38 +++++++++++++++++++++++++++++++-------
1 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/dji/sample/media/controller/FileController.java b/src/main/java/com/dji/sample/media/controller/FileController.java
index 25a6015..aaa400d 100644
--- a/src/main/java/com/dji/sample/media/controller/FileController.java
+++ b/src/main/java/com/dji/sample/media/controller/FileController.java
@@ -1,15 +1,16 @@
package com.dji.sample.media.controller;
+import com.dji.sample.common.model.PaginationData;
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.media.model.MediaFileDTO;
+import com.dji.sample.media.model.MediaFileQueryParam;
import com.dji.sample.media.service.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
-import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URL;
/**
* @author sean
@@ -25,12 +26,35 @@
/**
* Get information about all the media files in this workspace based on the workspace id.
+ * 根据工作空间id获取有关此工作空间中所有媒体文件的信息。
* @param workspaceId
* @return
*/
@GetMapping("/{workspace_id}/files")
- public ResponseResult<List<MediaFileDTO>> getFilesList(@PathVariable(name = "workspace_id") String workspaceId) {
- List<MediaFileDTO> filesList = fileService.getAllFilesByWorkspaceId(workspaceId);
+ public ResponseResult<PaginationData<MediaFileDTO>> getFilesList(@RequestParam(defaultValue = "1") Long page,
+ @RequestParam(name = "page_size", defaultValue = "10") Long pageSize,
+ @PathVariable(name = "workspace_id") String workspaceId,
+ MediaFileQueryParam mediaFileQueryParam) {
+ PaginationData<MediaFileDTO> filesList = fileService.getMediaFilesPaginationByWorkspaceId(workspaceId, page, pageSize,mediaFileQueryParam);
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 workspaceId
+ * @param fileId
+ * @param response
+ */
+ @GetMapping("/{workspace_id}/file/{file_id}/url")
+ public void getFileUrl(@PathVariable(name = "workspace_id") String workspaceId,
+ @PathVariable(name = "file_id") String fileId, HttpServletResponse response) {
+
+ try {
+ URL url = fileService.getObjectUrl(workspaceId, fileId);
+ response.sendRedirect(url.toString());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
--
Gitblit v1.9.3