136 lines
2.7 KiB
C#
136 lines
2.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.FileProviders;
|
|
using Shadow.Data;
|
|
using Shadow.DTOs;
|
|
using Shadow.Entities;
|
|
using Shadow.Mapping;
|
|
using Shadow.Tools;
|
|
|
|
namespace Shadow.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("rest")]
|
|
[Produces("application/json")]
|
|
public class AlbumController : ControllerBase
|
|
{
|
|
|
|
private readonly ApplicationDbContext db;
|
|
private readonly GeneralUseHelpers guhf;
|
|
|
|
public AlbumController(ApplicationDbContext _db, GeneralUseHelpers _guhf)
|
|
{
|
|
db = _db;
|
|
guhf = _guhf;
|
|
}
|
|
|
|
[HttpGet("getCoverArt")]
|
|
[HttpGet("getCoverArt.view")]
|
|
[HttpPost("getCoverArt.view")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(404)]
|
|
public async Task<IActionResult> GetCoverArt()
|
|
{
|
|
string thumbnailPath = db.Globals
|
|
.First(g => g.Key == "musicThumbnailPath").Value!;
|
|
|
|
IFileInfo fileInfo = new PhysicalFileProvider(thumbnailPath)
|
|
.GetFileInfo("default.png");
|
|
|
|
if (!fileInfo.Exists) return NotFound();
|
|
return PhysicalFile(fileInfo.PhysicalPath!, "image/png");
|
|
}
|
|
|
|
[HttpGet("getAlbumList2")]
|
|
[ProducesResponseType(200)]
|
|
public async Task<IActionResult> GetAlbumList2()
|
|
{
|
|
// First, check if user is authorized
|
|
User? user = await guhf.GetUserFromParams(Request);
|
|
|
|
if (user == null)
|
|
{
|
|
// Craft an error
|
|
return Ok(new ResponseWrapper
|
|
{
|
|
SubsonicResponse = new SubsonicResponseDTO
|
|
{
|
|
Status = "failed",
|
|
error = new ErrorDTO()
|
|
}
|
|
});
|
|
}
|
|
|
|
List<AlbumViewShortDTO> albumsDTO = [];
|
|
List<Album> albums = db.Albums
|
|
.Where(a => a.State != 1)
|
|
.Include(a => a.Artist)
|
|
.Include(a => a.Songs)
|
|
.ToList();
|
|
|
|
foreach (Album al in albums)
|
|
{
|
|
albumsDTO.Add(
|
|
AlbumMapping.ToAlbumViewShort(al)
|
|
);
|
|
}
|
|
|
|
return Ok(new ResponseWrapper
|
|
{
|
|
SubsonicResponse = new SubsonicResponseDTO
|
|
{
|
|
albumList2 = new AlbumList2DTO
|
|
{
|
|
album = albumsDTO
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
[HttpPost("getAlbumList2.view")]
|
|
[ProducesResponseType(200)]
|
|
public async Task<IActionResult> GetAlbumList2Form()
|
|
{
|
|
// First, check if user is authorized
|
|
User? user = await guhf.GetUserFromForm(Request);
|
|
|
|
if (user == null)
|
|
{
|
|
// Craft an error
|
|
return Ok(new ResponseWrapper
|
|
{
|
|
SubsonicResponse = new SubsonicResponseDTO
|
|
{
|
|
Status = "failed",
|
|
error = new ErrorDTO()
|
|
}
|
|
});
|
|
}
|
|
|
|
List<AlbumViewShortDTO> albumsDTO = [];
|
|
List<Album> albums = db.Albums
|
|
.Where(a => a.State != 1)
|
|
.Include(a => a.Artist)
|
|
.Include(a => a.Songs)
|
|
.ToList();
|
|
|
|
foreach (Album al in albums)
|
|
{
|
|
albumsDTO.Add(
|
|
AlbumMapping.ToAlbumViewShort(al)
|
|
);
|
|
}
|
|
|
|
return Ok(new ResponseWrapper
|
|
{
|
|
SubsonicResponse = new SubsonicResponseDTO
|
|
{
|
|
albumList2 = new AlbumList2DTO
|
|
{
|
|
album = albumsDTO
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|