Files
icarus/Models/CoverArt.cs
T
Kun Deng 71656aa940 #94: Saving the file type of cover art, but there is still some work to do (#100)
* #94: Saving the file type of cover art, but there is still some work to do

The filename of cover art is hard coded to have the png extension. Need to correct this

* #94: Added a TODO

* #94: Corrected file extension being saved in the db

* Cleanup

* Saving databasescripts
2024-06-21 20:26:44 -04:00

51 lines
1.3 KiB
C#

using Newtonsoft.Json;
namespace Icarus.Models;
public class CoverArt
{
#region Properties
[JsonProperty("cover_art_id")]
public int CoverArtID { get; set; }
[JsonProperty("title")]
public string SongTitle { get; set; }
[JsonIgnore]
public string Directory { get; set; }
[JsonProperty("filename")]
public string Filename { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
#endregion
#region Methods
public string ImagePath()
{
var fullPath = this.Directory;
if (fullPath[fullPath.Length -1] != '/')
{
fullPath += "/";
}
fullPath += Filename;
return fullPath;
}
public string GenerateFilename(int flag)
{
int length = Constants.DirectoryPaths.FILENAME_LENGTH;
string chars = Constants.DirectoryPaths.FILENAME_CHARACTERS;
var random = new Random();
var filename = new string(Enumerable.Repeat(chars, length).Select(s =>
s[random.Next(s.Length)]).ToArray());
var extension = Constants.FileExtensions.JPG_EXTENSION;
return (flag == 0) ? filename : $"{filename}{extension}";
}
public async Task<byte[]> GetData() => await File.ReadAllBytesAsync(this.ImagePath());
#endregion
}