remove genserver
This commit is contained in:
parent
d14eec8dd7
commit
e46cebb8bb
3 changed files with 0 additions and 119 deletions
|
@ -1,29 +0,0 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>disable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
|
||||||
<DebugType>none</DebugType>
|
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\HTTP\HTTP.csproj" />
|
|
||||||
<ProjectReference Include="..\PNG\PNG.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Using Include="System" />
|
|
||||||
<Using Include="System.Collections.Generic" />
|
|
||||||
<Using Include="System.IO" />
|
|
||||||
<Using Include="System.Linq" />
|
|
||||||
<Using Include="System.Threading.Tasks" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
|
@ -1,89 +0,0 @@
|
||||||
using System.Security.Cryptography.X509Certificates;
|
|
||||||
using Uwaa.HTTP;
|
|
||||||
using Uwaa.HTTP.Routing;
|
|
||||||
using Uwaa.PNG;
|
|
||||||
|
|
||||||
namespace GeneratorServer;
|
|
||||||
|
|
||||||
internal class Program
|
|
||||||
{
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Creating router");
|
|
||||||
Router router = CreateRouter();
|
|
||||||
|
|
||||||
Console.WriteLine("Starting HTTP");
|
|
||||||
HttpServer http = new HttpServer(80, null, router);
|
|
||||||
http.Start();
|
|
||||||
|
|
||||||
if (!File.Exists("certs/certificate.crt") || !File.Exists("certs/private.key"))
|
|
||||||
{
|
|
||||||
#if RELEASE
|
|
||||||
Console.WriteLine("Warning: No HTTPS, \"certificate.crt\" and/or \"private.key\" are missing in \"certs\" directory.");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Starting HTTPS");
|
|
||||||
HttpServer https = new HttpServer(443, X509Certificate2.CreateFromPemFile("certs/certificate.crt", "certs/private.key"), router);
|
|
||||||
https.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Ready");
|
|
||||||
Task.Delay(-1).Wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
static Router CreateRouter()
|
|
||||||
{
|
|
||||||
var router = new Router();
|
|
||||||
router.Add("background", new BGGenerator());
|
|
||||||
router.Add(new StaticEndpoint(HttpResponse.NotFound()));
|
|
||||||
return router;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BGGenerator : RouterBase
|
|
||||||
{
|
|
||||||
public override HttpMethod Method => HttpMethod.GET;
|
|
||||||
|
|
||||||
public override int Arguments => 0;
|
|
||||||
|
|
||||||
protected override Task<HttpResponse?> GetResponseInner(HttpRequest req, HttpClientInfo info, ArraySegment<string> path)
|
|
||||||
{
|
|
||||||
MIMEType contentType = new MIMEType("image", "png");
|
|
||||||
if (!req.CanAccept(contentType))
|
|
||||||
return Task.FromResult(HttpResponse.NotAcceptable())!;
|
|
||||||
|
|
||||||
const int width = 100;
|
|
||||||
const int height = 100;
|
|
||||||
PngBuilder png = PngBuilder.Create(width, height, false);
|
|
||||||
|
|
||||||
Pixel left = new Pixel((byte)Random.Shared.Next(0, 256), (byte)Random.Shared.Next(0, 256), (byte)Random.Shared.Next(0, 256));
|
|
||||||
Pixel right = new Pixel((byte)Random.Shared.Next(0, 256), (byte)Random.Shared.Next(0, 256), (byte)Random.Shared.Next(0, 256));
|
|
||||||
Pixel top = new Pixel((byte)Random.Shared.Next(0, 256), (byte)Random.Shared.Next(0, 256), (byte)Random.Shared.Next(0, 256));
|
|
||||||
Pixel bottom = new Pixel((byte)Random.Shared.Next(0, 256), (byte)Random.Shared.Next(0, 256), (byte)Random.Shared.Next(0, 256));
|
|
||||||
for (int y = 0; y < height; y++)
|
|
||||||
for (int x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
Pixel px = Lerp(Lerp(left, right, (float)x / width), Lerp(top, bottom, (float)y / height), 0.5f);
|
|
||||||
png.SetPixel(px, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.FromResult(HttpResponse.OK(new HttpContent(contentType, png.Save())))!;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Pixel Lerp(Pixel min, Pixel max, float factor)
|
|
||||||
{
|
|
||||||
return new Pixel(Lerp(min.R, max.R, factor), Lerp(min.G, max.G, factor), Lerp(min.B, max.B, factor));
|
|
||||||
}
|
|
||||||
|
|
||||||
static byte Lerp(byte min, byte max, float factor)
|
|
||||||
{
|
|
||||||
return (byte)(min + (max - min) * factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
static float Lerp(float min, float max, float factor)
|
|
||||||
{
|
|
||||||
return min + (max - min) * factor;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
HTTP server which generates images on request
|
|
Loading…
Reference in a new issue