-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDocsResolveController.java
More file actions
42 lines (36 loc) · 1.46 KB
/
DocsResolveController.java
File metadata and controls
42 lines (36 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.involutionhell.backend.docs.controller;
import com.involutionhell.backend.docs.service.DocPathService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.net.URI;
import java.util.Optional;
/**
* 文档路径解析端点。
*
* GET /api/docs/resolve?path=/zh/docs/community/dev-tips/git101
* → 301 Location: /docs/community/dev-tips/git101 (canonical,无 locale)
* → 404(路径不认识)
*
* canonical 不带 locale 前缀,前端 Block 3 负责拼 locale 后再跳转。
* 公开端点,无需登录(已加入 SaTokenConfigure 白名单)。
*/
@RestController
public class DocsResolveController {
private final DocPathService docPathService;
public DocsResolveController(DocPathService docPathService) {
this.docPathService = docPathService;
}
@GetMapping("/api/docs/resolve")
public ResponseEntity<Void> resolve(@RequestParam String path) {
Optional<String> canonical = docPathService.resolveCanonical(path);
if (canonical.isPresent()) {
return ResponseEntity.status(HttpStatus.MOVED_PERMANENTLY)
.location(URI.create(canonical.get()))
.build();
}
return ResponseEntity.notFound().build();
}
}