Use KSP template
This commit is contained in:
parent
427ea184f2
commit
8d3347aa3b
7 changed files with 165 additions and 4 deletions
|
@ -14,5 +14,6 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<div id="svelte-root"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -27,11 +27,20 @@
|
|||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
:global(g):hover > ellipse {
|
||||
fill: #ffb3a2
|
||||
}
|
||||
ellipse {
|
||||
fill: #69b3a2
|
||||
}
|
||||
</style>
|
||||
|
||||
<g on:mouseenter={enter} on:mouseleave={leave}>
|
||||
{#if !hovering}
|
||||
<ellipse rx={ellipse_rx} ry={ellipse_ry} style="fill: #69b3a2" {cx} {cy} />
|
||||
<ellipse rx={ellipse_rx} ry={ellipse_ry} {cx} {cy} />
|
||||
{:else}
|
||||
<ellipse rx={ellipse_rx} ry={ellipse_ry} style="fill: #ffb3a2" {cx} {cy} />
|
||||
<ellipse rx={ellipse_rx} ry={ellipse_ry} {cx} {cy} />
|
||||
{/if}
|
||||
<text
|
||||
bind:this={text_element}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import App from './App.svelte';
|
||||
|
||||
const app = new App({
|
||||
target: document.body,
|
||||
target: document.getElementById("svelte-root")!,
|
||||
props: {
|
||||
name: 'world'
|
||||
}
|
||||
});
|
||||
|
||||
export default app;
|
||||
export default app;
|
||||
|
|
34
server/.vscode/launch.json
vendored
Normal file
34
server/.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (web)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
"program": "${workspaceFolder}/Ksp.WebServer/bin/Debug/netcoreapp3.1/Ksp.WebServer.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/Ksp.WebServer",
|
||||
"stopAtEntry": false,
|
||||
"serverReadyAction": {
|
||||
"action": "openExternally",
|
||||
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
|
||||
},
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/Views": "${workspaceFolder}/Views"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
42
server/.vscode/tasks.json
vendored
Normal file
42
server/.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/Ksp.WebServer/Ksp.WebServer.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/Ksp.WebServer/Ksp.WebServer.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/Ksp.WebServer/Ksp.WebServer.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
73
server/Ksp.WebServer/Controllers/GrafikPageController.cs
Normal file
73
server/Ksp.WebServer/Controllers/GrafikPageController.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using AngleSharp;
|
||||
using AngleSharp.Dom;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using AngleSharp.Html;
|
||||
|
||||
namespace Ksp.WebServer.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("grafik")]
|
||||
public class GrafikPageController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<TasksController> logger;
|
||||
private readonly IWebHostEnvironment env;
|
||||
|
||||
public GrafikPageController(
|
||||
ILogger<TasksController> logger,
|
||||
IWebHostEnvironment env)
|
||||
{
|
||||
this.env = env;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
async Task<string> 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<IActionResult> 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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AngleSharp" Version="0.14.0" />
|
||||
<PackageReference Include="AspNetCore.Proxy" Version="4.1.0" />
|
||||
<PackageReference Include="XUnit.Assert" Version="2.4.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
|
Reference in a new issue