mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
WIP
This commit is contained in:
parent
26f5f84292
commit
b0d523215e
11 changed files with 568 additions and 107 deletions
|
@ -1,25 +1,19 @@
|
|||
using Mapster;
|
||||
using Microsoft.AspNet.OData;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Roadie.Api.Services;
|
||||
using Roadie.Library.Caching;
|
||||
using Roadie.Library.Data;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using models = Roadie.Library.Models;
|
||||
|
||||
namespace Roadie.Api.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("image")]
|
||||
[ApiController]
|
||||
// [Authorize]
|
||||
[Authorize]
|
||||
public class ImageController : EntityControllerBase
|
||||
{
|
||||
private IImageService ImageService { get; }
|
||||
|
@ -27,7 +21,7 @@ namespace Roadie.Api.Controllers
|
|||
public ImageController(IImageService imageService, ILoggerFactory logger, ICacheManager cacheManager, IConfiguration configuration)
|
||||
: base(cacheManager, configuration)
|
||||
{
|
||||
this._logger = logger.CreateLogger("RoadieApi.Controllers.ImageController");
|
||||
this._logger = logger.CreateLogger("RoadieApi.Controllers.ImageController");
|
||||
this.ImageService = imageService;
|
||||
}
|
||||
|
||||
|
@ -37,6 +31,48 @@ namespace Roadie.Api.Controllers
|
|||
// return Ok(this._RoadieDbContext.Tracks.ProjectToType<models.Image>());
|
||||
//}
|
||||
|
||||
[HttpGet("thumbnail/artist/{id}/{width:int?}/{height:int?}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> ArtistThumbnail(Guid id, int? width, int? height)
|
||||
{
|
||||
var result = await this.ImageService.ArtistThumbnail(id, width ?? this.RoadieSettings.Thumbnails.Width, height ?? this.RoadieSettings.Thumbnails.Height);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return File(fileContents: result.Data.Bytes,
|
||||
contentType: result.ContentType,
|
||||
fileDownloadName: $"{ result.Data.Caption ?? id.ToString()}.jpg",
|
||||
lastModified: result.LastModified,
|
||||
entityTag: result.ETag);
|
||||
}
|
||||
|
||||
[HttpGet("thumbnail/collection/{id}/{width:int?}/{height:int?}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> CollectionThumbnail(Guid id, int? width, int? height)
|
||||
{
|
||||
var result = await this.ImageService.CollectionThumbnail(id, width ?? this.RoadieSettings.Thumbnails.Width, height ?? this.RoadieSettings.Thumbnails.Height);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return File(fileContents: result.Data.Bytes,
|
||||
contentType: result.ContentType,
|
||||
fileDownloadName: $"{ result.Data.Caption ?? id.ToString()}.jpg",
|
||||
lastModified: result.LastModified,
|
||||
entityTag: result.ETag);
|
||||
}
|
||||
|
||||
[HttpGet("{id}/{width:int?}/{height:int?}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
|
@ -51,19 +87,40 @@ namespace Roadie.Api.Controllers
|
|||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return File(fileContents:result.Data.Bytes,
|
||||
contentType: result.ContentType,
|
||||
return File(fileContents: result.Data.Bytes,
|
||||
contentType: result.ContentType,
|
||||
fileDownloadName: $"{ result.Data.Caption ?? id.ToString()}.jpg",
|
||||
lastModified: result.LastModified,
|
||||
lastModified: result.LastModified,
|
||||
entityTag: result.ETag);
|
||||
}
|
||||
|
||||
[HttpGet("thumbnail/artist/{id}/{width:int?}/{height:int?}")]
|
||||
[HttpGet("thumbnail/label/{id}/{width:int?}/{height:int?}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> ArtistThumbnail(Guid id, int? width, int? height)
|
||||
public async Task<IActionResult> LabelThumbnail(Guid id, int? width, int? height)
|
||||
{
|
||||
var result = await this.ImageService.ArtistThumbnail(id, width ?? this.RoadieSettings.Thumbnails.Width, height ?? this.RoadieSettings.Thumbnails.Height);
|
||||
var result = await this.ImageService.LabelThumbnail(id, width ?? this.RoadieSettings.Thumbnails.Width, height ?? this.RoadieSettings.Thumbnails.Height);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return File(fileContents: result.Data.Bytes,
|
||||
contentType: result.ContentType,
|
||||
fileDownloadName: $"{ result.Data.Caption ?? id.ToString()}.jpg",
|
||||
lastModified: result.LastModified,
|
||||
entityTag: result.ETag);
|
||||
}
|
||||
|
||||
[HttpGet("thumbnail/playlist/{id}/{width:int?}/{height:int?}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> PlaylistThumbnail(Guid id, int? width, int? height)
|
||||
{
|
||||
var result = await this.ImageService.PlaylistThumbnail(id, width ?? this.RoadieSettings.Thumbnails.Width, height ?? this.RoadieSettings.Thumbnails.Height);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
|
@ -100,5 +157,46 @@ namespace Roadie.Api.Controllers
|
|||
entityTag: result.ETag);
|
||||
}
|
||||
|
||||
[HttpGet("thumbnail/track/{id}/{width:int?}/{height:int?}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> TrackThumbnail(Guid id, int? width, int? height)
|
||||
{
|
||||
var result = await this.ImageService.TrackThumbnail(id, width ?? this.RoadieSettings.Thumbnails.Width, height ?? this.RoadieSettings.Thumbnails.Height);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return File(fileContents: result.Data.Bytes,
|
||||
contentType: result.ContentType,
|
||||
fileDownloadName: $"{ result.Data.Caption ?? id.ToString()}.jpg",
|
||||
lastModified: result.LastModified,
|
||||
entityTag: result.ETag);
|
||||
}
|
||||
|
||||
[HttpGet("thumbnail/user/{id}/{width:int?}/{height:int?}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> UserThumbnail(Guid id, int? width, int? height)
|
||||
{
|
||||
var result = await this.ImageService.UserThumbnail(id, width ?? this.RoadieSettings.Thumbnails.Width, height ?? this.RoadieSettings.Thumbnails.Height);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return File(fileContents: result.Data.Bytes,
|
||||
contentType: result.ContentType,
|
||||
fileDownloadName: $"{ result.Data.Caption ?? id.ToString()}.jpg",
|
||||
lastModified: result.LastModified,
|
||||
entityTag: result.ETag);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,16 +21,6 @@
|
|||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="wwwroot\Images\artist.gif" />
|
||||
<None Include="wwwroot\Images\collection.gif" />
|
||||
<None Include="wwwroot\Images\image-not-found.gif" />
|
||||
<None Include="wwwroot\Images\label.gif" />
|
||||
<None Include="wwwroot\Images\release.gif" />
|
||||
<None Include="wwwroot\Images\track.gif" />
|
||||
<None Include="wwwroot\Images\user.gif" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RoadieLibrary\Roadie.Library.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -1,14 +1,26 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Roadie.Library;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Roadie.Api.Services
|
||||
{
|
||||
public interface IImageService
|
||||
{
|
||||
Task<FileOperationResult<Library.Models.Image>> ImageById(Guid id, int? width, int? height, EntityTagHeaderValue etag = null);
|
||||
Task<FileOperationResult<Library.Models.Image>> ArtistThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null);
|
||||
|
||||
Task<FileOperationResult<Library.Models.Image>> CollectionThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null);
|
||||
|
||||
Task<FileOperationResult<Library.Models.Image>> ImageById(Guid id, int? width, int? height, EntityTagHeaderValue etag = null);
|
||||
|
||||
Task<FileOperationResult<Library.Models.Image>> LabelThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null);
|
||||
|
||||
Task<FileOperationResult<Library.Models.Image>> PlaylistThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null);
|
||||
|
||||
Task<FileOperationResult<Library.Models.Image>> ReleaseThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null);
|
||||
|
||||
Task<FileOperationResult<Library.Models.Image>> TrackThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null);
|
||||
|
||||
Task<FileOperationResult<Library.Models.Image>> UserThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ using Roadie.Library;
|
|||
using Roadie.Library.Caching;
|
||||
using Roadie.Library.Configuration;
|
||||
using Roadie.Library.Encoding;
|
||||
using Roadie.Library.Identity;
|
||||
using Roadie.Library.Imaging;
|
||||
using Roadie.Library.Models;
|
||||
using Roadie.Library.Utility;
|
||||
|
@ -47,16 +48,16 @@ namespace Roadie.Api.Services
|
|||
etag: etag);
|
||||
}
|
||||
|
||||
public async Task<FileOperationResult<Image>> ReleaseThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null)
|
||||
public async Task<FileOperationResult<Image>> CollectionThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
return await this.GetImageFileOperation(type: "ReleaseThumbnail",
|
||||
regionUrn: data.Release.CacheRegionUrn(id),
|
||||
return await this.GetImageFileOperation(type: "CollectionThumbnail",
|
||||
regionUrn: data.Collection.CacheRegionUrn(id),
|
||||
id: id,
|
||||
width: width,
|
||||
height: height,
|
||||
action: async () =>
|
||||
{
|
||||
return await this.ReleaseThumbnailAction(id, etag);
|
||||
return await this.CollectionThumbnailAction(id, etag);
|
||||
},
|
||||
etag: etag);
|
||||
}
|
||||
|
@ -75,6 +76,76 @@ namespace Roadie.Api.Services
|
|||
etag: etag);
|
||||
}
|
||||
|
||||
public async Task<FileOperationResult<Image>> LabelThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
return await this.GetImageFileOperation(type: "LabelThumbnail",
|
||||
regionUrn: data.Label.CacheRegionUrn(id),
|
||||
id: id,
|
||||
width: width,
|
||||
height: height,
|
||||
action: async () =>
|
||||
{
|
||||
return await this.LabelThumbnailAction(id, etag);
|
||||
},
|
||||
etag: etag);
|
||||
}
|
||||
|
||||
public async Task<FileOperationResult<Image>> PlaylistThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
return await this.GetImageFileOperation(type: "PlaylistThumbnail",
|
||||
regionUrn: data.Playlist.CacheRegionUrn(id),
|
||||
id: id,
|
||||
width: width,
|
||||
height: height,
|
||||
action: async () =>
|
||||
{
|
||||
return await this.PlaylistThumbnailAction(id, etag);
|
||||
},
|
||||
etag: etag);
|
||||
}
|
||||
|
||||
public async Task<FileOperationResult<Image>> ReleaseThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
return await this.GetImageFileOperation(type: "ReleaseThumbnail",
|
||||
regionUrn: data.Release.CacheRegionUrn(id),
|
||||
id: id,
|
||||
width: width,
|
||||
height: height,
|
||||
action: async () =>
|
||||
{
|
||||
return await this.ReleaseThumbnailAction(id, etag);
|
||||
},
|
||||
etag: etag);
|
||||
}
|
||||
|
||||
public async Task<FileOperationResult<Image>> TrackThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
return await this.GetImageFileOperation(type: "TrackThumbnail",
|
||||
regionUrn: data.Track.CacheRegionUrn(id),
|
||||
id: id,
|
||||
width: width,
|
||||
height: height,
|
||||
action: async () =>
|
||||
{
|
||||
return await this.TrackThumbnailAction(id, etag);
|
||||
},
|
||||
etag: etag);
|
||||
}
|
||||
|
||||
public async Task<FileOperationResult<Image>> UserThumbnail(Guid id, int? width, int? height, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
return await this.GetImageFileOperation(type: "UserById",
|
||||
regionUrn: ApplicationUser.CacheRegionUrn(id),
|
||||
id: id,
|
||||
width: width,
|
||||
height: height,
|
||||
action: async () =>
|
||||
{
|
||||
return await this.UserThumbnailAction(id, etag);
|
||||
},
|
||||
etag: etag);
|
||||
}
|
||||
|
||||
private async Task<FileOperationResult<Image>> ArtistThumbnailAction(Guid id, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
try
|
||||
|
@ -103,35 +174,34 @@ namespace Roadie.Api.Services
|
|||
return new FileOperationResult<Image>(OperationMessages.ErrorOccured);
|
||||
}
|
||||
|
||||
private async Task<FileOperationResult<Image>> ReleaseThumbnailAction(Guid id, EntityTagHeaderValue etag = null)
|
||||
private async Task<FileOperationResult<Image>> CollectionThumbnailAction(Guid id, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var release = this.GetRelease(id);
|
||||
if (release == null)
|
||||
var collection = this.GetCollection(id);
|
||||
if (collection == null)
|
||||
{
|
||||
return new FileOperationResult<Image>(true, string.Format("Release Not Found [{0}]", id));
|
||||
return new FileOperationResult<Image>(true, string.Format("Collection Not Found [{0}]", id));
|
||||
}
|
||||
var image = new data.Image
|
||||
{
|
||||
Bytes = release.Thumbnail,
|
||||
CreatedDate = release.CreatedDate,
|
||||
LastUpdated = release.LastUpdated
|
||||
Bytes = collection.Thumbnail,
|
||||
CreatedDate = collection.CreatedDate,
|
||||
LastUpdated = collection.LastUpdated
|
||||
};
|
||||
if (release.Thumbnail == null || !release.Thumbnail.Any())
|
||||
if (collection.Thumbnail == null || !collection.Thumbnail.Any())
|
||||
{
|
||||
image = this.DefaultNotFoundImages.Release;
|
||||
image = this.DefaultNotFoundImages.Label;
|
||||
}
|
||||
return GenerateFileOperationResult(id, image, etag);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError($"Error fetching Release Thumbnail [{ id }]", ex);
|
||||
this.Logger.LogError($"Error fetching Collection Thumbnail [{ id }]", ex);
|
||||
}
|
||||
return new FileOperationResult<Image>(OperationMessages.ErrorOccured);
|
||||
}
|
||||
|
||||
|
||||
private FileOperationResult<Image> GenerateFileOperationResult(Guid id, data.Image image, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
var imageEtag = EtagHelper.GenerateETag(this.HttpEncoder, image.Bytes);
|
||||
|
@ -208,5 +278,145 @@ namespace Roadie.Api.Services
|
|||
}
|
||||
return new FileOperationResult<Image>(OperationMessages.ErrorOccured);
|
||||
}
|
||||
|
||||
private async Task<FileOperationResult<Image>> LabelThumbnailAction(Guid id, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var label = this.GetLabel(id);
|
||||
if (label == null)
|
||||
{
|
||||
return new FileOperationResult<Image>(true, string.Format("Label Not Found [{0}]", id));
|
||||
}
|
||||
var image = new data.Image
|
||||
{
|
||||
Bytes = label.Thumbnail,
|
||||
CreatedDate = label.CreatedDate,
|
||||
LastUpdated = label.LastUpdated
|
||||
};
|
||||
if (label.Thumbnail == null || !label.Thumbnail.Any())
|
||||
{
|
||||
image = this.DefaultNotFoundImages.Label;
|
||||
}
|
||||
return GenerateFileOperationResult(id, image, etag);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError($"Error fetching Label Thumbnail [{ id }]", ex);
|
||||
}
|
||||
return new FileOperationResult<Image>(OperationMessages.ErrorOccured);
|
||||
}
|
||||
|
||||
private async Task<FileOperationResult<Image>> PlaylistThumbnailAction(Guid id, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var playlist = this.GetPlaylist(id);
|
||||
if (playlist == null)
|
||||
{
|
||||
return new FileOperationResult<Image>(true, string.Format("Playlist Not Found [{0}]", id));
|
||||
}
|
||||
var image = new data.Image
|
||||
{
|
||||
Bytes = playlist.Thumbnail,
|
||||
CreatedDate = playlist.CreatedDate,
|
||||
LastUpdated = playlist.LastUpdated
|
||||
};
|
||||
if (playlist.Thumbnail == null || !playlist.Thumbnail.Any())
|
||||
{
|
||||
image = this.DefaultNotFoundImages.Playlist;
|
||||
}
|
||||
return GenerateFileOperationResult(id, image, etag);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError($"Error fetching Playlist Thumbnail [{ id }]", ex);
|
||||
}
|
||||
return new FileOperationResult<Image>(OperationMessages.ErrorOccured);
|
||||
}
|
||||
|
||||
private async Task<FileOperationResult<Image>> ReleaseThumbnailAction(Guid id, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var release = this.GetRelease(id);
|
||||
if (release == null)
|
||||
{
|
||||
return new FileOperationResult<Image>(true, string.Format("Release Not Found [{0}]", id));
|
||||
}
|
||||
var image = new data.Image
|
||||
{
|
||||
Bytes = release.Thumbnail,
|
||||
CreatedDate = release.CreatedDate,
|
||||
LastUpdated = release.LastUpdated
|
||||
};
|
||||
if (release.Thumbnail == null || !release.Thumbnail.Any())
|
||||
{
|
||||
image = this.DefaultNotFoundImages.Release;
|
||||
}
|
||||
return GenerateFileOperationResult(id, image, etag);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError($"Error fetching Release Thumbnail [{ id }]", ex);
|
||||
}
|
||||
return new FileOperationResult<Image>(OperationMessages.ErrorOccured);
|
||||
}
|
||||
|
||||
private async Task<FileOperationResult<Image>> TrackThumbnailAction(Guid id, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var track = this.GetTrack(id);
|
||||
if (track == null)
|
||||
{
|
||||
return new FileOperationResult<Image>(true, string.Format("Track Not Found [{0}]", id));
|
||||
}
|
||||
var image = new data.Image
|
||||
{
|
||||
Bytes = track.Thumbnail,
|
||||
CreatedDate = track.CreatedDate,
|
||||
LastUpdated = track.LastUpdated
|
||||
};
|
||||
if (track.Thumbnail == null || !track.Thumbnail.Any())
|
||||
{
|
||||
image = this.DefaultNotFoundImages.Track;
|
||||
}
|
||||
return GenerateFileOperationResult(id, image, etag);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError($"Error fetching Track Thumbnail [{ id }]", ex);
|
||||
}
|
||||
return new FileOperationResult<Image>(OperationMessages.ErrorOccured);
|
||||
}
|
||||
|
||||
private async Task<FileOperationResult<Image>> UserThumbnailAction(Guid id, EntityTagHeaderValue etag = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = this.GetUser(id);
|
||||
if (user == null)
|
||||
{
|
||||
return new FileOperationResult<Image>(true, string.Format("User Not Found [{0}]", id));
|
||||
}
|
||||
var image = new data.Image
|
||||
{
|
||||
Bytes = user.Avatar,
|
||||
CreatedDate = user.CreatedDate.Value,
|
||||
LastUpdated = user.LastUpdated
|
||||
};
|
||||
if (user.Avatar == null || !user.Avatar.Any())
|
||||
{
|
||||
image = this.DefaultNotFoundImages.User;
|
||||
}
|
||||
return GenerateFileOperationResult(id, image, etag);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError($"Error fetching User Thumbnail [{ id }]", ex);
|
||||
}
|
||||
return new FileOperationResult<Image>(OperationMessages.ErrorOccured);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +1,14 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Roadie.Library;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Roadie.Library.Caching;
|
||||
using Roadie.Library.Configuration;
|
||||
using data = Roadie.Library.Data;
|
||||
using Roadie.Library.Encoding;
|
||||
using Roadie.Library.Identity;
|
||||
using Roadie.Library.Models;
|
||||
using Roadie.Library.Models.Pagination;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Roadie.Library.Utility;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using data = Roadie.Library.Data;
|
||||
|
||||
namespace Roadie.Api.Services
|
||||
{
|
||||
|
@ -20,9 +17,9 @@ namespace Roadie.Api.Services
|
|||
protected readonly ICacheManager _cacheManager = null;
|
||||
protected readonly IRoadieSettings _configuration = null;
|
||||
protected readonly data.IRoadieDbContext _dbContext = null;
|
||||
protected readonly IHttpContext _httpContext = null;
|
||||
protected readonly IHttpEncoder _httpEncoder = null;
|
||||
protected readonly ILogger _logger = null;
|
||||
protected readonly IHttpContext _httpContext = null;
|
||||
|
||||
protected ICacheManager CacheManager
|
||||
{
|
||||
|
@ -48,6 +45,14 @@ namespace Roadie.Api.Services
|
|||
}
|
||||
}
|
||||
|
||||
protected IHttpContext HttpContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._httpContext;
|
||||
}
|
||||
}
|
||||
|
||||
protected IHttpEncoder HttpEncoder
|
||||
{
|
||||
get
|
||||
|
@ -64,14 +69,6 @@ namespace Roadie.Api.Services
|
|||
}
|
||||
}
|
||||
|
||||
protected IHttpContext HttpContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._httpContext;
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceBase(IRoadieSettings configuration, IHttpEncoder httpEncoder, data.IRoadieDbContext context,
|
||||
ICacheManager cacheManager, ILogger logger, IHttpContext httpContext)
|
||||
{
|
||||
|
@ -83,46 +80,6 @@ namespace Roadie.Api.Services
|
|||
this._httpContext = httpContext;
|
||||
}
|
||||
|
||||
protected Image MakeArtistThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "artist");
|
||||
}
|
||||
|
||||
protected Image MakeCollectionThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "collection");
|
||||
}
|
||||
|
||||
protected Image MakePlaylistThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "playlist");
|
||||
}
|
||||
|
||||
protected Image MakeImage(Guid id, int width = 200, int height = 200)
|
||||
{
|
||||
return new Image($"{this.HttpContext.ImageBaseUrl }/{id}/{ width }/{ height }");
|
||||
}
|
||||
|
||||
protected Image MakeReleaseThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "release");
|
||||
}
|
||||
|
||||
protected Image MakeLabelThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "label");
|
||||
}
|
||||
|
||||
protected Image MakeUserThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "user");
|
||||
}
|
||||
|
||||
private Image MakeThumbnailImage(Guid id, string type)
|
||||
{
|
||||
return new Image($"{this.HttpContext.ImageBaseUrl }/{ type }/thumbnail/{id}");
|
||||
}
|
||||
|
||||
protected data.Artist GetArtist(Guid id)
|
||||
{
|
||||
return this.CacheManager.Get(data.Artist.CacheUrn(id), () =>
|
||||
|
@ -134,6 +91,33 @@ namespace Roadie.Api.Services
|
|||
}, data.Artist.CacheRegionUrn(id));
|
||||
}
|
||||
|
||||
protected data.Collection GetCollection(Guid id)
|
||||
{
|
||||
return this.CacheManager.Get(data.Collection.CacheUrn(id), () =>
|
||||
{
|
||||
return this.DbContext.Collections
|
||||
.FirstOrDefault(x => x.RoadieId == id);
|
||||
}, data.Collection.CacheRegionUrn(id));
|
||||
}
|
||||
|
||||
protected data.Label GetLabel(Guid id)
|
||||
{
|
||||
return this.CacheManager.Get(data.Label.CacheUrn(id), () =>
|
||||
{
|
||||
return this.DbContext.Labels
|
||||
.FirstOrDefault(x => x.RoadieId == id);
|
||||
}, data.Label.CacheRegionUrn(id));
|
||||
}
|
||||
|
||||
protected data.Playlist GetPlaylist(Guid id)
|
||||
{
|
||||
return this.CacheManager.Get(data.Playlist.CacheUrn(id), () =>
|
||||
{
|
||||
return this.DbContext.Playlists
|
||||
.FirstOrDefault(x => x.RoadieId == id);
|
||||
}, data.Playlist.CacheRegionUrn(id));
|
||||
}
|
||||
|
||||
protected data.Release GetRelease(Guid id)
|
||||
{
|
||||
return this.CacheManager.Get(data.Release.CacheUrn(id), () =>
|
||||
|
@ -142,5 +126,63 @@ namespace Roadie.Api.Services
|
|||
.FirstOrDefault(x => x.RoadieId == id);
|
||||
}, data.Release.CacheRegionUrn(id));
|
||||
}
|
||||
|
||||
protected ApplicationUser GetUser(Guid id)
|
||||
{
|
||||
return this.CacheManager.Get(ApplicationUser.CacheUrn(id), () =>
|
||||
{
|
||||
return this.DbContext.Users
|
||||
.FirstOrDefault(x => x.RoadieId == id);
|
||||
}, ApplicationUser.CacheRegionUrn(id));
|
||||
}
|
||||
|
||||
protected data.Track GetTrack(Guid id)
|
||||
{
|
||||
return this.CacheManager.Get(data.Track.CacheUrn(id), () =>
|
||||
{
|
||||
return this.DbContext.Tracks
|
||||
.FirstOrDefault(x => x.RoadieId == id);
|
||||
}, data.Track.CacheRegionUrn(id));
|
||||
}
|
||||
|
||||
protected Image MakeArtistThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "artist");
|
||||
}
|
||||
|
||||
protected Image MakeCollectionThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "collection");
|
||||
}
|
||||
|
||||
protected Image MakeImage(Guid id, int width = 200, int height = 200)
|
||||
{
|
||||
return new Image($"{this.HttpContext.ImageBaseUrl }/{id}/{ width }/{ height }");
|
||||
}
|
||||
|
||||
protected Image MakeLabelThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "label");
|
||||
}
|
||||
|
||||
protected Image MakePlaylistThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "playlist");
|
||||
}
|
||||
|
||||
protected Image MakeReleaseThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "release");
|
||||
}
|
||||
|
||||
protected Image MakeUserThumbnailImage(Guid id)
|
||||
{
|
||||
return MakeThumbnailImage(id, "user");
|
||||
}
|
||||
|
||||
private Image MakeThumbnailImage(Guid id, string type)
|
||||
{
|
||||
return new Image($"{this.HttpContext.ImageBaseUrl }/{ type }/thumbnail/{id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
RoadieLibrary/Data/CollectionPartial.cs
Normal file
27
RoadieLibrary/Data/CollectionPartial.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Roadie.Library.Data
|
||||
{
|
||||
public partial class Collection
|
||||
{
|
||||
public static string CacheRegionUrn(Guid Id)
|
||||
{
|
||||
return string.Format("urn:collection:{0}", Id);
|
||||
}
|
||||
|
||||
public static string CacheUrn(Guid Id)
|
||||
{
|
||||
return $"urn:collection_by_id:{ Id }";
|
||||
}
|
||||
|
||||
public string CacheKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return Collection.CacheUrn(this.RoadieId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,16 +5,29 @@ namespace Roadie.Library.Data
|
|||
{
|
||||
public partial class Label
|
||||
{
|
||||
public static string CacheRegionKey(Guid Id)
|
||||
public static string CacheRegionUrn(Guid Id)
|
||||
{
|
||||
return string.Format("urn:label:{0}", Id);
|
||||
}
|
||||
|
||||
public static string CacheUrn(Guid Id)
|
||||
{
|
||||
return $"urn:label_by_id:{ Id }";
|
||||
}
|
||||
|
||||
public string CacheKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return Label.CacheUrn(this.RoadieId);
|
||||
}
|
||||
}
|
||||
|
||||
public string CacheRegion
|
||||
{
|
||||
get
|
||||
{
|
||||
return Label.CacheRegionKey(this.RoadieId);
|
||||
return Label.CacheRegionUrn(this.RoadieId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
27
RoadieLibrary/Data/PlaylistPartial.cs
Normal file
27
RoadieLibrary/Data/PlaylistPartial.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Roadie.Library.Data
|
||||
{
|
||||
public partial class Playlist
|
||||
{
|
||||
public static string CacheRegionUrn(Guid Id)
|
||||
{
|
||||
return string.Format("urn:playlist:{0}", Id);
|
||||
}
|
||||
|
||||
public static string CacheUrn(Guid Id)
|
||||
{
|
||||
return $"urn:playlist_by_id:{ Id }";
|
||||
}
|
||||
|
||||
public string CacheKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return Playlist.CacheUrn(this.RoadieId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,16 +10,29 @@ namespace Roadie.Library.Data
|
|||
{
|
||||
public partial class Track
|
||||
{
|
||||
public static string CacheRegionKey(Guid Id)
|
||||
public static string CacheRegionUrn(Guid Id)
|
||||
{
|
||||
return string.Format("urn:track:{0}", Id);
|
||||
}
|
||||
|
||||
public static string CacheUrn(Guid Id)
|
||||
{
|
||||
return $"urn:track_by_id:{ Id }";
|
||||
}
|
||||
|
||||
public string CacheKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return Track.CacheUrn(this.RoadieId);
|
||||
}
|
||||
}
|
||||
|
||||
public string CacheRegion
|
||||
{
|
||||
get
|
||||
{
|
||||
return Track.CacheRegionKey(this.RoadieId);
|
||||
return Track.CacheRegionUrn(this.RoadieId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,5 +126,7 @@ namespace Roadie.Library.Identity
|
|||
public string Username { get; set; }
|
||||
|
||||
public virtual ICollection<ApplicationUserRole> UserRoles { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
27
RoadieLibrary/Identity/ApplicationUserPartial.cs
Normal file
27
RoadieLibrary/Identity/ApplicationUserPartial.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Roadie.Library.Identity
|
||||
{
|
||||
public partial class ApplicationUser
|
||||
{
|
||||
public static string CacheRegionUrn(Guid Id)
|
||||
{
|
||||
return string.Format("urn:user:{0}", Id);
|
||||
}
|
||||
|
||||
public static string CacheUrn(Guid Id)
|
||||
{
|
||||
return $"urn:user_by_id:{ Id }";
|
||||
}
|
||||
|
||||
public string CacheKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return ApplicationUser.CacheUrn(this.RoadieId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue