Skip to content

Commit

Permalink
Merge pull request #147 from jamebal/develop
Browse files Browse the repository at this point in the history
feat: 新增pdf和epub文件封面预览
  • Loading branch information
jamebal authored Aug 1, 2024
2 parents 5502a6a + 5b28a23 commit f368f72
Show file tree
Hide file tree
Showing 24 changed files with 591 additions and 169 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG VERSION

ENV MONGODB_URI "mongodb://mongo:27017/jmalcloud"
ENV RUN_ENVIRONMENT prod
ENV JVM_OPTS "-Xms50m -Xmx512m"
ENV JVM_OPTS "-Xms256m -Xmx1024m"
ENV LOG_LEVEL warn

ENV FILE_MONITOR true
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.base-aliyun-beijing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
environment:
MONGODB_URI: "mongodb://mongo:27017/jmalcloud"
TZ: "Asia/Shanghai"
JVM_OPTS: "-Xms256m -Xmx512m"
JVM_OPTS: "-Xms256m -Xmx1024m"
volumes:
- ./docker/jmalcloud/files:/jmalcloud/files/
restart: unless-stopped
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.base-aliyun-guangzhou.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
environment:
MONGODB_URI: "mongodb://mongo:27017/jmalcloud"
TZ: "Asia/Shanghai"
JVM_OPTS: "-Xms256m -Xmx512m"
JVM_OPTS: "-Xms256m -Xmx1024m"
volumes:
- ./docker/jmalcloud/files:/jmalcloud/files/
restart: unless-stopped
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.base.proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
environment:
MONGODB_URI: "mongodb://mongo:27017/jmalcloud"
TZ: "Asia/Shanghai"
JVM_OPTS: "-Xms256m -Xmx512m"
JVM_OPTS: "-Xms256m -Xmx1024m"
volumes:
- ./docker/jmalcloud/files:/jmalcloud/files/
restart: unless-stopped
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
environment:
MONGODB_URI: "mongodb://mongo:27017/jmalcloud"
TZ: "Asia/Shanghai"
JVM_OPTS: "-Xms256m -Xmx512m"
JVM_OPTS: "-Xms256m -Xmx1024m"
volumes:
- ./docker/jmalcloud/files:/jmalcloud/files/
restart: unless-stopped
Expand Down
84 changes: 71 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
<maven-jar-plugin.version>3.0.0</maven-jar-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lucene.version>9.10.0</lucene.version>

</properties>

<repositories>
<repository>
<id>openkm</id>
<url>https://maven.openkm.com/</url>
</repository>
<repository>
<id>e-iceblue</id>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
<!--lucene 核心包-->
<dependency>
Expand Down Expand Up @@ -63,6 +74,16 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -111,6 +132,12 @@
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>5.11.0</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- 反射-->
Expand Down Expand Up @@ -206,37 +233,68 @@
<artifactId>hutool-all</artifactId>
<version>5.8.25</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.2</version>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.2</version>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>3.0.2</version>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>nl.siegmann.epublib</groupId>
<artifactId>epublib-core</artifactId>
<version>3.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.5.0</version>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf</artifactId>
<version>9.9.0</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.xdocreport.converter.docx.xwpf</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>5.0.5</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,21 @@ public void packageDownload(HttpServletRequest request, HttpServletResponse resp
@GetMapping("/view/thumbnail")
@Permission("cloud:file:list")
@LogOperatingFun(logType = LogOperation.Type.BROWSE)
public ResponseEntity<Object> thumbnail(@RequestParam String id) {
public ResponseEntity<Object> thumbnail(@RequestParam String id, Boolean showCover) {
String ossPath = CaffeineUtil.getOssPath(Paths.get(id));
if (ossPath != null) {
return webOssService.thumbnail(ossPath, id);
}
Optional<FileDocument> file = fileService.thumbnail(id);
Optional<FileDocument> file = fileService.thumbnail(id, showCover);
return file.map(fileService::getObjectResponseEntity).orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).body("找不到该文件"));
}

