feat:change config
This commit is contained in:
parent
d7523f9419
commit
88914c29a3
@ -1,5 +1,8 @@
|
||||
package vin.vio.collaboraonline.controller;
|
||||
|
||||
import cn.hutool.log.Log;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -11,7 +14,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
import vin.vio.collaboraonline.model.WopiFile;
|
||||
import vin.vio.collaboraonline.service.FileService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@ -22,7 +24,6 @@ import java.util.Map;
|
||||
* @Created: by ZZSLL
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/wopi")
|
||||
public class WopiController {
|
||||
@ -33,10 +34,16 @@ public class WopiController {
|
||||
@Value("${collabora.host-server-addr}")
|
||||
private String host;
|
||||
|
||||
private static final Log log = LogFactory.get();
|
||||
|
||||
// 检查文件信息
|
||||
@GetMapping("/files/{fileId}")
|
||||
public ResponseEntity<?> checkFileInfo(@PathVariable String fileId, @RequestParam(required = false) String access_token) {
|
||||
public ResponseEntity<?> checkFileInfo(@PathVariable String fileId, @RequestParam(required = false) String access_token, HttpServletRequest request) {
|
||||
|
||||
|
||||
log.info("=========checkFileInfo===========start");
|
||||
log.info("{} {}", request.getPathInfo(), request.getMethod());
|
||||
log.info("{}", fileId);
|
||||
WopiFile file = fileService.getFileInfo(fileId);
|
||||
if (file == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
@ -44,13 +51,15 @@ public class WopiController {
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(createCheckFileInfoResponse(file));
|
||||
.body(createCheckFileInfoResponse(file, fileId));
|
||||
}
|
||||
|
||||
// 获取文件内容
|
||||
@GetMapping("/files/{fileId}/contents")
|
||||
public ResponseEntity<Resource> getFile(@PathVariable String fileId) {
|
||||
|
||||
public ResponseEntity<Resource> getFile(@PathVariable String fileId, HttpServletRequest request) {
|
||||
log.info("=========getFile===========start");
|
||||
log.info("{} {}", request.getPathInfo(), request.getMethod());
|
||||
log.info("{}", fileId);
|
||||
Resource fileResource = fileService.loadFileAsResource(fileId);
|
||||
if (fileResource == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
@ -64,15 +73,18 @@ public class WopiController {
|
||||
// 保存文件
|
||||
@RequestMapping(value = "/files/{fileId}/contents", method = {RequestMethod.POST, RequestMethod.PUT})
|
||||
public ResponseEntity<Void> putFile(
|
||||
@PathVariable String fileId, InputStream contentStream) {
|
||||
|
||||
@PathVariable String fileId, InputStream contentStream, HttpServletRequest request) {
|
||||
log.info("=========putFile===========start");
|
||||
log.info("{} {}", request.getPathInfo(), request.getMethod());
|
||||
log.info("{}", fileId);
|
||||
boolean success = fileService.saveFile(fileId, contentStream);
|
||||
return success ?
|
||||
ResponseEntity.ok().build() :
|
||||
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
|
||||
private Map<String, Object> createCheckFileInfoResponse(WopiFile file) {
|
||||
private Map<String, Object> createCheckFileInfoResponse(WopiFile file, String fileId) {
|
||||
log.info("=========createCheckFileInfoResponse===========start");
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
|
||||
// 强制开启所有编辑权限
|
||||
@ -96,7 +108,7 @@ public class WopiController {
|
||||
response.put("DisableCopy", false);
|
||||
|
||||
// 添加必要协议字段
|
||||
response.put("HostEditUrl", host + "/wopi/files/"+file.getFileName() + "?access_token=asdasd");
|
||||
response.put("HostEditUrl", host + "/wopi/files/" + fileId + "?access_token=asdasd");
|
||||
response.put("PostMessageOrigin", host); // 本地测试用
|
||||
|
||||
// 测试环境特殊配置
|
||||
@ -104,10 +116,11 @@ public class WopiController {
|
||||
response.put("BreadcrumbBrandUrl", host);
|
||||
response.put("BreadcrumbDocName", file.getFileName());
|
||||
|
||||
response.put("UserLogo", "https://web.wmyun.com/favicon.ico");
|
||||
// 绕过版本检查
|
||||
// response.put("LastModifiedTime", "2020-01-01T00:00:00Z");
|
||||
// response.put("Version", "test_version");
|
||||
|
||||
log.info("{}", response);
|
||||
return response;
|
||||
}
|
||||
}
|
@ -13,10 +13,7 @@ import org.springframework.stereotype.Service;
|
||||
import vin.vio.collaboraonline.exception.AllKingdeeException;
|
||||
import vin.vio.collaboraonline.kingdee.AuthService;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -82,6 +79,10 @@ public class KingdeeService {
|
||||
String url = data0.getString("url");
|
||||
String name = data0.getString("name");
|
||||
savePath = BASE_DIR + "/" + name;
|
||||
File existFile = new File(savePath);
|
||||
if (existFile.exists()) {
|
||||
existFile.delete();
|
||||
}
|
||||
downloadFile(url, savePath);
|
||||
}
|
||||
} else {
|
||||
|
@ -22,5 +22,7 @@ kingdee:
|
||||
attachKey: 'attachmentpanel'
|
||||
|
||||
collabora:
|
||||
host-server-addr: https://web-api.wmyun.com/yem
|
||||
file-storage-path: /work/projects/collabora-api/yem/file
|
||||
# host-server-addr: https://web-api.wmyun.com/yem
|
||||
# file-storage-path: /work/projects/collabora-api/yem/file
|
||||
host-server-addr: http://192.168.3.104:8080
|
||||
file-storage-path: E:\Code\CollaboraOnline\files
|
Loading…
Reference in New Issue
Block a user