diff --git a/frontend/public/grafik.html b/frontend/public/grafik.html index 5a61ab5..be1214d 100644 --- a/frontend/public/grafik.html +++ b/frontend/public/grafik.html @@ -14,5 +14,6 @@ +
diff --git a/frontend/src/GraphNode.svelte b/frontend/src/GraphNode.svelte index 2939407..2fe928f 100644 --- a/frontend/src/GraphNode.svelte +++ b/frontend/src/GraphNode.svelte @@ -27,11 +27,20 @@ }); + + {#if !hovering} - + {:else} - + {/if} logger; + private readonly IWebHostEnvironment env; + + public GrafikPageController( + ILogger logger, + IWebHostEnvironment env) + { + this.env = env; + this.logger = logger; + } + + async Task FetchBlankPage() + { + var c = new HttpClient(); + var rq = new HttpRequestMessage(HttpMethod.Get, "https://ksp-test.ks.matfyz.cz/blank"); + rq.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); + rq.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xhtml+xml")); + rq.Headers.Authorization = + new AuthenticationHeaderValue("Basic", "SECRET"); + if (HttpContext.Request.Headers.TryGetValue("Cookie", out var x)) + rq.Headers.Add("Cookie", x.AsEnumerable()); + var rs = await c.SendAsync(rq); + return await rs.Content.ReadAsStringAsync(); + } + + [HttpGet] + public async Task Get() + { + var grafikPage = await System.IO.File.ReadAllTextAsync(Path.Combine(env.ContentRootPath, "../../frontend/public/grafik.html")); + var p = new AngleSharp.Html.Parser.HtmlParser(); + var grafik = p.ParseDocument(grafikPage); + + var kspTemplate = p.ParseDocument(await FetchBlankPage()); + + var innerBody = grafik.Body; + innerBody.Replace(kspTemplate.Body); + var page = grafik.Body.QuerySelector("#page"); + page.Replace(innerBody.ChildNodes.ToArray()); + + foreach(var headElement in kspTemplate.Head.QuerySelectorAll("link, script")) + { + headElement.RemoveFromParent(); + grafik.Head.AppendChild(headElement); + } + + var outputHtml = new StringWriter(); + grafik.ToHtml(outputHtml, new PrettyMarkupFormatter() { Indentation = "\t", NewLine = "\n" }); + + + return this.Content(outputHtml.ToString(), "text/html"); + } + } +} diff --git a/server/Ksp.WebServer/Ksp.WebServer.csproj b/server/Ksp.WebServer/Ksp.WebServer.csproj index b4ad4b5..5714dc8 100644 --- a/server/Ksp.WebServer/Ksp.WebServer.csproj +++ b/server/Ksp.WebServer/Ksp.WebServer.csproj @@ -5,7 +5,9 @@ + +