mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Move different year duplication prevention logic to the API
This commit is contained in:
parent
8b256e4c60
commit
d36a20ce5e
@ -21,6 +21,7 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Abstractions.Controllers;
|
using Kyoo.Abstractions.Controllers;
|
||||||
using Kyoo.Abstractions.Models;
|
using Kyoo.Abstractions.Models;
|
||||||
|
using Kyoo.Abstractions.Models.Exceptions;
|
||||||
using Kyoo.Abstractions.Models.Utils;
|
using Kyoo.Abstractions.Models.Utils;
|
||||||
using Kyoo.Postgresql;
|
using Kyoo.Postgresql;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -45,6 +46,25 @@ public class MovieRepository(
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<Movie> Create(Movie obj)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return base.Create(obj);
|
||||||
|
}
|
||||||
|
catch (DuplicatedItemException ex)
|
||||||
|
when (ex.Existing is Movie existing
|
||||||
|
&& existing.Slug == obj.Slug
|
||||||
|
&& obj.AirDate is not null
|
||||||
|
&& existing.AirDate?.Year != obj.AirDate?.Year
|
||||||
|
)
|
||||||
|
{
|
||||||
|
obj.Slug = $"{obj.Slug}-{obj.AirDate!.Value.Year}";
|
||||||
|
return base.Create(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task Validate(Movie resource)
|
protected override async Task Validate(Movie resource)
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,7 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Abstractions.Controllers;
|
using Kyoo.Abstractions.Controllers;
|
||||||
using Kyoo.Abstractions.Models;
|
using Kyoo.Abstractions.Models;
|
||||||
|
using Kyoo.Abstractions.Models.Exceptions;
|
||||||
using Kyoo.Abstractions.Models.Utils;
|
using Kyoo.Abstractions.Models.Utils;
|
||||||
using Kyoo.Postgresql;
|
using Kyoo.Postgresql;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -45,6 +46,25 @@ public class ShowRepository(
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<Show> Create(Show obj)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return base.Create(obj);
|
||||||
|
}
|
||||||
|
catch (DuplicatedItemException ex)
|
||||||
|
when (ex.Existing is Show existing
|
||||||
|
&& existing.Slug == obj.Slug
|
||||||
|
&& obj.StartAir is not null
|
||||||
|
&& existing.StartAir?.Year != obj.StartAir?.Year
|
||||||
|
)
|
||||||
|
{
|
||||||
|
obj.Slug = $"{obj.Slug}-{obj.StartAir!.Value.Year}";
|
||||||
|
return base.Create(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task Validate(Show resource)
|
protected override async Task Validate(Show resource)
|
||||||
{
|
{
|
||||||
|
@ -112,20 +112,6 @@ class KyooClient:
|
|||||||
logger.error(f"Request error: {await r.text()}")
|
logger.error(f"Request error: {await r.text()}")
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
ret = await r.json()
|
ret = await r.json()
|
||||||
|
|
||||||
if r.status == 409 and (
|
|
||||||
(path == "shows" and ret["startAir"][:4] != str(data["start_air"].year))
|
|
||||||
or (
|
|
||||||
path == "movies"
|
|
||||||
and ret["airDate"][:4] != str(data["air_date"].year)
|
|
||||||
)
|
|
||||||
):
|
|
||||||
logger.info(
|
|
||||||
f"Found a {path} with the same slug ({ret['slug']}) and a different date, using the date as part of the slug"
|
|
||||||
)
|
|
||||||
year = (data["start_air"] if path == "movie" else data["air_date"]).year
|
|
||||||
data["slug"] = f"{ret['slug']}-{year}"
|
|
||||||
return await self.post(path, data=data)
|
|
||||||
return ret["id"]
|
return ret["id"]
|
||||||
|
|
||||||
async def delete(
|
async def delete(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user