Files
icarus/Models/CoverArt.cs
T
KD fd3ce9f96a #103: Remove WAV support (#105)
* #103: Adding checks to prevent .wav files from being uploaded:

* #103: Added method to create song and moving some code around

* #103: Fixed build issue

* tsk-103: Cleanup of temporary files

* tsk-103: Formatting changes

* tsk-103: Minor changes

* tsk-103: Fixing build issue

* tsk-103: Refactored enum

* CORE-23734: Refactoring

* tsk-103: Confirmed functionality is working

* Removed commented code

* Removed commented code
2025-02-16 17:24:50 -05:00

51 lines
1.3 KiB
C#

using Newtonsoft.Json;
namespace Icarus.Models;
public class CoverArt
{
#region Properties
[JsonProperty("id")]
public int Id { 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
}