fix: uploading books on Windows (dev env) doesn't work

This commit is contained in:
Oleh Astappiev
2025-04-19 11:17:24 -06:00
committed by Aditya Chandel
parent 41762e2e9a
commit edb31b77ff
4 changed files with 7 additions and 12 deletions
@@ -10,6 +10,5 @@ import org.springframework.stereotype.Component;
@Getter
@Setter
public class AppProperties {
private String pathBook;
private String pathConfig;
}
@@ -55,14 +55,14 @@ public class FileUploadService {
}
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());
Book book = processFile(file, libraryEntity, libraryPathEntity, storageFile);
notificationService.sendMessage(Topic.BOOK_ADD, book);
log.info("Book processed successfully: {}", book.getMetadata().getTitle());
return book;
} catch (IOException e) {
log.error("Error saving file: {}", e.getMessage());
log.error("Error saving file", e);
throw ApiError.FILE_READ_ERROR.createException(e.getMessage());
}
}
@@ -1,9 +1,8 @@
package com.adityachandel.booklore.service.fileprocessor;
import com.adityachandel.booklore.config.AppProperties;
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
import com.adityachandel.booklore.repository.BookRepository;
import com.adityachandel.booklore.service.AppSettingService;
import com.adityachandel.booklore.util.FileService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -26,24 +25,22 @@ import java.util.stream.Stream;
@Slf4j
public class FileProcessingUtils {
private final AppProperties appProperties;
private final FileService fileService;
private final AppSettingService appSettingService;
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());
}
public boolean saveCoverImage(BufferedImage coverImage, long bookId) throws IOException {
File coverDirectory = new File(appProperties.getPathConfig() + "/thumbs");
String resolution = appSettingService.getAppSettings().getCoverSettings().getResolution();
String[] split = resolution.split("x");
int x = Integer.parseInt(split[0]);
int y = Integer.parseInt(split[1]);
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.mkdirs()) {
throw new IOException("Failed to create directory: " + bookDirectory.getAbsolutePath());
@@ -65,7 +62,7 @@ public class FileProcessingUtils {
public void deleteBookCovers(Set<Long> bookIds) {
for (Long bookId : bookIds) {
String bookCoverFolder = appProperties.getPathConfig() + "/thumbs/" + bookId;
String bookCoverFolder = fileService.getThumbnailPath(bookId);
Path folderPath = Paths.get(bookCoverFolder);
try {
if (Files.exists(folderPath) && Files.isDirectory(folderPath)) {
@@ -1,5 +1,4 @@
app:
path-book: '/app/books'
path-config: '/app/data'
version: 'v0.0.40'