mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-04-09 13:18:02 +02:00
Render html server side for proper metadata tagging
This commit is contained in:
parent
cec5a01d5d
commit
0249b1cedf
@ -44,7 +44,7 @@ public class DownloadController : Controller
|
||||
var voidFile = await SetupDownload(gid);
|
||||
if (voidFile == default) return;
|
||||
|
||||
var egressReq = new EgressRequest(gid, GetRanges(Request, (long)voidFile!.Metadata!.Size));
|
||||
var egressReq = new EgressRequest(gid, GetRanges(Request, (long) voidFile!.Metadata!.Size));
|
||||
if (egressReq.Ranges.Count() > 1)
|
||||
{
|
||||
_logger.LogWarning("Multi-range request not supported!");
|
||||
@ -56,10 +56,10 @@ public class DownloadController : Controller
|
||||
}
|
||||
else if (egressReq.Ranges.Count() == 1)
|
||||
{
|
||||
Response.StatusCode = (int)HttpStatusCode.PartialContent;
|
||||
Response.StatusCode = (int) HttpStatusCode.PartialContent;
|
||||
if (egressReq.Ranges.Sum(a => a.Size) == 0)
|
||||
{
|
||||
Response.StatusCode = (int)HttpStatusCode.RequestedRangeNotSatisfiable;
|
||||
Response.StatusCode = (int) HttpStatusCode.RequestedRangeNotSatisfiable;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -95,7 +95,7 @@ public class DownloadController : Controller
|
||||
var orderId = Request.Headers.GetHeader("V-OrderId") ?? Request.Query["orderId"];
|
||||
if (!await IsOrderPaid(orderId))
|
||||
{
|
||||
Response.StatusCode = (int)HttpStatusCode.PaymentRequired;
|
||||
Response.StatusCode = (int) HttpStatusCode.PaymentRequired;
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@ -136,4 +136,4 @@ public class DownloadController : Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
55
VoidCat/Controllers/IndexController.cs
Normal file
55
VoidCat/Controllers/IndexController.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using VoidCat.Model;
|
||||
using VoidCat.Services.Abstractions;
|
||||
|
||||
namespace VoidCat.Controllers;
|
||||
|
||||
public class IndexController : Controller
|
||||
{
|
||||
private readonly IWebHostEnvironment _webHost;
|
||||
private readonly IFileMetadataStore _fileMetadata;
|
||||
|
||||
public IndexController(IFileMetadataStore fileMetadata, IWebHostEnvironment webHost)
|
||||
{
|
||||
_fileMetadata = fileMetadata;
|
||||
_webHost = webHost;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return html content with tags for file preview
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Route("{id}")]
|
||||
public async Task<IActionResult> FilePreview(string id)
|
||||
{
|
||||
if (!id.TryFromBase58Guid(out var gid)) return NotFound();
|
||||
|
||||
var meta = await _fileMetadata.Get(gid);
|
||||
if (meta == default) return NotFound();
|
||||
|
||||
var manifestPath = Path.Combine(_webHost.WebRootPath, "asset-manifest.json");
|
||||
if (!System.IO.File.Exists(manifestPath)) return StatusCode(500);
|
||||
|
||||
var jsonManifest = await System.IO.File.ReadAllTextAsync(manifestPath);
|
||||
return View("~/Pages/Index.cshtml", new IndexModel
|
||||
{
|
||||
Meta = meta,
|
||||
Manifest = JsonConvert.DeserializeObject<AssetManifest>(jsonManifest)!
|
||||
});
|
||||
}
|
||||
|
||||
public class IndexModel
|
||||
{
|
||||
public VoidFileMeta Meta { get; init; }
|
||||
|
||||
public AssetManifest Manifest { get; init; }
|
||||
}
|
||||
|
||||
public class AssetManifest
|
||||
{
|
||||
public Dictionary<string, string> Files { get; init; }
|
||||
public List<string> Entrypoints { get; init; }
|
||||
}
|
||||
}
|
64
VoidCat/Pages/Index.cshtml
Normal file
64
VoidCat/Pages/Index.cshtml
Normal file
@ -0,0 +1,64 @@
|
||||
@using VoidCat.Model
|
||||
@model VoidCat.Controllers.IndexController.IndexModel
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<meta name="theme-color" content="#000000"/>
|
||||
<link rel="icon" href="/favicon.ico"/>
|
||||
<link rel="apple-touch-icon" href="/logo.png"/>
|
||||
<link rel="manifest" href="/manifest.json"/>
|
||||
|
||||
<title>void.cat - @Model.Meta.Name</title>
|
||||
<meta name="description" content="@Model.Meta.Description"/>
|
||||
|
||||
<meta property="og:site_name" content="void.cat"/>
|
||||
<meta property="og:title" content="@Model.Meta.Name"/>
|
||||
<meta property="og:description" content="@Model.Meta.Description"/>
|
||||
<meta property="og:url" content="@($"https://{Context.Request.Host}/{Model.Meta.Id.ToBase58()}")"/>
|
||||
|
||||
@foreach (var ep in Model.Manifest.Entrypoints)
|
||||
{
|
||||
switch (System.IO.Path.GetExtension(ep))
|
||||
{
|
||||
case ".css":
|
||||
{
|
||||
<link rel="stylesheet" href="@ep"/>
|
||||
break;
|
||||
}
|
||||
case ".js":
|
||||
{
|
||||
<script defer src="@ep"></script>
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@{
|
||||
var mime = Model.Meta.MimeType;
|
||||
}
|
||||
@if (mime != default)
|
||||
{
|
||||
var link = $"https://{Context.Request.Host}/d/{Model.Meta.Id.ToBase58()}";
|
||||
if (mime.StartsWith("image/"))
|
||||
{
|
||||
<meta property="og:image" content="@link"/>
|
||||
<meta property="og:image:type" content="@mime"/>
|
||||
}
|
||||
else if (mime.StartsWith("video/"))
|
||||
{
|
||||
<meta property="og:video" content="@link"/>
|
||||
<meta property="og:video:type" content="@mime"/>
|
||||
}
|
||||
else if (mime.StartsWith("audio/"))
|
||||
{
|
||||
<meta property="og:audio" content="@link"/>
|
||||
<meta property="og:audio:type" content="@mime"/>
|
||||
}
|
||||
}
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
10
VoidCat/wwwroot/asset-manifest.json
Normal file
10
VoidCat/wwwroot/asset-manifest.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"files": {
|
||||
"main.js": "/static/js/bundle.js",
|
||||
"index.html": "/index.html",
|
||||
"bundle.js.map": "/static/js/bundle.js.map",
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/js/bundle.js"
|
||||
]
|
||||
}
|
@ -6,6 +6,9 @@ services:
|
||||
- "8001:80"
|
||||
volumes:
|
||||
- "./VoidCat/appsettings.compose.json:/app/appsettings.json:ro"
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
redis:
|
||||
image: "redis:alpine"
|
||||
postgres:
|
||||
|
Loading…
x
Reference in New Issue
Block a user