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