fix: uploading books on Windows (dev env) doesn't work
This commit is contained in:
committed by
Aditya Chandel
parent
41762e2e9a
commit
edb31b77ff
@@ -10,6 +10,5 @@ import org.springframework.stereotype.Component;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class AppProperties {
|
public class AppProperties {
|
||||||
private String pathBook;
|
|
||||||
private String pathConfig;
|
private String pathConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -55,14 +55,14 @@ public class FileUploadService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
file.transferTo(storageFile);
|
file.transferTo(storagePath); // storagePath here is required for windows, otherwise it will be resoled relative to Tomcat FS
|
||||||
log.info("File uploaded successfully: {}", storageFile.getAbsolutePath());
|
log.info("File uploaded successfully: {}", storageFile.getAbsolutePath());
|
||||||
Book book = processFile(file, libraryEntity, libraryPathEntity, storageFile);
|
Book book = processFile(file, libraryEntity, libraryPathEntity, storageFile);
|
||||||
notificationService.sendMessage(Topic.BOOK_ADD, book);
|
notificationService.sendMessage(Topic.BOOK_ADD, book);
|
||||||
log.info("Book processed successfully: {}", book.getMetadata().getTitle());
|
log.info("Book processed successfully: {}", book.getMetadata().getTitle());
|
||||||
return book;
|
return book;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error saving file: {}", e.getMessage());
|
log.error("Error saving file", e);
|
||||||
throw ApiError.FILE_READ_ERROR.createException(e.getMessage());
|
throw ApiError.FILE_READ_ERROR.createException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-8
@@ -1,9 +1,8 @@
|
|||||||
package com.adityachandel.booklore.service.fileprocessor;
|
package com.adityachandel.booklore.service.fileprocessor;
|
||||||
|
|
||||||
import com.adityachandel.booklore.config.AppProperties;
|
|
||||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||||
import com.adityachandel.booklore.repository.BookRepository;
|
|
||||||
import com.adityachandel.booklore.service.AppSettingService;
|
import com.adityachandel.booklore.service.AppSettingService;
|
||||||
|
import com.adityachandel.booklore.util.FileService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -26,24 +25,22 @@ import java.util.stream.Stream;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class FileProcessingUtils {
|
public class FileProcessingUtils {
|
||||||
|
|
||||||
private final AppProperties appProperties;
|
private final FileService fileService;
|
||||||
private final AppSettingService appSettingService;
|
private final AppSettingService appSettingService;
|
||||||
|
|
||||||
public void setBookCoverPath(long bookId, BookMetadataEntity bookMetadataEntity) {
|
public void setBookCoverPath(long bookId, BookMetadataEntity bookMetadataEntity) {
|
||||||
bookMetadataEntity.setThumbnail(appProperties.getPathConfig() + "/thumbs/" + bookId + "/f.jpg");
|
bookMetadataEntity.setThumbnail(fileService.getThumbnailPath(bookId) + "/f.jpg");
|
||||||
bookMetadataEntity.setCoverUpdatedOn(Instant.now());
|
bookMetadataEntity.setCoverUpdatedOn(Instant.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean saveCoverImage(BufferedImage coverImage, long bookId) throws IOException {
|
public boolean saveCoverImage(BufferedImage coverImage, long bookId) throws IOException {
|
||||||
File coverDirectory = new File(appProperties.getPathConfig() + "/thumbs");
|
|
||||||
|
|
||||||
String resolution = appSettingService.getAppSettings().getCoverSettings().getResolution();
|
String resolution = appSettingService.getAppSettings().getCoverSettings().getResolution();
|
||||||
String[] split = resolution.split("x");
|
String[] split = resolution.split("x");
|
||||||
int x = Integer.parseInt(split[0]);
|
int x = Integer.parseInt(split[0]);
|
||||||
int y = Integer.parseInt(split[1]);
|
int y = Integer.parseInt(split[1]);
|
||||||
|
|
||||||
BufferedImage resizedImage = resizeImage(coverImage, x, y);
|
BufferedImage resizedImage = resizeImage(coverImage, x, y);
|
||||||
File bookDirectory = new File(coverDirectory, String.valueOf(bookId));
|
File bookDirectory = new File(fileService.getThumbnailPath(bookId));
|
||||||
if (!bookDirectory.exists()) {
|
if (!bookDirectory.exists()) {
|
||||||
if (!bookDirectory.mkdirs()) {
|
if (!bookDirectory.mkdirs()) {
|
||||||
throw new IOException("Failed to create directory: " + bookDirectory.getAbsolutePath());
|
throw new IOException("Failed to create directory: " + bookDirectory.getAbsolutePath());
|
||||||
@@ -65,7 +62,7 @@ public class FileProcessingUtils {
|
|||||||
|
|
||||||
public void deleteBookCovers(Set<Long> bookIds) {
|
public void deleteBookCovers(Set<Long> bookIds) {
|
||||||
for (Long bookId : bookIds) {
|
for (Long bookId : bookIds) {
|
||||||
String bookCoverFolder = appProperties.getPathConfig() + "/thumbs/" + bookId;
|
String bookCoverFolder = fileService.getThumbnailPath(bookId);
|
||||||
Path folderPath = Paths.get(bookCoverFolder);
|
Path folderPath = Paths.get(bookCoverFolder);
|
||||||
try {
|
try {
|
||||||
if (Files.exists(folderPath) && Files.isDirectory(folderPath)) {
|
if (Files.exists(folderPath) && Files.isDirectory(folderPath)) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
app:
|
app:
|
||||||
path-book: '/app/books'
|
|
||||||
path-config: '/app/data'
|
path-config: '/app/data'
|
||||||
version: 'v0.0.40'
|
version: 'v0.0.40'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user