feat(openapi): integrate springdoc and API integration guide
- add springdoc-openapi and expose /v3/api-docs, /v3/api-docs.yaml and Swagger UI - keep API docs responses unwrapped by replacing the global return handler - add Chinese @Tag/@Operation/@Parameter docs for file and async task controllers - add docs/api-integration.md and local export scripts for AI agent consumption - ignore local OpenAPI snapshots and force LF for shell scripts
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package com.imyeyu.api.config;
|
||||
|
||||
import io.swagger.v3.oas.models.Components;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* OpenAPI 接口文档配置
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2026-11-24
|
||||
*/
|
||||
@Configuration
|
||||
public class OpenApiConfig {
|
||||
|
||||
/**
|
||||
* 移除 timi-spring 默认的全局返回处理器,由 {@link OpenApiGlobalReturnHandler} 替代。
|
||||
*
|
||||
* <p>默认处理器会把所有响应包装为 TimiResponse,导致 SpringDoc 的接口描述无法被 Swagger UI 解析。</p>
|
||||
*
|
||||
* @return Bean 定义注册后处理器
|
||||
*/
|
||||
@Bean
|
||||
public static BeanDefinitionRegistryPostProcessor openApiGlobalReturnHandlerReplacer() {
|
||||
return new BeanDefinitionRegistryPostProcessor() {
|
||||
|
||||
@Override
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
|
||||
for (String beanName : registry.getBeanDefinitionNames()) {
|
||||
BeanDefinition definition = registry.getBeanDefinition(beanName);
|
||||
if ("globalReturnHandler".equals(beanName)
|
||||
|| "com.imyeyu.spring.util.GlobalReturnHandler".equals(definition.getBeanClassName())) {
|
||||
registry.removeBeanDefinition(beanName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口文档信息与认证方式
|
||||
*
|
||||
* @return OpenAPI 配置
|
||||
*/
|
||||
@Bean
|
||||
public OpenAPI timiServerOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.info(new Info()
|
||||
.title("TimiServerAPI")
|
||||
.description("夜雨综合数据中心接口")
|
||||
.version("1.0.79"))
|
||||
.components(new Components()
|
||||
.addSecuritySchemes("Token", new SecurityScheme()
|
||||
.name("Token")
|
||||
.type(SecurityScheme.Type.APIKEY)
|
||||
.in(SecurityScheme.In.HEADER)
|
||||
.description("登录令牌或 API Key,也可通过 URL 参数 token 传递")))
|
||||
.addSecurityItem(new SecurityRequirement().addList("Token"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册字节数组消息转换器,确保接口文档以原始 JSON 输出。
|
||||
*
|
||||
* <p>项目的消息转换器配置仅注册了 Jackson 转换器,{@code byte[]} 会被序列化为 Base64 字符串,
|
||||
* 导致 Swagger UI 无法解析接口文档。</p>
|
||||
*
|
||||
* @return Web MVC 配置
|
||||
*/
|
||||
@Bean
|
||||
public WebMvcConfigurer openApiByteArrayMessageConverter() {
|
||||
return new WebMvcConfigurer() {
|
||||
|
||||
@Override
|
||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(0, new ByteArrayHttpMessageConverter());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.imyeyu.api.config;
|
||||
|
||||
import com.imyeyu.spring.util.GlobalReturnHandler;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
/**
|
||||
* 全局返回处理器,跳过 SpringDoc 接口。
|
||||
*
|
||||
* <p>接口文档响应需要保持原始 JSON 结构,不能包装为 TimiResponse。</p>
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2026-11-24
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class OpenApiGlobalReturnHandler extends GlobalReturnHandler {
|
||||
|
||||
@Override
|
||||
public boolean supports(@NonNull MethodParameter returnType, @NonNull Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
Class<?> containingClass = returnType.getContainingClass();
|
||||
if (containingClass != null && containingClass.getName().startsWith("org.springdoc.")) {
|
||||
return false;
|
||||
}
|
||||
return super.supports(returnType, converterType);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@ import com.imyeyu.api.modules.system.vo.AsyncTaskView;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -26,6 +29,7 @@ import java.util.List;
|
||||
* @author 夜雨
|
||||
* @version 2022-08-13 19:38
|
||||
*/
|
||||
@Tag(name = "系统-异步任务", description = "异步任务查询、控制与进度订阅接口")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -36,9 +40,12 @@ public class AsyncTaskController {
|
||||
private final AsyncTaskEventService eventService;
|
||||
private final UserLoginService userLoginService;
|
||||
|
||||
@Operation(summary = "创建调试任务", description = "创建一个持续指定秒数的调试任务,返回任务 ID。")
|
||||
@AOPLog
|
||||
@PostMapping("/debug")
|
||||
public String debug(@RequestParam("second") Integer second) {
|
||||
public String debug(
|
||||
@Parameter(description = "任务持续秒数,默认 60")
|
||||
@RequestParam(value = "second", required = false) Integer second) {
|
||||
if (second == null) {
|
||||
second = 60;
|
||||
}
|
||||
@@ -47,8 +54,11 @@ public class AsyncTaskController {
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取任务详情")
|
||||
@GetMapping("/detail")
|
||||
public AbstractAsyncTask detail(@RequestParam ("uuid") String uuid) {
|
||||
public AbstractAsyncTask detail(
|
||||
@Parameter(description = "任务 ID", required = true)
|
||||
@RequestParam("uuid") String uuid) {
|
||||
return service.getAsyncTask(uuid);
|
||||
}
|
||||
|
||||
@@ -61,32 +71,45 @@ public class AsyncTaskController {
|
||||
* @param uuid 任务 ID
|
||||
* @return SSE 事件流
|
||||
*/
|
||||
@Operation(summary = "订阅任务事件", description = "以 SSE 推送任务状态与进度,任务结束后服务端主动关闭连接。")
|
||||
@IgnoreGlobalReturn
|
||||
@GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public SseEmitter events(@RequestParam("uuid") String uuid) {
|
||||
public SseEmitter events(
|
||||
@Parameter(description = "任务 ID", required = true)
|
||||
@RequestParam("uuid") String uuid) {
|
||||
return eventService.subscribe(uuid, userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
|
||||
@Operation(summary = "获取任务列表")
|
||||
@PostMapping("/list")
|
||||
public List<AsyncTaskView> list() {
|
||||
return service.listAllView();
|
||||
}
|
||||
|
||||
@Operation(summary = "启动任务")
|
||||
@AOPLog
|
||||
@PostMapping("/start")
|
||||
public void start(@RequestParam ("uuid") String uuid) {
|
||||
public void start(
|
||||
@Parameter(description = "任务 ID", required = true)
|
||||
@RequestParam("uuid") String uuid) {
|
||||
service.start(uuid);
|
||||
}
|
||||
|
||||
@Operation(summary = "暂停任务")
|
||||
@AOPLog
|
||||
@PostMapping("/pause")
|
||||
public void pause(@RequestParam ("uuid") String uuid) {
|
||||
public void pause(
|
||||
@Parameter(description = "任务 ID", required = true)
|
||||
@RequestParam("uuid") String uuid) {
|
||||
service.pause(uuid);
|
||||
}
|
||||
|
||||
@Operation(summary = "中断任务")
|
||||
@AOPLog
|
||||
@PostMapping("/interrupt")
|
||||
public void interrupt(@RequestParam ("uuid") String uuid) {
|
||||
public void interrupt(
|
||||
@Parameter(description = "任务 ID", required = true)
|
||||
@RequestParam("uuid") String uuid) {
|
||||
service.interrupt(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ import com.imyeyu.api.modules.user.service.PermissionChecker;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -31,6 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* @author 夜雨
|
||||
* @version 2026-11-24
|
||||
*/
|
||||
@Tag(name = "系统-文件归档", description = "文件压缩、解压、复制与移动异步任务接口")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/system/file")
|
||||
@@ -41,6 +44,7 @@ public class FileArchiveController {
|
||||
private final UserLoginService userLoginService;
|
||||
private final PermissionChecker permissionChecker;
|
||||
|
||||
@Operation(summary = "创建 ZIP 压缩任务", description = "将 list 中的文件或目录压缩到 to,返回异步任务 ID。")
|
||||
@AOPLog
|
||||
@OperationAudit(AuditOperation.FILE_ARCHIVE)
|
||||
@RequestRateLimit
|
||||
@@ -52,6 +56,7 @@ public class FileArchiveController {
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
@Operation(summary = "创建 ZIP 解压任务", description = "将 file 解压到 to,返回异步任务 ID。")
|
||||
@AOPLog
|
||||
@OperationAudit(AuditOperation.FILE_ARCHIVE)
|
||||
@RequestRateLimit
|
||||
@@ -63,6 +68,7 @@ public class FileArchiveController {
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
@Operation(summary = "创建 TAR 压缩任务", description = "将 list 中的文件或目录打包到 to,返回异步任务 ID。")
|
||||
@AOPLog
|
||||
@OperationAudit(AuditOperation.FILE_ARCHIVE)
|
||||
@RequestRateLimit
|
||||
@@ -74,6 +80,7 @@ public class FileArchiveController {
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
@Operation(summary = "创建 TAR 解压任务", description = "将 file 解压到 to,返回异步任务 ID。")
|
||||
@AOPLog
|
||||
@OperationAudit(AuditOperation.FILE_ARCHIVE)
|
||||
@RequestRateLimit
|
||||
@@ -85,6 +92,7 @@ public class FileArchiveController {
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
@Operation(summary = "创建移动任务", description = "将 list 中的文件或目录移动到 to,返回异步任务 ID。")
|
||||
@AOPLog
|
||||
@OperationAudit(AuditOperation.FILE_ARCHIVE)
|
||||
@RequestRateLimit
|
||||
@@ -96,6 +104,7 @@ public class FileArchiveController {
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
@Operation(summary = "创建复制任务", description = "将 list 中的文件或目录复制到 to,返回异步任务 ID。")
|
||||
@AOPLog
|
||||
@OperationAudit(AuditOperation.FILE_ARCHIVE)
|
||||
@RequestRateLimit
|
||||
|
||||
@@ -5,6 +5,9 @@ import com.imyeyu.api.bean.CorePermissionCode;
|
||||
import com.imyeyu.api.modules.system.service.FileContentService;
|
||||
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -20,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* @author 夜雨
|
||||
* @version 2026-11-24
|
||||
*/
|
||||
@Tag(name = "系统-文件内容", description = "文件内容读取、下载与预览接口")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/system/file")
|
||||
@@ -27,27 +31,39 @@ public class FileContentController {
|
||||
|
||||
private final FileContentService contentService;
|
||||
|
||||
@Operation(summary = "读取文件", description = "以内联方式输出文件内容,支持 Range 与条件请求。")
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@IgnoreGlobalReturn
|
||||
@GetMapping("/read/{*path}")
|
||||
public void read(HttpServletRequest req, HttpServletResponse resp, @PathVariable("path") String path) {
|
||||
public void read(
|
||||
HttpServletRequest req, HttpServletResponse resp,
|
||||
@Parameter(description = "文件虚拟路径,以 / 开头", required = true)
|
||||
@PathVariable("path") String path) {
|
||||
FileBinaryResponder.serve(resp, () -> contentService.serve(req, resp, path, false));
|
||||
}
|
||||
|
||||
@Operation(summary = "下载文件", description = "以附件方式输出文件内容,支持 Range 与 HEAD 请求。")
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@IgnoreGlobalReturn
|
||||
@RequestMapping(value = "/download/{*path}", method = {RequestMethod.GET, RequestMethod.HEAD})
|
||||
public void download(HttpServletRequest req, HttpServletResponse resp, @PathVariable("path") String path) {
|
||||
public void download(
|
||||
HttpServletRequest req, HttpServletResponse resp,
|
||||
@Parameter(description = "文件虚拟路径,以 / 开头", required = true)
|
||||
@PathVariable("path") String path) {
|
||||
FileBinaryResponder.serve(resp, () -> contentService.serve(req, resp, path, true));
|
||||
}
|
||||
|
||||
@Operation(summary = "预览文件", description = "图片和视频返回 PNG 缩略图,PDF 与文本返回原始内容。")
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@IgnoreGlobalReturn
|
||||
@GetMapping("/preview/{*path}")
|
||||
public void preview(HttpServletRequest req, HttpServletResponse resp, @PathVariable("path") String path) {
|
||||
public void preview(
|
||||
HttpServletRequest req, HttpServletResponse resp,
|
||||
@Parameter(description = "文件虚拟路径,以 / 开头", required = true)
|
||||
@PathVariable("path") String path) {
|
||||
FileBinaryResponder.serve(resp, () -> contentService.preview(req, resp, path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ import com.imyeyu.api.modules.user.service.PermissionChecker;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -33,6 +36,7 @@ import java.util.List;
|
||||
* @author 夜雨
|
||||
* @version 2022-01-01 20:00
|
||||
*/
|
||||
@Tag(name = "系统-文件", description = "文件元数据、目录与检索接口")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/system/file")
|
||||
@@ -44,22 +48,29 @@ public class FileController {
|
||||
private final UserLoginService userLoginService;
|
||||
private final PermissionChecker permissionChecker;
|
||||
|
||||
@Operation(summary = "获取文件属性", description = "返回指定路径的文件或目录属性。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@GetMapping("/object/{*path}")
|
||||
public ServerFile object(@PathVariable("path") String path) {
|
||||
public ServerFile object(
|
||||
@Parameter(description = "文件虚拟路径,以 / 开头", required = true)
|
||||
@PathVariable("path") String path) {
|
||||
return fileService.object(path);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取目录列表", description = "返回指定目录下的文件与子目录列表。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@GetMapping("/list")
|
||||
public List<ServerFile> list(@RequestParam(defaultValue = "/") String path) {
|
||||
public List<ServerFile> list(
|
||||
@Parameter(description = "目录虚拟路径,默认为根目录 /")
|
||||
@RequestParam(defaultValue = "/") String path) {
|
||||
return fileService.list(path);
|
||||
}
|
||||
|
||||
@Operation(summary = "搜索文件", description = "在指定目录下按关键字搜索,返回匹配项、是否截断及扫描数量。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@@ -68,22 +79,29 @@ public class FileController {
|
||||
return fileService.search(request.path(), request.keyword());
|
||||
}
|
||||
|
||||
@Operation(summary = "判断路径是否存在")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@GetMapping("/exist")
|
||||
public boolean exist(@RequestParam String path) {
|
||||
public boolean exist(
|
||||
@Parameter(description = "文件或目录虚拟路径", required = true)
|
||||
@RequestParam String path) {
|
||||
return fileService.exists(path);
|
||||
}
|
||||
|
||||
@Operation(summary = "计算文件 SHA-256", description = "同步计算单个文件的 SHA-256,大文件请谨慎调用。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@GetMapping("/hash")
|
||||
public FileService.FileHash hash(@RequestParam String path) {
|
||||
public FileService.FileHash hash(
|
||||
@Parameter(description = "文件虚拟路径", required = true)
|
||||
@RequestParam String path) {
|
||||
return fileService.hash(path);
|
||||
}
|
||||
|
||||
@Operation(summary = "统计目录大小", description = "创建异步任务统计目录大小,返回任务 ID,可通过异步任务接口订阅进度。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@@ -96,6 +114,7 @@ public class FileController {
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
@Operation(summary = "创建目录")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_WRITE)
|
||||
@@ -104,6 +123,7 @@ public class FileController {
|
||||
return fileService.mkdir(request.path(), request.name());
|
||||
}
|
||||
|
||||
@Operation(summary = "重命名或移动", description = "将文件或目录从 from 重命名或移动到 to。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_WRITE)
|
||||
|
||||
@@ -12,6 +12,10 @@ import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.IgnoreGlobalReturn;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirements;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -34,6 +38,7 @@ import java.util.List;
|
||||
* @author 夜雨
|
||||
* @version 2026-11-24
|
||||
*/
|
||||
@Tag(name = "系统-文件分享", description = "文件分享创建、管理与公开下载接口")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/system/file")
|
||||
@@ -44,6 +49,7 @@ public class FileShareController {
|
||||
private final UserLoginService userLoginService;
|
||||
private final LoggerService loggerService;
|
||||
|
||||
@Operation(summary = "创建文件分享", description = "对指定文件创建分享链接,可设置访问密码、过期时间与最大下载次数。")
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission({CorePermissionCode.FILE_READ, CorePermissionCode.FILE_SHARE})
|
||||
@PostMapping("/share")
|
||||
@@ -51,6 +57,7 @@ public class FileShareController {
|
||||
return shareService.create(request.path(), request.password(), request.expiresAt(), request.maxDownloads(), userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
|
||||
@Operation(summary = "获取分享列表")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_SHARE)
|
||||
@@ -59,19 +66,29 @@ public class FileShareController {
|
||||
return shareService.list();
|
||||
}
|
||||
|
||||
@Operation(summary = "取消文件分享")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_SHARE)
|
||||
@DeleteMapping("/share/{id}")
|
||||
public FileShare revokeShare(@PathVariable String id) {
|
||||
public FileShare revokeShare(
|
||||
@Parameter(description = "分享记录 ID", required = true)
|
||||
@PathVariable String id) {
|
||||
return shareService.revoke(id);
|
||||
}
|
||||
|
||||
/// 公开分享下载,只校验令牌与密码,不要求登录权限。
|
||||
@Operation(summary = "下载分享文件", description = "公开接口,仅校验分享令牌与访问密码,不要求登录。")
|
||||
@SecurityRequirements
|
||||
@RequestRateLimit
|
||||
@IgnoreGlobalReturn
|
||||
@RequestMapping(value = "/share/{token}/download", method = {RequestMethod.GET, RequestMethod.HEAD})
|
||||
public void downloadShare(@PathVariable String token, @RequestParam(required = false) String password, HttpServletRequest req, HttpServletResponse resp) {
|
||||
public void downloadShare(
|
||||
@Parameter(description = "分享令牌", required = true)
|
||||
@PathVariable String token,
|
||||
@Parameter(description = "分享访问密码,未设置密码时省略")
|
||||
@RequestParam(required = false) String password,
|
||||
HttpServletRequest req, HttpServletResponse resp) {
|
||||
FileBinaryResponder.serve(resp, () -> {
|
||||
boolean consume = !"HEAD".equalsIgnoreCase(req.getMethod());
|
||||
FileShare share = shareService.open(token, password, consume);
|
||||
|
||||
@@ -10,6 +10,9 @@ import com.imyeyu.api.modules.system.vo.IdRequest;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
@@ -28,6 +31,7 @@ import java.util.List;
|
||||
* @author 夜雨
|
||||
* @version 2026-11-24
|
||||
*/
|
||||
@Tag(name = "系统-文件回收站", description = "文件删除、恢复与回收站清理接口")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/system/file")
|
||||
@@ -36,6 +40,7 @@ public class FileTrashController {
|
||||
private final FileTrashService trashService;
|
||||
private final UserLoginService userLoginService;
|
||||
|
||||
@Operation(summary = "删除到回收站", description = "将 list 中的文件或目录移入回收站,返回删除记录。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_DELETE)
|
||||
@@ -44,6 +49,7 @@ public class FileTrashController {
|
||||
return trashService.trash(request.list(), userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
|
||||
@Operation(summary = "获取回收站列表")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_READ)
|
||||
@@ -52,6 +58,7 @@ public class FileTrashController {
|
||||
return trashService.list();
|
||||
}
|
||||
|
||||
@Operation(summary = "恢复回收站文件", description = "将回收站记录恢复到删除前的路径。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_WRITE)
|
||||
@@ -60,14 +67,18 @@ public class FileTrashController {
|
||||
return trashService.restore(request.id());
|
||||
}
|
||||
|
||||
@Operation(summary = "彻底删除回收站记录")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_DELETE)
|
||||
@DeleteMapping("/trash/{id}")
|
||||
public void purge(@PathVariable String id) {
|
||||
public void purge(
|
||||
@Parameter(description = "回收站记录 ID", required = true)
|
||||
@PathVariable String id) {
|
||||
trashService.purge(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "清空回收站", description = "彻底删除回收站中的全部记录,返回清理数量。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_DELETE)
|
||||
|
||||
@@ -8,6 +8,9 @@ import com.imyeyu.api.modules.system.vo.UploadCompleteRequest;
|
||||
import com.imyeyu.api.modules.system.vo.UploadInitRequest;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -24,6 +27,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
* @author 夜雨
|
||||
* @version 2026-11-24
|
||||
*/
|
||||
@Tag(name = "系统-文件上传", description = "文件直传与分片上传接口")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/system/file")
|
||||
@@ -31,19 +35,25 @@ public class FileUploadController {
|
||||
|
||||
private final FileUploadService uploadService;
|
||||
|
||||
@Operation(summary = "上传文件", description = "以 multipart/form-data 直接上传文件,overwrite 为 true 时覆盖同名文件。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_WRITE)
|
||||
@PostMapping("/upload")
|
||||
public ServerFile upload(
|
||||
@Parameter(description = "目标目录虚拟路径", required = true)
|
||||
@RequestParam String path,
|
||||
@Parameter(description = "保存的文件名", required = true)
|
||||
@RequestParam String name,
|
||||
@Parameter(description = "是否覆盖同名文件,默认 false")
|
||||
@RequestParam(defaultValue = "false") boolean overwrite,
|
||||
@Parameter(description = "文件内容", required = true)
|
||||
@RequestPart("file") MultipartFile file
|
||||
) {
|
||||
return uploadService.upload(path, name, file, overwrite);
|
||||
}
|
||||
|
||||
@Operation(summary = "初始化分片上传", description = "按文件大小与 SHA-256 创建上传会话,返回分片大小与分片数量。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_WRITE)
|
||||
@@ -52,13 +62,21 @@ public class FileUploadController {
|
||||
return uploadService.init(request.path(), request.name(), request.size(), request.sha256());
|
||||
}
|
||||
|
||||
@Operation(summary = "上传分片", description = "上传指定索引的分片,分片索引从 0 开始。")
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_WRITE)
|
||||
@PostMapping("/upload/chunk")
|
||||
public void uploadChunk(@RequestParam String uploadId, @RequestParam int index, @RequestPart("file") MultipartFile file) {
|
||||
public void uploadChunk(
|
||||
@Parameter(description = "上传会话 ID", required = true)
|
||||
@RequestParam String uploadId,
|
||||
@Parameter(description = "分片索引,从 0 开始", required = true)
|
||||
@RequestParam int index,
|
||||
@Parameter(description = "分片内容", required = true)
|
||||
@RequestPart("file") MultipartFile file) {
|
||||
uploadService.chunk(uploadId, index, file);
|
||||
}
|
||||
|
||||
@Operation(summary = "完成分片上传", description = "合并全部分片并校验 SHA-256,返回最终文件属性。")
|
||||
@AOPLog
|
||||
@RequestRateLimit
|
||||
@RequireCorePermission(CorePermissionCode.FILE_WRITE)
|
||||
|
||||
Reference in New Issue
Block a user