mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 05:04:15 -04:00
Add news repository and api
This commit is contained in:
parent
43a4a0e6ee
commit
44521d0d5f
@ -17,6 +17,7 @@ RUN dotnet restore
|
|||||||
WORKDIR /kyoo
|
WORKDIR /kyoo
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
ENV DOTNET_USE_POLLING_FILE_WATCHER 1
|
ENV DOTNET_USE_POLLING_FILE_WATCHER 1
|
||||||
HEALTHCHECK --interval=5s CMD curl --fail http://localhost:5000/health || exit
|
# HEALTHCHECK --interval=5s CMD curl --fail http://localhost:5000/health || exit
|
||||||
|
HEALTHCHECK CMD true
|
||||||
CMD dotnet watch run --no-restore --project /app/src/Kyoo.Host
|
CMD dotnet watch run --no-restore --project /app/src/Kyoo.Host
|
||||||
|
|
||||||
|
147
back/src/Kyoo.Abstractions/Models/News.cs
Normal file
147
back/src/Kyoo.Abstractions/Models/News.cs
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
// Kyoo - A portable and vast media library solution.
|
||||||
|
// Copyright (c) Kyoo.
|
||||||
|
//
|
||||||
|
// See AUTHORS.md and LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
// Kyoo is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// any later version.
|
||||||
|
//
|
||||||
|
// Kyoo is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Kyoo.Abstractions.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The type of item, ether a show, a movie or a collection.
|
||||||
|
/// </summary>
|
||||||
|
public enum NewsKind
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="LibraryItem"/> is an <see cref="Episode"/>.
|
||||||
|
/// </summary>
|
||||||
|
Episode,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="LibraryItem"/> is a Movie.
|
||||||
|
/// </summary>
|
||||||
|
Movie,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A new item
|
||||||
|
/// </summary>
|
||||||
|
public class News : IResource, IMetadata, IThumbnails, IAddedDate
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
[MaxLength(256)]
|
||||||
|
public string Slug { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The title of this show.
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A catchphrase for this movie.
|
||||||
|
/// </summary>
|
||||||
|
public string? Tagline { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The list of alternative titles of this show.
|
||||||
|
/// </summary>
|
||||||
|
public string[] Aliases { get; set; } = Array.Empty<string>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path of the movie video file.
|
||||||
|
/// </summary>
|
||||||
|
public string Path { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The summary of this show.
|
||||||
|
/// </summary>
|
||||||
|
public string? Overview { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A list of tags that match this movie.
|
||||||
|
/// </summary>
|
||||||
|
public string[] Tags { get; set; } = Array.Empty<string>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The list of genres (themes) this show has.
|
||||||
|
/// </summary>
|
||||||
|
public Genre[] Genres { get; set; } = Array.Empty<Genre>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is this show airing, not aired yet or finished?
|
||||||
|
/// </summary>
|
||||||
|
public Status? Status { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The date this movie aired.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? AirDate { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public DateTime AddedDate { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Image? Poster { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Image? Thumbnail { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Image? Logo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A video of a few minutes that tease the content.
|
||||||
|
/// </summary>
|
||||||
|
public string? Trailer { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Dictionary<string, MetadataId> ExternalId { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The season in witch this episode is in.
|
||||||
|
/// </summary>
|
||||||
|
public int? SeasonNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of this episode in it's season.
|
||||||
|
/// </summary>
|
||||||
|
public int? EpisodeNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The absolute number of this episode. It's an episode number that is not reset to 1 after a new season.
|
||||||
|
/// </summary>
|
||||||
|
public int? AbsoluteNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is the item a a movie or an episode?
|
||||||
|
/// </summary>
|
||||||
|
public NewsKind Kind { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Links to watch this movie.
|
||||||
|
/// </summary>
|
||||||
|
public VideoLinks Links => new()
|
||||||
|
{
|
||||||
|
Direct = $"/video/{Kind.ToString().ToLower()}/{Slug}/direct",
|
||||||
|
Hls = $"/video/{Kind.ToString().ToLower()}/{Slug}/master.m3u8",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,6 @@ using System.Linq;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using EntityFrameworkCore.Projectables;
|
using EntityFrameworkCore.Projectables;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Kyoo.Abstractions.Controllers;
|
|
||||||
using Kyoo.Abstractions.Models.Attributes;
|
using Kyoo.Abstractions.Models.Attributes;
|
||||||
|
|
||||||
namespace Kyoo.Abstractions.Models
|
namespace Kyoo.Abstractions.Models
|
||||||
|
@ -20,7 +20,6 @@ using System;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Kyoo.Abstractions.Models.Attributes;
|
|
||||||
|
|
||||||
namespace Kyoo.Abstractions.Models
|
namespace Kyoo.Abstractions.Models
|
||||||
{
|
{
|
||||||
@ -60,24 +59,6 @@ namespace Kyoo.Abstractions.Models
|
|||||||
[MaxLength(32)]
|
[MaxLength(32)]
|
||||||
public string Blurhash { get; set; }
|
public string Blurhash { get; set; }
|
||||||
|
|
||||||
[SerializeIgnore]
|
|
||||||
public string Path { private get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The url to retrieve the low quality image.
|
|
||||||
/// </summary>
|
|
||||||
public string Low => $"{Path}?quality=low";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The url to retrieve the medium quality image.
|
|
||||||
/// </summary>
|
|
||||||
public string Medium => $"{Path}?quality=medium";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The url to retrieve the high quality image.
|
|
||||||
/// </summary>
|
|
||||||
public string High => $"{Path}?quality=high";
|
|
||||||
|
|
||||||
public Image(string source, string? blurhash = null)
|
public Image(string source, string? blurhash = null)
|
||||||
{
|
{
|
||||||
Source = source;
|
Source = source;
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
// Kyoo - A portable and vast media library solution.
|
||||||
|
// Copyright (c) Kyoo.
|
||||||
|
//
|
||||||
|
// See AUTHORS.md and LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
// Kyoo is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// any later version.
|
||||||
|
//
|
||||||
|
// Kyoo is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Kyoo.Abstractions.Controllers;
|
||||||
|
using Kyoo.Abstractions.Models;
|
||||||
|
using Kyoo.Postgresql;
|
||||||
|
|
||||||
|
namespace Kyoo.Core.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A local repository to handle shows
|
||||||
|
/// </summary>
|
||||||
|
public class NewsRepository : LocalRepository<News>
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override Sort<News> DefaultSort => new Sort<News>.By(x => x.AddedDate);
|
||||||
|
|
||||||
|
public NewsRepository(DatabaseContext database, IThumbnailsManager thumbs)
|
||||||
|
: base(database, thumbs)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<ICollection<News>> Search(string query)
|
||||||
|
=> throw new InvalidOperationException();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<News> Create(News obj)
|
||||||
|
=> throw new InvalidOperationException();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<News> CreateIfNotExists(News obj)
|
||||||
|
=> throw new InvalidOperationException();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<News> Edit(News edited)
|
||||||
|
=> throw new InvalidOperationException();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<News> Patch(int id, Func<News, Task<bool>> patch)
|
||||||
|
=> throw new InvalidOperationException();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task Delete(int id)
|
||||||
|
=> throw new InvalidOperationException();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task Delete(string slug)
|
||||||
|
=> throw new InvalidOperationException();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task Delete(News obj)
|
||||||
|
=> throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
}
|
@ -59,6 +59,7 @@ namespace Kyoo.Core
|
|||||||
builder.RegisterRepository<PeopleRepository>();
|
builder.RegisterRepository<PeopleRepository>();
|
||||||
builder.RegisterRepository<StudioRepository>();
|
builder.RegisterRepository<StudioRepository>();
|
||||||
builder.RegisterRepository<UserRepository>();
|
builder.RegisterRepository<UserRepository>();
|
||||||
|
builder.RegisterType<NewsRepository>().OwnedByLifetimeScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -58,7 +58,7 @@ namespace Kyoo.Core.Api
|
|||||||
{
|
{
|
||||||
property.ShouldSerialize = _ =>
|
property.ShouldSerialize = _ =>
|
||||||
{
|
{
|
||||||
ICollection<string> fields = (ICollection<string>)_httpContextAccessor.HttpContext!.Items["fields"]!;
|
ICollection<string>? fields = (ICollection<string>)_httpContextAccessor.HttpContext!.Items["fields"]!;
|
||||||
if (fields == null)
|
if (fields == null)
|
||||||
return false;
|
return false;
|
||||||
return fields.Contains(member.Name);
|
return fields.Contains(member.Name);
|
||||||
|
61
back/src/Kyoo.Core/Views/Resources/NewsApi.cs
Normal file
61
back/src/Kyoo.Core/Views/Resources/NewsApi.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// Kyoo - A portable and vast media library solution.
|
||||||
|
// Copyright (c) Kyoo.
|
||||||
|
//
|
||||||
|
// See AUTHORS.md and LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
// Kyoo is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// any later version.
|
||||||
|
//
|
||||||
|
// Kyoo is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Kyoo.Abstractions.Controllers;
|
||||||
|
using Kyoo.Abstractions.Models;
|
||||||
|
using Kyoo.Abstractions.Models.Attributes;
|
||||||
|
using Kyoo.Abstractions.Models.Permissions;
|
||||||
|
using Kyoo.Core.Controllers;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using static Kyoo.Abstractions.Models.Utils.Constants;
|
||||||
|
|
||||||
|
namespace Kyoo.Core.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// List new items added to kyoo.
|
||||||
|
/// </summary>
|
||||||
|
[Route("news")]
|
||||||
|
[Route("new", Order = AlternativeRoute)]
|
||||||
|
[ApiController]
|
||||||
|
[ResourceView]
|
||||||
|
[PartialPermission("LibraryItem")]
|
||||||
|
[ApiDefinition("News", Group = ResourcesGroup)]
|
||||||
|
public class NewsApi : BaseApi
|
||||||
|
{
|
||||||
|
private readonly NewsRepository _news;
|
||||||
|
|
||||||
|
public NewsApi(NewsRepository news)
|
||||||
|
{
|
||||||
|
_news = news;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ActionResult<Page<News>>> GetAll(
|
||||||
|
[FromQuery] Dictionary<string, string> where,
|
||||||
|
[FromQuery] Pagination pagination)
|
||||||
|
{
|
||||||
|
ICollection<News> resources = await _news.GetNews(
|
||||||
|
ApiHelper.ParseWhere<News>(where),
|
||||||
|
pagination
|
||||||
|
);
|
||||||
|
|
||||||
|
return Page(resources, pagination.Limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -100,6 +100,14 @@ namespace Kyoo.Postgresql
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public DbSet<LibraryItem> LibraryItems { get; set; }
|
public DbSet<LibraryItem> LibraryItems { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The list of new items (episodes and movies).
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This set is ready only, on most database this will be a view.
|
||||||
|
/// </remarks>
|
||||||
|
public DbSet<News> News { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a many to many link between two resources.
|
/// Add a many to many link between two resources.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -283,6 +291,7 @@ namespace Kyoo.Postgresql
|
|||||||
.UsingEntity(x => x.ToTable(LinkName<User, Show>()));
|
.UsingEntity(x => x.ToTable(LinkName<User, Show>()));
|
||||||
|
|
||||||
_HasMetadata<LibraryItem>(modelBuilder);
|
_HasMetadata<LibraryItem>(modelBuilder);
|
||||||
|
_HasMetadata<News>(modelBuilder);
|
||||||
_HasMetadata<Collection>(modelBuilder);
|
_HasMetadata<Collection>(modelBuilder);
|
||||||
_HasMetadata<Movie>(modelBuilder);
|
_HasMetadata<Movie>(modelBuilder);
|
||||||
_HasMetadata<Show>(modelBuilder);
|
_HasMetadata<Show>(modelBuilder);
|
||||||
@ -292,6 +301,7 @@ namespace Kyoo.Postgresql
|
|||||||
_HasMetadata<Studio>(modelBuilder);
|
_HasMetadata<Studio>(modelBuilder);
|
||||||
|
|
||||||
_HasImages<LibraryItem>(modelBuilder);
|
_HasImages<LibraryItem>(modelBuilder);
|
||||||
|
_HasImages<News>(modelBuilder);
|
||||||
_HasImages<Collection>(modelBuilder);
|
_HasImages<Collection>(modelBuilder);
|
||||||
_HasImages<Movie>(modelBuilder);
|
_HasImages<Movie>(modelBuilder);
|
||||||
_HasImages<Show>(modelBuilder);
|
_HasImages<Show>(modelBuilder);
|
||||||
@ -300,6 +310,7 @@ namespace Kyoo.Postgresql
|
|||||||
_HasImages<People>(modelBuilder);
|
_HasImages<People>(modelBuilder);
|
||||||
|
|
||||||
_HasAddedDate<LibraryItem>(modelBuilder);
|
_HasAddedDate<LibraryItem>(modelBuilder);
|
||||||
|
_HasAddedDate<News>(modelBuilder);
|
||||||
_HasAddedDate<Collection>(modelBuilder);
|
_HasAddedDate<Collection>(modelBuilder);
|
||||||
_HasAddedDate<Movie>(modelBuilder);
|
_HasAddedDate<Movie>(modelBuilder);
|
||||||
_HasAddedDate<Show>(modelBuilder);
|
_HasAddedDate<Show>(modelBuilder);
|
||||||
@ -347,6 +358,8 @@ namespace Kyoo.Postgresql
|
|||||||
.Ignore(x => x.Links);
|
.Ignore(x => x.Links);
|
||||||
modelBuilder.Entity<LibraryItem>()
|
modelBuilder.Entity<LibraryItem>()
|
||||||
.Ignore(x => x.Links);
|
.Ignore(x => x.Links);
|
||||||
|
modelBuilder.Entity<News>()
|
||||||
|
.Ignore(x => x.Links);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -51,6 +51,7 @@ namespace Kyoo.Postgresql
|
|||||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
|
NpgsqlConnection.GlobalTypeMapper.MapEnum<Status>();
|
||||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<Genre>();
|
NpgsqlConnection.GlobalTypeMapper.MapEnum<Genre>();
|
||||||
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemKind>();
|
NpgsqlConnection.GlobalTypeMapper.MapEnum<ItemKind>();
|
||||||
|
NpgsqlConnection.GlobalTypeMapper.MapEnum<NewsKind>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -104,6 +105,7 @@ namespace Kyoo.Postgresql
|
|||||||
modelBuilder.HasPostgresEnum<Status>();
|
modelBuilder.HasPostgresEnum<Status>();
|
||||||
modelBuilder.HasPostgresEnum<Genre>();
|
modelBuilder.HasPostgresEnum<Genre>();
|
||||||
modelBuilder.HasPostgresEnum<ItemKind>();
|
modelBuilder.HasPostgresEnum<ItemKind>();
|
||||||
|
modelBuilder.HasPostgresEnum<NewsKind>();
|
||||||
|
|
||||||
modelBuilder.HasDbFunction(typeof(DatabaseContext).GetMethod(nameof(MD5))!)
|
modelBuilder.HasDbFunction(typeof(DatabaseContext).GetMethod(nameof(MD5))!)
|
||||||
.HasTranslation(args =>
|
.HasTranslation(args =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user