From 664cae654867b528ea339f187ebe290cb04d6fcf Mon Sep 17 00:00:00 2001
From: xyc <jc_xiong@hotmail.com>
Date: 星期四, 27 八月 2026 18:41:21 +0800
Subject: [PATCH] docs: 关机前交接——运行状态、待验证项、外置配置要点
---
traffic-audit-server/src/main/java/com/trafficaudit/config/TemplateDownloadController.java | 64 ++++++++++++++++++++++++++++++++
1 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/config/TemplateDownloadController.java b/traffic-audit-server/src/main/java/com/trafficaudit/config/TemplateDownloadController.java
new file mode 100644
index 0000000..662cbb4
--- /dev/null
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/config/TemplateDownloadController.java
@@ -0,0 +1,64 @@
+package com.trafficaudit.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+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 java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
+
+/**
+ * 鏁版嵁瀵煎叆椤点�屼笅杞芥ā鏉裤�嶏細/api/templates/** -> docs 鐩綍涓嬬殑妯℃澘鏂囦欢銆�
+ * 鐢� Controller 鑰岄潪闈欐�佽祫婧愭槧灏勶紝渚夸簬璁剧疆涓枃鏂囦欢鍚嶇殑涓嬭浇澶村苟闃茶矾寰勭┛瓒娿��
+ */
+@RestController
+@RequestMapping("/api/templates")
+public class TemplateDownloadController {
+
+ @Value("${docs.template-root:docs}")
+ private String templateRoot;
+
+ @GetMapping("/{*path}")
+ public ResponseEntity<Resource> download(@PathVariable String path) throws IOException {
+ File file = resolveTemplateFile(path);
+ if (file == null) {
+ return ResponseEntity.notFound().build();
+ }
+ String encoded = URLEncoder.encode(file.getName(), "UTF-8").replace("+", "%20");
+ return ResponseEntity.ok()
+ .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename*=UTF-8''" + encoded)
+ .contentType(MediaType.APPLICATION_OCTET_STREAM)
+ .contentLength(file.length())
+ .body(new FileSystemResource(file));
+ }
+
+ /** 妯℃澘瀹氫綅锛氶厤缃洰褰� 鈫� user.dir 鈫� user.dir/.. 閫愮骇鍥為��锛堜笌鎶ヨ〃妯″潡涓�鑷达級锛屽苟闃茶矾寰勭┛瓒� */
+ private File resolveTemplateFile(String rel) throws IOException {
+ String r = rel;
+ while (r.startsWith("./")) r = r.substring(2);
+ if (r.contains("..")) {
+ return null;
+ }
+ String[] roots = {
+ templateRoot,
+ System.getProperty("user.dir") + "/" + templateRoot,
+ System.getProperty("user.dir") + "/../" + templateRoot
+ };
+ for (String root : roots) {
+ if (root == null || root.trim().isEmpty()) continue;
+ File f = new File(root, r);
+ if (f.exists() && f.isFile()) {
+ return f.getCanonicalFile();
+ }
+ }
+ return null;
+ }
+}
--
Gitblit v1.9.1