mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2026-10-27 01:16:07 +03:00
20 lines
702 B
C#
20 lines
702 B
C#
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using DHT.Server.Database;
|
|
using DHT.Server.Download;
|
|
using DHT.Utils.Http;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace DHT.Server.Endpoints;
|
|
|
|
sealed class GetDownloadedFileEndpoint(IDatabaseFile db) : BaseEndpoint(db) {
|
|
protected override async Task Respond(HttpRequest request, HttpResponse response) {
|
|
string url = WebUtility.UrlDecode((string) request.RouteValues["url"]!);
|
|
string normalizedUrl = DiscordCdn.NormalizeUrl(url);
|
|
|
|
if (!await Db.Downloads.GetSuccessfulDownloadWithData(normalizedUrl, (download, stream) => response.WriteStreamAsync(download.Type, download.Size, stream))) {
|
|
response.Redirect(url, permanent: false);
|
|
}
|
|
}
|
|
}
|