Skip to content

Commit

Permalink
feat: 文件在线预览支持更多的文件类型 #2765
Browse files Browse the repository at this point in the history
1.office插件启动失败问题
  • Loading branch information
liuliaozhong committed Dec 20, 2024
1 parent 3d0c571 commit 0fe91e5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class PreviewConfig {
* openoffice 或 LibreOffice 的 home 路径
*/
@Value("\${preview.office.home:/opt/libreoffice7.6}")
val officeHome: String? = null
val officeHome: String = "/opt/libreoffice7.6"

/**
* office 转换服务的端口,默认开启两个进程
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

package com.tencent.bkrepo.preview.service

import javax.annotation.PostConstruct
import javax.annotation.PreDestroy
import org.apache.commons.lang3.StringUtils
import org.jodconverter.core.office.InstalledOfficeManagerHolder
import org.jodconverter.core.office.OfficeUtils
Expand All @@ -44,8 +46,6 @@ import org.springframework.stereotype.Component
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.IOException
import javax.annotation.PostConstruct
import javax.annotation.PreDestroy

/**
* 创建office文件转换器
Expand All @@ -66,12 +66,16 @@ class OfficePluginManager {
@Value("\${preview.office.plugin.task.maxTasksPerProcess:5}")
private val maxTasksPerProcess = 5

@Value("\${preview.office.home:/opt/libreoffice7.6}")
private val officeHome: String = "/opt/libreoffice7.6"

/**
* 启动Office组件进程
*/
@PostConstruct
fun startOfficeManager() {
val officeHome: File = LocalOfficeUtils.getDefaultOfficeHome()
val officeHome: File = getOfficeHome(officeHome)
logger.info("Office component path:${officeHome.path}")
val killOffice = killProcess()
if (killOffice) {
logger.warn("A running Office process has been detected and the process has been automatically terminated")
Expand All @@ -95,6 +99,14 @@ class OfficePluginManager {
}
}

private fun getOfficeHome(homePath: String?): File {
if (homePath.isNullOrEmpty()) {
return LocalOfficeUtils.getDefaultOfficeHome()
}
val officeHome = File(homePath)
return if (officeHome.exists()) officeHome else LocalOfficeUtils.getDefaultOfficeHome()
}

private fun killProcess(): Boolean {
var flag = false
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
spring.application.name: preview
server.port: 25822
office.home: ${preview.office.home:/opt/libreoffice7.6}
server.port: 25822
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ spec:
value: {{ include "common.names.fullname" . }}-
ports:
- name: http
containerPort: 25801
containerPort: 25822
protocol: TCP
livenessProbe:
httpGet:
Expand Down

0 comments on commit 0fe91e5

Please sign in to comment.