feat(system): 支持后台维护三语协议
This commit is contained in:
1 parent
16ba79a336
commit
22edf34ff1
12 files changed
+470
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.app.controller;
|
||||
|
||||
import com.fruitshorts.system.service.LegalDocumentService;
|
||||
import com.fruitshorts.system.service.LegalPages;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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.RestController;
|
||||
|
||||
/**
|
||||
* 协议公开页。客户端按当前语言打开 /privacy/zh 或 /terms/en,不需要登录。
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class LegalPageController {
|
||||
|
||||
private static final MediaType HTML = MediaType.parseMediaType("text/html;charset=UTF-8");
|
||||
|
||||
private final LegalDocumentService legalDocumentService;
|
||||
|
||||
/** 隐私协议。语言只接受 zh、en、id。 */
|
||||
@GetMapping("/" + LegalPages.PATH_PRIVACY + "/{lang}")
|
||||
public ResponseEntity<String> privacy(@PathVariable String lang) {
|
||||
return page(LegalPages.PATH_PRIVACY, lang);
|
||||
}
|
||||
|
||||
/** 服务条款。语言只接受 zh、en、id。 */
|
||||
@GetMapping("/" + LegalPages.PATH_TERMS + "/{lang}")
|
||||
public ResponseEntity<String> terms(@PathVariable String lang) {
|
||||
return page(LegalPages.PATH_TERMS, lang);
|
||||
}
|
||||
|
||||
private ResponseEntity<String> page(String path, String lang) {
|
||||
String html = legalDocumentService.render(path, lang);
|
||||
if (html == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
return ResponseEntity.ok().contentType(HTML).body(html);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user