mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-04-17 22:03:41 +00:00
Refine archive preview and PDF defaults
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -26,6 +26,7 @@ nbdist/
|
|||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.artifacts/
|
||||||
|
|
||||||
server/src/main/cache/
|
server/src/main/cache/
|
||||||
server/src/main/file/
|
server/src/main/file/
|
||||||
|
|||||||
@@ -97,11 +97,11 @@ office.type.web = ${KK_OFFICE_TYPE_WEB:web}
|
|||||||
|
|
||||||
# Office文档预览类型
|
# Office文档预览类型
|
||||||
# 支持动态配置,可选值:image/pdf
|
# 支持动态配置,可选值:image/pdf
|
||||||
office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image}
|
office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:pdf}
|
||||||
|
|
||||||
# 是否关闭Office预览模式切换开关,默认为false(允许切换)
|
# 是否关闭Office预览模式切换开关,默认为false(允许切换)
|
||||||
# 设置为true时,用户无法在图片和PDF模式间切换
|
# 设置为true时,用户无法在图片和PDF模式间切换
|
||||||
office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false}
|
office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:true}
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -475,4 +475,4 @@ kk.scriptjs = true
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# 纯文本文件类型,直接显示
|
# 纯文本文件类型,直接显示
|
||||||
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}
|
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}
|
||||||
|
|||||||
@@ -59,21 +59,26 @@ public class CompressFileReader {
|
|||||||
for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
|
for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
|
||||||
if (!item.isFolder()) {
|
if (!item.isFolder()) {
|
||||||
final Path filePathInsideArchive = getFilePathInsideArchive(item, folderPath);
|
final Path filePathInsideArchive = getFilePathInsideArchive(item, folderPath);
|
||||||
ExtractOperationResult result = item.extractSlow(data -> {
|
Files.deleteIfExists(filePathInsideArchive);
|
||||||
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(filePathInsideArchive.toFile(), true))) {
|
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(filePathInsideArchive.toFile(), false))) {
|
||||||
out.write(data);
|
ExtractOperationResult result = item.extractSlow(data -> {
|
||||||
} catch (IOException e) {
|
try {
|
||||||
throw new RuntimeException(e);
|
out.write(data);
|
||||||
}
|
} catch (IOException e) {
|
||||||
return data.length;
|
throw new RuntimeException(e);
|
||||||
}, filePassword);
|
}
|
||||||
if (result != ExtractOperationResult.OK) {
|
return data.length;
|
||||||
ExtractOperationResult result1 = ExtractOperationResult.valueOf("WRONG_PASSWORD");
|
}, filePassword);
|
||||||
if (result1.equals(result)) {
|
if (result != ExtractOperationResult.OK) {
|
||||||
throw new Exception("Password");
|
ExtractOperationResult result1 = ExtractOperationResult.valueOf("WRONG_PASSWORD");
|
||||||
}else {
|
if (result1.equals(result)) {
|
||||||
throw new Exception("Failed to extract RAR file.");
|
throw new Exception("Password");
|
||||||
|
} else {
|
||||||
|
throw new Exception("Failed to extract RAR file.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileType type = FileType.typeFromUrl(filePathInsideArchive.toString());
|
FileType type = FileType.typeFromUrl(filePathInsideArchive.toString());
|
||||||
@@ -110,4 +115,4 @@ public class CompressFileReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -348,4 +348,4 @@ public class OfficeFilePreviewImpl implements FilePreview {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -27,7 +27,7 @@
|
|||||||
if (kkagent === 'true' || !url.startsWith(baseUrl)) {
|
if (kkagent === 'true' || !url.startsWith(baseUrl)) {
|
||||||
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(Base64.encode(url))+ "&key=${kkkey}";
|
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(Base64.encode(url))+ "&key=${kkkey}";
|
||||||
}
|
}
|
||||||
document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?file=" + encodeURIComponent(url) + "&disablepresentationmode=${pdfPresentationModeDisable}&disableopenfile=${pdfOpenFileDisable}&disableprint=${pdfPrintDisable}&disabledownload=${pdfDownloadDisable}&disablebookmark=${pdfBookmarkDisable}&disableediting=${pdfDisableEditing}";
|
document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?file=" + encodeURIComponent(url) + "&disablepresentationmode=${pdfPresentationModeDisable}&disableopenfile=${pdfOpenFileDisable}&disableprint=${pdfPrintDisable}&disabledownload=${pdfDownloadDisable}&disablebookmark=${pdfBookmarkDisable}&disableediting=${pdfDisableEditing}#page=1&pagemode=thumbs";
|
||||||
document.getElementsByTagName('iframe')[0].height = document.documentElement.clientHeight - 10;
|
document.getElementsByTagName('iframe')[0].height = document.documentElement.clientHeight - 10;
|
||||||
/**
|
/**
|
||||||
* 页面变化调整高度
|
* 页面变化调整高度
|
||||||
|
|||||||
@@ -9,7 +9,11 @@
|
|||||||
<script src="js/base64.min.js"></script>
|
<script src="js/base64.min.js"></script>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: #404040;
|
background-color: #f1f3f5;
|
||||||
|
}
|
||||||
|
.viewer-container:focus,
|
||||||
|
.viewer-container:focus-visible {
|
||||||
|
outline: none !important;
|
||||||
}
|
}
|
||||||
#image { width: 800px; margin: 0 auto; font-size: 0;}
|
#image { width: 800px; margin: 0 auto; font-size: 0;}
|
||||||
#image li { display: inline-block;width: 50px;height: 50px; margin-left: 1%; padding-top: 1%;}
|
#image li { display: inline-block;width: 50px;height: 50px; margin-left: 1%; padding-top: 1%;}
|
||||||
@@ -77,4 +81,4 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -26,10 +26,38 @@ public class PdfViewerCompatibilityTests {
|
|||||||
assertTrue(workerScript.contains("import \"../web/compatibility.mjs\";"));
|
assertTrue(workerScript.contains("import \"../web/compatibility.mjs\";"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldOpenPdfPreviewWithThumbnailSidebarByDefault() throws IOException {
|
||||||
|
String pdfTemplate = readWebResource("/web/pdf.ftl");
|
||||||
|
|
||||||
|
assertTrue(pdfTemplate.contains("#page=1&pagemode=thumbs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldPreferPdfForOfficePreviewByDefault() throws IOException {
|
||||||
|
String properties = readConfigResource("/application.properties");
|
||||||
|
|
||||||
|
assertTrue(properties.contains("office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:pdf}"));
|
||||||
|
}
|
||||||
|
|
||||||
private String readResource(String resourcePath) throws IOException {
|
private String readResource(String resourcePath) throws IOException {
|
||||||
try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) {
|
try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) {
|
||||||
assertNotNull(inputStream);
|
assertNotNull(inputStream);
|
||||||
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String readWebResource(String resourcePath) throws IOException {
|
||||||
|
try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) {
|
||||||
|
assertNotNull(inputStream);
|
||||||
|
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readConfigResource(String resourcePath) throws IOException {
|
||||||
|
try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) {
|
||||||
|
assertNotNull(inputStream);
|
||||||
|
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user