Add option to install a userscript instead of manually copying the tracking script

This commit is contained in:
chylex committed 2025-03-29 08:32:17 +01:00
1 parent 3b569ad5d6
commit 0d3600492e
11 files changed
+411 -58

No files matched your search

@@ -0,0 +1,18 @@
using System.Threading;
using System.Threading.Tasks;
using DHT.Server.Service.Middlewares;
using DHT.Utils.Resources;
using Microsoft.AspNetCore.Http;
namespace DHT.Server.Endpoints;
[ServerAuthorizationMiddleware.NoAuthorization]
sealed class GetUserscriptEndpoint(ResourceLoader resources) : BaseEndpoint {
protected override async Task Respond(HttpRequest request, HttpResponse response, CancellationToken cancellationToken) {
const string FileName = "dht.user.js";
const string ResourcePath = "Tracker/loader/" + FileName;
byte[]? resourceBytes = await resources.ReadBytesAsyncIfExists(ResourcePath);
await WriteFileIfFound(response, FileName, resourceBytes, cancellationToken);
}
}