Webtoon Reader Fixup (#405)
* Navigate users to library page instead of home to prevent history block. * Cleaned up the Contributing to describe new code structure * Fixed a critical bug for how we find files for a chapter download (use ChapterId for lookup, not MangaFile.Id). Refactored how downloading works on the UI side to use the backend's filename whenever possible, else provide a custom name (and use backend's extension) for bundled downloads. * Fixed a bug where scroll intersection wasn't working on books without a table of content, even though it should have. * If user is using a direct url and hits an authentication guard, cache the url, allow authentication, then redirect them to said url * Added a transaction for bookmarking due to a rare case (in dev machines) where bookmark progress can duplicate * Re-enabled webtoon preference in reader settings. Refactored gotopage into it's own, dedicated handler to simplify logic. * Moved the prefetching code to occur whenever the page number within infinite scroller changes. This results in an easier to understand functioning. * Fixed isElementVisible() which was not properly calculating element visibility * GoToPage going forwards is working as expected, going backwards is completly broken * After performing a gotopage, make sure we update the scrolling direction based on the delta. * Removed some stuff thats not used, split the prefetching code up into separate functions to prepare for a rewrite. * Reworked prefetching to ensure we have a buffer of pages around ourselves. It is not fully tested, but working much better than previous implementation. Will be enhanced with DOM Pruning. * Cleaned up some old cruft from the backend code * Cleaned up the webtoon page change handler to use setPageNum, which will handle the correct prefetching of next/prev chapter * More cleanup around the codebase * Refactored the code to use a map to keep track of what is loaded or not, which works better than max/min in cases where you jump to a page that doesn't have anything preloaded and loads images out of order * Fixed a bad placement of code for when you are unauthenticated, the code will now redirect to the original location you requested before you had to login. * Some cleanup. Fixed the scrolling issue with prev page, spec seems to not work on intersection observer. using 0.01 instead of 0.0.
This commit is contained in:
parent
1cd68be4e2
commit
eb88967545
21 changed files with 275 additions and 299 deletions
|
@ -1,4 +1,4 @@
|
|||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Series } from 'src/app/_models/series';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
@ -35,15 +35,15 @@ export class DownloadService {
|
|||
}
|
||||
|
||||
private downloadSeriesAPI(seriesId: number) {
|
||||
return this.httpClient.get(this.baseUrl + 'download/series?seriesId=' + seriesId, {responseType: 'blob' as 'text'});
|
||||
return this.httpClient.get(this.baseUrl + 'download/series?seriesId=' + seriesId, {observe: 'response', responseType: 'blob' as 'text'});
|
||||
}
|
||||
|
||||
private downloadVolumeAPI(volumeId: number) {
|
||||
return this.httpClient.get(this.baseUrl + 'download/volume?volumeId=' + volumeId, {responseType: 'blob' as 'text'});
|
||||
return this.httpClient.get(this.baseUrl + 'download/volume?volumeId=' + volumeId, {observe: 'response', responseType: 'blob' as 'text'});
|
||||
}
|
||||
|
||||
private downloadChapterAPI(chapterId: number) {
|
||||
return this.httpClient.get(this.baseUrl + 'download/chapter?chapterId=' + chapterId, {responseType: 'blob' as 'text'});
|
||||
return this.httpClient.get(this.baseUrl + 'download/chapter?chapterId=' + chapterId, {observe: 'response', responseType: 'blob' as 'text'});
|
||||
}
|
||||
|
||||
downloadSeries(series: Series) {
|
||||
|
@ -51,9 +51,10 @@ export class DownloadService {
|
|||
if (size >= this.SIZE_WARNING && !await this.confirmService.confirm('The series is ' + this.humanFileSize(size) + '. Are you sure you want to continue?')) {
|
||||
return;
|
||||
}
|
||||
this.downloadSeriesAPI(series.id).subscribe(res => {
|
||||
const filename = series.name + '.zip';
|
||||
this.preformSave(res, filename);
|
||||
this.downloadSeriesAPI(series.id).subscribe(resp => {
|
||||
//const filename = series.name + '.zip';
|
||||
//this.preformSave(res, filename);
|
||||
this.preformSave(resp.body || '', this.getFilenameFromHeader(resp.headers, series.name));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -63,9 +64,8 @@ export class DownloadService {
|
|||
if (size >= this.SIZE_WARNING && !await this.confirmService.confirm('The chapter is ' + this.humanFileSize(size) + '. Are you sure you want to continue?')) {
|
||||
return;
|
||||
}
|
||||
this.downloadChapterAPI(chapter.id).subscribe(res => {
|
||||
const filename = seriesName + ' - Chapter ' + chapter.number + '.zip';
|
||||
this.preformSave(res, filename);
|
||||
this.downloadChapterAPI(chapter.id).subscribe((resp: HttpResponse<string>) => {
|
||||
this.preformSave(resp.body || '', this.getFilenameFromHeader(resp.headers, seriesName + ' - Chapter ' + chapter.number));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -75,9 +75,8 @@ export class DownloadService {
|
|||
if (size >= this.SIZE_WARNING && !await this.confirmService.confirm('The chapter is ' + this.humanFileSize(size) + '. Are you sure you want to continue?')) {
|
||||
return;
|
||||
}
|
||||
this.downloadVolumeAPI(volume.id).subscribe(res => {
|
||||
const filename = seriesName + ' - Volume ' + volume.name + '.zip';
|
||||
this.preformSave(res, filename);
|
||||
this.downloadVolumeAPI(volume.id).subscribe(resp => {
|
||||
this.preformSave(resp.body || '', this.getFilenameFromHeader(resp.headers, seriesName + ' - Volume ' + volume.name));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -88,6 +87,23 @@ export class DownloadService {
|
|||
this.toastr.success('File downloaded successfully: ' + filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to parse out the filename from Content-Disposition header.
|
||||
* If it fails, will default to defaultName and add the correct extension. If no extension is found in header, will use zip.
|
||||
* @param headers
|
||||
* @param defaultName
|
||||
* @returns
|
||||
*/
|
||||
private getFilenameFromHeader(headers: HttpHeaders, defaultName: string) {
|
||||
const tokens = (headers.get('content-disposition') || '').split(';');
|
||||
let filename = tokens[1].replace('filename=', '').replace('"', '').trim();
|
||||
if (filename.startsWith('download_') || filename.startsWith('kavita_download_')) {
|
||||
const ext = filename.substring(filename.lastIndexOf('.'), filename.length);
|
||||
return defaultName + ext;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format bytes as human-readable text.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue