feat(kobo): add optional EPUB → KEpub conversion for Kobo downloads (#969)
This commit is contained in:
+46
-2
@@ -1,7 +1,7 @@
|
||||
<p-confirmDialog></p-confirmDialog>
|
||||
|
||||
<p class="text-lg flex items-center gap-2 px-4 pt-4 pb-2">
|
||||
Kobo Sync Settings:
|
||||
Kobo Integration Token:
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Click to view Kobo setup documentation"
|
||||
tooltipPosition="right"
|
||||
@@ -10,7 +10,7 @@
|
||||
</i>
|
||||
</p>
|
||||
|
||||
@if (hasPermission) {
|
||||
@if (hasKoboTokenPermission) {
|
||||
<form #koboForm="ngForm" class="px-4 py-2">
|
||||
<div class="flex flex-col px-4 py-4 space-y-4">
|
||||
<div class="flex flex-col gap-1 max-w-[33rem]">
|
||||
@@ -50,6 +50,50 @@
|
||||
</p-button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@if (isAdmin) {
|
||||
<div class="px-4 py-4">
|
||||
<p class="text-lg mb-4">Kobo Settings (Admin Only):</p>
|
||||
<div class="flex flex-col px-4 py-4 space-y-6 max-w-[75rem]">
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<p-toggle-switch
|
||||
id="convertToKepub"
|
||||
[(ngModel)]="koboSettings.convertToKepub"
|
||||
(ngModelChange)="onToggleChange()">
|
||||
</p-toggle-switch>
|
||||
<label for="convertToKepub" class="font-medium">Convert to KEPUB</label>
|
||||
</div>
|
||||
<p class="text-zinc-400 text-sm">
|
||||
<strong>Pros:</strong> KEPUB format enables enhanced Kobo features like better typography, reading stats, and faster page turns.
|
||||
<br>
|
||||
<strong>Cons:</strong> Conversion takes extra processing time and may occasionally fail for complex layouts.
|
||||
Books over the size limit below will skip conversion automatically.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex items-center gap-6">
|
||||
<label for="conversionLimit" class="font-medium">Conversion Size Limit: {{ koboSettings.conversionLimitInMb }} MB</label>
|
||||
</div>
|
||||
<p-slider
|
||||
class="max-w-64"
|
||||
id="conversionLimit"
|
||||
[(ngModel)]="koboSettings.conversionLimitInMb"
|
||||
[min]="1"
|
||||
[max]="250"
|
||||
[step]="1"
|
||||
(ngModelChange)="onSliderChange()">
|
||||
</p-slider>
|
||||
<p class="text-zinc-400 text-sm">
|
||||
Large files (100MB+) can cause conversion timeouts and server strain. Lower limits ensure faster syncing but may skip conversion of larger books.
|
||||
<br>
|
||||
<strong>Recommended:</strong> 50-100MB for most libraries. Very large books will sync as regular EPUB regardless of this setting.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="px-4 py-4 m-4 rounded-lg bg-red-700/30 border border-red-600 text-red-200 flex items-center gap-2 max-w-lg">
|
||||
<i class="pi pi-lock text-red-400 text-xl"></i>
|
||||
|
||||
+90
-14
@@ -8,15 +8,20 @@ import {InputText} from 'primeng/inputtext';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {UserService} from '../../user-management/user.service';
|
||||
import {Subject} from 'rxjs';
|
||||
import {filter, takeUntil} from 'rxjs/operators';
|
||||
import {debounceTime, filter, take, takeUntil} from 'rxjs/operators';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {SettingsHelperService} from '../../../core/service/settings-helper.service';
|
||||
import {AppSettingKey, KoboSettings} from '../../../core/model/app-settings.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-kobo-sync-setting-component',
|
||||
standalone: true,
|
||||
templateUrl: './kobo-sync-settings-component.html',
|
||||
styleUrl: './kobo-sync-settings-component.scss',
|
||||
imports: [FormsModule, Button, InputText, ConfirmDialog, Tooltip],
|
||||
imports: [FormsModule, Button, InputText, ConfirmDialog, Tooltip, ToggleSwitch, Slider],
|
||||
providers: [MessageService, ConfirmationService]
|
||||
})
|
||||
export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
@@ -25,34 +30,77 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private clipboard = inject(Clipboard);
|
||||
protected userService = inject(UserService);
|
||||
protected appSettingsService = inject(AppSettingsService);
|
||||
protected settingsHelperService = inject(SettingsHelperService);
|
||||
|
||||
private readonly destroy$ = new Subject<void>();
|
||||
hasPermission = false;
|
||||
private readonly sliderChange$ = new Subject<void>();
|
||||
|
||||
hasKoboTokenPermission = false;
|
||||
isAdmin = false;
|
||||
koboToken = '';
|
||||
credentialsSaved = false;
|
||||
showToken = false;
|
||||
|
||||
koboSettings: KoboSettings = {
|
||||
convertToKepub: false,
|
||||
conversionLimitInMb: 100
|
||||
};
|
||||
|
||||
ngOnInit() {
|
||||
this.setupSliderDebouncing();
|
||||
this.setupUserStateSubscription();
|
||||
}
|
||||
|
||||
private setupSliderDebouncing() {
|
||||
this.sliderChange$.pipe(
|
||||
debounceTime(500),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(() => {
|
||||
this.saveSettings();
|
||||
});
|
||||
}
|
||||
|
||||
private setupUserStateSubscription() {
|
||||
this.userService.userState$.pipe(
|
||||
filter(userState => !!userState?.user && userState.loaded),
|
||||
takeUntil(this.destroy$)
|
||||
).subscribe(userState => {
|
||||
this.hasPermission = (userState.user?.permissions.canSyncKobo || userState.user?.permissions.admin) ?? false;
|
||||
if (this.hasPermission) {
|
||||
this.koboService.getUser().subscribe({
|
||||
next: (settings: KoboSyncSettings) => {
|
||||
this.koboToken = settings.token;
|
||||
this.credentialsSaved = !!settings.token;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load Kobo settings'});
|
||||
}
|
||||
});
|
||||
this.hasKoboTokenPermission = (userState.user?.permissions.canSyncKobo) ?? false;
|
||||
this.isAdmin = userState.user?.permissions.admin ?? false;
|
||||
if (this.hasKoboTokenPermission) {
|
||||
this.loadKoboToken();
|
||||
}
|
||||
if (this.isAdmin) {
|
||||
this.loadKoboSettings();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private loadKoboToken() {
|
||||
this.koboService.getUser().subscribe({
|
||||
next: (settings: KoboSyncSettings) => {
|
||||
this.koboToken = settings.token;
|
||||
this.credentialsSaved = !!settings.token;
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load Kobo settings'});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private loadKoboSettings() {
|
||||
this.appSettingsService.appSettings$
|
||||
.pipe(
|
||||
filter(settings => settings != null),
|
||||
take(1),
|
||||
)
|
||||
.subscribe(settings => {
|
||||
this.koboSettings.convertToKepub = settings?.koboSettings?.convertToKepub ?? true;
|
||||
this.koboSettings.conversionLimitInMb = settings?.koboSettings?.conversionLimitInMb ?? 100;
|
||||
});
|
||||
}
|
||||
|
||||
copyText(text: string) {
|
||||
this.clipboard.copy(text);
|
||||
this.messageService.add({severity: 'success', summary: 'Copied', detail: 'Token copied to clipboard'});
|
||||
@@ -84,6 +132,34 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
onToggleChange() {
|
||||
this.saveSettings();
|
||||
}
|
||||
|
||||
onSliderChange() {
|
||||
this.sliderChange$.next();
|
||||
}
|
||||
|
||||
saveSettings() {
|
||||
this.settingsHelperService.saveSetting(AppSettingKey.KOBO_SETTINGS, this.koboSettings)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Settings Saved',
|
||||
detail: 'Kobo settings updated successfully'
|
||||
});
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Save Failed',
|
||||
detail: 'Failed to save Kobo settings'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openKoboDocumentation(): void {
|
||||
window.open('https://booklore-app.github.io/booklore-docs/docs/devices/kobo', '_blank');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user