-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathMarkDownController.java
More file actions
145 lines (130 loc) · 6.04 KB
/
MarkDownController.java
File metadata and controls
145 lines (130 loc) · 6.04 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package com.jmal.clouddisk.controller.rest;
import cn.hutool.core.text.CharSequenceUtil;
import com.jmal.clouddisk.annotation.LogOperatingFun;
import com.jmal.clouddisk.annotation.Permission;
import com.jmal.clouddisk.model.ArticleDTO;
import com.jmal.clouddisk.model.ArticleParamDTO;
import com.jmal.clouddisk.model.LogOperation;
import com.jmal.clouddisk.model.UploadApiParamDTO;
import com.jmal.clouddisk.model.UploadImageDTO;
import com.jmal.clouddisk.model.file.FileDocument;
import com.jmal.clouddisk.oss.web.WebOssService;
import com.jmal.clouddisk.service.IMarkdownService;
import com.jmal.clouddisk.service.IUserService;
import com.jmal.clouddisk.service.impl.CommonFileService;
import com.jmal.clouddisk.util.CaffeineUtil;
import com.jmal.clouddisk.util.ResponseResult;
import com.jmal.clouddisk.util.ResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
/**
* @author jmal
* @Description markdown
*/
@Controller
@Tag(name = "markdown管理")
@RestController
@RequiredArgsConstructor
public class MarkDownController {
private final IMarkdownService markdownService;
private final WebOssService webOssService;
private final CommonFileService commonFileService;
private final IUserService userService;
@Operation(summary = "获取markdown内容")
@GetMapping("/markdown/p")
@LogOperatingFun(logType = LogOperation.Type.BROWSE)
public ResponseResult<?> getMarkDownContent(ArticleDTO articleDTO, Integer pageIndex, Integer pageSize) {
articleDTO.setPageIndex(pageIndex);
articleDTO.setPageSize(pageSize);
if (CharSequenceUtil.isBlank(articleDTO.getMark())) {
return markdownService.getMarkdownList(articleDTO);
} else {
return markdownService.getMarkDownOne(articleDTO);
}
}
@Operation(summary = "编辑文档(根据fileId)")
@PostMapping("/markdown/edit")
@Permission("cloud:file:update")
@LogOperatingFun(logType = LogOperation.Type.OPERATION)
public ResponseResult<Object> editMarkdown(@RequestBody @Validated ArticleParamDTO upload) {
return markdownService.editMarkdown(upload);
}
@Operation(summary = "修改文档排序")
@PostMapping("/markdown/sort")
@Permission("cloud:file:update")
@LogOperatingFun
public ResponseResult<Object> sortMarkdown(@RequestBody String[] fileIdList) {
return markdownService.sortMarkdown(Arrays.asList(fileIdList));
}
@Operation(summary = "删除草稿")
@DeleteMapping("/markdown/deleteDraft")
@Permission("cloud:file:delete")
@LogOperatingFun(logType = LogOperation.Type.OPERATION)
public ResponseResult<Object> deleteDraft(@RequestParam String fileId, @RequestParam String username) {
return markdownService.deleteDraft(fileId, username);
}
@Operation(summary = "编辑文档(根据path)")
@PostMapping("/markdown/edit1")
@Permission("cloud:file:update")
public ResponseResult<Object> editTextByPath(@RequestBody UploadApiParamDTO upload) {
ResultUtil.checkParamIsNull(upload.getUsername(), upload.getUserId(), upload.getRelativePath(),
upload.getContentText());
if (!CharSequenceUtil.isBlank(upload.getMountFileId())) {
FileDocument fileDocument = commonFileService.getById(upload.getMountFileId());
upload.setUserId(fileDocument.getUserId());
upload.setUsername(userService.getUserNameById(fileDocument.getUserId()));
upload.setRelativePath(fileDocument.getPath() + fileDocument.getName());
upload.setOperationPermissionList(fileDocument.getOperationPermissionList());
}
Path prePth = Paths.get(upload.getUsername(), upload.getRelativePath());
String ossPath = CaffeineUtil.getOssPath(prePth);
if (ossPath != null) {
webOssService.putObjectText(ossPath, prePth, upload.getContentText());
return ResultUtil.success();
}
return markdownService.editTextByPath(upload);
}
@Operation(summary = "上传文档里的图片")
@PostMapping("/upload-markdown-image")
@Permission("cloud:file:upload")
public ResponseResult<Object> uploadMarkdownImage(UploadImageDTO upload) {
if (CharSequenceUtil.isBlank(upload.getUserId()) || CharSequenceUtil.isBlank(upload.getUsername())) {
return ResultUtil.warning("参数里缺少 userId 或 username");
}
return markdownService.uploadMarkdownImage(upload);
}
@Operation(summary = "上传文档里链接图片")
@PostMapping("/upload-markdown-link-image")
@Permission("cloud:file:upload")
@LogOperatingFun
public ResponseResult<Object> uploadMarkdownLinkImage(HttpServletRequest request,
@RequestBody UploadImageDTO uploadImageDTO) {
String userId = uploadImageDTO.getUserId();
String username = uploadImageDTO.getUsername();
if (CharSequenceUtil.isBlank(userId)) {
userId = request.getHeader("userId");
uploadImageDTO.setUserId(userId);
}
if (CharSequenceUtil.isBlank(username)) {
username = request.getHeader("username");
uploadImageDTO.setUsername(username);
}
if (CharSequenceUtil.isBlank(userId) || CharSequenceUtil.isBlank(username)) {
return ResultUtil.warning("请求头里或参数里必须含有userId和username");
}
return markdownService.uploadMarkdownLinkImage(uploadImageDTO);
}
}