Fix additional file uploader bugs and move formats to metadata header (#2816)
This commit is contained in:
+6
-13
@@ -30,22 +30,11 @@
|
||||
[disabled]="isUploading"
|
||||
></p-select>
|
||||
|
||||
<!-- Description Field -->
|
||||
<div class="description-field">
|
||||
<label for="description" class="description-label">{{ t('descriptionLabel') }}</label>
|
||||
<p-textarea
|
||||
[(ngModel)]="description"
|
||||
rows="3"
|
||||
[attr.placeholder]="t('descriptionPlaceholder')"
|
||||
class="full-width"
|
||||
[disabled]="isUploading"
|
||||
></p-textarea>
|
||||
</div>
|
||||
|
||||
<!-- File Upload -->
|
||||
<p-fileupload class="file-upload" name="file"
|
||||
[customUpload]="true"
|
||||
[multiple]="false"
|
||||
accept=".pdf,.epub,.cbz,.cbr,.cb7,.fb2,.mobi,.azw,.azw3,.m4b,.m4a,.mp3"
|
||||
(onSelect)="onFilesSelect($event)"
|
||||
(uploadHandler)="uploadFiles($event)"
|
||||
[disabled]="isUploading">
|
||||
@@ -133,7 +122,11 @@
|
||||
<div class="empty-state">
|
||||
<i class="pi pi-cloud-upload empty-icon"></i>
|
||||
<p class="empty-text">{{ t('dragDropText') }}</p>
|
||||
<p class="empty-subtext" [innerHTML]="t('uploadForBook', { title: book.metadata?.title || t('thisBook') })"></p>
|
||||
<p class="empty-subtext">
|
||||
<span [innerHTML]="t('supportedFormats')"></span>
|
||||
<br/>
|
||||
{{ t('maxFileSize', { size: maxFileSizeDisplay }) }}
|
||||
</p>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-fileupload>
|
||||
|
||||
-11
@@ -40,17 +40,6 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.description-field {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.description-label {
|
||||
display: block;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.upload-header-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
+21
-20
@@ -1,19 +1,19 @@
|
||||
import { Component, OnInit, OnDestroy, ChangeDetectorRef, inject } from '@angular/core';
|
||||
import {ChangeDetectorRef, Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/dynamicdialog';
|
||||
import { Select } from 'primeng/select';
|
||||
import { Button } from 'primeng/button';
|
||||
import { FileSelectEvent, FileUpload, FileUploadHandlerEvent } from 'primeng/fileupload';
|
||||
import { Badge } from 'primeng/badge';
|
||||
import { Tooltip } from 'primeng/tooltip';
|
||||
import { Subject, takeUntil } from 'rxjs';
|
||||
import { BookFileService } from '../../service/book-file.service';
|
||||
import { AppSettingsService } from '../../../../shared/service/app-settings.service';
|
||||
import { Book, AdditionalFileType } from '../../model/book.model';
|
||||
import { MessageService } from 'primeng/api';
|
||||
import { filter, take } from 'rxjs/operators';
|
||||
import { TranslocoDirective, TranslocoService } from '@jsverse/transloco';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Button} from 'primeng/button';
|
||||
import {FileSelectEvent, FileUpload, FileUploadHandlerEvent} from 'primeng/fileupload';
|
||||
import {Badge} from 'primeng/badge';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {Subject} from 'rxjs';
|
||||
import {BookFileService} from '../../service/book-file.service';
|
||||
import {AppSettingsService} from '../../../../shared/service/app-settings.service';
|
||||
import {AdditionalFileType, Book} from '../../model/book.model';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
interface FileTypeOption {
|
||||
label: string;
|
||||
@@ -37,7 +37,7 @@ interface UploadingFile {
|
||||
Badge,
|
||||
Tooltip,
|
||||
TranslocoDirective
|
||||
],
|
||||
],
|
||||
templateUrl: './additional-file-uploader.component.html',
|
||||
styleUrls: ['./additional-file-uploader.component.scss']
|
||||
})
|
||||
@@ -47,9 +47,9 @@ export class AdditionalFileUploaderComponent implements OnInit, OnDestroy {
|
||||
book!: Book;
|
||||
files: UploadingFile[] = [];
|
||||
fileType: AdditionalFileType = AdditionalFileType.ALTERNATIVE_FORMAT;
|
||||
description: string = '';
|
||||
isUploading = false;
|
||||
maxFileSizeBytes?: number;
|
||||
maxFileSizeDisplay: string = '100 MB';
|
||||
|
||||
fileTypeOptions: FileTypeOption[] = [];
|
||||
|
||||
@@ -77,7 +77,9 @@ export class AdditionalFileUploaderComponent implements OnInit, OnDestroy {
|
||||
)
|
||||
.subscribe(settings => {
|
||||
if (settings) {
|
||||
this.maxFileSizeBytes = (settings.maxFileUploadSizeInMb || 100) * 1024 * 1024;
|
||||
const maxSizeMb = settings.maxFileUploadSizeInMb || 100;
|
||||
this.maxFileSizeBytes = maxSizeMb * 1024 * 1024;
|
||||
this.maxFileSizeDisplay = `${maxSizeMb} MB`;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -155,8 +157,7 @@ export class AdditionalFileUploaderComponent implements OnInit, OnDestroy {
|
||||
this.bookFileService.uploadAdditionalFile(
|
||||
this.book.id,
|
||||
uploadFile.file,
|
||||
this.fileType,
|
||||
this.description || undefined
|
||||
this.fileType
|
||||
).subscribe({
|
||||
next: () => {
|
||||
uploadFile.status = 'Uploaded';
|
||||
|
||||
@@ -136,7 +136,7 @@ export class BookFileService {
|
||||
);
|
||||
}
|
||||
|
||||
uploadAdditionalFile(bookId: number, file: File, fileType: AdditionalFileType, description?: string): Observable<AdditionalFile> {
|
||||
uploadAdditionalFile(bookId: number, file: File, fileType: AdditionalFileType): Observable<AdditionalFile> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
@@ -146,24 +146,21 @@ export class BookFileService {
|
||||
if (isBook) {
|
||||
const lower = (file?.name || '').toLowerCase();
|
||||
const ext = lower.includes('.') ? lower.substring(lower.lastIndexOf('.') + 1) : '';
|
||||
const bookType = ext === 'pdf'
|
||||
? 'PDF'
|
||||
: ext === 'epub'
|
||||
? 'EPUB'
|
||||
: (ext === 'cbz' || ext === 'cbr' || ext === 'cb7' || ext === 'cbt')
|
||||
? 'CBX'
|
||||
: (ext === 'm4b' || ext === 'm4a' || ext === 'mp3')
|
||||
? 'AUDIOBOOK'
|
||||
: null;
|
||||
const EXTENSION_TO_BOOK_TYPE: Record<string, string> = {
|
||||
pdf: 'PDF',
|
||||
epub: 'EPUB',
|
||||
cbz: 'CBX', cbr: 'CBX', cb7: 'CBX',
|
||||
mobi: 'MOBI',
|
||||
azw3: 'AZW3', azw: 'AZW3',
|
||||
fb2: 'FB2',
|
||||
m4b: 'AUDIOBOOK', m4a: 'AUDIOBOOK', mp3: 'AUDIOBOOK',
|
||||
};
|
||||
const bookType = EXTENSION_TO_BOOK_TYPE[ext] ?? null;
|
||||
|
||||
if (bookType) {
|
||||
formData.append('bookType', bookType);
|
||||
}
|
||||
}
|
||||
if (description) {
|
||||
formData.append('description', description);
|
||||
}
|
||||
|
||||
return this.http.post<AdditionalFile>(`${this.url}/${bookId}/files`, formData).pipe(
|
||||
tap((newFile) => {
|
||||
const currentState = this.bookStateService.getCurrentBookState();
|
||||
|
||||
Reference in New Issue
Block a user