From 014874cd11e10c90db9e6c7f1f49286282c3ed9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Staicu?= Date: Fri, 21 Nov 2025 06:11:45 +0200 Subject: [PATCH] set the correct file name when triggering a download (#1513) --- .../book-browser/book-card/book-card.component.ts | 12 ++++++------ .../src/app/features/book/service/book.service.ts | 13 +++++++------ .../metadata-viewer/metadata-viewer.component.html | 4 ++-- .../metadata-viewer/metadata-viewer.component.ts | 12 ++++++------ 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-card/book-card.component.ts b/booklore-ui/src/app/features/book/components/book-browser/book-card/book-card.component.ts index 4d2b0117a..5ea5831d7 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-card/book-card.component.ts +++ b/booklore-ui/src/app/features/book/components/book-browser/book-card/book-card.component.ts @@ -213,7 +213,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy { label: 'Download', icon: 'pi pi-download', command: () => { - this.bookService.downloadFile(this.book.id); + this.bookService.downloadFile(this.book); } }); } else { @@ -512,7 +512,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy { label: `${this.book.fileName || 'Book File'}`, icon: 'pi pi-file', command: () => { - this.bookService.downloadFile(this.book.id); + this.bookService.downloadFile(this.book); } }); @@ -528,7 +528,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy { items.push({ label: `${format.fileName} (${this.getFileSizeInMB(format)})`, icon: this.getFileIcon(extension), - command: () => this.downloadAdditionalFile(this.book.id, format.id) + command: () => this.downloadAdditionalFile(this.book, format.id) }); }); } @@ -546,7 +546,7 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy { items.push({ label: `${file.fileName} (${this.getFileSizeInMB(file)})`, icon: this.getFileIcon(extension), - command: () => this.downloadAdditionalFile(this.book.id, file.id) + command: () => this.downloadAdditionalFile(this.book, file.id) }); }); } @@ -619,8 +619,8 @@ export class BookCardComponent implements OnInit, OnChanges, OnDestroy { !!(this.book.supplementaryFiles && this.book.supplementaryFiles.length > 0); } - private downloadAdditionalFile(bookId: number, fileId: number): void { - this.bookService.downloadAdditionalFile(bookId, fileId); + private downloadAdditionalFile(book: Book, fileId: number): void { + this.bookService.downloadAdditionalFile(book, fileId); } private deleteAdditionalFile(bookId: number, fileId: number, fileName: string): void { diff --git a/booklore-ui/src/app/features/book/service/book.service.ts b/booklore-ui/src/app/features/book/service/book.service.ts index 636aefec2..844074f9e 100644 --- a/booklore-ui/src/app/features/book/service/book.service.ts +++ b/booklore-ui/src/app/features/book/service/book.service.ts @@ -355,14 +355,15 @@ export class BookService { ); } - downloadFile(bookId: number): void { - const downloadUrl = `${this.url}/${bookId}/download`; - this.fileDownloadService.downloadFile(downloadUrl, `book_${bookId}`); + downloadFile(book: Book): void { + const downloadUrl = `${this.url}/${book.id}/download`; + this.fileDownloadService.downloadFile(downloadUrl, book.fileName!); } - downloadAdditionalFile(bookId: number, fileId: number): void { - const downloadUrl = `${this.url}/${bookId}/files/${fileId}/download`; - this.fileDownloadService.downloadFile(downloadUrl, `additional_file_${fileId}`); + downloadAdditionalFile(book: Book, fileId: number): void { + const additionalFile = book.alternativeFormats!.find((f: AdditionalFile) => f.id === fileId); + const downloadUrl = `${this.url}/${additionalFile!.id}/files/${fileId}/download`; + this.fileDownloadService.downloadFile(downloadUrl, additionalFile!.fileName!); } savePdfProgress(bookId: number, page: number, percentage: number): Observable { diff --git a/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.html b/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.html index efe02579c..cbc9cc999 100644 --- a/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.html +++ b/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.html @@ -462,7 +462,7 @@ label="Download" icon="pi pi-download" [model]="downloadItems" - (onClick)="download(book!.id)" + (onClick)="download(book)" severity="success" outlined/> } @@ -472,7 +472,7 @@ icon="pi pi-download" severity="success" outlined - (onClick)="download(book!.id)"> + (onClick)="download(book)"> } } diff --git a/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts b/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts index d50fc33cc..1b0f05c30 100644 --- a/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts +++ b/booklore-ui/src/app/features/metadata/component/book-metadata-center/metadata-viewer/metadata-viewer.component.ts @@ -157,7 +157,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges { items.push({ label: `${format.fileName} (${this.getFileSizeInMB(format)})`, icon: this.getFileIcon(extension), - command: () => this.downloadAdditionalFile(book.id, format.id) + command: () => this.downloadAdditionalFile(book, format.id) }); }); } @@ -175,7 +175,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges { items.push({ label: `${file.fileName} (${this.getFileSizeInMB(file)})`, icon: this.getFileIcon(extension), - command: () => this.downloadAdditionalFile(book.id, file.id) + command: () => this.downloadAdditionalFile(book, file.id) }); }); } @@ -354,12 +354,12 @@ export class MetadataViewerComponent implements OnInit, OnChanges { if (bookId) this.bookService.readBook(bookId, reader); } - download(bookId: number) { - this.bookService.downloadFile(bookId); + download(book: Book) { + this.bookService.downloadFile(book); } - downloadAdditionalFile(bookId: number, fileId: number) { - this.bookService.downloadAdditionalFile(bookId, fileId); + downloadAdditionalFile(book: Book, fileId: number) { + this.bookService.downloadAdditionalFile(book, fileId); } deleteAdditionalFile(bookId: number, fileId: number, fileName: string) {