mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 05:34:23 -04:00
Update csharpier
This commit is contained in:
parent
042cc018cb
commit
a5638203a6
@ -9,7 +9,7 @@
|
||||
]
|
||||
},
|
||||
"csharpier": {
|
||||
"version": "0.26.4",
|
||||
"version": "0.27.2",
|
||||
"commands": [
|
||||
"dotnet-csharpier"
|
||||
]
|
||||
|
@ -202,13 +202,11 @@ namespace Kyoo.Abstractions.Models
|
||||
|
||||
private Episode? _PreviousEpisode =>
|
||||
Show!
|
||||
.Episodes!
|
||||
.OrderBy(x => x.AbsoluteNumber == null)
|
||||
.Episodes!.OrderBy(x => x.AbsoluteNumber == null)
|
||||
.ThenByDescending(x => x.AbsoluteNumber)
|
||||
.ThenByDescending(x => x.SeasonNumber)
|
||||
.ThenByDescending(x => x.EpisodeNumber)
|
||||
.FirstOrDefault(
|
||||
x =>
|
||||
.FirstOrDefault(x =>
|
||||
x.AbsoluteNumber < AbsoluteNumber
|
||||
|| x.SeasonNumber < SeasonNumber
|
||||
|| (x.SeasonNumber == SeasonNumber && x.EpisodeNumber < EpisodeNumber)
|
||||
@ -242,12 +240,10 @@ namespace Kyoo.Abstractions.Models
|
||||
|
||||
private Episode? _NextEpisode =>
|
||||
Show!
|
||||
.Episodes!
|
||||
.OrderBy(x => x.AbsoluteNumber)
|
||||
.Episodes!.OrderBy(x => x.AbsoluteNumber)
|
||||
.ThenBy(x => x.SeasonNumber)
|
||||
.ThenBy(x => x.EpisodeNumber)
|
||||
.FirstOrDefault(
|
||||
x =>
|
||||
.FirstOrDefault(x =>
|
||||
x.AbsoluteNumber > AbsoluteNumber
|
||||
|| x.SeasonNumber > SeasonNumber
|
||||
|| (x.SeasonNumber == SeasonNumber && x.EpisodeNumber > EpisodeNumber)
|
||||
|
@ -205,8 +205,7 @@ public abstract record Filter<T> : Filter
|
||||
if (type.IsEnum)
|
||||
{
|
||||
return Parse
|
||||
.LetterOrDigit
|
||||
.Many()
|
||||
.LetterOrDigit.Many()
|
||||
.Text()
|
||||
.Then(x =>
|
||||
{
|
||||
@ -259,13 +258,10 @@ public abstract record Filter<T> : Filter
|
||||
}
|
||||
|
||||
PropertyInfo? propInfo = types
|
||||
.Select(
|
||||
x =>
|
||||
.Select(x =>
|
||||
x.GetProperty(
|
||||
prop,
|
||||
BindingFlags.IgnoreCase
|
||||
| BindingFlags.Public
|
||||
| BindingFlags.Instance
|
||||
BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance
|
||||
)
|
||||
)
|
||||
.FirstOrDefault();
|
||||
|
@ -62,17 +62,14 @@ public class Include<T> : Include
|
||||
.SelectMany(key =>
|
||||
{
|
||||
var relations = types
|
||||
.Select(
|
||||
x =>
|
||||
.Select(x =>
|
||||
x.GetProperty(
|
||||
key,
|
||||
BindingFlags.IgnoreCase
|
||||
| BindingFlags.Public
|
||||
| BindingFlags.Instance
|
||||
BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance
|
||||
)!
|
||||
)
|
||||
.Select(
|
||||
prop => (prop, attr: prop?.GetCustomAttribute<LoadableRelationAttribute>()!)
|
||||
.Select(prop =>
|
||||
(prop, attr: prop?.GetCustomAttribute<LoadableRelationAttribute>()!)
|
||||
)
|
||||
.Where(x => x.prop != null && x.attr != null)
|
||||
.ToList();
|
||||
|
@ -120,8 +120,7 @@ namespace Kyoo.Abstractions.Controllers
|
||||
Type[] types =
|
||||
typeof(T).GetCustomAttribute<OneOfAttribute>()?.Types ?? new[] { typeof(T) };
|
||||
PropertyInfo? property = types
|
||||
.Select(
|
||||
x =>
|
||||
.Select(x =>
|
||||
x.GetProperty(
|
||||
key,
|
||||
BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance
|
||||
|
@ -60,8 +60,8 @@ namespace Kyoo.Utils
|
||||
hasChanged = false;
|
||||
if (second == null)
|
||||
return first;
|
||||
hasChanged = second.Any(
|
||||
x => !first.ContainsKey(x.Key) || x.Value?.Equals(first[x.Key]) == false
|
||||
hasChanged = second.Any(x =>
|
||||
!first.ContainsKey(x.Key) || x.Value?.Equals(first[x.Key]) == false
|
||||
);
|
||||
foreach ((T key, T2 value) in first)
|
||||
second.TryAdd(key, value);
|
||||
@ -98,8 +98,7 @@ namespace Kyoo.Utils
|
||||
|
||||
Type type = typeof(T);
|
||||
IEnumerable<PropertyInfo> properties = type.GetProperties()
|
||||
.Where(
|
||||
x =>
|
||||
.Where(x =>
|
||||
x is { CanRead: true, CanWrite: true }
|
||||
&& Attribute.GetCustomAttribute(x, typeof(NotMergeableAttribute)) == null
|
||||
);
|
||||
|
@ -206,8 +206,8 @@ namespace Kyoo.Utils
|
||||
: type.GetInheritanceTree();
|
||||
return types
|
||||
.Prepend(type)
|
||||
.FirstOrDefault(
|
||||
x => x.IsGenericType && x.GetGenericTypeDefinition() == genericType
|
||||
.FirstOrDefault(x =>
|
||||
x.IsGenericType && x.GetGenericTypeDefinition() == genericType
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -229,11 +229,10 @@ namespace Kyoo.Authentication
|
||||
private AuthenticateResult _ApiKeyCheck(ActionContext context)
|
||||
{
|
||||
if (
|
||||
!context
|
||||
.HttpContext
|
||||
.Request
|
||||
.Headers
|
||||
.TryGetValue("X-API-Key", out StringValues apiKey)
|
||||
!context.HttpContext.Request.Headers.TryGetValue(
|
||||
"X-API-Key",
|
||||
out StringValues apiKey
|
||||
)
|
||||
)
|
||||
return AuthenticateResult.NoResult();
|
||||
if (!_options.ApiKeys.Contains<string>(apiKey!))
|
||||
@ -262,9 +261,9 @@ namespace Kyoo.Authentication
|
||||
|
||||
private async Task<AuthenticateResult> _JwtCheck(ActionContext context)
|
||||
{
|
||||
AuthenticateResult ret = await context
|
||||
.HttpContext
|
||||
.AuthenticateAsync(JwtBearerDefaults.AuthenticationScheme);
|
||||
AuthenticateResult ret = await context.HttpContext.AuthenticateAsync(
|
||||
JwtBearerDefaults.AuthenticationScheme
|
||||
);
|
||||
// Change the failure message to make the API nice to use.
|
||||
if (ret.Failure != null)
|
||||
return AuthenticateResult.Fail(
|
||||
|
@ -40,10 +40,8 @@ namespace Kyoo.Authentication.Models
|
||||
get
|
||||
{
|
||||
return Enum.GetNames<Group>()
|
||||
.SelectMany(
|
||||
group =>
|
||||
Enum.GetNames<Kind>()
|
||||
.Select(kind => $"{group}.{kind}".ToLowerInvariant())
|
||||
.SelectMany(group =>
|
||||
Enum.GetNames<Kind>().Select(kind => $"{group}.{kind}".ToLowerInvariant())
|
||||
)
|
||||
.ToArray();
|
||||
}
|
||||
|
@ -65,8 +65,7 @@ public static class DapperHelper
|
||||
.Where(x => !x.Key.StartsWith('_'))
|
||||
// If first char is lower, assume manual sql instead of reflection.
|
||||
.Where(x => char.IsLower(key.First()) || x.Value.GetProperty(key) != null)
|
||||
.Select(
|
||||
x =>
|
||||
.Select(x =>
|
||||
$"{x.Key}.{x.Value.GetProperty(key)?.GetCustomAttribute<ColumnAttribute>()?.Name ?? key.ToSnakeCase()}"
|
||||
)
|
||||
.ToArray();
|
||||
@ -149,8 +148,7 @@ public static class DapperHelper
|
||||
T Map(T item, IEnumerable<object?> relations)
|
||||
{
|
||||
IEnumerable<string> metadatas = include
|
||||
.Metadatas
|
||||
.Where(x => x is not Include.ProjectedRelation)
|
||||
.Metadatas.Where(x => x is not Include.ProjectedRelation)
|
||||
.Select(x => x.Name);
|
||||
foreach ((string name, object? value) in metadatas.Zip(relations))
|
||||
{
|
||||
@ -179,8 +177,7 @@ public static class DapperHelper
|
||||
'\n',
|
||||
config
|
||||
.Skip(1)
|
||||
.Select(
|
||||
x =>
|
||||
.Select(x =>
|
||||
$"when {x.Key}.id is not null then '{x.Value.Name.ToLowerInvariant()}'"
|
||||
)
|
||||
);
|
||||
@ -196,8 +193,7 @@ public static class DapperHelper
|
||||
.Where(x => !x.Key.StartsWith('_'))
|
||||
// If first char is lower, assume manual sql instead of reflection.
|
||||
.Where(x => char.IsLower(key.First()) || x.Value.GetProperty(key) != null)
|
||||
.Select(
|
||||
x =>
|
||||
.Select(x =>
|
||||
$"{x.Key}.{x.Value.GetProperty(key)?.GetCustomAttribute<ColumnAttribute>()?.Name ?? key.ToSnakeCase()}"
|
||||
);
|
||||
|
||||
@ -245,8 +241,7 @@ public static class DapperHelper
|
||||
public static string ExpendProjections(Type type, string? prefix, Include include)
|
||||
{
|
||||
IEnumerable<string> projections = include
|
||||
.Metadatas
|
||||
.Select(x => (x as Include.ProjectedRelation)!)
|
||||
.Metadatas.Select(x => (x as Include.ProjectedRelation)!)
|
||||
.Where(x => x != null)
|
||||
.Where(x => type.GetProperty(x.Name) != null)
|
||||
.Select(x => x.Sql.Replace("\"this\".", prefix));
|
||||
@ -336,8 +331,8 @@ public static class DapperHelper
|
||||
{
|
||||
string posterProj = string.Join(
|
||||
", ",
|
||||
new[] { "poster", "thumbnail", "logo" }.Select(
|
||||
x => $"{prefix}{x}_source as source, {prefix}{x}_blurhash as blurhash"
|
||||
new[] { "poster", "thumbnail", "logo" }.Select(x =>
|
||||
$"{prefix}{x}_source as source, {prefix}{x}_blurhash as blurhash"
|
||||
)
|
||||
);
|
||||
projection = string.IsNullOrEmpty(projection)
|
||||
|
@ -47,12 +47,10 @@ namespace Kyoo.Core.Controllers
|
||||
IRepository<Show>.OnEdited += async (show) =>
|
||||
{
|
||||
await using AsyncServiceScope scope = CoreModule.Services.CreateAsyncScope();
|
||||
DatabaseContext database = scope
|
||||
.ServiceProvider
|
||||
.GetRequiredService<DatabaseContext>();
|
||||
DatabaseContext database =
|
||||
scope.ServiceProvider.GetRequiredService<DatabaseContext>();
|
||||
List<Episode> episodes = await database
|
||||
.Episodes
|
||||
.AsTracking()
|
||||
.Episodes.AsTracking()
|
||||
.Where(x => x.ShowId == show.Id)
|
||||
.ToListAsync();
|
||||
foreach (Episode ep in episodes)
|
||||
@ -96,18 +94,13 @@ namespace Kyoo.Core.Controllers
|
||||
protected override Task<Episode?> GetDuplicated(Episode item)
|
||||
{
|
||||
if (item is { SeasonNumber: not null, EpisodeNumber: not null })
|
||||
return _database
|
||||
.Episodes
|
||||
.FirstOrDefaultAsync(
|
||||
x =>
|
||||
return _database.Episodes.FirstOrDefaultAsync(x =>
|
||||
x.ShowId == item.ShowId
|
||||
&& x.SeasonNumber == item.SeasonNumber
|
||||
&& x.EpisodeNumber == item.EpisodeNumber
|
||||
);
|
||||
return _database
|
||||
.Episodes
|
||||
.FirstOrDefaultAsync(
|
||||
x => x.ShowId == item.ShowId && x.AbsoluteNumber == item.AbsoluteNumber
|
||||
return _database.Episodes.FirstOrDefaultAsync(x =>
|
||||
x.ShowId == item.ShowId && x.AbsoluteNumber == item.AbsoluteNumber
|
||||
);
|
||||
}
|
||||
|
||||
@ -140,10 +133,8 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
if (resource.SeasonId == null && resource.SeasonNumber != null)
|
||||
{
|
||||
resource.Season = await _database
|
||||
.Seasons
|
||||
.FirstOrDefaultAsync(
|
||||
x => x.ShowId == resource.ShowId && x.SeasonNumber == resource.SeasonNumber
|
||||
resource.Season = await _database.Seasons.FirstOrDefaultAsync(x =>
|
||||
x.ShowId == resource.ShowId && x.SeasonNumber == resource.SeasonNumber
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -152,8 +143,7 @@ namespace Kyoo.Core.Controllers
|
||||
public override async Task Delete(Episode obj)
|
||||
{
|
||||
int epCount = await _database
|
||||
.Episodes
|
||||
.Where(x => x.ShowId == obj.ShowId)
|
||||
.Episodes.Where(x => x.ShowId == obj.ShowId)
|
||||
.Take(2)
|
||||
.CountAsync();
|
||||
_database.Entry(obj).State = EntityState.Deleted;
|
||||
|
@ -47,12 +47,10 @@ namespace Kyoo.Core.Controllers
|
||||
IRepository<Show>.OnEdited += async (show) =>
|
||||
{
|
||||
await using AsyncServiceScope scope = CoreModule.Services.CreateAsyncScope();
|
||||
DatabaseContext database = scope
|
||||
.ServiceProvider
|
||||
.GetRequiredService<DatabaseContext>();
|
||||
DatabaseContext database =
|
||||
scope.ServiceProvider.GetRequiredService<DatabaseContext>();
|
||||
List<Season> seasons = await database
|
||||
.Seasons
|
||||
.AsTracking()
|
||||
.Seasons.AsTracking()
|
||||
.Where(x => x.ShowId == show.Id)
|
||||
.ToListAsync();
|
||||
foreach (Season season in seasons)
|
||||
@ -77,10 +75,8 @@ namespace Kyoo.Core.Controllers
|
||||
|
||||
protected override Task<Season?> GetDuplicated(Season item)
|
||||
{
|
||||
return _database
|
||||
.Seasons
|
||||
.FirstOrDefaultAsync(
|
||||
x => x.ShowId == item.ShowId && x.SeasonNumber == item.SeasonNumber
|
||||
return _database.Seasons.FirstOrDefaultAsync(x =>
|
||||
x.ShowId == item.ShowId && x.SeasonNumber == item.SeasonNumber
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -66,11 +66,10 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
{
|
||||
await using AsyncServiceScope scope = CoreModule.Services.CreateAsyncScope();
|
||||
DatabaseContext db = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
|
||||
WatchStatusRepository repo = scope
|
||||
.ServiceProvider
|
||||
.GetRequiredService<WatchStatusRepository>();
|
||||
List<Guid> users = await db.ShowWatchStatus
|
||||
.IgnoreQueryFilters()
|
||||
WatchStatusRepository repo =
|
||||
scope.ServiceProvider.GetRequiredService<WatchStatusRepository>();
|
||||
List<Guid> users = await db
|
||||
.ShowWatchStatus.IgnoreQueryFilters()
|
||||
.Where(x => x.ShowId == ep.ShowId && x.Status == WatchStatus.Completed)
|
||||
.Select(x => x.UserId)
|
||||
.ToListAsync();
|
||||
@ -189,8 +188,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
{
|
||||
if (include != null)
|
||||
include.Metadatas = include
|
||||
.Metadatas
|
||||
.Where(x => x.Name != nameof(Show.WatchStatus))
|
||||
.Metadatas.Where(x => x.Name != nameof(Show.WatchStatus))
|
||||
.ToList();
|
||||
|
||||
// We can't use the generic after id hanler since the sort depends on a relation.
|
||||
@ -226,9 +224,9 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
/// <inheritdoc />
|
||||
public Task<MovieWatchStatus?> GetMovieStatus(Guid movieId, Guid userId)
|
||||
{
|
||||
return _database
|
||||
.MovieWatchStatus
|
||||
.FirstOrDefaultAsync(x => x.MovieId == movieId && x.UserId == userId);
|
||||
return _database.MovieWatchStatus.FirstOrDefaultAsync(x =>
|
||||
x.MovieId == movieId && x.UserId == userId
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -277,8 +275,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
PlayedDate = status == WatchStatus.Completed ? DateTime.UtcNow : null,
|
||||
};
|
||||
await _database
|
||||
.MovieWatchStatus
|
||||
.Upsert(ret)
|
||||
.MovieWatchStatus.Upsert(ret)
|
||||
.UpdateIf(x => status != Watching || x.Status != Completed)
|
||||
.RunAsync();
|
||||
return ret;
|
||||
@ -288,17 +285,16 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
public async Task DeleteMovieStatus(Guid movieId, Guid userId)
|
||||
{
|
||||
await _database
|
||||
.MovieWatchStatus
|
||||
.Where(x => x.MovieId == movieId && x.UserId == userId)
|
||||
.MovieWatchStatus.Where(x => x.MovieId == movieId && x.UserId == userId)
|
||||
.ExecuteDeleteAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ShowWatchStatus?> GetShowStatus(Guid showId, Guid userId)
|
||||
{
|
||||
return _database
|
||||
.ShowWatchStatus
|
||||
.FirstOrDefaultAsync(x => x.ShowId == showId && x.UserId == userId);
|
||||
return _database.ShowWatchStatus.FirstOrDefaultAsync(x =>
|
||||
x.ShowId == showId && x.UserId == userId
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -315,12 +311,9 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
int unseenEpisodeCount =
|
||||
status != WatchStatus.Completed
|
||||
? await _database
|
||||
.Episodes
|
||||
.Where(x => x.ShowId == showId)
|
||||
.Where(
|
||||
x =>
|
||||
x.Watched!.First(x => x.UserId == userId)!.Status
|
||||
!= WatchStatus.Completed
|
||||
.Episodes.Where(x => x.ShowId == showId)
|
||||
.Where(x =>
|
||||
x.Watched!.First(x => x.UserId == userId)!.Status != WatchStatus.Completed
|
||||
)
|
||||
.CountAsync()
|
||||
: 0;
|
||||
@ -332,25 +325,20 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
if (status == WatchStatus.Watching)
|
||||
{
|
||||
var cursor = await _database
|
||||
.Episodes
|
||||
.IgnoreQueryFilters()
|
||||
.Episodes.IgnoreQueryFilters()
|
||||
.Where(x => x.ShowId == showId)
|
||||
.OrderByDescending(x => x.AbsoluteNumber)
|
||||
.ThenByDescending(x => x.SeasonNumber)
|
||||
.ThenByDescending(x => x.EpisodeNumber)
|
||||
.Select(
|
||||
x =>
|
||||
new
|
||||
.Select(x => new
|
||||
{
|
||||
x.Id,
|
||||
x.AbsoluteNumber,
|
||||
x.SeasonNumber,
|
||||
x.EpisodeNumber,
|
||||
Status = x.Watched!.First(x => x.UserId == userId)
|
||||
}
|
||||
)
|
||||
.FirstOrDefaultAsync(
|
||||
x =>
|
||||
})
|
||||
.FirstOrDefaultAsync(x =>
|
||||
x.Status.Status == WatchStatus.Completed
|
||||
|| x.Status.Status == WatchStatus.Watching
|
||||
);
|
||||
@ -359,14 +347,12 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
cursor?.Status.Status == WatchStatus.Watching
|
||||
? cursor.Id
|
||||
: await _database
|
||||
.Episodes
|
||||
.IgnoreQueryFilters()
|
||||
.Episodes.IgnoreQueryFilters()
|
||||
.Where(x => x.ShowId == showId)
|
||||
.OrderBy(x => x.AbsoluteNumber)
|
||||
.ThenBy(x => x.SeasonNumber)
|
||||
.ThenBy(x => x.EpisodeNumber)
|
||||
.Where(
|
||||
x =>
|
||||
.Where(x =>
|
||||
cursor == null
|
||||
|| x.AbsoluteNumber > cursor.AbsoluteNumber
|
||||
|| x.SeasonNumber > cursor.SeasonNumber
|
||||
@ -375,14 +361,11 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
&& x.EpisodeNumber > cursor.EpisodeNumber
|
||||
)
|
||||
)
|
||||
.Select(
|
||||
x =>
|
||||
new
|
||||
.Select(x => new
|
||||
{
|
||||
x.Id,
|
||||
Status = x.Watched!.FirstOrDefault(x => x.UserId == userId)
|
||||
}
|
||||
)
|
||||
})
|
||||
.Where(x => x.Status == null || x.Status.Status != WatchStatus.Completed)
|
||||
// The as Guid? is here to add the nullability status of the queryable.
|
||||
// Without this, FirstOrDefault returns new Guid() when no result is found (which is 16 0s and invalid in sql).
|
||||
@ -392,24 +375,19 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
else if (status == WatchStatus.Completed)
|
||||
{
|
||||
List<Guid> episodes = await _database
|
||||
.Episodes
|
||||
.Where(x => x.ShowId == showId)
|
||||
.Episodes.Where(x => x.ShowId == showId)
|
||||
.Select(x => x.Id)
|
||||
.ToListAsync();
|
||||
await _database
|
||||
.EpisodeWatchStatus
|
||||
.UpsertRange(
|
||||
episodes.Select(
|
||||
episodeId =>
|
||||
new EpisodeWatchStatus
|
||||
.EpisodeWatchStatus.UpsertRange(
|
||||
episodes.Select(episodeId => new EpisodeWatchStatus
|
||||
{
|
||||
UserId = userId,
|
||||
EpisodeId = episodeId,
|
||||
Status = WatchStatus.Completed,
|
||||
AddedDate = DateTime.UtcNow,
|
||||
PlayedDate = DateTime.UtcNow
|
||||
}
|
||||
)
|
||||
})
|
||||
)
|
||||
.UpdateIf(x => x.Status == Watching || x.Status == Planned)
|
||||
.RunAsync();
|
||||
@ -435,8 +413,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
PlayedDate = status == WatchStatus.Completed ? DateTime.UtcNow : null,
|
||||
};
|
||||
await _database
|
||||
.ShowWatchStatus
|
||||
.Upsert(ret)
|
||||
.ShowWatchStatus.Upsert(ret)
|
||||
.UpdateIf(x => status != Watching || x.Status != Completed || newEpisode)
|
||||
.RunAsync();
|
||||
return ret;
|
||||
@ -446,22 +423,20 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
public async Task DeleteShowStatus(Guid showId, Guid userId)
|
||||
{
|
||||
await _database
|
||||
.ShowWatchStatus
|
||||
.IgnoreAutoIncludes()
|
||||
.ShowWatchStatus.IgnoreAutoIncludes()
|
||||
.Where(x => x.ShowId == showId && x.UserId == userId)
|
||||
.ExecuteDeleteAsync();
|
||||
await _database
|
||||
.EpisodeWatchStatus
|
||||
.Where(x => x.Episode.ShowId == showId && x.UserId == userId)
|
||||
.EpisodeWatchStatus.Where(x => x.Episode.ShowId == showId && x.UserId == userId)
|
||||
.ExecuteDeleteAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<EpisodeWatchStatus?> GetEpisodeStatus(Guid episodeId, Guid userId)
|
||||
{
|
||||
return _database
|
||||
.EpisodeWatchStatus
|
||||
.FirstOrDefaultAsync(x => x.EpisodeId == episodeId && x.UserId == userId);
|
||||
return _database.EpisodeWatchStatus.FirstOrDefaultAsync(x =>
|
||||
x.EpisodeId == episodeId && x.UserId == userId
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -510,8 +485,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
PlayedDate = status == WatchStatus.Completed ? DateTime.UtcNow : null,
|
||||
};
|
||||
await _database
|
||||
.EpisodeWatchStatus
|
||||
.Upsert(ret)
|
||||
.EpisodeWatchStatus.Upsert(ret)
|
||||
.UpdateIf(x => status != Watching || x.Status != Completed)
|
||||
.RunAsync();
|
||||
await SetShowStatus(episode.ShowId, userId, WatchStatus.Watching);
|
||||
@ -522,8 +496,7 @@ public class WatchStatusRepository : IWatchStatusRepository
|
||||
public async Task DeleteEpisodeStatus(Guid episodeId, Guid userId)
|
||||
{
|
||||
await _database
|
||||
.EpisodeWatchStatus
|
||||
.Where(x => x.EpisodeId == episodeId && x.UserId == userId)
|
||||
.EpisodeWatchStatus.Where(x => x.EpisodeId == episodeId && x.UserId == userId)
|
||||
.ExecuteDeleteAsync();
|
||||
}
|
||||
}
|
||||
|
@ -212,8 +212,7 @@ namespace Kyoo.Core.Controllers
|
||||
{
|
||||
IEnumerable<string> images = new[] { "poster", "thumbnail", "logo" }
|
||||
.SelectMany(x => _GetBaseImagePath(item, x))
|
||||
.SelectMany(
|
||||
x =>
|
||||
.SelectMany(x =>
|
||||
new[]
|
||||
{
|
||||
ImageQuality.High.ToString().ToLowerInvariant(),
|
||||
|
@ -105,8 +105,8 @@ namespace Kyoo.Core
|
||||
options.SuppressMapClientErrors = true;
|
||||
options.InvalidModelStateResponseFactory = ctx =>
|
||||
{
|
||||
string[] errors = ctx.ModelState
|
||||
.SelectMany(x => x.Value!.Errors)
|
||||
string[] errors = ctx
|
||||
.ModelState.SelectMany(x => x.Value!.Errors)
|
||||
.Select(x => x.ErrorMessage)
|
||||
.ToArray();
|
||||
return new BadRequestObjectResult(new RequestError(errors));
|
||||
|
@ -45,9 +45,7 @@ namespace Kyoo.Core.Api
|
||||
protected Page<TResult> Page<TResult>(ICollection<TResult> resources, int limit)
|
||||
where TResult : IResource
|
||||
{
|
||||
Dictionary<string, string> query = Request
|
||||
.Query
|
||||
.ToDictionary(
|
||||
Dictionary<string, string> query = Request.Query.ToDictionary(
|
||||
x => x.Key,
|
||||
x => x.Value.ToString(),
|
||||
StringComparer.InvariantCultureIgnoreCase
|
||||
@ -66,9 +64,7 @@ namespace Kyoo.Core.Api
|
||||
protected SearchPage<TResult> SearchPage<TResult>(SearchPage<TResult>.SearchResult result)
|
||||
where TResult : IResource
|
||||
{
|
||||
Dictionary<string, string> query = Request
|
||||
.Query
|
||||
.ToDictionary(
|
||||
Dictionary<string, string> query = Request.Query.ToDictionary(
|
||||
x => x.Key,
|
||||
x => x.Value.ToString(),
|
||||
StringComparer.InvariantCultureIgnoreCase
|
||||
|
@ -28,14 +28,13 @@ public class FilterBinder : IModelBinder
|
||||
{
|
||||
public Task BindModelAsync(ModelBindingContext bindingContext)
|
||||
{
|
||||
ValueProviderResult fields = bindingContext
|
||||
.ValueProvider
|
||||
.GetValue(bindingContext.FieldName);
|
||||
ValueProviderResult fields = bindingContext.ValueProvider.GetValue(
|
||||
bindingContext.FieldName
|
||||
);
|
||||
try
|
||||
{
|
||||
object? filter = bindingContext
|
||||
.ModelType
|
||||
.GetMethod(nameof(Filter<object>.From))!
|
||||
.ModelType.GetMethod(nameof(Filter<object>.From))!
|
||||
.Invoke(null, new object?[] { fields.FirstValue });
|
||||
bindingContext.Result = ModelBindingResult.Success(filter);
|
||||
return Task.CompletedTask;
|
||||
|
@ -31,14 +31,13 @@ public class IncludeBinder : IModelBinder
|
||||
|
||||
public Task BindModelAsync(ModelBindingContext bindingContext)
|
||||
{
|
||||
ValueProviderResult fields = bindingContext
|
||||
.ValueProvider
|
||||
.GetValue(bindingContext.FieldName);
|
||||
ValueProviderResult fields = bindingContext.ValueProvider.GetValue(
|
||||
bindingContext.FieldName
|
||||
);
|
||||
try
|
||||
{
|
||||
object include = bindingContext
|
||||
.ModelType
|
||||
.GetMethod(nameof(Include<object>.From))!
|
||||
.ModelType.GetMethod(nameof(Include<object>.From))!
|
||||
.Invoke(null, new object?[] { fields.FirstValue })!;
|
||||
bindingContext.Result = ModelBindingResult.Success(include);
|
||||
bindingContext.HttpContext.Items["fields"] = ((dynamic)include).Fields;
|
||||
|
@ -32,9 +32,9 @@ public class SortBinder : IModelBinder
|
||||
|
||||
public Task BindModelAsync(ModelBindingContext bindingContext)
|
||||
{
|
||||
ValueProviderResult sortBy = bindingContext
|
||||
.ValueProvider
|
||||
.GetValue(bindingContext.FieldName);
|
||||
ValueProviderResult sortBy = bindingContext.ValueProvider.GetValue(
|
||||
bindingContext.FieldName
|
||||
);
|
||||
uint seed = BitConverter.ToUInt32(
|
||||
BitConverter.GetBytes(_rng.Next(int.MinValue, int.MaxValue)),
|
||||
0
|
||||
@ -42,8 +42,7 @@ public class SortBinder : IModelBinder
|
||||
try
|
||||
{
|
||||
object sort = bindingContext
|
||||
.ModelType
|
||||
.GetMethod(nameof(Sort<Movie>.From))!
|
||||
.ModelType.GetMethod(nameof(Sort<Movie>.From))!
|
||||
.Invoke(null, new object?[] { sortBy.FirstValue, seed })!;
|
||||
bindingContext.Result = ModelBindingResult.Success(sort);
|
||||
bindingContext.HttpContext.Items["seed"] = seed;
|
||||
|
@ -85,13 +85,8 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Show> fields
|
||||
)
|
||||
{
|
||||
ICollection<Show> resources = await _libraryManager
|
||||
.Shows
|
||||
.GetAll(
|
||||
Filter.And(
|
||||
filter,
|
||||
identifier.Matcher<Show>(x => x.StudioId, x => x.Studio!.Slug)
|
||||
),
|
||||
ICollection<Show> resources = await _libraryManager.Shows.GetAll(
|
||||
Filter.And(filter, identifier.Matcher<Show>(x => x.StudioId, x => x.Studio!.Slug)),
|
||||
sortBy,
|
||||
fields,
|
||||
pagination
|
||||
|
@ -200,13 +200,8 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Show>? fields
|
||||
)
|
||||
{
|
||||
ICollection<Show> resources = await _libraryManager
|
||||
.Shows
|
||||
.GetAll(
|
||||
Filter.And(
|
||||
filter,
|
||||
identifier.IsContainedIn<Show, Collection>(x => x.Collections)
|
||||
),
|
||||
ICollection<Show> resources = await _libraryManager.Shows.GetAll(
|
||||
Filter.And(filter, identifier.IsContainedIn<Show, Collection>(x => x.Collections)),
|
||||
sortBy == new Sort<Show>.Default() ? new Sort<Show>.By(x => x.AirDate) : sortBy,
|
||||
fields,
|
||||
pagination
|
||||
@ -249,16 +244,9 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Movie>? fields
|
||||
)
|
||||
{
|
||||
ICollection<Movie> resources = await _libraryManager
|
||||
.Movies
|
||||
.GetAll(
|
||||
Filter.And(
|
||||
filter,
|
||||
identifier.IsContainedIn<Movie, Collection>(x => x.Collections)
|
||||
),
|
||||
sortBy == new Sort<Movie>.Default()
|
||||
? new Sort<Movie>.By(x => x.AirDate)
|
||||
: sortBy,
|
||||
ICollection<Movie> resources = await _libraryManager.Movies.GetAll(
|
||||
Filter.And(filter, identifier.IsContainedIn<Movie, Collection>(x => x.Collections)),
|
||||
sortBy == new Sort<Movie>.Default() ? new Sort<Movie>.By(x => x.AirDate) : sortBy,
|
||||
fields,
|
||||
pagination
|
||||
);
|
||||
|
@ -77,9 +77,10 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Show> fields
|
||||
)
|
||||
{
|
||||
return await _libraryManager
|
||||
.Shows
|
||||
.Get(identifier.IsContainedIn<Show, Episode>(x => x.Episodes!), fields);
|
||||
return await _libraryManager.Shows.Get(
|
||||
identifier.IsContainedIn<Show, Episode>(x => x.Episodes!),
|
||||
fields
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -103,9 +104,10 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Season> fields
|
||||
)
|
||||
{
|
||||
Season? ret = await _libraryManager
|
||||
.Seasons
|
||||
.GetOrDefault(identifier.IsContainedIn<Season, Episode>(x => x.Episodes!), fields);
|
||||
Season? ret = await _libraryManager.Seasons.GetOrDefault(
|
||||
identifier.IsContainedIn<Season, Episode>(x => x.Episodes!),
|
||||
fields
|
||||
);
|
||||
if (ret != null)
|
||||
return ret;
|
||||
Episode? episode = await identifier.Match(
|
||||
@ -170,9 +172,13 @@ namespace Kyoo.Core.Api
|
||||
id => Task.FromResult(id),
|
||||
async slug => (await _libraryManager.Episodes.Get(slug)).Id
|
||||
);
|
||||
return await _libraryManager
|
||||
.WatchStatus
|
||||
.SetEpisodeStatus(id, User.GetIdOrThrow(), status, watchedTime, percent);
|
||||
return await _libraryManager.WatchStatus.SetEpisodeStatus(
|
||||
id,
|
||||
User.GetIdOrThrow(),
|
||||
status,
|
||||
watchedTime,
|
||||
percent
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -113,9 +113,10 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Studio> fields
|
||||
)
|
||||
{
|
||||
return await _libraryManager
|
||||
.Studios
|
||||
.Get(identifier.IsContainedIn<Studio, Movie>(x => x.Movies!), fields);
|
||||
return await _libraryManager.Studios.Get(
|
||||
identifier.IsContainedIn<Studio, Movie>(x => x.Movies!),
|
||||
fields
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -146,9 +147,7 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Collection> fields
|
||||
)
|
||||
{
|
||||
ICollection<Collection> resources = await _libraryManager
|
||||
.Collections
|
||||
.GetAll(
|
||||
ICollection<Collection> resources = await _libraryManager.Collections.GetAll(
|
||||
Filter.And(filter, identifier.IsContainedIn<Collection, Movie>(x => x.Movies)),
|
||||
sortBy,
|
||||
fields,
|
||||
@ -219,9 +218,13 @@ namespace Kyoo.Core.Api
|
||||
id => Task.FromResult(id),
|
||||
async slug => (await _libraryManager.Movies.Get(slug)).Id
|
||||
);
|
||||
return await _libraryManager
|
||||
.WatchStatus
|
||||
.SetMovieStatus(id, User.GetIdOrThrow(), status, watchedTime, percent);
|
||||
return await _libraryManager.WatchStatus.SetMovieStatus(
|
||||
id,
|
||||
User.GetIdOrThrow(),
|
||||
status,
|
||||
watchedTime,
|
||||
percent
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -86,9 +86,7 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Episode> fields
|
||||
)
|
||||
{
|
||||
ICollection<Episode> resources = await _libraryManager
|
||||
.Episodes
|
||||
.GetAll(
|
||||
ICollection<Episode> resources = await _libraryManager.Episodes.GetAll(
|
||||
Filter.And(
|
||||
filter,
|
||||
identifier.Matcher<Episode>(x => x.SeasonId, x => x.Season!.Slug)
|
||||
@ -125,9 +123,10 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Show> fields
|
||||
)
|
||||
{
|
||||
Show? ret = await _libraryManager
|
||||
.Shows
|
||||
.GetOrDefault(identifier.IsContainedIn<Show, Season>(x => x.Seasons!), fields);
|
||||
Show? ret = await _libraryManager.Shows.GetOrDefault(
|
||||
identifier.IsContainedIn<Show, Season>(x => x.Seasons!),
|
||||
fields
|
||||
);
|
||||
if (ret == null)
|
||||
return NotFound();
|
||||
return ret;
|
||||
|
@ -88,13 +88,8 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Season> fields
|
||||
)
|
||||
{
|
||||
ICollection<Season> resources = await _libraryManager
|
||||
.Seasons
|
||||
.GetAll(
|
||||
Filter.And(
|
||||
filter,
|
||||
identifier.Matcher<Season>(x => x.ShowId, x => x.Show!.Slug)
|
||||
),
|
||||
ICollection<Season> resources = await _libraryManager.Seasons.GetAll(
|
||||
Filter.And(filter, identifier.Matcher<Season>(x => x.ShowId, x => x.Show!.Slug)),
|
||||
sortBy,
|
||||
fields,
|
||||
pagination
|
||||
@ -136,13 +131,8 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Episode> fields
|
||||
)
|
||||
{
|
||||
ICollection<Episode> resources = await _libraryManager
|
||||
.Episodes
|
||||
.GetAll(
|
||||
Filter.And(
|
||||
filter,
|
||||
identifier.Matcher<Episode>(x => x.ShowId, x => x.Show!.Slug)
|
||||
),
|
||||
ICollection<Episode> resources = await _libraryManager.Episodes.GetAll(
|
||||
Filter.And(filter, identifier.Matcher<Episode>(x => x.ShowId, x => x.Show!.Slug)),
|
||||
sortBy,
|
||||
fields,
|
||||
pagination
|
||||
@ -210,9 +200,10 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Studio> fields
|
||||
)
|
||||
{
|
||||
return await _libraryManager
|
||||
.Studios
|
||||
.Get(identifier.IsContainedIn<Studio, Show>(x => x.Shows!), fields);
|
||||
return await _libraryManager.Studios.Get(
|
||||
identifier.IsContainedIn<Studio, Show>(x => x.Shows!),
|
||||
fields
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -243,9 +234,7 @@ namespace Kyoo.Core.Api
|
||||
[FromQuery] Include<Collection> fields
|
||||
)
|
||||
{
|
||||
ICollection<Collection> resources = await _libraryManager
|
||||
.Collections
|
||||
.GetAll(
|
||||
ICollection<Collection> resources = await _libraryManager.Collections.GetAll(
|
||||
Filter.And(filter, identifier.IsContainedIn<Collection, Show>(x => x.Shows!)),
|
||||
sortBy,
|
||||
fields,
|
||||
|
@ -35,14 +35,13 @@ namespace Kyoo.Core.Api
|
||||
public class ProxyApi : Controller
|
||||
{
|
||||
private readonly HttpProxyOptions _proxyOptions = HttpProxyOptionsBuilder
|
||||
.Instance
|
||||
.WithHandleFailure(
|
||||
.Instance.WithHandleFailure(
|
||||
async (context, exception) =>
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
|
||||
await context
|
||||
.Response
|
||||
.WriteAsJsonAsync(new RequestError("Service unavailable"));
|
||||
await context.Response.WriteAsJsonAsync(
|
||||
new RequestError("Service unavailable")
|
||||
);
|
||||
}
|
||||
)
|
||||
.Build();
|
||||
|
@ -150,8 +150,7 @@ namespace Kyoo.Host
|
||||
.ConfigureAppConfiguration(x => _SetupConfig(x, args))
|
||||
.UseSerilog((host, services, builder) => _ConfigureLogging(builder))
|
||||
.ConfigureServices(x => x.AddRouting())
|
||||
.ConfigureWebHost(
|
||||
x =>
|
||||
.ConfigureWebHost(x =>
|
||||
x.UseKestrel(options =>
|
||||
{
|
||||
options.AddServerHeader = false;
|
||||
@ -159,15 +158,10 @@ namespace Kyoo.Host
|
||||
.UseIIS()
|
||||
.UseIISIntegration()
|
||||
.UseUrls(
|
||||
Environment.GetEnvironmentVariable("KYOO_BIND_URL")
|
||||
?? "http://*:5000"
|
||||
)
|
||||
.UseStartup(
|
||||
host =>
|
||||
PluginsStartup.FromWebHost(
|
||||
host,
|
||||
new LoggerFactory().AddSerilog()
|
||||
Environment.GetEnvironmentVariable("KYOO_BIND_URL") ?? "http://*:5000"
|
||||
)
|
||||
.UseStartup(host =>
|
||||
PluginsStartup.FromWebHost(host, new LoggerFactory().AddSerilog())
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -196,20 +190,13 @@ namespace Kyoo.Host
|
||||
"[{@t:HH:mm:ss} {@l:u3} {Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), 25} "
|
||||
+ "({@i:D10})] {@m}{#if not EndsWith(@m, '\n')}\n{#end}{@x}";
|
||||
builder
|
||||
.MinimumLevel
|
||||
.Warning()
|
||||
.MinimumLevel
|
||||
.Override("Kyoo", LogEventLevel.Verbose)
|
||||
.MinimumLevel
|
||||
.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Verbose)
|
||||
.MinimumLevel
|
||||
.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Fatal)
|
||||
.WriteTo
|
||||
.Console(new ExpressionTemplate(template, theme: TemplateTheme.Code))
|
||||
.Enrich
|
||||
.WithThreadId()
|
||||
.Enrich
|
||||
.FromLogContext();
|
||||
.MinimumLevel.Warning()
|
||||
.MinimumLevel.Override("Kyoo", LogEventLevel.Verbose)
|
||||
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Verbose)
|
||||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Fatal)
|
||||
.WriteTo.Console(new ExpressionTemplate(template, theme: TemplateTheme.Code))
|
||||
.Enrich.WithThreadId()
|
||||
.Enrich.FromLogContext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,8 +127,8 @@ namespace Kyoo.Host
|
||||
.SelectMany(x => x.ConfigureSteps)
|
||||
.OrderByDescending(x => x.Priority);
|
||||
|
||||
using ILifetimeScope scope = container.BeginLifetimeScope(
|
||||
x => x.RegisterInstance(app).SingleInstance().ExternallyOwned()
|
||||
using ILifetimeScope scope = container.BeginLifetimeScope(x =>
|
||||
x.RegisterInstance(app).SingleInstance().ExternallyOwned()
|
||||
);
|
||||
IServiceProvider provider = scope.Resolve<IServiceProvider>();
|
||||
foreach (IStartupAction step in steps)
|
||||
|
@ -39,8 +39,10 @@ public class SearchManager : ISearchManager
|
||||
Sort<T>.By @sortBy
|
||||
=> MeilisearchModule
|
||||
.IndexSettings[index]
|
||||
.SortableAttributes
|
||||
.Contains(sortBy.Key, StringComparer.InvariantCultureIgnoreCase)
|
||||
.SortableAttributes.Contains(
|
||||
sortBy.Key,
|
||||
StringComparer.InvariantCultureIgnoreCase
|
||||
)
|
||||
? new[]
|
||||
{
|
||||
$"{CamelCase.ConvertName(sortBy.Key)}:{(sortBy.Desendant ? "desc" : "asc")}"
|
||||
|
@ -369,16 +369,13 @@ namespace Kyoo.Postgresql
|
||||
modelBuilder.Entity<Season>().HasIndex(x => x.Slug).IsUnique();
|
||||
modelBuilder
|
||||
.Entity<Episode>()
|
||||
.HasIndex(
|
||||
x =>
|
||||
new
|
||||
.HasIndex(x => new
|
||||
{
|
||||
ShowID = x.ShowId,
|
||||
x.SeasonNumber,
|
||||
x.EpisodeNumber,
|
||||
x.AbsoluteNumber
|
||||
}
|
||||
)
|
||||
})
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<Episode>().HasIndex(x => x.Slug).IsUnique();
|
||||
modelBuilder.Entity<User>().HasIndex(x => x.Slug).IsUnique();
|
||||
|
@ -41,8 +41,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "collections",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
slug = table.Column<string>(
|
||||
@ -85,8 +84,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "studios",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
slug = table.Column<string>(
|
||||
@ -105,8 +103,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "users",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
slug = table.Column<string>(
|
||||
@ -138,8 +135,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "movies",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
slug = table.Column<string>(
|
||||
@ -203,8 +199,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "shows",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
slug = table.Column<string>(
|
||||
@ -270,8 +265,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "link_collection_movie",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
collection_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
movie_id = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
@ -301,8 +295,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "link_collection_show",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
collection_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
show_id = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
@ -332,8 +325,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "seasons",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
slug = table.Column<string>(
|
||||
@ -393,8 +385,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "episodes",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
slug = table.Column<string>(
|
||||
|
@ -46,8 +46,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "episode_watch_status",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
episode_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
@ -89,8 +88,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "movie_watch_status",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
movie_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
@ -129,8 +127,7 @@ namespace Kyoo.Postgresql.Migrations
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "show_watch_status",
|
||||
columns: table =>
|
||||
new
|
||||
columns: table => new
|
||||
{
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
show_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
|
@ -99,17 +99,14 @@ namespace Kyoo.Postgresql
|
||||
|
||||
modelBuilder
|
||||
.HasDbFunction(typeof(DatabaseContext).GetMethod(nameof(MD5))!)
|
||||
.HasTranslation(
|
||||
args =>
|
||||
new SqlFunctionExpression(
|
||||
.HasTranslation(args => new SqlFunctionExpression(
|
||||
"md5",
|
||||
args,
|
||||
nullable: true,
|
||||
argumentsPropagateNullability: new[] { false },
|
||||
type: args[0].Type,
|
||||
typeMapping: args[0].TypeMapping
|
||||
)
|
||||
);
|
||||
));
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
@ -39,8 +39,7 @@ namespace Kyoo.Swagger
|
||||
{
|
||||
// We can't reorder items by assigning the sorted value to the Paths variable since it has no setter.
|
||||
List<KeyValuePair<string, OpenApiPathItem>> sorted = postProcess
|
||||
.Paths
|
||||
.OrderBy(x => x.Key)
|
||||
.Paths.OrderBy(x => x.Key)
|
||||
.ToList();
|
||||
postProcess.Paths.Clear();
|
||||
foreach ((string key, OpenApiPathItem value) in sorted)
|
||||
|
@ -21,10 +21,10 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using Kyoo.Abstractions.Models.Attributes;
|
||||
using Kyoo.Swagger.Models;
|
||||
using Namotion.Reflection;
|
||||
using NSwag;
|
||||
using NSwag.Generation.AspNetCore;
|
||||
using NSwag.Generation.Processors.Contexts;
|
||||
using Namotion.Reflection;
|
||||
|
||||
namespace Kyoo.Swagger
|
||||
{
|
||||
@ -42,24 +42,19 @@ namespace Kyoo.Swagger
|
||||
/// <returns>This always return <c>true</c> since it should not remove operations.</returns>
|
||||
public static bool OperationFilter(OperationProcessorContext context)
|
||||
{
|
||||
ApiDefinitionAttribute def = context
|
||||
.ControllerType
|
||||
.GetCustomAttribute<ApiDefinitionAttribute>();
|
||||
ApiDefinitionAttribute def =
|
||||
context.ControllerType.GetCustomAttribute<ApiDefinitionAttribute>();
|
||||
string name = def?.Name ?? context.ControllerType.Name;
|
||||
|
||||
ApiDefinitionAttribute methodOverride = context
|
||||
.MethodInfo
|
||||
.GetCustomAttribute<ApiDefinitionAttribute>();
|
||||
ApiDefinitionAttribute methodOverride =
|
||||
context.MethodInfo.GetCustomAttribute<ApiDefinitionAttribute>();
|
||||
if (methodOverride != null)
|
||||
name = methodOverride.Name;
|
||||
|
||||
context.OperationDescription.Operation.Tags.Add(name);
|
||||
if (context.Document.Tags.All(x => x.Name != name))
|
||||
{
|
||||
context
|
||||
.Document
|
||||
.Tags
|
||||
.Add(
|
||||
context.Document.Tags.Add(
|
||||
new OpenApiTag
|
||||
{
|
||||
Name = name,
|
||||
@ -106,8 +101,7 @@ namespace Kyoo.Swagger
|
||||
{
|
||||
List<TagGroups> tagGroups = (List<TagGroups>)postProcess.ExtensionData["x-tagGroups"];
|
||||
List<string> tagsWithoutGroup = postProcess
|
||||
.Tags
|
||||
.Select(x => x.Name)
|
||||
.Tags.Select(x => x.Name)
|
||||
.Where(x => tagGroups.SelectMany(y => y.Tags).All(y => y != x))
|
||||
.ToList();
|
||||
if (tagsWithoutGroup.Any())
|
||||
|
@ -49,8 +49,7 @@ namespace Kyoo.Swagger
|
||||
foreach (ActionModel action in context.Result.Controllers.SelectMany(x => x.Actions))
|
||||
{
|
||||
IEnumerable<ProducesResponseTypeAttribute> responses = action
|
||||
.Filters
|
||||
.OfType<ProducesResponseTypeAttribute>()
|
||||
.Filters.OfType<ProducesResponseTypeAttribute>()
|
||||
.Where(x => x.Type == typeof(ActionResult<>));
|
||||
foreach (ProducesResponseTypeAttribute response in responses)
|
||||
{
|
||||
|
@ -17,8 +17,8 @@
|
||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using NSwag;
|
||||
using Newtonsoft.Json;
|
||||
using NSwag;
|
||||
|
||||
namespace Kyoo.Swagger.Models
|
||||
{
|
||||
|
@ -39,8 +39,7 @@ namespace Kyoo.Swagger
|
||||
context.OperationDescription.Operation.Security ??=
|
||||
new List<OpenApiSecurityRequirement>();
|
||||
OpenApiSecurityRequirement perms = context
|
||||
.MethodInfo
|
||||
.GetCustomAttributes<UserOnlyAttribute>()
|
||||
.MethodInfo.GetCustomAttributes<UserOnlyAttribute>()
|
||||
.Aggregate(
|
||||
new OpenApiSecurityRequirement(),
|
||||
(agg, _) =>
|
||||
@ -51,8 +50,7 @@ namespace Kyoo.Swagger
|
||||
);
|
||||
|
||||
perms = context
|
||||
.MethodInfo
|
||||
.GetCustomAttributes<PermissionAttribute>()
|
||||
.MethodInfo.GetCustomAttributes<PermissionAttribute>()
|
||||
.Aggregate(
|
||||
perms,
|
||||
(agg, cur) =>
|
||||
@ -64,14 +62,12 @@ namespace Kyoo.Swagger
|
||||
}
|
||||
);
|
||||
|
||||
PartialPermissionAttribute controller = context
|
||||
.ControllerType
|
||||
.GetCustomAttribute<PartialPermissionAttribute>();
|
||||
PartialPermissionAttribute controller =
|
||||
context.ControllerType.GetCustomAttribute<PartialPermissionAttribute>();
|
||||
if (controller != null)
|
||||
{
|
||||
perms = context
|
||||
.MethodInfo
|
||||
.GetCustomAttributes<PartialPermissionAttribute>()
|
||||
.MethodInfo.GetCustomAttributes<PartialPermissionAttribute>()
|
||||
.Aggregate(
|
||||
perms,
|
||||
(agg, cur) =>
|
||||
|
@ -82,11 +82,7 @@ namespace Kyoo.Swagger
|
||||
!= AlternativeRoute;
|
||||
return true;
|
||||
});
|
||||
document
|
||||
.SchemaGenerator
|
||||
.Settings
|
||||
.TypeMappers
|
||||
.Add(
|
||||
document.SchemaGenerator.Settings.TypeMappers.Add(
|
||||
new PrimitiveTypeMapper(
|
||||
typeof(Identifier),
|
||||
x =>
|
||||
|
@ -54,10 +54,7 @@ namespace Kyoo.Tests.Database
|
||||
{
|
||||
Episode episode = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||
await Repositories
|
||||
.LibraryManager
|
||||
.Shows
|
||||
.Patch(
|
||||
await Repositories.LibraryManager.Shows.Patch(
|
||||
episode.ShowId,
|
||||
(x) =>
|
||||
{
|
||||
@ -92,10 +89,7 @@ namespace Kyoo.Tests.Database
|
||||
{
|
||||
Episode episode = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||
episode = await Repositories
|
||||
.LibraryManager
|
||||
.Episodes
|
||||
.Patch(
|
||||
episode = await Repositories.LibraryManager.Episodes.Patch(
|
||||
episode.Id,
|
||||
(x) =>
|
||||
{
|
||||
@ -143,10 +137,7 @@ namespace Kyoo.Tests.Database
|
||||
public async Task SlugEditAbsoluteTest()
|
||||
{
|
||||
Episode episode = await _repository.Create(TestSample.GetAbsoluteEpisode());
|
||||
await Repositories
|
||||
.LibraryManager
|
||||
.Shows
|
||||
.Patch(
|
||||
await Repositories.LibraryManager.Shows.Patch(
|
||||
episode.ShowId,
|
||||
(x) =>
|
||||
{
|
||||
|
@ -53,10 +53,7 @@ namespace Kyoo.Tests.Database
|
||||
{
|
||||
Season season = await _repository.Get(1.AsGuid());
|
||||
Assert.Equal("anohana-s1", season.Slug);
|
||||
await Repositories
|
||||
.LibraryManager
|
||||
.Shows
|
||||
.Patch(
|
||||
await Repositories.LibraryManager.Shows.Patch(
|
||||
season.ShowId,
|
||||
(x) =>
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user