using Houston.Model.Documents; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace Houston.Pages.Document; /// /// Anonymous landing page for shared document links. It exposes only metadata derived from the /// document id and never fetches or renders file contents. /// public class Share : PageModel { [BindProperty(SupportsGet = true)] public string Id { get; set; } = String.Empty; public string Title { get; private set; } = "Dokument"; public string ImageUrl { get; private set; } = String.Empty; public string ExplorerUrl { get; private set; } = String.Empty; public IActionResult OnGet() { var docId = new DocumentId(Id); if (!docId.TryDecode(out var relativePath)) return NotFound(); var type = relativePath.Value.Type; var name = relativePath.Value.Name; var iconPath = type.PreviewPath; Title = name.DisplayName; ImageUrl = AbsoluteUrl(iconPath); ExplorerUrl = AbsoluteUrl("/documents", BuildExplorerQuery(type, name), $"#{Documents.DocumentViewId(docId)}"); return Page(); } private static QueryString BuildExplorerQuery(DocumentType? type, DocumentName name) { return new QueryBuilder { { "q", name.DisplayName }, { "types", type.Name } }.ToQueryString(); } private string AbsoluteUrl(string path, QueryString query = default, string? fragment = null) { return UriHelper.BuildAbsolute( Request.Scheme, Request.Host, Request.PathBase, path, query, fragment: fragment is null ? default : new FragmentString(fragment) ); } }