Skip to content

Commit

Permalink
v0.7.8 - New Filtering System (Kareadita#2260)
Browse files Browse the repository at this point in the history
Co-authored-by: JeanPaulDOT <[email protected]>
Co-authored-by: Francois Wilhelmy <[email protected]>
Co-authored-by: Gazy Mahomar <[email protected]>
Co-authored-by: Stijn <[email protected]>
Co-authored-by: 無情天 <[email protected]>
Co-authored-by: Havokdan <[email protected]>
Co-authored-by: Andre <[email protected]>
Co-authored-by: Mateusz <[email protected]>
Co-authored-by: Antonio Sanchez Castellón <[email protected]>
Co-authored-by: Duarte Silva <[email protected]>
Co-authored-by: LeeWan1210 <[email protected]>
Co-authored-by: aleixcox <[email protected]>
Co-authored-by: Tomas Battistini <[email protected]>
Co-authored-by: mareczek82 <[email protected]>
Co-authored-by: Hans Kalisvaart <[email protected]>
Co-authored-by: majora2007 <[email protected]>
Co-authored-by: afermar <[email protected]>
Co-authored-by: oxygen44k <[email protected]>
Co-authored-by: Weblate (bot) <[email protected]>
Co-authored-by: Hadrien b <[email protected]>
Co-authored-by: Robbie Davis <[email protected]>
Co-authored-by: Andre Smith <[email protected]>
Co-authored-by: Safu Wan <[email protected]>
Co-authored-by: sibeck <[email protected]>
Co-authored-by: Florestano Pepe <[email protected]>
Co-authored-by: 书签 <[email protected]>
Co-authored-by: Stéphane Dupont <[email protected]>
Co-authored-by: gallegonovato <[email protected]>
Co-authored-by: AlienHack <[email protected]>
Co-authored-by: 周書丞 <[email protected]>
Co-authored-by: Andre Smith <[email protected]>
Co-authored-by: xe1st <[email protected]>
Co-authored-by: Jiří Heger <[email protected]>
Co-authored-by: DR <[email protected]>
Co-authored-by: Mathieu Ares <[email protected]>
Co-authored-by: Stavros Kois <[email protected]>
Co-authored-by: Gazy Mahomar <[email protected]>
Co-authored-by: Elias Jakob <[email protected]>
Co-authored-by: Christian Zanon <[email protected]>
Co-authored-by: Eryk Michalak <[email protected]>
Co-authored-by: Hoshino0881118 <[email protected]>
  • Loading branch information
Show file tree
Hide file tree
Showing 221 changed files with 23,436 additions and 6,896 deletions.
58 changes: 31 additions & 27 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: dotnet restore

- name: Set up JDK 17
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
Expand Down Expand Up @@ -107,9 +107,10 @@ jobs:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }}
steps:
- name: Find Current Pull Request
uses: jwalton/gh-find-current-pr@v1.3.2
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
state: all
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Parse PR body
Expand All @@ -130,15 +131,15 @@ jobs:
body=${body//$'`'/'%60'}
body=${body//$'>'/'%3E'}
echo $body
echo "::set-output name=BODY::$body"
echo "BODY=$body" >> $GITHUB_OUTPUT
- name: Check Out Repo
uses: actions/checkout@v3
with:
ref: develop

- name: NodeJS to Compile WebUI
uses: actions/setup-node@v2.1.5
uses: actions/setup-node@v3
with:
node-version: '16'
- run: |
Expand All @@ -155,15 +156,15 @@ jobs:
cd ../ || exit
- name: Get csproj Version
uses: naminodarie/get-net-sdk-project-versions-action@v1
uses: kzrnm/get-net-sdk-project-versions-action@v1
id: get-version
with:
proj-path: Kavita.Common/Kavita.Common.csproj

- name: Parse Version
run: |
version='${{steps.get-version.outputs.assembly-version}}'
echo "::set-output name=VERSION::$version"
echo "VERSION=$version" >> $GITHUB_OUTPUT
id: parse-version

- name: Echo csproj version
Expand Down Expand Up @@ -193,15 +194,15 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64
Expand All @@ -216,7 +217,7 @@ jobs:
with:
severity: info
description: v${{steps.get-version.outputs.assembly-version}} - ${{ steps.findPr.outputs.title }}
details: '${{ steps.parse-body.outputs.BODY }}'
details: '${{ steps.findPr.outputs.body }}'
text: <@&939225459156217917> <@&939225350775406643> A new nightly build has been released for docker.
webhookUrl: ${{ secrets.DISCORD_DOCKER_UPDATE_URL }}

Expand All @@ -227,13 +228,14 @@ jobs:
permissions:
packages: write
contents: read
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')) }}
steps:

- name: Find Current Pull Request
uses: jwalton/gh-find-current-pr@v1.0.2
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
state: all
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Parse PR body
Expand All @@ -254,15 +256,16 @@ jobs:
body=${body//$'`'/'%60'}
body=${body//$'>'/'%3E'}
echo $body
echo "::set-output name=BODY::$body"
echo "BODY=$body" >> $GITHUB_OUTPUT
- name: Check Out Repo
uses: actions/checkout@v3
with:
ref: main

- name: NodeJS to Compile WebUI
uses: actions/setup-node@v2.1.5
uses: actions/setup-node@v3
with:
node-version: '16'
- run: |
Expand All @@ -280,7 +283,7 @@ jobs:
cd ../ || exit
- name: Get csproj Version
uses: naminodarie/get-net-sdk-project-versions-action@v1
uses: kzrnm/get-net-sdk-project-versions-action@v1
id: get-version
with:
proj-path: Kavita.Common/Kavita.Common.csproj
Expand All @@ -293,7 +296,7 @@ jobs:
version='${{steps.get-version.outputs.assembly-version}}'
newVersion=${version%.*}
echo $newVersion
echo "::set-output name=VERSION::$newVersion"
echo "VERSION=$newVersion" >> $GITHUB_OUTPUT
id: parse-version

- name: Compile dotnet app
Expand All @@ -319,15 +322,15 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64
Expand All @@ -342,7 +345,7 @@ jobs:
with:
severity: info
description: v${{steps.get-version.outputs.assembly-version}} - ${{ steps.findPr.outputs.title }}
details: '${{ steps.parse-body.outputs.BODY }}'
details: '${{ steps.findPr.outputs.body }}'
text: <@&939225192553644133> A new stable build has been released.
webhookUrl: ${{ secrets.DISCORD_DOCKER_UPDATE_URL }}

Expand All @@ -356,9 +359,10 @@ jobs:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/canary' }}
steps:
- name: Find Current Pull Request
uses: jwalton/gh-find-current-pr@v1.0.2
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
state: all
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check Out Repo
Expand All @@ -367,7 +371,7 @@ jobs:
ref: canary

- name: NodeJS to Compile WebUI
uses: actions/setup-node@v2.1.5
uses: actions/setup-node@v3
with:
node-version: '16'
- run: |
Expand All @@ -384,15 +388,15 @@ jobs:
cd ../ || exit
- name: Get csproj Version
uses: naminodarie/get-net-sdk-project-versions-action@v1
uses: kzrnm/get-net-sdk-project-versions-action@v1
id: get-version
with:
proj-path: Kavita.Common/Kavita.Common.csproj

- name: Parse Version
run: |
version='${{steps.get-version.outputs.assembly-version}}'
echo "::set-output name=VERSION::$version"
echo "VERSION=$version" >> $GITHUB_OUTPUT
id: parse-version

- name: Echo csproj version
Expand Down Expand Up @@ -422,15 +426,15 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64
Expand Down
28 changes: 28 additions & 0 deletions API.Tests/Extensions/SeriesFilterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using API.DTOs.Filtering.v2;
using API.Extensions.QueryExtensions.Filtering;
using Microsoft.EntityFrameworkCore;
using Xunit;

namespace API.Tests.Extensions;

public class SeriesFilterTests : AbstractDbTest
{

protected override Task ResetDb()
{
return Task.CompletedTask;
}

#region HasLanguage

[Fact]
public async Task HasLanguage_Works()
{
var foundSeries = await _context.Series.HasLanguage(true, FilterComparison.Contains, new List<string>() { }).ToListAsync();

}

#endregion
}
2 changes: 1 addition & 1 deletion API.Tests/Services/CacheServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public int GetNumberOfPages(string filePath, MangaFormat format)
return 1;
}

public string GetCoverImage(string fileFilePath, string fileName, MangaFormat format, EncodeFormat encodeFormat)
public string GetCoverImage(string fileFilePath, string fileName, MangaFormat format, EncodeFormat encodeFormat, CoverImageSize size = CoverImageSize.Default)
{
return string.Empty;
}
Expand Down
2 changes: 1 addition & 1 deletion API.Tests/Services/ParseScannedFilesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int GetNumberOfPages(string filePath, MangaFormat format)
return 1;
}

public string GetCoverImage(string fileFilePath, string fileName, MangaFormat format, EncodeFormat encodeFormat)
public string GetCoverImage(string fileFilePath, string fileName, MangaFormat format, EncodeFormat encodeFormat, CoverImageSize size = CoverImageSize.Default)
{
return string.Empty;
}
Expand Down
20 changes: 20 additions & 0 deletions API.Tests/Services/SeriesServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,26 @@ private static Series CreateSeriesMock()
return series;
}

[Fact]
public void GetFirstChapterForMetadata_BookWithOnlyVolumeNumbers_Test()
{
var file = new MangaFileBuilder("Test.cbz", MangaFormat.Archive, 1).Build();

var series = new SeriesBuilder("Test")
.WithVolume(new VolumeBuilder("1")
.WithChapter(new ChapterBuilder("0").WithPages(1).WithFile(file).Build())
.Build())

.WithVolume(new VolumeBuilder("1.5")
.WithChapter(new ChapterBuilder("0").WithPages(2).WithFile(file).Build())
.Build())
.Build();
series.Library = new LibraryBuilder("Test LIb", LibraryType.Book).Build();

var firstChapter = SeriesService.GetFirstChapterForMetadata(series);
Assert.Equal(1, firstChapter.Pages);
}

[Fact]
public void GetFirstChapterForMetadata_Book_Test()
{
Expand Down
4 changes: 4 additions & 0 deletions API/Constants/CacheProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public static class EasyCacheProfiles
/// Cache the libraries on the server
/// </summary>
public const string Library = "library";
/// <summary>
/// Metadata filter
/// </summary>
public const string Filter = "filter";
public const string KavitaPlusReviews = "kavita+reviews";
public const string KavitaPlusRecommendations = "kavita+recommendations";
public const string KavitaPlusRatings = "kavita+ratings";
Expand Down
28 changes: 26 additions & 2 deletions API/Controllers/CollectionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CollectionController(IUnitOfWork unitOfWork, ICollectionTagService collec
}

/// <summary>
/// Return a list of all collection tags on the server
/// Return a list of all collection tags on the server for the logged in user.
/// </summary>
/// <returns></returns>
[HttpGet]
Expand Down Expand Up @@ -130,7 +130,6 @@ public async Task<ActionResult> RemoveTagFromMultipleSeries(UpdateSeriesForTagDt
{
var tag = await _unitOfWork.CollectionTagRepository.GetTagAsync(updateSeriesForTagDto.Tag.Id, CollectionTagIncludes.SeriesMetadata);
if (tag == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "collection-doesnt-exist"));
tag.SeriesMetadatas ??= new List<SeriesMetadata>();

if (await _collectionService.RemoveTagFromSeries(tag, updateSeriesForTagDto.SeriesIdsToRemove))
return Ok(await _localizationService.Translate(User.GetUserId(), "collection-updated"));
Expand All @@ -142,4 +141,29 @@ public async Task<ActionResult> RemoveTagFromMultipleSeries(UpdateSeriesForTagDt

return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-error"));
}

/// <summary>
/// Removes the collection tag from all Series it was attached to
/// </summary>
/// <param name="tagId"></param>
/// <returns></returns>
[Authorize(Policy = "RequireAdminRole")]
[HttpDelete]
public async Task<ActionResult> DeleteTag(int tagId)
{
try
{
var tag = await _unitOfWork.CollectionTagRepository.GetTagAsync(tagId, CollectionTagIncludes.SeriesMetadata);
if (tag == null) return BadRequest(await _localizationService.Translate(User.GetUserId(), "collection-doesnt-exist"));

if (await _collectionService.DeleteTag(tag))
return Ok(await _localizationService.Translate(User.GetUserId(), "collection-deleted"));
}
catch (Exception)
{
await _unitOfWork.RollbackAsync();
}

return BadRequest(await _localizationService.Translate(User.GetUserId(), "generic-error"));
}
}
7 changes: 3 additions & 4 deletions API/Controllers/DeviceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public async Task<ActionResult> DeleteDevice(int deviceId)
[HttpGet]
public async Task<ActionResult<IEnumerable<DeviceDto>>> GetDevices()
{
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
return Ok(await _unitOfWork.DeviceRepository.GetDevicesForUserAsync(userId));
return Ok(await _unitOfWork.DeviceRepository.GetDevicesForUserAsync(User.GetUserId()));
}

[HttpPost("send-to")]
Expand All @@ -100,7 +99,7 @@ public async Task<ActionResult> SendToDevice(SendToDeviceDto dto)
if (await _emailService.IsDefaultEmailService())
return BadRequest(await _localizationService.Translate(User.GetUserId(), "send-to-kavita-email"));

var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
var userId = User.GetUserId();
await _eventHub.SendMessageToAsync(MessageFactory.NotificationProgress,
MessageFactory.SendingToDeviceEvent(await _localizationService.Translate(User.GetUserId(), "send-to-device-status"),
"started"), userId);
Expand Down Expand Up @@ -134,7 +133,7 @@ public async Task<ActionResult> SendSeriesToDevice(SendSeriesToDeviceDto dto)
if (await _emailService.IsDefaultEmailService())
return BadRequest(await _localizationService.Translate(User.GetUserId(), "send-to-kavita-email"));

var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
var userId = User.GetUserId();
await _eventHub.SendMessageToAsync(MessageFactory.NotificationProgress,
MessageFactory.SendingToDeviceEvent(await _localizationService.Translate(User.GetUserId(), "send-to-device-status"),
"started"), userId);
Expand Down
Loading

0 comments on commit 9795080

Please sign in to comment.