using AutoMapper; using LANCommander.Server.Data; using LANCommander.Server.Data.Models; using LANCommander.Server.Extensions; using LANCommander.Server.Models; using LANCommander.SDK; using LANCommander.Server.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace LANCommander.Server.Controllers.Api { [Authorize(AuthenticationSchemes = "Bearer")] [Route("api/[controller]")] [ApiController] public class MediaController : ControllerBase { private readonly IMapper Mapper; private readonly Services.MediaService MediaService; private readonly LANCommanderSettings Settings = SettingService.GetSettings(); public MediaController(IMapper mapper, Services.MediaService mediaService) { Mapper = mapper; MediaService = mediaService; } [HttpGet] public async Task> Get() { return Mapper.Map>(await MediaService.Get()); } [HttpGet("{id}")] public async Task Get(Guid id) { return Mapper.Map(await MediaService.Get(id)); } [AllowAnonymous] [HttpGet("{id}/Download")] public async Task Download(Guid id) { try { var media = await MediaService.Get(id); var fs = System.IO.File.OpenRead(Services.MediaService.GetImagePath(media)); return File(fs, media.MimeType); } catch (Exception ex) { return NotFound(); } } } }