集成onlyoffice
This commit is contained in:
parent
a4a0f8c5c5
commit
a04e5a7c4a
|
|
@ -25,9 +25,6 @@ public class DocumentController {
|
|||
@RequestParam(defaultValue = "view") String mode) {
|
||||
try {
|
||||
Map<String, Object> config = onlyOfficeService.getConfigWithToken(fileId, fileName, mode);
|
||||
// String token = onlyOfficeService.getConfigWithToken(fileId, fileName, mode);
|
||||
// Map<String, String> response = new HashMap<>();
|
||||
// response.put("token", token);
|
||||
return AjaxResult.success(config);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@
|
|||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringWeb模块 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ public class SysFile
|
|||
*/
|
||||
private String url;
|
||||
|
||||
/**文件访问路径-公共权限下访问的路径*/
|
||||
private String filePath;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
|
@ -88,11 +89,12 @@ public class FileUploadService {
|
|||
*/
|
||||
public SysFile getFile(String filePath) {
|
||||
try{
|
||||
String fileUrl = minioUtil.getFileUrl(minioConfig.getBucketName(), filePath, 60 * 60 * 12);
|
||||
String fileUrl = minioUtil.getFileUrl(minioConfig.getBucketName(), filePath, 60 * 60 * 24);
|
||||
String lsUrl= fileUrl.replace(minioConfig.getEndpoint(),minioConfig.getUrl());
|
||||
String url = minioConfig.getUrl() + File.separator + minioConfig.getBucketName() + File.separator + filePath;
|
||||
return SysFile.builder()
|
||||
.name("文件名称")
|
||||
.url(lsUrl).build();
|
||||
.url(lsUrl).filePath(url).build();
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import io.jsonwebtoken.SignatureAlgorithm;
|
|||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -25,7 +26,8 @@ public class OnlyOfficeJwtService {
|
|||
// 实现 JWT 生成逻辑
|
||||
return Jwts.builder()
|
||||
.setClaims(payload)
|
||||
.signWith(SignatureAlgorithm.HS256, jwtSecret)
|
||||
.signWith(SignatureAlgorithm.HS256, jwtSecret.getBytes())
|
||||
.setExpiration(new Date(System.currentTimeMillis() + 3600000))
|
||||
.compact();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,13 +49,9 @@ public class OnlyOfficeService {
|
|||
|
||||
public Map<String, Object> getConfigWithToken(String fileKey, String fileName, String mode) throws Exception {
|
||||
Map<String, Object> map = buildEditorConfig(fileKey, fileName, mode);
|
||||
log.info("map:{}",map);
|
||||
String token = generateJwtToken(map);
|
||||
boolean b = onlyOfficeJwtService.verifyToken(token);
|
||||
log.info("b:{}",b);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> editorConfig = (Map<String, Object>) map.getOrDefault("editorConfig", new HashMap<>());
|
||||
log.info("token:{}",token);
|
||||
// 添加token
|
||||
editorConfig.put("token", token);
|
||||
// 确保editorConfig被放回map中
|
||||
|
|
@ -68,8 +64,7 @@ public class OnlyOfficeService {
|
|||
|
||||
// 清理文件名,只保留最终文件名
|
||||
String cleanFileName = extractFileName(fileName);
|
||||
String fileUrl = fileUploadService.getFile(fileName).getUrl();
|
||||
// fileUrl = URLEncoder.encode(fileUrl, "UTF-8").replaceAll("\\+", "%20");
|
||||
String fileUrl = fileUploadService.getFile(fileName).getFilePath();
|
||||
Map<String, Object> config = new HashMap<>();
|
||||
|
||||
// 文档配置
|
||||
|
|
@ -95,11 +90,11 @@ public class OnlyOfficeService {
|
|||
|
||||
// 自定义配置
|
||||
Map<String, Object> customization = new HashMap<>();
|
||||
customization.put("forcesave", false);
|
||||
customization.put("about", false);
|
||||
customization.put("feedback", false);
|
||||
customization.put("hideRightMenu", false);
|
||||
customization.put("compactToolbar", false);
|
||||
customization.put("forcesave", true);
|
||||
customization.put("about", true);
|
||||
customization.put("feedback", true);
|
||||
customization.put("hideRightMenu", true);
|
||||
customization.put("compactToolbar", true);
|
||||
editorConfig.put("customization", customization);
|
||||
|
||||
config.put("document", document);
|
||||
|
|
@ -107,7 +102,7 @@ public class OnlyOfficeService {
|
|||
config.put("editorConfig", editorConfig);
|
||||
config.put("type", "embedded");
|
||||
config.put("width", "100%");
|
||||
config.put("height", "600px");
|
||||
config.put("height", "100%");
|
||||
// 缓存文档信息
|
||||
cacheDocumentInfo(fileKey, fileName);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue