From f5e57d083dfc113b83e3a886558bfe961a082261 Mon Sep 17 00:00:00 2001 From: Steven Hildreth Date: Thu, 27 Dec 2018 15:56:40 -0600 Subject: [PATCH] Artist edit work --- Roadie.Api.Library/Data/Artist.cs | 2 +- .../Engines/ArtistLookupEngine.cs | 6 +++--- Roadie.Api.Library/Factories/ArtistFactory.cs | 2 +- Roadie.Api.Library/Models/Artist.cs | 20 ++++++++++++++----- Roadie.Api.Services/ArtistService.cs | 14 ++++++++++--- Roadie.Api.Services/ReleaseService.cs | 2 +- Roadie.Api.Services/ServiceBase.cs | 12 +++++------ Roadie.Api/Controllers/ImageController.cs | 16 +++++++-------- 8 files changed, 46 insertions(+), 28 deletions(-) diff --git a/Roadie.Api.Library/Data/Artist.cs b/Roadie.Api.Library/Data/Artist.cs index b96df1a..b03b6c7 100644 --- a/Roadie.Api.Library/Data/Artist.cs +++ b/Roadie.Api.Library/Data/Artist.cs @@ -39,7 +39,7 @@ namespace Roadie.Library.Data [Column("isniList", TypeName = "text")] [MaxLength(65535)] - public string ISNIList { get; set; } + public string ISNI { get; set; } [Column("iTunesId")] [MaxLength(100)] diff --git a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs index e9a29bf..d552fac 100644 --- a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs +++ b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs @@ -274,7 +274,7 @@ namespace Roadie.Library.Engines } if (i.ISNIs != null) { - result.ISNIList = result.ISNIList.AddToDelimitedList(i.ISNIs); + result.ISNI = result.ISNI.AddToDelimitedList(i.ISNIs); } if (i.ImageUrls != null) { @@ -329,7 +329,7 @@ namespace Roadie.Library.Engines } if (mb.ISNIs != null) { - result.ISNIList = result.ISNIList.AddToDelimitedList(mb.ISNIs); + result.ISNI = result.ISNI.AddToDelimitedList(mb.ISNIs); } if (mb.ImageUrls != null) { @@ -388,7 +388,7 @@ namespace Roadie.Library.Engines } if (l.ISNIs != null) { - result.ISNIList = result.ISNIList.AddToDelimitedList(l.ISNIs); + result.ISNI = result.ISNI.AddToDelimitedList(l.ISNIs); } if (l.ImageUrls != null) { diff --git a/Roadie.Api.Library/Factories/ArtistFactory.cs b/Roadie.Api.Library/Factories/ArtistFactory.cs index b378e1e..a5b6362 100644 --- a/Roadie.Api.Library/Factories/ArtistFactory.cs +++ b/Roadie.Api.Library/Factories/ArtistFactory.cs @@ -154,7 +154,7 @@ namespace Roadie.Library.Factories altNames.Add(ArtistToMerge.SortName); artistToMergeInto.AlternateNames = artistToMergeInto.AlternateNames.AddToDelimitedList(altNames); artistToMergeInto.URLs = artistToMergeInto.URLs.AddToDelimitedList(ArtistToMerge.URLs.ToListFromDelimited()); - artistToMergeInto.ISNIList = artistToMergeInto.ISNIList.AddToDelimitedList(ArtistToMerge.ISNIList.ToListFromDelimited()); + artistToMergeInto.ISNI = artistToMergeInto.ISNI.AddToDelimitedList(ArtistToMerge.ISNI.ToListFromDelimited()); artistToMergeInto.LastUpdated = now; if (doDbUpdates) diff --git a/Roadie.Api.Library/Models/Artist.cs b/Roadie.Api.Library/Models/Artist.cs index 04e1915..848f255 100644 --- a/Roadie.Api.Library/Models/Artist.cs +++ b/Roadie.Api.Library/Models/Artist.cs @@ -45,18 +45,28 @@ namespace Roadie.Library.Models [MaxLength(65535)] [JsonIgnore] [IgnoreDataMember] - public string ISNIList { get; set; } + public string ISNI { get; set; } + + private IEnumerable _isniList = null; [JsonProperty("isniList")] - public IEnumerable ISNIListList + public IEnumerable ISNIList { get { - if (string.IsNullOrEmpty(this.ISNIList)) + if (this._isniList == null) { - return null; + if (string.IsNullOrEmpty(this.ISNI)) + { + return null; + } + return this.ISNI.Split('|'); } - return this.ISNIList.Split('|'); + return this._isniList; + } + set + { + this._isniList = value; } } diff --git a/Roadie.Api.Services/ArtistService.cs b/Roadie.Api.Services/ArtistService.cs index fe78687..3d284d7 100644 --- a/Roadie.Api.Services/ArtistService.cs +++ b/Roadie.Api.Services/ArtistService.cs @@ -542,7 +542,7 @@ namespace Roadie.Api.Services artist.DiscogsId = model.DiscogsId; artist.EndDate = model.EndDate; artist.IsLocked = model.IsLocked; - artist.ISNIList = model.ISNIList.ToDelimitedList(); + artist.ISNI = model.ISNIList.ToDelimitedList(); artist.ITunesId = model.ITunesId; artist.MusicBrainzId = model.MusicBrainzId; artist.Name = model.Name; @@ -808,8 +808,16 @@ namespace Roadie.Api.Services // Ensure is jpeg first artist.Thumbnail = ImageHelper.ConvertToJpegFormat(artist.Thumbnail); + // Ensure artist folder exists + var artistFolder = artist.ArtistFileFolder(this.Configuration, this.Configuration.LibraryFolder); + if(!Directory.Exists(artistFolder)) + { + Directory.CreateDirectory(artistFolder); + this.Logger.LogInformation("Created Artist Folder [0] for `artist`", artistFolder, artist); + } + // Save unaltered image to artist file - var coverFileName = Path.Combine(artist.ArtistFileFolder(this.Configuration, this.Configuration.LibraryFolder), "artist.jpg"); + var coverFileName = Path.Combine(artistFolder, "artist.jpg"); File.WriteAllBytes(coverFileName, artist.Thumbnail); // Resize to store in database as thumbnail @@ -830,7 +838,7 @@ namespace Roadie.Api.Services return new OperationResult { IsSuccess = !errors.Any(), - Data = this.MakeArtistThumbnailImage(id), + Data = base.MakeThumbnailImage(id, "artist", this.Configuration.MediumImageSize.Width, this.Configuration.MediumImageSize.Height, true), OperationTime = sw.ElapsedMilliseconds, Errors = errors }; diff --git a/Roadie.Api.Services/ReleaseService.cs b/Roadie.Api.Services/ReleaseService.cs index 95efd7d..9cb3afd 100644 --- a/Roadie.Api.Services/ReleaseService.cs +++ b/Roadie.Api.Services/ReleaseService.cs @@ -941,7 +941,7 @@ namespace Roadie.Api.Services return new OperationResult { IsSuccess = !errors.Any(), - Data = this.MakeReleaseThumbnailImage(id), + Data = base.MakeThumbnailImage(id, "release", this.Configuration.MediumImageSize.Width, this.Configuration.MediumImageSize.Height, true), OperationTime = sw.ElapsedMilliseconds, Errors = errors }; diff --git a/Roadie.Api.Services/ServiceBase.cs b/Roadie.Api.Services/ServiceBase.cs index 73560df..3d83a5a 100644 --- a/Roadie.Api.Services/ServiceBase.cs +++ b/Roadie.Api.Services/ServiceBase.cs @@ -82,9 +82,9 @@ namespace Roadie.Api.Services this._httpContext = httpContext; } - public Image MakeThumbnailImage(Guid id, string type, int? width = null, int? height = null) + public Image MakeThumbnailImage(Guid id, string type, int? width = null, int? height = null, bool includeCachebuster = false) { - return this.MakeImage(id, type, width ?? this.Configuration.ThumbnailImageSize.Width, height ?? this.Configuration.ThumbnailImageSize.Height); + return this.MakeImage(id, type, width ?? this.Configuration.ThumbnailImageSize.Width, height ?? this.Configuration.ThumbnailImageSize.Height, null, includeCachebuster); } protected data.Artist GetArtist(string artistName) @@ -236,9 +236,9 @@ namespace Roadie.Api.Services return MakeThumbnailImage(id, "collection"); } - protected Image MakeImage(Guid id, int width = 200, int height = 200, string caption = null) + protected Image MakeImage(Guid id, int width = 200, int height = 200, string caption = null, bool includeCachebuster = false) { - return new Image($"{this.HttpContext.ImageBaseUrl }/{id}/{ width }/{ height }", caption, $"{this.HttpContext.ImageBaseUrl }/{id}/{ this.Configuration.SmallImageSize.Width }/{ this.Configuration.SmallImageSize.Height }"); + return new Image($"{this.HttpContext.ImageBaseUrl }/{id}/{ width }/{ height }/{ (includeCachebuster ? DateTime.UtcNow.Ticks.ToString() : string.Empty) }", caption, $"{this.HttpContext.ImageBaseUrl }/{id}/{ this.Configuration.SmallImageSize.Width }/{ this.Configuration.SmallImageSize.Height }"); } protected Image MakeFullsizeImage(Guid id, string caption = null) @@ -594,11 +594,11 @@ namespace Roadie.Api.Services } - private Image MakeImage(Guid id, string type, int? width, int? height, string caption = null) + private Image MakeImage(Guid id, string type, int? width, int? height, string caption = null, bool includeCachebuster = false) { if (width.HasValue && height.HasValue && (width.Value != this.Configuration.ThumbnailImageSize.Width || height.Value != this.Configuration.ThumbnailImageSize.Height)) { - return new Image($"{this.HttpContext.ImageBaseUrl }/{type}/{id}/{width}/{height}", caption, $"{this.HttpContext.ImageBaseUrl }/{type}/{id}/{ this.Configuration.ThumbnailImageSize.Width }/{ this.Configuration.ThumbnailImageSize.Height }"); + return new Image($"{this.HttpContext.ImageBaseUrl }/{type}/{id}/{width}/{height}/{ (includeCachebuster ? DateTime.UtcNow.Ticks.ToString() : string.Empty) }", caption, $"{this.HttpContext.ImageBaseUrl }/{type}/{id}/{ this.Configuration.ThumbnailImageSize.Width }/{ this.Configuration.ThumbnailImageSize.Height }"); } return new Image($"{this.HttpContext.ImageBaseUrl }/{type}/{id}", caption, null); } diff --git a/Roadie.Api/Controllers/ImageController.cs b/Roadie.Api/Controllers/ImageController.cs index 94b69ab..4b374a4 100644 --- a/Roadie.Api/Controllers/ImageController.cs +++ b/Roadie.Api/Controllers/ImageController.cs @@ -33,7 +33,7 @@ namespace Roadie.Api.Controllers // return Ok(this._RoadieDbContext.Tracks.ProjectToType()); //} - [HttpGet("artist/{id}/{width:int?}/{height:int?}")] + [HttpGet("artist/{id}/{width:int?}/{height:int?}/{cacheBuster?}")] [ProducesResponseType(200)] [ProducesResponseType(404)] public async Task ArtistImage(Guid id, int? width, int? height) @@ -55,7 +55,7 @@ namespace Roadie.Api.Controllers } - [HttpGet("collection/{id}/{width:int?}/{height:int?}")] + [HttpGet("collection/{id}/{width:int?}/{height:int?}/{cacheBuster?}")] [ProducesResponseType(200)] [ProducesResponseType(404)] public async Task CollectionImage(Guid id, int? width, int? height) @@ -93,7 +93,7 @@ namespace Roadie.Api.Controllers return Ok(result); } - [HttpGet("{id}/{width:int?}/{height:int?}")] + [HttpGet("{id}/{width:int?}/{height:int?}/{cacheBuster?}")] [ProducesResponseType(200)] [ProducesResponseType(404)] public async Task Get(Guid id, int? width, int? height) @@ -114,7 +114,7 @@ namespace Roadie.Api.Controllers entityTag: result.ETag); } - [HttpGet("label/{id}/{width:int?}/{height:int?}")] + [HttpGet("label/{id}/{width:int?}/{height:int?}/{cacheBuster?}")] [ProducesResponseType(200)] [ProducesResponseType(404)] public async Task LabelImage(Guid id, int? width, int? height) @@ -135,7 +135,7 @@ namespace Roadie.Api.Controllers entityTag: result.ETag); } - [HttpGet("playlist/{id}/{width:int?}/{height:int?}")] + [HttpGet("playlist/{id}/{width:int?}/{height:int?}/{cacheBuster?}")] [ProducesResponseType(200)] [ProducesResponseType(404)] public async Task PlaylistImage(Guid id, int? width, int? height) @@ -156,7 +156,7 @@ namespace Roadie.Api.Controllers entityTag: result.ETag); } - [HttpGet("release/{id}/{width:int?}/{height:int?}")] + [HttpGet("release/{id}/{width:int?}/{height:int?}/{cacheBuster?}")] [ProducesResponseType(200)] [ProducesResponseType(404)] public async Task ReleaseImage(Guid id, int? width, int? height) @@ -177,7 +177,7 @@ namespace Roadie.Api.Controllers entityTag: result.ETag); } - [HttpGet("track/{id}/{width:int?}/{height:int?}")] + [HttpGet("track/{id}/{width:int?}/{height:int?}/{cacheBuster?}")] [ProducesResponseType(200)] [ProducesResponseType(404)] public async Task TrackImage(Guid id, int? width, int? height) @@ -201,7 +201,7 @@ namespace Roadie.Api.Controllers /// /// NOTE that user images/avatars are PNG not JPG this is so it looks better in the menus/applications /// - [HttpGet("user/{id}/{width:int?}/{height:int?}")] + [HttpGet("user/{id}/{width:int?}/{height:int?}/{cacheBuster?}")] [ProducesResponseType(200)] [ProducesResponseType(404)] public async Task UserImage(Guid id, int? width, int? height)