Compare commits

...

11 Commits

Author SHA1 Message Date
e0b9d8f476 Bump xstream from 1.4.17 to 1.4.18 in /server
Bumps [xstream](https://github.com/x-stream/xstream) from 1.4.17 to 1.4.18.
- [Release notes](https://github.com/x-stream/xstream/releases)
- [Commits](https://github.com/x-stream/xstream/commits)

---
updated-dependencies:
- dependency-name: com.thoughtworks.xstream:xstream
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-25 15:56:05 +00:00
db2ed3a555 修复某些版本LibreOffice本地安装了,但检测不到问题 2021-08-25 15:27:36 +08:00
6efc375066 Fix:修复install.sh安装脚本路径错误 2021-08-24 16:05:41 +08:00
9a4c864490 重命名 env() 2021-08-24 13:56:07 +08:00
a3081ef4a9 修复单元测试失败的问题 2021-08-24 13:56:07 +08:00
43374e02bd 让 office-plugin 项目的语言级别与父项目保持一致 2021-08-24 11:05:12 +08:00
fb8a19469b Merge pull request #272 from jerrykcode/master
修复: 文件名含有特殊字符时无法预览
2021-08-21 14:19:40 +08:00
f2d5f4a86c 为WebUtils.encodeUrlFileName方法添加测试用例 2021-08-20 14:15:42 +08:00
2177aed64f 修复: 文件名含有特殊字符时无法预览 2021-08-19 20:26:37 +08:00
2395a489a3 Update startup.sh
Add `/usr/lib64/libreoffice` to search path list.
2021-07-21 15:42:11 +08:00
0b8eedf935 feat: add dxf file type in cad scope 2021-07-21 15:41:35 +08:00
10 changed files with 93 additions and 27 deletions

View File

@ -86,16 +86,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>

View File

@ -104,9 +104,14 @@ public class OfficeUtils {
"/opt/openoffice.org3",
"/opt/openoffice",
"/opt/libreoffice",
"/opt/libreoffice6.0",
"/opt/libreoffice6.1",
"/opt/libreoffice6.2",
"/opt/libreoffice6.3",
"/opt/libreoffice6.4",
"/opt/libreoffice7.0",
"/opt/libreoffice7.1",
"/opt/libreoffice7.2",
"/opt/openoffice4",
"/usr/lib/openoffice",
"/usr/lib/libreoffice"

View File

@ -29,23 +29,45 @@ public class ConfigUtils {
return userDir;
}
// 获取环境变量,如果找不到则返回默认值
@SuppressWarnings("SameParameterValue")
private static String getEnvOrDefault(String key, String def) {
String value = System.getenv(key);
return value == null ? def : value;
}
public static String getOfficePluginPath() {
String userDir = System.getenv("KKFILEVIEW_BIN_FOLDER");
if (userDir == null) {
userDir = System.getProperty("user.dir");
}
if (userDir.endsWith("bin")) {
userDir = userDir.substring(0, userDir.length() - 4);
} else {
String separator = File.separator;
if (!userDir.contains(OFFICE_PLUGIN_NAME)) {
userDir = userDir + separator + OFFICE_PLUGIN_NAME;
// 返回参数列表中第一个真实存在的路径,或者 null
private static String firstExists(File... paths) {
for (File path : paths) {
if (path.exists()) {
return path.getAbsolutePath();
}
}
return userDir;
return null;
}
public static String getOfficePluginPath() {
String userDir = System.getProperty("user.dir");
String binFolder = getEnvOrDefault("KKFILEVIEW_BIN_FOLDER", userDir);
File pluginPath = new File(binFolder);
// 如果指定了 bin 或其父目录,则返回父目录
// 否则在当前目录和父目录中寻找 office-plugin
if (new File(pluginPath, "bin").exists()) {
return pluginPath.getAbsolutePath();
} else if (pluginPath.exists() && pluginPath.getName().equals("bin")) {
return pluginPath.getParentFile().getAbsolutePath();
} else {
return firstExists(
new File(pluginPath, OFFICE_PLUGIN_NAME),
new File(pluginPath.getParentFile(), OFFICE_PLUGIN_NAME)
);
}
}
public static String getCustomizedConfigPath() {
String homePath = getHomePath();
String separator = java.io.File.separator;

View File

@ -149,7 +149,7 @@
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.17</version>
<version>1.4.18</version>
</dependency>
<dependency>
<groupId>com.googlecode.concurrentlinkedhashmap</groupId>

View File

@ -7,7 +7,7 @@ install_redhat() {
if [ $? -eq 0 ];then
yum install -y libXext.x86_64
yum groupinstall -y "X Window System"
yum installlocalho
yum localinstall *.rpm
echo 'install finshed...'
else
echo 'download package error...'
@ -15,7 +15,7 @@ install_redhat() {
}
install_ubuntu() {
wget https://kkfileview.keking.cn/LibreOffice_7.1.4_Linux_x86-64_deb.tar.gz -cO LibreOffice_7_deb.gz && tar -zxf /tmp/LibreOffice_7_deb.tar.gz && cd /tmp/LibreOffice_7.1.4.2_Linux_x86-deb/RPMS
wget https://kkfileview.keking.cn/LibreOffice_7.1.4_Linux_x86-64_deb.tar.gz -cO LibreOffice_7_deb.tar.gz && tar -zxf /tmp/LibreOffice_7_deb.tar.gz && cd /tmp/LibreOffice_7.1.4.2_Linux_x86-64_deb/DEBS
echo $?
if [ $? -eq 0 ];then
apt-get install -y libxinerama1 libcairo2 libcups2 libx11-xcb1

View File

@ -1,5 +1,5 @@
#!/bin/bash
DIR_HOME=("/opt/openoffice.org3" "/opt/libreoffice" "/opt/libreoffice6.1" "/opt/libreoffice7.0" "/opt/libreoffice7.1" "/opt/openoffice4" "/usr/lib/openoffice" "/usr/lib/libreoffice")
DIR_HOME=("/opt/openoffice.org3" "/opt/libreoffice" "/opt/libreoffice6.0" "/opt/libreoffice6.1" "/opt/libreoffice6.2" "/opt/libreoffice6.3" "/opt/libreoffice6.4" "/opt/libreoffice7.0" "/opt/libreoffice7.1" "/opt/libreoffice7.2" "/opt/openoffice4" "/usr/lib/openoffice" "/usr/lib/libreoffice" "/usr/lib64/libreoffice")
FLAG=
OFFICE_HOME=
KKFILEVIEW_BIN_FOLDER=$(cd "$(dirname "$0")";pwd)

View File

@ -32,6 +32,7 @@ public enum FileType {
private static final String[] ARCHIVE_TYPES = {"rar", "zip", "jar", "7-zip", "tar", "gzip", "7z"};
private static final String[] TIFF_TYPES = {"tif", "tiff"};
private static final String[] OFD_TYPES = {"ofd"};
private static final String[] CAD_TYPES = {"dwg", "dxf"};
private static final String[] SSIM_TEXT_TYPES = ConfigConstants.getSimText();
private static final String[] CODES = {"java", "c", "php", "go", "python", "py", "js", "html", "ftl", "css", "lua", "sh", "rb", "yaml", "yml", "json", "h", "cpp", "cs", "aspx", "jsp"};
private static final String[] MEDIA_TYPES = ConfigConstants.getMedia();
@ -66,10 +67,12 @@ public enum FileType {
for (String ofd : OFD_TYPES) {
FILE_TYPE_MAPPER.put(ofd, FileType.OFD);
}
for (String cad : CAD_TYPES) {
FILE_TYPE_MAPPER.put(cad, FileType.CAD);
}
FILE_TYPE_MAPPER.put("md", FileType.MARKDOWN);
FILE_TYPE_MAPPER.put("xml", FileType.XML);
FILE_TYPE_MAPPER.put("pdf", FileType.PDF);
FILE_TYPE_MAPPER.put("dwg", FileType.CAD);
FILE_TYPE_MAPPER.put("flv", FileType.FLV);
}

View File

@ -273,6 +273,7 @@ public class FileHandlerService {
attribute.setType(type);
attribute.setName(fileName);
attribute.setSuffix(suffix);
url = WebUtils.encodeUrlFileName(url);
attribute.setUrl(url);
if (req != null) {
String officePreviewType = req.getParameter("officePreviewType");

View File

@ -2,8 +2,10 @@ package cn.keking.utils;
import io.mola.galimatias.GalimatiasParseException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
@ -97,4 +99,23 @@ public class WebUtils {
String fileName = nonPramStr.substring(nonPramStr.lastIndexOf("/") + 1);
return KkFileUtils.suffixFromFileName(fileName);
}
/**
* 对url中的文件名进行UTF-8编码
*
* @param url url
* @return 文件名编码后的url
*/
public static String encodeUrlFileName(String url) {
String noQueryUrl = url.substring(0, url.contains("?") ? url.indexOf("?") : url.length());
int fileNameStartIndex = noQueryUrl.lastIndexOf('/') + 1;
int fileNameEndIndex = noQueryUrl.lastIndexOf('.');
String encodedFileName;
try {
encodedFileName = URLEncoder.encode(noQueryUrl.substring(fileNameStartIndex, fileNameEndIndex), "UTF-8");
} catch (UnsupportedEncodingException e) {
return null;
}
return url.substring(0, fileNameStartIndex) + encodedFileName + url.substring(fileNameEndIndex);
}
}

View File

@ -0,0 +1,24 @@
package cn.keking.utils;
import org.junit.jupiter.api.Test;
public class WebUtilsTests {
@Test
void encodeUrlFileNameTest() {
// 测试对URL中的文件名部分进行UTF-8编码
String in = "https://file.keking.cn/demo/hello#0.txt";
String out = "https://file.keking.cn/demo/hello%230.txt";
assert WebUtils.encodeUrlFileName(in).equals(out);
}
@Test
void encodeUrlFileNameTestWithParams() {
// 测试对URL中的文件名部分进行UTF-8编码
// URL带参数
// 文件名"#hello&world"中的"&"应该被编码成为"%26",而?后的参数列表中的"&"不会被编码
String in = "https://file.keking.cn/demo/#hello&world.txt?param0=0&param1=1";
String out = "https://file.keking.cn/demo/%23hello%26world.txt?param0=0&param1=1";
assert WebUtils.encodeUrlFileName(in).equals(out);
}
}