Fallback to index

This commit is contained in:
Kieran 2022-07-09 23:42:38 +01:00
parent 0249b1cedf
commit d85dd7b937
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 40 additions and 37 deletions

View File

@ -24,10 +24,7 @@ public class IndexController : Controller
[Route("{id}")] [Route("{id}")]
public async Task<IActionResult> FilePreview(string id) public async Task<IActionResult> FilePreview(string id)
{ {
if (!id.TryFromBase58Guid(out var gid)) return NotFound(); id.TryFromBase58Guid(out var gid);
var meta = await _fileMetadata.Get(gid);
if (meta == default) return NotFound();
var manifestPath = Path.Combine(_webHost.WebRootPath, "asset-manifest.json"); var manifestPath = Path.Combine(_webHost.WebRootPath, "asset-manifest.json");
if (!System.IO.File.Exists(manifestPath)) return StatusCode(500); if (!System.IO.File.Exists(manifestPath)) return StatusCode(500);
@ -35,14 +32,14 @@ public class IndexController : Controller
var jsonManifest = await System.IO.File.ReadAllTextAsync(manifestPath); var jsonManifest = await System.IO.File.ReadAllTextAsync(manifestPath);
return View("~/Pages/Index.cshtml", new IndexModel return View("~/Pages/Index.cshtml", new IndexModel
{ {
Meta = meta, Meta = await _fileMetadata.Get(gid),
Manifest = JsonConvert.DeserializeObject<AssetManifest>(jsonManifest)! Manifest = JsonConvert.DeserializeObject<AssetManifest>(jsonManifest)!
}); });
} }
public class IndexModel public class IndexModel
{ {
public VoidFileMeta Meta { get; init; } public VoidFileMeta? Meta { get; init; }
public AssetManifest Manifest { get; init; } public AssetManifest Manifest { get; init; }
} }

View File

@ -10,34 +10,17 @@
<link rel="apple-touch-icon" href="/logo.png"/> <link rel="apple-touch-icon" href="/logo.png"/>
<link rel="manifest" href="/manifest.json"/> <link rel="manifest" href="/manifest.json"/>
@if (Model.Meta != default)
{
<title>void.cat - @Model.Meta.Name</title> <title>void.cat - @Model.Meta.Name</title>
<meta name="description" content="@Model.Meta.Description"/> <meta name="description" content="@Model.Meta.Description"/>
<meta property="og:site_name" content="void.cat"/> <meta property="og:site_name" content="void.cat"/>
<meta property="og:title" content="@Model.Meta.Name"/> <meta property="og:title" content="@Model.Meta.Name"/>
<meta property="og:description" content="@Model.Meta.Description"/> <meta property="og:description" content="@Model.Meta.Description"/>
<meta property="og:url" content="@($"https://{Context.Request.Host}/{Model.Meta.Id.ToBase58()}")"/> <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; var mime = Model.Meta.MimeType;
} if (mime != default)
@if (mime != default)
{ {
var link = $"https://{Context.Request.Host}/d/{Model.Meta.Id.ToBase58()}"; var link = $"https://{Context.Request.Host}/d/{Model.Meta.Id.ToBase58()}";
if (mime.StartsWith("image/")) if (mime.StartsWith("image/"))
@ -56,6 +39,29 @@
<meta property="og:audio:type" content="@mime"/> <meta property="og:audio:type" content="@mime"/>
} }
} }
}
else
{
<title>void.cat</title>
<meta name="description" content="void.cat - free, simple file sharing."/>
}
@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;
}
}
}
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>