diff --git a/backend/src/main/java/org/booklore/model/dto/settings/PublicAppSetting.java b/backend/src/main/java/org/booklore/model/dto/settings/PublicAppSetting.java index 7901c6fcf..eeff29ba3 100644 --- a/backend/src/main/java/org/booklore/model/dto/settings/PublicAppSetting.java +++ b/backend/src/main/java/org/booklore/model/dto/settings/PublicAppSetting.java @@ -11,4 +11,4 @@ public class PublicAppSetting { private boolean remoteAuthEnabled; private OidcProviderDetails oidcProviderDetails; private boolean oidcForceOnlyMode; -} \ No newline at end of file +} diff --git a/backend/src/main/java/org/booklore/service/customfont/CustomFontService.java b/backend/src/main/java/org/booklore/service/customfont/CustomFontService.java index 8db7f6b6b..b014c2440 100644 --- a/backend/src/main/java/org/booklore/service/customfont/CustomFontService.java +++ b/backend/src/main/java/org/booklore/service/customfont/CustomFontService.java @@ -2,6 +2,7 @@ package org.booklore.service.customfont; import org.booklore.config.AppProperties; import org.booklore.exception.APIException; +import org.booklore.exception.ApiError; import org.booklore.mapper.CustomFontMapper; import org.booklore.model.dto.CustomFontDto; import org.booklore.model.entity.BookLoreUserEntity; @@ -44,7 +45,8 @@ public class CustomFontService { private final AppProperties appProperties; private static final int MAX_FONTS_PER_USER = 10; - private static final long MAX_FILE_SIZE_BYTES = 5L * 1024 * 1024; + private static final int MAX_FILE_SIZE_MB = 50; + private static final long MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024L * 1024L; private static final String CUSTOM_FONTS_DIR = "custom-fonts"; private static final int MAX_FONT_NAME_LENGTH = 100; @@ -191,7 +193,7 @@ public class CustomFontService { } if (file.getSize() > MAX_FILE_SIZE_BYTES) { - throw new IllegalArgumentException("File size exceeds maximum limit of 5MB"); + throw ApiError.FILE_TOO_LARGE.createException(MAX_FILE_SIZE_MB); } int currentFontCount = customFontRepository.countByUserId(userId); diff --git a/backend/src/test/java/org/booklore/service/customfont/CustomFontServiceTest.java b/backend/src/test/java/org/booklore/service/customfont/CustomFontServiceTest.java index 7b0aa520f..fed58e596 100644 --- a/backend/src/test/java/org/booklore/service/customfont/CustomFontServiceTest.java +++ b/backend/src/test/java/org/booklore/service/customfont/CustomFontServiceTest.java @@ -1,6 +1,8 @@ package org.booklore.service.customfont; import org.booklore.config.AppProperties; +import org.booklore.exception.APIException; +import org.booklore.exception.ApiError; import org.booklore.mapper.CustomFontMapper; import org.booklore.model.dto.CustomFontDto; import org.booklore.model.entity.BookLoreUserEntity; @@ -119,19 +121,65 @@ class CustomFontServiceTest { void uploadFont_withOversizedFile_shouldThrowException() { // Arrange Long userId = 1L; - byte[] largeContent = new byte[6 * 1024 * 1024]; // 6MB (exceeds 5MB limit) + byte[] largeContent = new byte[51 * 1024 * 1024]; // 51MB (exceeds default 50MB limit) MultipartFile file = new MockMultipartFile("font.ttf", "font.ttf", "font/ttf", largeContent); when(customFontRepository.countByUserId(userId)).thenReturn(0); // Act & Assert - assertThatThrownBy(() -> service.uploadFont(file, "Font", userId)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("File size exceeds maximum limit"); + assertThatExceptionOfType(APIException.class) + .isThrownBy(() -> service.uploadFont(file, "Font", userId)) + .satisfies(ex -> { + assertThat(ex.getStatus()).isEqualTo(ApiError.FILE_TOO_LARGE.getStatus()); + assertThat(ex.getMessage()).contains("50"); + }); verify(customFontRepository, never()).save(any()); } + @Test + @DisplayName("uploadFont_withFileAboveOldLimit_shouldAllowFileUnder50Mb") + void uploadFont_withFileAboveOldLimit_shouldAllowFileUnder50Mb() throws IOException { + // Arrange + Long userId = 1L; + String fontName = "Large Font"; + byte[] fontContent = new byte[5 * 1024 * 1024 + 1]; + fontContent[0] = 0x00; + fontContent[1] = 0x01; + fontContent[2] = 0x00; + fontContent[3] = 0x00; + MultipartFile file = new MockMultipartFile("font.ttf", "font.ttf", "font/ttf", fontContent); + + BookLoreUserEntity user = new BookLoreUserEntity(); + user.setId(userId); + + CustomFontEntity savedEntity = CustomFontEntity.builder() + .id(1L) + .user(user) + .fontName(fontName) + .fileName("user_1_font_123.ttf") + .originalFileName("font.ttf") + .format(FontFormat.TTF) + .fileSize((long) fontContent.length) + .build(); + + CustomFontDto expectedDto = new CustomFontDto(); + expectedDto.setId(1L); + expectedDto.setFontName(fontName); + + when(userRepository.findById(userId)).thenReturn(Optional.of(user)); + when(customFontRepository.countByUserId(userId)).thenReturn(0); + when(customFontRepository.save(any(CustomFontEntity.class))).thenReturn(savedEntity); + when(customFontMapper.toDto(savedEntity)).thenReturn(expectedDto); + + // Act + CustomFontDto result = service.uploadFont(file, fontName, userId); + + // Assert + assertThat(result.getFontName()).isEqualTo(fontName); + verify(customFontRepository).save(any(CustomFontEntity.class)); + } + @Test @DisplayName("uploadFont_withInvalidExtension_shouldThrowException") void uploadFont_withInvalidExtension_shouldThrowException() { diff --git a/frontend/src/app/features/settings/custom-fonts/font-upload-dialog/font-upload-dialog.component.ts b/frontend/src/app/features/settings/custom-fonts/font-upload-dialog/font-upload-dialog.component.ts index 1e78fc689..fbe1710f7 100644 --- a/frontend/src/app/features/settings/custom-fonts/font-upload-dialog/font-upload-dialog.component.ts +++ b/frontend/src/app/features/settings/custom-fonts/font-upload-dialog/font-upload-dialog.component.ts @@ -30,9 +30,9 @@ export class FontUploadDialogComponent implements OnDestroy { isLoadingPreview = false; currentPreviewToken: number | null = null; - readonly maxFileSize = 5242880; readonly maxFonts = 10; readonly acceptedFormats = ['.ttf', '.otf', '.woff', '.woff2']; + readonly maxFileSize = 50 * 1024 * 1024; onUploadZoneClick(): void { if (this.isUploading) { diff --git a/frontend/src/i18n/de/settings-reader.json b/frontend/src/i18n/de/settings-reader.json index 3557c95c7..957c5bccd 100644 --- a/frontend/src/i18n/de/settings-reader.json +++ b/frontend/src/i18n/de/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Schriftdatei auswählen", "dragDrop": "Schriftdatei per Drag & Drop hierher ziehen", "supportedFormats": "Unterstützte Formate: TTF, OTF, WOFF, WOFF2", - "maxSize": "Maximale Dateigröße: 5 MB", + "maxSize": "Maximale Dateigröße: 50 MB", "fontPreview": "Schriftvorschau", "displayName": "Anzeigename der Schriftart", "displayNameDesc": "Dieser Name erscheint in der Schriftauswahl beim Lesen von EPUB-Büchern.", diff --git a/frontend/src/i18n/en/settings-reader.json b/frontend/src/i18n/en/settings-reader.json index 23e4e6fb6..d57782632 100644 --- a/frontend/src/i18n/en/settings-reader.json +++ b/frontend/src/i18n/en/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Select Font File", "dragDrop": "Drag and Drop Font File", "supportedFormats": "Supported formats: TTF, OTF, WOFF, WOFF2", - "maxSize": "Maximum file size: 5 MB", + "maxSize": "Maximum file size: 50 MB", "fontPreview": "Font Preview", "displayName": "Font Display Name", "displayNameDesc": "This name will appear in the font selector when reading EPUB books.", diff --git a/frontend/src/i18n/es/settings-reader.json b/frontend/src/i18n/es/settings-reader.json index 4f2a39c16..dfa477624 100644 --- a/frontend/src/i18n/es/settings-reader.json +++ b/frontend/src/i18n/es/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Seleccionar archivo de fuente", "dragDrop": "Arrastra y suelta el archivo de fuente", "supportedFormats": "Formatos compatibles: TTF, OTF, WOFF, WOFF2", - "maxSize": "Tamaño máximo del archivo: 5 MB", + "maxSize": "Tamaño máximo del archivo: 50 MB", "fontPreview": "Vista previa de la fuente", "displayName": "Nombre de la fuente", "displayNameDesc": "Este nombre aparecerá en el selector de fuentes al leer libros EPUB.", diff --git a/frontend/src/i18n/fr/settings-reader.json b/frontend/src/i18n/fr/settings-reader.json index 667dc176b..aa747e470 100644 --- a/frontend/src/i18n/fr/settings-reader.json +++ b/frontend/src/i18n/fr/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Sélectionner un fichier de police", "dragDrop": "Glisser-déposer un fichier de police", "supportedFormats": "Formats pris en charge : TTF, OTF, WOFF, WOFF2", - "maxSize": "Taille maximale : 5 Mo", + "maxSize": "Taille maximale : 50 Mo", "fontPreview": "Aperçu de la police", "displayName": "Nom d'affichage de la police", "displayNameDesc": "Ce nom apparaîtra dans le sélecteur de polices lors de la lecture de livres EPUB.", diff --git a/frontend/src/i18n/hr/settings-reader.json b/frontend/src/i18n/hr/settings-reader.json index ba0ba5b0d..354a270c6 100644 --- a/frontend/src/i18n/hr/settings-reader.json +++ b/frontend/src/i18n/hr/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Odaberite datoteku fonta", "dragDrop": "Povucite i ispustite datoteku fonta", "supportedFormats": "Podržani formati: TTF, OTF, WOFF, WOFF2", - "maxSize": "Maksimalna veličina datoteke: 5 MB", + "maxSize": "Maksimalna veličina datoteke: 50 MB", "fontPreview": "Pregled fonta", "displayName": "Prikazni naziv fonta", "displayNameDesc": "Ovaj naziv će se pojaviti u biraču fontova prilikom čitanja EPUB knjiga.", diff --git a/frontend/src/i18n/it/settings-reader.json b/frontend/src/i18n/it/settings-reader.json index af63d4a78..2f976ea20 100644 --- a/frontend/src/i18n/it/settings-reader.json +++ b/frontend/src/i18n/it/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Seleziona file font", "dragDrop": "Trascina e rilascia il file font", "supportedFormats": "Formati supportati: TTF, OTF, WOFF, WOFF2", - "maxSize": "Dimensione massima: 5 MB", + "maxSize": "Dimensione massima: 50 MB", "fontPreview": "Anteprima font", "displayName": "Nome visualizzato font", "displayNameDesc": "Questo nome apparirà nel selettore font durante la lettura di libri EPUB.", diff --git a/frontend/src/i18n/ja/settings-reader.json b/frontend/src/i18n/ja/settings-reader.json index b75307063..4b742a899 100644 --- a/frontend/src/i18n/ja/settings-reader.json +++ b/frontend/src/i18n/ja/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "フォントファイルを選択", "dragDrop": "フォントファイルをドラッグ&ドロップ", "supportedFormats": "対応形式: TTF、OTF、WOFF、WOFF2", - "maxSize": "最大ファイルサイズ: 5 MB", + "maxSize": "最大ファイルサイズ: 50 MB", "fontPreview": "フォントプレビュー", "displayName": "フォント表示名", "displayNameDesc": "EPUB本を読む際のフォントセレクターに表示される名前です。", diff --git a/frontend/src/i18n/pl/settings-reader.json b/frontend/src/i18n/pl/settings-reader.json index cc744105a..36d7545ac 100644 --- a/frontend/src/i18n/pl/settings-reader.json +++ b/frontend/src/i18n/pl/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Wybierz plik czcionki", "dragDrop": "Przeciągnij i upuść plik czcionki", "supportedFormats": "Obsługiwane formaty: TTF, OTF, WOFF, WOFF2", - "maxSize": "Maksymalny rozmiar pliku: 5 MB", + "maxSize": "Maksymalny rozmiar pliku: 50 MB", "fontPreview": "Podgląd czcionki", "displayName": "Nazwa wyświetlana czcionki", "displayNameDesc": "Ta nazwa będzie widoczna w selektorze czcionek podczas czytania książek EPUB.", diff --git a/frontend/src/i18n/pt/settings-reader.json b/frontend/src/i18n/pt/settings-reader.json index 460c8cb25..5e750ace2 100644 --- a/frontend/src/i18n/pt/settings-reader.json +++ b/frontend/src/i18n/pt/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Selecionar Arquivo de Fonte", "dragDrop": "Arraste e Solte o Arquivo de Fonte", "supportedFormats": "Formatos suportados: TTF, OTF, WOFF, WOFF2", - "maxSize": "Tamanho máximo do arquivo: 5 MB", + "maxSize": "Tamanho máximo do arquivo: 50 MB", "fontPreview": "Prévia da Fonte", "displayName": "Nome de Exibição da Fonte", "displayNameDesc": "Este nome aparecerá no seletor de fontes ao ler livros EPUB.", diff --git a/frontend/src/i18n/ru/settings-reader.json b/frontend/src/i18n/ru/settings-reader.json index ca6350abe..343f5e01a 100644 --- a/frontend/src/i18n/ru/settings-reader.json +++ b/frontend/src/i18n/ru/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Выбрать файл шрифта", "dragDrop": "Перетащите файл шрифта", "supportedFormats": "Поддерживаемые форматы: TTF, OTF, WOFF, WOFF2", - "maxSize": "Максимальный размер файла: 5 МБ", + "maxSize": "Максимальный размер файла: 50 МБ", "fontPreview": "Предпросмотр шрифта", "displayName": "Отображаемое имя шрифта", "displayNameDesc": "Это имя будет отображаться в выборе шрифтов при чтении EPUB-книг.", diff --git a/frontend/src/i18n/sl/settings-reader.json b/frontend/src/i18n/sl/settings-reader.json index 75d19be3f..518ad9df3 100644 --- a/frontend/src/i18n/sl/settings-reader.json +++ b/frontend/src/i18n/sl/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Izberi datoteko pisave", "dragDrop": "Povleci in spusti datoteko pisave sem", "supportedFormats": "Podprti formati: TTF, OTF, WOFF, WOFF2", - "maxSize": "Največja velikost datoteke: 5 MB", + "maxSize": "Največja velikost datoteke: 50 MB", "fontPreview": "Predogled pisave", "displayName": "Prikazno ime pisave", "displayNameDesc": "To ime se bo pojavilo v izbirniku pisav med branjem e-knjig.", diff --git a/frontend/src/i18n/sv/settings-reader.json b/frontend/src/i18n/sv/settings-reader.json index e0c97b137..9e424a0e7 100644 --- a/frontend/src/i18n/sv/settings-reader.json +++ b/frontend/src/i18n/sv/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Välj typsnittsfil", "dragDrop": "Dra och släpp typsnittsfil", "supportedFormats": "Format som stöds: TTF, OTF, WOFF, WOFF2", - "maxSize": "Maximal filstorlek: 5 MB", + "maxSize": "Maximal filstorlek: 50 MB", "fontPreview": "Förhandsvisning av typsnitt", "displayName": "Visningsnamn", "displayNameDesc": "Detta namn visas i typsnittsväljaren när du läser EPUB-böcker.", diff --git a/frontend/src/i18n/uk/settings-reader.json b/frontend/src/i18n/uk/settings-reader.json index f95db000b..70e33cbcb 100644 --- a/frontend/src/i18n/uk/settings-reader.json +++ b/frontend/src/i18n/uk/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "Виберіть файл шрифту", "dragDrop": "Перетягніть файл шрифту", "supportedFormats": "Підтримувані формати: TTF, OTF, WOFF, WOFF2", - "maxSize": "Максимальний розмір файлу: 5 MB", + "maxSize": "Максимальний розмір файлу: 50 МБ", "fontPreview": "Попередній перегляд шрифту", "displayName": "Назва шрифту", "displayNameDesc": "Ця назва відображатиметься у списку шрифтів під час читання EPUB-книг.", diff --git a/frontend/src/i18n/zh/settings-reader.json b/frontend/src/i18n/zh/settings-reader.json index 8331f96cb..2e7954884 100644 --- a/frontend/src/i18n/zh/settings-reader.json +++ b/frontend/src/i18n/zh/settings-reader.json @@ -163,7 +163,7 @@ "selectFile": "选择字体文件", "dragDrop": "拖放字体文件", "supportedFormats": "支持的格式:TTF、OTF、WOFF、WOFF2", - "maxSize": "最大文件大小:5 MB", + "maxSize": "最大文件大小:50 MB", "fontPreview": "字体预览", "displayName": "字体显示名称", "displayNameDesc": "此名称将在阅读 EPUB 图书时显示在字体选择器中。",