| | | 1 | | using Anichron.Core.Domain; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | |
| | | 4 | | namespace Anichron.Core.Data.Repository; |
| | | 5 | | |
| | | 6 | | public sealed record VisibleProxy(string ProxyPath, string ContentHash); |
| | | 7 | | |
| | | 8 | | public interface IMediaAssetReadRepository |
| | | 9 | | { |
| | | 10 | | Task<VisibleProxy?> FindVisibleProxyAsync(Guid assetId, Guid userId, ProxyType proxyType, CancellationToken ct); |
| | | 11 | | } |
| | | 12 | | |
| | 5 | 13 | | public sealed class EfMediaAssetReadRepository(AnichronDbContext db) : IMediaAssetReadRepository |
| | | 14 | | { |
| | | 15 | | public Task<VisibleProxy?> FindVisibleProxyAsync(Guid assetId, Guid userId, ProxyType proxyType, CancellationToken c |
| | 5 | 16 | | => VisibleProxyQuery(db, assetId, userId, proxyType).FirstOrDefaultAsync(ct); |
| | | 17 | | |
| | | 18 | | internal static IQueryable<VisibleProxy> VisibleProxyQuery( |
| | | 19 | | AnichronDbContext db, Guid assetId, Guid userId, ProxyType proxyType) |
| | 6 | 20 | | => db.MediaAssets.VisibleTo(userId) |
| | 6 | 21 | | .Where(a => a.Id == assetId) |
| | 6 | 22 | | .Join( |
| | 6 | 23 | | db.ProxyFiles.Where(p => p.ProxyType == proxyType), |
| | 6 | 24 | | a => a.Id, |
| | 6 | 25 | | p => p.AssetId, |
| | 6 | 26 | | (a, p) => new VisibleProxy(p.ProxyPath, a.ContentHash)); |
| | | 27 | | } |