@Operation(summary = "显示缩略图")
@GetMapping("/view/thumbnail/{filename}")
@Permission("cloud:file:list")
@LogOperatingFun(logType = LogOperation.Type.BROWSE)
public ResponseEntity<Object> thumbnailName(@RequestParam String id) {
return thumbnail(id);
public ResponseEntity<Object> thumbnailName(@RequestParam String id, Boolean showCover) {
return thumbnail(id, showCover);
}

@Operation(summary = "显示缩略图(媒体封面)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,22 @@ public void publicPackageDownloadOne(HttpServletRequest request, HttpServletResp
@Operation(summary = "显示缩略图")
@GetMapping("/articles/s/view/thumbnail")
@LogOperatingFun(logType = LogOperation.Type.BROWSE)
public ResponseEntity<Object> articlesThumbnail(String id) {
return thumbnail(id, null);
public ResponseEntity<Object> articlesThumbnail(String id, Boolean showCover) {
return thumbnail(id, showCover, null);
}

@Operation(summary = "显示缩略图")
@GetMapping("/public/s/view/thumbnail")
@LogOperatingFun(logType = LogOperation.Type.BROWSE)
public ResponseEntity<Object> publicThumbnail(String id, HttpServletRequest request) {
return thumbnail(id, request);
public ResponseEntity<Object> publicThumbnail(String id, Boolean showCover, HttpServletRequest request) {
return thumbnail(id, showCover, request);
}

@Operation(summary = "显示缩略图")
@GetMapping("/public/s/view/thumbnail/{filename}")
@LogOperatingFun(logType = LogOperation.Type.BROWSE)
public ResponseEntity<Object> publicThumbnailName(String id, HttpServletRequest request) {
return publicThumbnail(id, request);
public ResponseEntity<Object> publicThumbnailName(String id, Boolean showCover, HttpServletRequest request) {
return publicThumbnail(id, showCover, request);
}

@Operation(summary = "显示缩略图(媒体封面)")
Expand All @@ -207,9 +207,9 @@ public ResponseEntity<Object> coverOfMedia(String id, String name) {
return file.map(fileService::getObjectResponseEntity).orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).body("找不到该文件"));
}

private ResponseEntity<Object> thumbnail(String id, HttpServletRequest request) {
private ResponseEntity<Object> thumbnail(String id, Boolean showCover, HttpServletRequest request) {
ResultUtil.checkParamIsNull(id);
Optional<FileDocument> file = fileService.thumbnail(id);
Optional<FileDocument> file = fileService.thumbnail(id, showCover);
if (fileInterceptor.isNotAllowAccess(file.orElse(null), request)) {
return null;
}
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/jmal/clouddisk/lucene/LuceneService.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class LuceneService {
private final SearcherManager searcherManager;
private final IUserService userService;
private final TagService tagService;
private final ReadPDFContentService readPDFContentService;
private final ReadContentService readContentService;
private final RebuildIndexTaskService rebuildIndexTaskService;

public final static String MONGO_INDEX_FIELD = "index";
Expand Down Expand Up @@ -248,7 +248,7 @@ private void updateIndex(boolean readContent, FileIntroVO fileIntroVO) {
setFileIndex(fileIndex);
String content = null;
if (readContent) {
content = readFileContent(file);
content = readFileContent(file, fileIntroVO.getId());
if (StrUtil.isBlank(content)) {
rebuildIndexTaskService.incrementIndexedTaskSize();
updateIndexStatus(fileIntroVO, IndexStatus.INDEXED);
Expand Down Expand Up @@ -333,7 +333,7 @@ private void setType(File file, FileIndex fileIndex) {
}
}

private String readFileContent(File file) {
private String readFileContent(File file, String fileId) {
try {
if (file == null) {
return null;
Expand All @@ -343,13 +343,16 @@ private String readFileContent(File file) {
}
String type = FileTypeUtil.getType(file);
if ("pdf".equals(type)) {
return readPDFContentService.read(file);
return readContentService.readPdfContent(file, fileId);
}
if ("epub".equals(type)) {
return readContentService.readEpubContent(file, fileId);
}
if ("ppt".equals(type) || "pptx".equals(type)) {
return FileContentUtil.readPPTContent(file);
return readContentService.readPPTContent(file);
}
if ("doc".equals(type) || "docx".equals(type)) {
return FileContentUtil.readWordContent(file);
return readContentService.readWordContent(file);
}
if (fileProperties.getSimText().contains(type)) {
String charset = UniversalDetector.detectCharset(file);
Expand Down
Loading

0 comments on commit f368f72

Please sign in to comment.