Downloading Enhancements (#2599)

This commit is contained in:
Joe Milazzo 2024-01-11 14:08:57 -06:00 committed by GitHub
parent e6f6090fcf
commit 70cb687ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 139 additions and 45 deletions

View File

@ -118,7 +118,7 @@ public class DownloadController : BaseApiController
return await _accountService.HasDownloadPermission(user); return await _accountService.HasDownloadPermission(user);
} }
private ActionResult GetFirstFileDownload(IEnumerable<MangaFile> files) private PhysicalFileResult GetFirstFileDownload(IEnumerable<MangaFile> files)
{ {
var (zipFile, contentType, fileDownloadName) = _downloadService.GetFirstFileDownload(files); var (zipFile, contentType, fileDownloadName) = _downloadService.GetFirstFileDownload(files);
return PhysicalFile(zipFile, contentType, Uri.EscapeDataString(fileDownloadName), true); return PhysicalFile(zipFile, contentType, Uri.EscapeDataString(fileDownloadName), true);
@ -150,31 +150,40 @@ public class DownloadController : BaseApiController
private async Task<ActionResult> DownloadFiles(ICollection<MangaFile> files, string tempFolder, string downloadName) private async Task<ActionResult> DownloadFiles(ICollection<MangaFile> files, string tempFolder, string downloadName)
{ {
var username = User.GetUsername();
var filename = Path.GetFileNameWithoutExtension(downloadName);
try try
{ {
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress, await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(User.GetUsername(), MessageFactory.DownloadProgressEvent(username,
Path.GetFileNameWithoutExtension(downloadName), 0F, "started")); filename, $"Downloading {filename}", 0F, "started"));
if (files.Count == 1) if (files.Count == 1)
{ {
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress, await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(User.GetUsername(), MessageFactory.DownloadProgressEvent(username,
Path.GetFileNameWithoutExtension(downloadName), 1F, "ended")); filename, $"Downloading {filename}",1F, "ended"));
return GetFirstFileDownload(files); return GetFirstFileDownload(files);
} }
var filePath = _archiveService.CreateZipForDownload(files.Select(c => c.FilePath), tempFolder); var filePath = _archiveService.CreateZipFromFoldersForDownload(files.Select(c => c.FilePath).ToList(), tempFolder, ProgressCallback);
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress, await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(User.GetUsername(), MessageFactory.DownloadProgressEvent(username,
Path.GetFileNameWithoutExtension(downloadName), 1F, "ended")); filename, "Download Complete", 1F, "ended"));
return PhysicalFile(filePath, DefaultContentType, Uri.EscapeDataString(downloadName), true); return PhysicalFile(filePath, DefaultContentType, Uri.EscapeDataString(downloadName), true);
async Task ProgressCallback(Tuple<string, float> progressInfo)
{
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(username, filename, $"Extracting {Path.GetFileNameWithoutExtension(progressInfo.Item1)}",
Math.Clamp(progressInfo.Item2, 0F, 1F)));
}
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "There was an exception when trying to download files"); _logger.LogError(ex, "There was an exception when trying to download files");
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress, await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(User.GetUsername(), MessageFactory.DownloadProgressEvent(User.GetUsername(),
Path.GetFileNameWithoutExtension(downloadName), 1F, "ended")); filename, "Download Complete", 1F, "ended"));
throw; throw;
} }
} }
@ -216,12 +225,12 @@ public class DownloadController : BaseApiController
var filename = $"{series!.Name} - Bookmarks.zip"; var filename = $"{series!.Name} - Bookmarks.zip";
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress, await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(username, Path.GetFileNameWithoutExtension(filename), 0F)); MessageFactory.DownloadProgressEvent(username, Path.GetFileNameWithoutExtension(filename), $"Downloading {filename}",0F));
var seriesIds = string.Join("_", downloadBookmarkDto.Bookmarks.Select(b => b.SeriesId).Distinct()); var seriesIds = string.Join("_", downloadBookmarkDto.Bookmarks.Select(b => b.SeriesId).Distinct());
var filePath = _archiveService.CreateZipForDownload(files, var filePath = _archiveService.CreateZipForDownload(files,
$"download_{userId}_{seriesIds}_bookmarks"); $"download_{userId}_{seriesIds}_bookmarks");
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress, await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.DownloadProgressEvent(username, Path.GetFileNameWithoutExtension(filename), 1F)); MessageFactory.DownloadProgressEvent(username, Path.GetFileNameWithoutExtension(filename), $"Downloading {filename}", 1F));
return PhysicalFile(filePath, DefaultContentType, System.Web.HttpUtility.UrlEncode(filename), true); return PhysicalFile(filePath, DefaultContentType, System.Web.HttpUtility.UrlEncode(filename), true);

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.Serialization; using System.Xml.Serialization;
using API.Archive; using API.Archive;
@ -30,13 +31,21 @@ public interface IArchiveService
ArchiveLibrary CanOpen(string archivePath); ArchiveLibrary CanOpen(string archivePath);
bool ArchiveNeedsFlattening(ZipArchive archive); bool ArchiveNeedsFlattening(ZipArchive archive);
/// <summary> /// <summary>
/// Creates a zip file form the listed files and outputs to the temp folder. /// Creates a zip file form the listed files and outputs to the temp folder. This will combine into one zip of multiple zips.
/// </summary> /// </summary>
/// <param name="files">List of files to be zipped up. Should be full file paths.</param> /// <param name="files">List of files to be zipped up. Should be full file paths.</param>
/// <param name="tempFolder">Temp folder name to use for preparing the files. Will be created and deleted</param> /// <param name="tempFolder">Temp folder name to use for preparing the files. Will be created and deleted</param>
/// <returns>Path to the temp zip</returns> /// <returns>Path to the temp zip</returns>
/// <exception cref="KavitaException"></exception> /// <exception cref="KavitaException"></exception>
string CreateZipForDownload(IEnumerable<string> files, string tempFolder); string CreateZipForDownload(IEnumerable<string> files, string tempFolder);
/// <summary>
/// Creates a zip file form the listed files and outputs to the temp folder. This will extract each archive and combine them into one zip.
/// </summary>
/// <param name="files">List of files to be zipped up. Should be full file paths.</param>
/// <param name="tempFolder">Temp folder name to use for preparing the files. Will be created and deleted</param>
/// <returns>Path to the temp zip</returns>
/// <exception cref="KavitaException"></exception>
string CreateZipFromFoldersForDownload(IList<string> files, string tempFolder, Func<Tuple<string, float>, Task> progressCallback);
} }
/// <summary> /// <summary>
@ -322,6 +331,54 @@ public class ArchiveService : IArchiveService
return zipPath; return zipPath;
} }
public string CreateZipFromFoldersForDownload(IList<string> files, string tempFolder, Func<Tuple<string, float>, Task> progressCallback)
{
var dateString = DateTime.UtcNow.ToShortDateString().Replace("/", "_");
var potentialExistingFile = _directoryService.FileSystem.FileInfo.New(Path.Join(_directoryService.TempDirectory, $"kavita_{tempFolder}_{dateString}.zip"));
if (potentialExistingFile.Exists)
{
// A previous download exists, just return it immediately
return potentialExistingFile.FullName;
}
// Extract all the files to a temp directory and create zip on that
var tempLocation = Path.Join(_directoryService.TempDirectory, $"{tempFolder}_{dateString}");
var totalFiles = files.Count + 1;
var count = 1f;
try
{
_directoryService.ExistOrCreate(tempLocation);
foreach (var path in files)
{
var tempPath = Path.Join(tempLocation, _directoryService.FileSystem.Path.GetFileNameWithoutExtension(_directoryService.FileSystem.FileInfo.New(path).Name));
_directoryService.ExistOrCreate(tempPath);
progressCallback(Tuple.Create(_directoryService.FileSystem.FileInfo.New(path).Name, (1.0f * totalFiles) / count));
ExtractArchive(path, tempPath);
count++;
}
}
catch
{
throw new KavitaException("bad-copy-files-for-download");
}
var zipPath = Path.Join(_directoryService.TempDirectory, $"kavita_{tempFolder}_{dateString}.zip");
try
{
ZipFile.CreateFromDirectory(tempLocation, zipPath);
// Remove the folder as we have the zip
_directoryService.ClearAndDeleteDirectory(tempLocation);
}
catch (AggregateException ex)
{
_logger.LogError(ex, "There was an issue creating temp archive");
throw new KavitaException("generic-create-temp-archive");
}
return zipPath;
}
/// <summary> /// <summary>
/// Test if the archive path exists and an archive /// Test if the archive path exists and an archive
@ -477,7 +534,7 @@ public class ArchiveService : IArchiveService
{ {
if (!IsValidArchive(archivePath)) return; if (!IsValidArchive(archivePath)) return;
if (Directory.Exists(extractPath)) return; if (_directoryService.FileSystem.Directory.Exists(extractPath)) return;
if (!_directoryService.FileSystem.File.Exists(archivePath)) if (!_directoryService.FileSystem.File.Exists(archivePath))
{ {

View File

@ -376,13 +376,13 @@ public static class MessageFactory
}; };
} }
public static SignalRMessage DownloadProgressEvent(string username, string downloadName, float progress, string eventType = "updated") public static SignalRMessage DownloadProgressEvent(string username, string downloadName, string subtitle, float progress, string eventType = "updated")
{ {
return new SignalRMessage() return new SignalRMessage()
{ {
Name = DownloadProgress, Name = DownloadProgress,
Title = $"Downloading {downloadName}", Title = $"Preparing {username.SentenceCase()} the download of {downloadName}",
SubTitle = $"Preparing {username.SentenceCase()} the download of {downloadName}", SubTitle = subtitle,
EventType = eventType, EventType = eventType,
Progress = ProgressType.Determinate, Progress = ProgressType.Determinate,
Body = new Body = new

View File

@ -68,6 +68,7 @@
"optimization": true, "optimization": true,
"outputHashing": "all", "outputHashing": "all",
"namedChunks": false, "namedChunks": false,
"aot": true,
"extractLicenses": true, "extractLicenses": true,
"budgets": [ "budgets": [
{ {

View File

@ -994,6 +994,7 @@
"version": "17.0.8", "version": "17.0.8",
"resolved": "https://registry.npmjs.org/@angular/compiler-cli/-/compiler-cli-17.0.8.tgz", "resolved": "https://registry.npmjs.org/@angular/compiler-cli/-/compiler-cli-17.0.8.tgz",
"integrity": "sha512-ny2SMVgl+icjMuU5ZM57yFGUrhjR0hNxfCn0otAD3jUFliz/Onu9l6EPRKA5Cr8MZx3mg3rTLSBMD17YT8rsOg==", "integrity": "sha512-ny2SMVgl+icjMuU5ZM57yFGUrhjR0hNxfCn0otAD3jUFliz/Onu9l6EPRKA5Cr8MZx3mg3rTLSBMD17YT8rsOg==",
"dev": true,
"dependencies": { "dependencies": {
"@babel/core": "7.23.2", "@babel/core": "7.23.2",
"@jridgewell/sourcemap-codec": "^1.4.14", "@jridgewell/sourcemap-codec": "^1.4.14",
@ -5858,6 +5859,7 @@
"version": "3.1.3", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
"integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==",
"dev": true,
"dependencies": { "dependencies": {
"normalize-path": "^3.0.0", "normalize-path": "^3.0.0",
"picomatch": "^2.0.4" "picomatch": "^2.0.4"
@ -6114,6 +6116,7 @@
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
"dev": true,
"engines": { "engines": {
"node": ">=8" "node": ">=8"
} }
@ -6721,6 +6724,7 @@
"version": "3.5.3", "version": "3.5.3",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz",
"integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==",
"dev": true,
"funding": [ "funding": [
{ {
"type": "individual", "type": "individual",
@ -7008,7 +7012,8 @@
"node_modules/convert-source-map": { "node_modules/convert-source-map": {
"version": "1.9.0", "version": "1.9.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz",
"integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==" "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==",
"dev": true
}, },
"node_modules/cookie": { "node_modules/cookie": {
"version": "0.4.2", "version": "0.4.2",
@ -8005,6 +8010,7 @@
"version": "0.1.13", "version": "0.1.13",
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz",
"integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==",
"dev": true,
"optional": true, "optional": true,
"dependencies": { "dependencies": {
"iconv-lite": "^0.6.2" "iconv-lite": "^0.6.2"
@ -8014,6 +8020,7 @@
"version": "0.6.3", "version": "0.6.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
"dev": true,
"optional": true, "optional": true,
"dependencies": { "dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0" "safer-buffer": ">= 2.1.2 < 3.0.0"
@ -9295,6 +9302,7 @@
"version": "2.3.2", "version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"hasInstallScript": true, "hasInstallScript": true,
"optional": true, "optional": true,
"os": [ "os": [
@ -10078,6 +10086,7 @@
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
"integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
"dev": true,
"dependencies": { "dependencies": {
"binary-extensions": "^2.0.0" "binary-extensions": "^2.0.0"
}, },
@ -11990,6 +11999,7 @@
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
"dev": true,
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=0.10.0"
} }
@ -13416,6 +13426,7 @@
"version": "3.6.0", "version": "3.6.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
"integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==",
"dev": true,
"dependencies": { "dependencies": {
"picomatch": "^2.2.1" "picomatch": "^2.2.1"
}, },
@ -13426,7 +13437,8 @@
"node_modules/reflect-metadata": { "node_modules/reflect-metadata": {
"version": "0.1.13", "version": "0.1.13",
"resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz",
"integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==",
"dev": true
}, },
"node_modules/regenerate": { "node_modules/regenerate": {
"version": "1.4.2", "version": "1.4.2",
@ -13896,7 +13908,7 @@
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"devOptional": true "dev": true
}, },
"node_modules/sass": { "node_modules/sass": {
"version": "1.69.5", "version": "1.69.5",
@ -14012,6 +14024,7 @@
"version": "7.5.3", "version": "7.5.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz",
"integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==",
"dev": true,
"dependencies": { "dependencies": {
"lru-cache": "^6.0.0" "lru-cache": "^6.0.0"
}, },
@ -14026,6 +14039,7 @@
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"dependencies": { "dependencies": {
"yallist": "^4.0.0" "yallist": "^4.0.0"
}, },
@ -14036,7 +14050,8 @@
"node_modules/semver/node_modules/yallist": { "node_modules/semver/node_modules/yallist": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
}, },
"node_modules/send": { "node_modules/send": {
"version": "0.16.2", "version": "0.16.2",
@ -15287,6 +15302,7 @@
"version": "5.2.2", "version": "5.2.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz",
"integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==",
"dev": true,
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",
"tsserver": "bin/tsserver" "tsserver": "bin/tsserver"

View File

@ -1,12 +1,12 @@
{ {
"name": "kavita-webui", "name": "kavita-webui",
"version": "0.4.2", "version": "0.7.12.1",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve", "start": "ng serve",
"build": "ng build", "build": "ng build",
"minify-langs": "node minify-json.js", "minify-langs": "node minify-json.js",
"prod": "ng build --configuration production --aot --output-hashing=all && npm run minify-langs", "prod": "ng build --configuration production && npm run minify-langs",
"explore": "ng build --stats-json && webpack-bundle-analyzer dist/stats.json", "explore": "ng build --stats-json && webpack-bundle-analyzer dist/stats.json",
"lint": "ng lint", "lint": "ng lint",
"e2e": "ng e2e" "e2e": "ng e2e"

View File

@ -40,7 +40,7 @@ export class NavService {
this.renderer = rendererFactory.createRenderer(null, null); this.renderer = rendererFactory.createRenderer(null, null);
// To avoid flashing, let's check if we are authenticated before we show // To avoid flashing, let's check if we are authenticated before we show
this.accountService.currentUser$.subscribe(u => { this.accountService.currentUser$.pipe(take(1)).subscribe(u => {
if (u) { if (u) {
this.showNavBar(); this.showNavBar();
} }

View File

@ -19,7 +19,7 @@ export class ReviewSeriesModalComponent implements OnInit {
protected readonly modal = inject(NgbActiveModal); protected readonly modal = inject(NgbActiveModal);
private readonly seriesService = inject(SeriesService); private readonly seriesService = inject(SeriesService);
private readonly cdRef = inject(ChangeDetectorRef); private readonly cdRef = inject(ChangeDetectorRef);
protected readonly minLength = 20; protected readonly minLength = 5;
@Input({required: true}) review!: UserReview; @Input({required: true}) review!: UserReview;
reviewGroup!: FormGroup; reviewGroup!: FormGroup;

View File

@ -277,11 +277,23 @@ export class CardItemComponent implements OnInit {
}); });
this.download$ = this.downloadService.activeDownloads$.pipe(takeUntilDestroyed(this.destroyRef), map((events) => { this.download$ = this.downloadService.activeDownloads$.pipe(takeUntilDestroyed(this.destroyRef), map((events) => {
if(this.utilityService.isSeries(this.entity)) return events.find(e => e.entityType === 'series' && e.subTitle === this.downloadService.downloadSubtitle('series', (this.entity as Series))) || null; if(this.utilityService.isSeries(this.entity)) {
if(this.utilityService.isVolume(this.entity)) return events.find(e => e.entityType === 'volume' && e.subTitle === this.downloadService.downloadSubtitle('volume', (this.entity as Volume))) || null; return events.find(e => e.entityType === 'series' && e.id == this.entity.id
if(this.utilityService.isChapter(this.entity)) return events.find(e => e.entityType === 'chapter' && e.subTitle === this.downloadService.downloadSubtitle('chapter', (this.entity as Chapter))) || null; && e.subTitle === this.downloadService.downloadSubtitle('series', (this.entity as Series))) || null;
}
if(this.utilityService.isVolume(this.entity)) {
return events.find(e => e.entityType === 'volume' && e.id == this.entity.id
&& e.subTitle === this.downloadService.downloadSubtitle('volume', (this.entity as Volume))) || null;
}
if(this.utilityService.isChapter(this.entity)) {
return events.find(e => e.entityType === 'chapter' && e.id == this.entity.id
&& e.subTitle === this.downloadService.downloadSubtitle('chapter', (this.entity as Chapter))) || null;
}
// Is PageBookmark[] // Is PageBookmark[]
if(this.entity.hasOwnProperty('length')) return events.find(e => e.entityType === 'bookmark' && e.subTitle === this.downloadService.downloadSubtitle('bookmark', [(this.entity as PageBookmark)])) || null; if(this.entity.hasOwnProperty('length')) {
return events.find(e => e.entityType === 'bookmark'
&& e.subTitle === this.downloadService.downloadSubtitle('bookmark', [(this.entity as PageBookmark)])) || null;
}
return null; return null;
})); }));

View File

@ -20,6 +20,4 @@ export class DownloadIndicatorComponent {
* Observable that represents when the download completes * Observable that represents when the download completes
*/ */
@Input({required: true}) download$!: Observable<Download | DownloadEvent | null> | null; @Input({required: true}) download$!: Observable<Download | DownloadEvent | null> | null;
constructor() { }
} }

View File

@ -48,7 +48,7 @@
<div class="btn-group me-3"> <div class="btn-group me-3">
<button type="button" class="btn btn-primary" (click)="continue()"> <button type="button" class="btn btn-primary" (click)="continue()">
<span> <span>
<i class="fa fa-book-open" aria-hidden="true"></i> <i class="fa fa-book-open me-1" aria-hidden="true"></i>
<span class="read-btn--text">{{t('continue')}}</span> <span class="read-btn--text">{{t('continue')}}</span>
</span> </span>
</button> </button>
@ -63,7 +63,7 @@
</button> </button>
<button ngbDropdownItem (click)="continue(true)"> <button ngbDropdownItem (click)="continue(true)">
<span> <span>
<i class="fa fa-book-open" aria-hidden="true"></i> <i class="fa fa-book-open me-1" aria-hidden="true"></i>
<span class="read-btn--text">{{t('continue')}}</span> <span class="read-btn--text">{{t('continue')}}</span>
(<i class="fa fa-glasses ms-1" aria-hidden="true"></i>) (<i class="fa fa-glasses ms-1" aria-hidden="true"></i>)
<span class="visually-hidden">{{t('incognito-alt')}}</span> <span class="visually-hidden">{{t('incognito-alt')}}</span>
@ -71,7 +71,7 @@
</button> </button>
<button ngbDropdownItem (click)="read(true)"> <button ngbDropdownItem (click)="read(true)">
<span> <span>
<i class="fa fa-book" aria-hidden="true"></i> <i class="fa fa-book me-1" aria-hidden="true"></i>
<span class="read-btn--text">&nbsp;{{t('read')}}</span> <span class="read-btn--text">&nbsp;{{t('read')}}</span>
(<i class="fa fa-glasses ms-1" aria-hidden="true"></i>) (<i class="fa fa-glasses ms-1" aria-hidden="true"></i>)
<span class="visually-hidden">{{t('incognito-alt')}}</span> <span class="visually-hidden">{{t('incognito-alt')}}</span>

View File

@ -40,6 +40,10 @@ export interface DownloadEvent {
* Progress of the download itself * Progress of the download itself
*/ */
progress: number; progress: number;
/**
* Entity id. For entities without id like logs or bookmarks, uses 0 instead
*/
id: number;
} }
/** /**
@ -178,7 +182,7 @@ export class DownloadService {
download((blob, filename) => { download((blob, filename) => {
this.save(blob, decodeURIComponent(filename)); this.save(blob, decodeURIComponent(filename));
}), }),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)), tap((d) => this.updateDownloadState(d, downloadType, subtitle, 0)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle)) finalize(() => this.finalizeDownloadState(downloadType, subtitle))
); );
} }
@ -193,7 +197,7 @@ export class DownloadService {
download((blob, filename) => { download((blob, filename) => {
this.save(blob, decodeURIComponent(filename)); this.save(blob, decodeURIComponent(filename));
}), }),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)), tap((d) => this.updateDownloadState(d, downloadType, subtitle, series.id)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle)) finalize(() => this.finalizeDownloadState(downloadType, subtitle))
); );
} }
@ -204,12 +208,12 @@ export class DownloadService {
this.downloadsSource.next(values); this.downloadsSource.next(values);
} }
private updateDownloadState(d: Download, entityType: DownloadEntityType, entitySubtitle: string) { private updateDownloadState(d: Download, entityType: DownloadEntityType, entitySubtitle: string, id: number) {
let values = this.downloadsSource.getValue(); let values = this.downloadsSource.getValue();
if (d.state === 'PENDING') { if (d.state === 'PENDING') {
const index = values.findIndex(v => v.entityType === entityType && v.subTitle === entitySubtitle); const index = values.findIndex(v => v.entityType === entityType && v.subTitle === entitySubtitle);
if (index >= 0) return; // Don't let us duplicate add if (index >= 0) return; // Don't let us duplicate add
values.push({entityType: entityType, subTitle: entitySubtitle, progress: 0}); values.push({entityType: entityType, subTitle: entitySubtitle, progress: 0, id});
} else if (d.state === 'IN_PROGRESS') { } else if (d.state === 'IN_PROGRESS') {
const index = values.findIndex(v => v.entityType === entityType && v.subTitle === entitySubtitle); const index = values.findIndex(v => v.entityType === entityType && v.subTitle === entitySubtitle);
if (index >= 0) { if (index >= 0) {
@ -232,7 +236,7 @@ export class DownloadService {
download((blob, filename) => { download((blob, filename) => {
this.save(blob, decodeURIComponent(filename)); this.save(blob, decodeURIComponent(filename));
}), }),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)), tap((d) => this.updateDownloadState(d, downloadType, subtitle, chapter.id)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle)) finalize(() => this.finalizeDownloadState(downloadType, subtitle))
); );
} }
@ -247,14 +251,14 @@ export class DownloadService {
download((blob, filename) => { download((blob, filename) => {
this.save(blob, decodeURIComponent(filename)); this.save(blob, decodeURIComponent(filename));
}), }),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)), tap((d) => this.updateDownloadState(d, downloadType, subtitle, volume.id)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle)) finalize(() => this.finalizeDownloadState(downloadType, subtitle))
); );
} }
private async confirmSize(size: number, entityType: DownloadEntityType) { private async confirmSize(size: number, entityType: DownloadEntityType) {
return (size < this.SIZE_WARNING || return (size < this.SIZE_WARNING ||
await this.confirmService.confirm(translate('toasts.confirm-download-size', {entityType: 'entity-type.' + entityType, size: bytesPipe.transform(size)}))); await this.confirmService.confirm(translate('toasts.confirm-download-size', {entityType: translate('entity-type.' + entityType), size: bytesPipe.transform(size)})));
} }
private downloadBookmarks(bookmarks: PageBookmark[]) { private downloadBookmarks(bookmarks: PageBookmark[]) {
@ -268,7 +272,7 @@ export class DownloadService {
download((blob, filename) => { download((blob, filename) => {
this.save(blob, decodeURIComponent(filename)); this.save(blob, decodeURIComponent(filename));
}), }),
tap((d) => this.updateDownloadState(d, downloadType, subtitle)), tap((d) => this.updateDownloadState(d, downloadType, subtitle, 0)),
finalize(() => this.finalizeDownloadState(downloadType, subtitle)) finalize(() => this.finalizeDownloadState(downloadType, subtitle))
); );
} }

View File

@ -3,7 +3,6 @@
} }
.stat-container { .stat-container {
max-width: 700px;
height: auto; height: auto;
box-sizing:border-box; box-sizing:border-box;
} }

View File

@ -32,7 +32,6 @@ export class ReadingActivityComponent implements OnInit {
@Input() individualUserMode: boolean = false; @Input() individualUserMode: boolean = false;
private readonly destroyRef = inject(DestroyRef); private readonly destroyRef = inject(DestroyRef);
//private readonly translocoService = inject(TranslocoService);
private readonly statService = inject(StatisticsService); private readonly statService = inject(StatisticsService);
private readonly memberService = inject(MemberService); private readonly memberService = inject(MemberService);
@ -44,7 +43,6 @@ export class ReadingActivityComponent implements OnInit {
users$: Observable<Member[]> | undefined; users$: Observable<Member[]> | undefined;
data$: Observable<Array<PieDataItem>>; data$: Observable<Array<PieDataItem>>;
timePeriods = TimePeriods; timePeriods = TimePeriods;
//mangaFormatPipe = new MangaFormatPipe(this.translocoService);
constructor() { constructor() {
this.data$ = this.formGroup.valueChanges.pipe( this.data$ = this.formGroup.valueChanges.pipe(

View File

@ -7,7 +7,7 @@
"name": "GPL-3.0", "name": "GPL-3.0",
"url": "https://github.com/Kareadita/Kavita/blob/develop/LICENSE" "url": "https://github.com/Kareadita/Kavita/blob/develop/LICENSE"
}, },
"version": "0.7.12.0" "version": "0.7.12.1"
}, },
"servers": [ "servers": [
{ {