mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
artist work
This commit is contained in:
parent
b08c53de54
commit
66badbd0a2
10 changed files with 159 additions and 23 deletions
|
@ -12,7 +12,7 @@ namespace Roadie.Library.Factories
|
|||
|
||||
Task<OperationResult<bool>> CheckAndChangeReleaseTitle(Release release, string oldReleaseFolder, string destinationFolder = null);
|
||||
|
||||
Task<OperationResult<bool>> Delete(Release release, bool doDeleteFiles = false);
|
||||
Task<OperationResult<bool>> Delete(Release release, bool doDeleteFiles = false, bool doUpdateArtistCounts = true);
|
||||
|
||||
Task<OperationResult<bool>> DeleteReleases(IEnumerable<Guid> releaseIds, bool doDeleteFiles = false);
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ namespace Roadie.Library.Factories
|
|||
};
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> Delete(Data.Release release, bool doDeleteFiles = false)
|
||||
public async Task<OperationResult<bool>> Delete(Data.Release release, bool doDeleteFiles = false, bool doUpdateArtistCounts = true)
|
||||
{
|
||||
SimpleContract.Requires<ArgumentNullException>(release != null, "Invalid Release");
|
||||
SimpleContract.Requires<ArgumentNullException>(release.Artist != null, "Invalid Artist");
|
||||
|
@ -177,6 +177,7 @@ namespace Roadie.Library.Factories
|
|||
this.Logger.LogError(ex);
|
||||
}
|
||||
}
|
||||
var releaseLabelIds = this.DbContext.ReleaseLabels.Where(x => x.ReleaseId == release.Id).Select(x => x.LabelId).ToArray();
|
||||
this.DbContext.Releases.Remove(release);
|
||||
var i = await this.DbContext.SaveChangesAsync();
|
||||
result = true;
|
||||
|
@ -189,6 +190,18 @@ namespace Roadie.Library.Factories
|
|||
{
|
||||
this.Logger.LogError(ex, string.Format("Error Clearing Cache For Release [{0}] Exception [{1}]", release.Id, ex.Serialize()));
|
||||
}
|
||||
var now = DateTime.UtcNow;
|
||||
if (doUpdateArtistCounts)
|
||||
{
|
||||
await base.UpdateArtistCounts(release.Artist.Id, now);
|
||||
}
|
||||
if (releaseLabelIds != null && releaseLabelIds.Any())
|
||||
{
|
||||
foreach(var releaseLabelId in releaseLabelIds)
|
||||
{
|
||||
await base.UpdateLabelCounts(releaseLabelId, now);
|
||||
}
|
||||
}
|
||||
sw.Stop();
|
||||
return new OperationResult<bool>
|
||||
{
|
||||
|
@ -205,17 +218,23 @@ namespace Roadie.Library.Factories
|
|||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var releases = (from r in this.DbContext.Releases.Include(r => r.Artist)
|
||||
where releaseIds.Contains(r.RoadieId)
|
||||
select r
|
||||
).ToArray();
|
||||
|
||||
var artistIds = releases.Select(x => x.ArtistId).Distinct().ToArray();
|
||||
|
||||
foreach (var release in releases)
|
||||
{
|
||||
var defaultResult = await this.Delete(release, doDeleteFiles);
|
||||
var defaultResult = await this.Delete(release, doDeleteFiles, false);
|
||||
result = result & defaultResult.IsSuccess;
|
||||
}
|
||||
|
||||
foreach(var artistId in artistIds)
|
||||
{
|
||||
await base.UpdateArtistCounts(artistId, now);
|
||||
}
|
||||
sw.Stop();
|
||||
|
||||
return new OperationResult<bool>
|
||||
|
|
|
@ -329,7 +329,7 @@ namespace Roadie.Api.Services
|
|||
|
||||
}
|
||||
|
||||
public async Task<OperationResult<bool>> DeleteArtistReleases(ApplicationUser user, Guid artistId)
|
||||
public async Task<OperationResult<bool>> DeleteArtistReleases(ApplicationUser user, Guid artistId, bool doDeleteFiles = false)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
@ -342,7 +342,7 @@ namespace Roadie.Api.Services
|
|||
}
|
||||
try
|
||||
{
|
||||
this.DbContext.Releases.RemoveRange(this.DbContext.Releases.Where(x => x.ArtistId == artist.Id));
|
||||
await this.ReleaseFactory.DeleteReleases(this.DbContext.Releases.Where(x => x.ArtistId == artist.Id).Select(x => x.RoadieId).ToArray(), doDeleteFiles);
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Mapster;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
|
@ -8,6 +9,7 @@ using Roadie.Library.Configuration;
|
|||
using Roadie.Library.Encoding;
|
||||
using Roadie.Library.Enums;
|
||||
using Roadie.Library.Extensions;
|
||||
using Roadie.Library.Imaging;
|
||||
using Roadie.Library.Models;
|
||||
using Roadie.Library.Models.Pagination;
|
||||
using Roadie.Library.Models.Releases;
|
||||
|
@ -17,6 +19,7 @@ using Roadie.Library.Utility;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Dynamic.Core;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -458,5 +461,68 @@ namespace Roadie.Api.Services
|
|||
Rows = rows
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<OperationResult<Library.Models.Image>> SetReleaseImageByUrl(User user, Guid id, string imageUrl)
|
||||
{
|
||||
return await this.SaveImageBytes(user, id, WebHelper.BytesForImageUrl(imageUrl));
|
||||
}
|
||||
|
||||
public async Task<OperationResult<Library.Models.Image>> UploadArtistImage(User user, Guid id, IFormFile file)
|
||||
{
|
||||
var bytes = new byte[0];
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
file.CopyTo(ms);
|
||||
bytes = ms.ToArray();
|
||||
}
|
||||
return await this.SaveImageBytes(user, id, bytes);
|
||||
}
|
||||
|
||||
private async Task<OperationResult<Library.Models.Image>> SaveImageBytes(User user, Guid id, byte[] imageBytes)
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var errors = new List<Exception>();
|
||||
var artist = this.DbContext.Artists.FirstOrDefault(x => x.RoadieId == id);
|
||||
if (artist == null)
|
||||
{
|
||||
return new OperationResult<Library.Models.Image>(true, string.Format("Artist Not Found [{0}]", id));
|
||||
}
|
||||
try
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
artist.Thumbnail = imageBytes;
|
||||
if (artist.Thumbnail != null)
|
||||
{
|
||||
// Ensure is jpeg first
|
||||
artist.Thumbnail = ImageHelper.ConvertToJpegFormat(artist.Thumbnail);
|
||||
|
||||
// Save unaltered image to artist file
|
||||
var coverFileName = Path.Combine(artist.ArtistFileFolder(this.Configuration, this.Configuration.LibraryFolder), "artist.jpg");
|
||||
File.WriteAllBytes(coverFileName, artist.Thumbnail);
|
||||
|
||||
// Resize to store in database as thumbnail
|
||||
artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail, this.Configuration.MediumImageSize.Width, this.Configuration.MediumImageSize.Height);
|
||||
}
|
||||
artist.LastUpdated = now;
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
this.CacheManager.ClearRegion(artist.CacheRegion);
|
||||
this.Logger.LogInformation($"SaveImageBytes `{ artist }` By User `{ user }`");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
errors.Add(ex);
|
||||
}
|
||||
sw.Stop();
|
||||
|
||||
return new OperationResult<Library.Models.Image>
|
||||
{
|
||||
IsSuccess = !errors.Any(),
|
||||
Data = this.MakeArtistThumbnailImage(id),
|
||||
OperationTime = sw.ElapsedMilliseconds,
|
||||
Errors = errors
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@ namespace Roadie.Api.Services
|
|||
Task<OperationResult<bool>> ScanRelease(ApplicationUser user, Guid releaseId, bool isReadOnly = false);
|
||||
Task<OperationResult<bool>> DeleteRelease(ApplicationUser user, Guid releaseId, bool? doDeleteFiles);
|
||||
Task<OperationResult<bool>> DeleteArtist(ApplicationUser user, Guid artistId);
|
||||
Task<OperationResult<bool>> DeleteArtistReleases(ApplicationUser user, Guid artistId);
|
||||
Task<OperationResult<bool>> DeleteArtistReleases(ApplicationUser user, Guid artistId, bool doDeleteFiles = false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Roadie.Library;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Roadie.Library;
|
||||
using Roadie.Library.Models;
|
||||
using Roadie.Library.Models.Pagination;
|
||||
using Roadie.Library.Models.Users;
|
||||
|
@ -13,5 +14,7 @@ namespace Roadie.Api.Services
|
|||
Task<OperationResult<Artist>> ById(User roadieUser, Guid id, IEnumerable<string> includes);
|
||||
|
||||
Task<PagedResult<ArtistList>> List(User roadieUser, PagedRequest request, bool? doRandomize = false, bool? onlyIncludeWithReleases = true);
|
||||
Task<OperationResult<Library.Models.Image>> SetReleaseImageByUrl(User user, Guid id, string imageUrl);
|
||||
Task<OperationResult<Library.Models.Image>> UploadArtistImage(User user, Guid id, IFormFile file);
|
||||
}
|
||||
}
|
|
@ -263,22 +263,18 @@ namespace Roadie.Api.Services
|
|||
string artistFolder = null;
|
||||
try
|
||||
{
|
||||
// Artist thumbnail is updated on artist rescan.
|
||||
if (artist.Thumbnail == null)
|
||||
// See if artist images exists in artist folder
|
||||
artistFolder = artist.ArtistFileFolder(this.Configuration, this.Configuration.LibraryFolder);
|
||||
if (!Directory.Exists(artistFolder))
|
||||
{
|
||||
// See if artist images exists in artist folder
|
||||
artistFolder = artist.ArtistFileFolder(this.Configuration, this.Configuration.LibraryFolder);
|
||||
if (!Directory.Exists(artistFolder))
|
||||
this.Logger.LogWarning($"Artist Folder [{ artistFolder }], Not Found For Artist `{ artist.ToString() }`");
|
||||
}
|
||||
else
|
||||
{
|
||||
var artistImages = Directory.GetFiles(artistFolder, "artist*.*");
|
||||
if (artistImages.Any())
|
||||
{
|
||||
this.Logger.LogWarning($"Artist Folder [{ artistFolder }], Not Found For Artist `{ artist.ToString() }`");
|
||||
}
|
||||
else
|
||||
{
|
||||
var artistImages = Directory.GetFiles(artistFolder, "artist*.*");
|
||||
if (artistImages.Any())
|
||||
{
|
||||
imageBytes = File.ReadAllBytes(artistImages.First());
|
||||
}
|
||||
imageBytes = File.ReadAllBytes(artistImages.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -929,7 +929,7 @@ namespace Roadie.Api.Services
|
|||
release.LastUpdated = now;
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
this.CacheManager.ClearRegion(release.CacheRegion);
|
||||
this.Logger.LogInformation($"UploadReleaseImage `{ release }` By User `{ user }`");
|
||||
this.Logger.LogInformation($"SaveImageBytes `{ release }` By User `{ user }`");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
@ -10,6 +11,7 @@ using Roadie.Library.Models.Pagination;
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using models = Roadie.Library.Models;
|
||||
|
||||
namespace Roadie.Api.Controllers
|
||||
|
@ -65,5 +67,39 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("setImageByUrl/{id}/{imageUrl}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> SetArtistImageByUrl(Guid id, string imageUrl)
|
||||
{
|
||||
var result = await this.ArtistService.SetReleaseImageByUrl(await this.CurrentUserModel(), id, HttpUtility.UrlDecode(imageUrl));
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("uploadImage/{id}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> UploadImage(Guid id, IFormFile file)
|
||||
{
|
||||
var result = await this.ArtistService.UploadArtistImage(await this.CurrentUserModel(), id, file);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -239,6 +239,22 @@ namespace Roadie.Api.Controllers
|
|||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost("search/artist/{query}/{resultsCount:int?}")]
|
||||
[ProducesResponseType(200)]
|
||||
[ProducesResponseType(404)]
|
||||
public async Task<IActionResult> SearchForArtistImage(string query, int? resultsCount)
|
||||
{
|
||||
var result = await this.ImageService.Search(query, resultsCount ?? 10);
|
||||
if (result == null || result.IsNotFoundResult)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue