mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-23 07:20:32 -04:00
Komf API (#3050)
This commit is contained in:
parent
e43b6110bb
commit
c7f444a185
@ -155,21 +155,3 @@ jobs:
|
|||||||
|
|
||||||
- name: Image digest
|
- name: Image digest
|
||||||
run: echo ${{ steps.docker_build_nightly.outputs.digest }}
|
run: echo ${{ steps.docker_build_nightly.outputs.digest }}
|
||||||
|
|
||||||
- name: Notify Discord
|
|
||||||
uses: rjstone/discord-webhook-notify@v1
|
|
||||||
with:
|
|
||||||
severity: info
|
|
||||||
description: v${{steps.get-version.outputs.assembly-version}} - ${{ steps.findPr.outputs.title }}
|
|
||||||
details: '${{ steps.findPr.outputs.body }}'
|
|
||||||
text: <@&939225192553644133> A new stable build has been released.
|
|
||||||
webhookUrl: ${{ secrets.DISCORD_DOCKER_UPDATE_URL }}
|
|
||||||
|
|
||||||
- name: Notify Discord
|
|
||||||
uses: rjstone/discord-webhook-notify@v1
|
|
||||||
with:
|
|
||||||
severity: info
|
|
||||||
description: v${{steps.get-version.outputs.assembly-version}} - ${{ steps.findPr.outputs.title }}
|
|
||||||
details: '${{ steps.findPr.outputs.body }}'
|
|
||||||
text: <@&939225459156217917> <@&939225350775406643> A new nightly build has been released for docker.
|
|
||||||
webhookUrl: ${{ secrets.DISCORD_DOCKER_UPDATE_URL }}
|
|
@ -13,6 +13,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="Build" Condition=" '$(Configuration)' == 'Debug' ">
|
<Target Name="PostBuild" AfterTargets="Build" Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
<Delete Files="../openapi.json" />
|
||||||
<Exec Command="swagger tofile --output ../openapi.json bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).dll v1" />
|
<Exec Command="swagger tofile --output ../openapi.json bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).dll v1" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using API.Constants;
|
using API.Constants;
|
||||||
using API.Data;
|
using API.Data;
|
||||||
|
using API.Data.Repositories;
|
||||||
using API.DTOs.Uploads;
|
using API.DTOs.Uploads;
|
||||||
using API.Entities.Enums;
|
using API.Entities.Enums;
|
||||||
using API.Extensions;
|
using API.Extensions;
|
||||||
@ -293,6 +295,65 @@ public class UploadController : BaseApiController
|
|||||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-cover-chapter-save"));
|
return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-cover-chapter-save"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replaces volume cover image and locks it with a base64 encoded image.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>This is a helper API for Komf - Kavita UI does not use. Volume will find first chapter to update.</remarks>
|
||||||
|
/// <param name="uploadFileDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Authorize(Policy = "RequireAdminRole")]
|
||||||
|
[RequestSizeLimit(ControllerConstants.MaxUploadSizeBytes)]
|
||||||
|
[HttpPost("volume")]
|
||||||
|
public async Task<ActionResult> UploadVolumeCoverImageFromUrl(UploadFileDto uploadFileDto)
|
||||||
|
{
|
||||||
|
// Check if Url is non empty, request the image and place in temp, then ask image service to handle it.
|
||||||
|
// See if we can do this all in memory without touching underlying system
|
||||||
|
if (string.IsNullOrEmpty(uploadFileDto.Url))
|
||||||
|
{
|
||||||
|
return BadRequest(await _localizationService.Translate(User.GetUserId(), "url-required"));
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var volume = await _unitOfWork.VolumeRepository.GetVolumeAsync(uploadFileDto.Id, VolumeIncludes.Chapters);
|
||||||
|
if (volume == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "volume-doesnt-exist"));
|
||||||
|
|
||||||
|
// Find the first chapter of the volume
|
||||||
|
var chapter = volume.Chapters[0];
|
||||||
|
|
||||||
|
var filePath = await CreateThumbnail(uploadFileDto, $"{ImageService.GetChapterFormat(chapter.Id, uploadFileDto.Id)}");
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(filePath))
|
||||||
|
{
|
||||||
|
chapter.CoverImage = filePath;
|
||||||
|
chapter.CoverImageLocked = true;
|
||||||
|
_unitOfWork.ChapterRepository.Update(chapter);
|
||||||
|
|
||||||
|
volume.CoverImage = chapter.CoverImage;
|
||||||
|
_unitOfWork.VolumeRepository.Update(volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_unitOfWork.HasChanges())
|
||||||
|
{
|
||||||
|
await _unitOfWork.CommitAsync();
|
||||||
|
await _eventHub.SendMessageAsync(MessageFactory.CoverUpdate,
|
||||||
|
MessageFactory.CoverUpdateEvent(chapter.VolumeId, MessageFactoryEntityTypes.Volume), false);
|
||||||
|
await _eventHub.SendMessageAsync(MessageFactory.CoverUpdate,
|
||||||
|
MessageFactory.CoverUpdateEvent(volume.Id, MessageFactoryEntityTypes.Chapter), false);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "There was an issue uploading cover image for Volume {Id}", uploadFileDto.Id);
|
||||||
|
await _unitOfWork.RollbackAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-cover-volume-save"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces library cover image with a base64 encoded image. If empty string passed, will reset to null.
|
/// Replaces library cover image with a base64 encoded image. If empty string passed, will reset to null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -138,6 +138,8 @@
|
|||||||
"generic-cover-reading-list-save": "Unable to save cover image to Reading List",
|
"generic-cover-reading-list-save": "Unable to save cover image to Reading List",
|
||||||
"generic-cover-chapter-save": "Unable to save cover image to Chapter",
|
"generic-cover-chapter-save": "Unable to save cover image to Chapter",
|
||||||
"generic-cover-library-save": "Unable to save cover image to Library",
|
"generic-cover-library-save": "Unable to save cover image to Library",
|
||||||
|
"generic-cover-person-save": "Unable to save cover image to Person",
|
||||||
|
"generic-cover-volume-save": "Unable to save cover image to Volume",
|
||||||
"access-denied": "You do not have access",
|
"access-denied": "You do not have access",
|
||||||
"reset-chapter-lock": "Unable to resetting cover lock for Chapter",
|
"reset-chapter-lock": "Unable to resetting cover lock for Chapter",
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ public class ImageService : IImageService
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a thumbnail out of a memory stream and saves to <see cref="DirectoryService.CoverImageDirectory"/> with the passed
|
/// Creates a thumbnail out of a memory stream and saves to <see cref="DirectoryService.CoverImageDirectory"/> with the passed
|
||||||
/// fileName and .png extension.
|
/// fileName and the appropriate extension.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stream">Stream to write to disk. Ensure this is rewinded.</param>
|
/// <param name="stream">Stream to write to disk. Ensure this is rewinded.</param>
|
||||||
/// <param name="fileName">filename to save as without extension</param>
|
/// <param name="fileName">filename to save as without extension</param>
|
||||||
@ -235,7 +235,6 @@ public class ImageService : IImageService
|
|||||||
var (targetWidth, targetHeight) = size.GetDimensions();
|
var (targetWidth, targetHeight) = size.GetDimensions();
|
||||||
if (stream.CanSeek) stream.Position = 0;
|
if (stream.CanSeek) stream.Position = 0;
|
||||||
using var sourceImage = Image.NewFromStream(stream);
|
using var sourceImage = Image.NewFromStream(stream);
|
||||||
if (stream.CanSeek) stream.Position = 0;
|
|
||||||
|
|
||||||
var scalingSize = GetSizeForDimensions(sourceImage, targetWidth, targetHeight);
|
var scalingSize = GetSizeForDimensions(sourceImage, targetWidth, targetHeight);
|
||||||
var scalingCrop = GetCropForDimensions(sourceImage, targetWidth, targetHeight);
|
var scalingCrop = GetCropForDimensions(sourceImage, targetWidth, targetHeight);
|
||||||
|
34
openapi.json
34
openapi.json
@ -12448,6 +12448,40 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/Upload/volume": {
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"Upload"
|
||||||
|
],
|
||||||
|
"summary": "Replaces volume cover image and locks it with a base64 encoded image.",
|
||||||
|
"description": "This is a helper API for Komf - Kavita UI does not use. Volume will find first chapter to update.",
|
||||||
|
"requestBody": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/UploadFileDto"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"text/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/UploadFileDto"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"application/*+json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/UploadFileDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/Upload/library": {
|
"/api/Upload/library": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": [
|
"tags": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user