using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Net.Http.Headers; using System.Collections; using System.IO; using zero.Backoffice.Services; namespace zero.Backoffice.Endpoints.UI; public class UIController : ZeroBackofficeController { readonly IEnumerable SettingsGroups; readonly IAuthenticationService AuthenticationService; readonly IAuthorizationService AuthorizationService; readonly IApplicationStore ApplicationStore; readonly IIconService IconService; readonly IResourceService ResourceService; readonly ISectionService SectionService; readonly IMediaManagement Media; public UIController(IEnumerable settingsGroups, IAuthenticationService authenticationService, IAuthorizationService authorizationService, IApplicationStore applicationStore, IIconService iconService, IResourceService resourceService, ISectionService sectionService, IMediaManagement media) { SettingsGroups = settingsGroups; AuthenticationService = authenticationService; AuthorizationService = authorizationService; ApplicationStore = applicationStore; IconService = iconService; ResourceService = resourceService; SectionService = sectionService; Media = media; } [HttpGet("sections")] //[ZeroAuthorize(CountryPermissions.Create)] public async Task> GetSections() => Ok(await SectionService.GetSections()); [HttpGet("settingareas")] public async Task> GetSettingGroups() => Ok(await SectionService.GetSettingsAreas()); [HttpGet("iconsets")] public async Task> GetIconSets() { return Ok(await IconService.GetSets()); } [HttpGet("translations")] public async Task>> GetTranslations() { return Ok(await ResourceService.GetTranslations("en-us")); } [HttpGet("mediapreview/{id}/{size?}")] public async Task GetSource(string id, string size = null) { Media.Media media = await Media.GetFile(id); if (media == null) { return NotFound(); } string path = Media.GetPublicFilePath(media); if (path == null) { return NotFound(); } if (path.StartsWith("url://")) { path = path.Substring(6); } FileExtensionContentTypeProvider provider = new(); string contentType; if (!provider.TryGetContentType(Path.GetFileName(path), out contentType)) { contentType = "application/octet-stream"; } try { return File(await Media.GetFileStream(media), contentType, DateTimeOffset.Now, EntityTagHeaderValue.Any); } catch (FileSystemException) { return NotFound(); } } }