feat: configurable download origin via gmp.download-origin

This commit is contained in:
agentuser
2026-05-11 17:34:36 +08:00
parent 2f6c68a2e2
commit b53f43fb67
3 changed files with 15 additions and 5 deletions
+4 -3
View File
@@ -42,7 +42,7 @@ paths:
code: 0 code: 0
msg: "success" msg: "success"
data: data:
url: "/api/docx/download?id=d8d4122719c8465ea75ab62b37f6ce10" url: "http://localhost:6666/api/docx/download?id=d8d4122719c8465ea75ab62b37f6ce10"
fileName: "annualReport.docx" fileName: "annualReport.docx"
"400": "400":
description: 参数校验失败(exportId 为空 / businessData 为空) description: 参数校验失败(exportId 为空 / businessData 为空)
@@ -175,8 +175,9 @@ components:
properties: properties:
url: url:
type: string type: string
description: 文件下载路径(pathname only,无 origin) format: uri
example: "/api/docx/download?id=d8d4122719c8465ea75ab62b37f6ce10" description: 文件下载 URL(由 gmp.download-origin 配置 + 路径组成,未配置则只返回路径)
example: "http://localhost:6666/api/docx/download?id=d8d4122719c8465ea75ab62b37f6ce10"
fileName: fileName:
type: string type: string
description: 文件名 description: 文件名
@@ -2,6 +2,7 @@ package com.gmp.mock.controller;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@@ -26,10 +27,13 @@ public class DocxController {
private final DocxService docxService; private final DocxService docxService;
private final FileCacheService fileCache; private final FileCacheService fileCache;
private final String downloadOrigin;
public DocxController(DocxService docxService, FileCacheService fileCache) { public DocxController(DocxService docxService, FileCacheService fileCache,
@Value("${gmp.download-origin:}") String downloadOrigin) {
this.docxService = docxService; this.docxService = docxService;
this.fileCache = fileCache; this.fileCache = fileCache;
this.downloadOrigin = downloadOrigin;
} }
/** /**
@@ -51,7 +55,9 @@ public class DocxController {
) { ) {
CachedResult result = docxService.export(request.getExportId(), request.getBusinessData()); CachedResult result = docxService.export(request.getExportId(), request.getBusinessData());
String url = "/api/docx/download?id=" + result.key(); String url = downloadOrigin.isBlank()
? "/api/docx/download?id=" + result.key()
: downloadOrigin + "/api/docx/download?id=" + result.key();
ExportResultData data = new ExportResultData(url, result.fileName()); ExportResultData data = new ExportResultData(url, result.fileName());
return ResponseEntity.ok(ApiResponse.ok(data)); return ResponseEntity.ok(ApiResponse.ok(data));
+3
View File
@@ -4,3 +4,6 @@ server:
spring: spring:
application: application:
name: gmp-mock-service name: gmp-mock-service
gmp:
download-origin: http://193.112.146.124:6666