Skip to content

Commit 597715c

Browse files
authored
Merge pull request #738 from kekingcn/paseo/kkfileview
Refine archive preview and PDF defaults
2 parents b246bfd + a8a08c1 commit 597715c

8 files changed

Lines changed: 1011 additions & 81 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ nbdist/
2626
### VS Code ###
2727
.vscode/
2828
.DS_Store
29+
.artifacts/
2930

3031
server/src/main/cache/
3132
server/src/main/file/

server/src/main/config/application.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ office.type.web = ${KK_OFFICE_TYPE_WEB:web}
9797

9898
# Office文档预览类型
9999
# 支持动态配置,可选值:image/pdf
100-
office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image}
100+
office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:pdf}
101101

102102
# 是否关闭Office预览模式切换开关,默认为false(允许切换)
103103
# 设置为true时,用户无法在图片和PDF模式间切换
104-
office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false}
104+
office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:true}
105105

106106

107107
###############################################################################
@@ -475,4 +475,4 @@ kk.scriptjs = true
475475
###############################################################################
476476

477477
# 纯文本文件类型,直接显示
478-
simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}
478+
simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}

server/src/main/java/cn/keking/service/CompressFileReader.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,26 @@ public String unRar(String filePath, String filePassword, String fileName, FileA
5959
for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
6060
if (!item.isFolder()) {
6161
final Path filePathInsideArchive = getFilePathInsideArchive(item, folderPath);
62-
ExtractOperationResult result = item.extractSlow(data -> {
63-
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(filePathInsideArchive.toFile(), true))) {
64-
out.write(data);
65-
} catch (IOException e) {
66-
throw new RuntimeException(e);
67-
}
68-
return data.length;
69-
}, filePassword);
70-
if (result != ExtractOperationResult.OK) {
71-
ExtractOperationResult result1 = ExtractOperationResult.valueOf("WRONG_PASSWORD");
72-
if (result1.equals(result)) {
73-
throw new Exception("Password");
74-
}else {
75-
throw new Exception("Failed to extract RAR file.");
62+
Files.deleteIfExists(filePathInsideArchive);
63+
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(filePathInsideArchive.toFile(), false))) {
64+
ExtractOperationResult result = item.extractSlow(data -> {
65+
try {
66+
out.write(data);
67+
} catch (IOException e) {
68+
throw new RuntimeException(e);
69+
}
70+
return data.length;
71+
}, filePassword);
72+
if (result != ExtractOperationResult.OK) {
73+
ExtractOperationResult result1 = ExtractOperationResult.valueOf("WRONG_PASSWORD");
74+
if (result1.equals(result)) {
75+
throw new Exception("Password");
76+
} else {
77+
throw new Exception("Failed to extract RAR file.");
78+
}
7679
}
80+
} catch (IOException e) {
81+
throw new RuntimeException(e);
7782
}
7883

7984
FileType type = FileType.typeFromUrl(filePathInsideArchive.toString());
@@ -110,4 +115,4 @@ private Path getFilePathInsideArchive(ISimpleInArchiveItem item, Path folderPath
110115
}
111116

112117

113-
}
118+
}

server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,4 @@ public String checkAndHandleConvertStatus(Model model, String fileName, String c
348348
}
349349
return null;
350350
}
351-
}
351+
}

0 commit comments

Comments
 (0)