mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-04-09 00:18:02 +02:00
Support plain uploads
This commit is contained in:
parent
e2449d3384
commit
c7b668fbe8
@ -30,7 +30,7 @@ namespace VoidCat.Controllers
|
||||
[HttpPost]
|
||||
[DisableRequestSizeLimit]
|
||||
[DisableFormValueModelBinding]
|
||||
public async Task<UploadResult> UploadFile()
|
||||
public async Task<IActionResult> UploadFile([FromQuery] bool cli = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -45,13 +45,24 @@ namespace VoidCat.Controllers
|
||||
};
|
||||
|
||||
var digest = Request.Headers.GetHeader("V-Digest");
|
||||
var vf = await _storage.Ingress(new(Request.Body, meta, digest!), HttpContext.RequestAborted);
|
||||
|
||||
return UploadResult.Success(vf);
|
||||
var vf = await _storage.Ingress(new(Request.Body, meta)
|
||||
{
|
||||
Hash = digest
|
||||
}, HttpContext.RequestAborted);
|
||||
|
||||
if (cli)
|
||||
{
|
||||
var urlBuilder = new UriBuilder(Request.IsHttps ? "https" : "http", Request.Host.Host, Request.Host.Port ?? 80,
|
||||
$"/d/{vf.Id.ToBase58()}");
|
||||
|
||||
return Content(urlBuilder.Uri.ToString(), "text/plain");
|
||||
}
|
||||
|
||||
return Json(UploadResult.Success(vf));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return UploadResult.Error(ex.Message);
|
||||
return Json(UploadResult.Error(ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,8 +80,9 @@ namespace VoidCat.Controllers
|
||||
|
||||
var editSecret = Request.Headers.GetHeader("V-EditSecret");
|
||||
var digest = Request.Headers.GetHeader("V-Digest");
|
||||
var vf = await _storage.Ingress(new(Request.Body, meta, digest!)
|
||||
var vf = await _storage.Ingress(new(Request.Body, meta)
|
||||
{
|
||||
Hash = digest,
|
||||
EditSecret = editSecret?.FromBase58Guid() ?? Guid.Empty,
|
||||
Id = gid
|
||||
}, HttpContext.RequestAborted);
|
||||
|
@ -1,9 +1,10 @@
|
||||
namespace VoidCat.Model;
|
||||
|
||||
public sealed record IngressPayload(Stream InStream, SecretVoidFileMeta Meta, string Hash)
|
||||
public sealed record IngressPayload(Stream InStream, SecretVoidFileMeta Meta)
|
||||
{
|
||||
public Guid? Id { get; init; }
|
||||
public Guid? EditSecret { get; init; }
|
||||
|
||||
public string? Hash { get; init; }
|
||||
|
||||
public bool IsAppend => Id.HasValue && EditSecret.HasValue;
|
||||
}
|
@ -67,7 +67,7 @@ public class LocalDiskFileStore : IFileStore
|
||||
|
||||
var (total, hash) = await IngressInternal(id, payload.InStream, fsTemp, cts);
|
||||
|
||||
if (!hash.Equals(payload.Hash, StringComparison.InvariantCultureIgnoreCase))
|
||||
if (payload.Hash != null && !hash.Equals(payload.Hash, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
throw new CryptographicException("Invalid file hash");
|
||||
}
|
||||
@ -83,6 +83,7 @@ public class LocalDiskFileStore : IFileStore
|
||||
{
|
||||
meta = meta! with
|
||||
{
|
||||
Digest = hash,
|
||||
Uploaded = DateTimeOffset.UtcNow,
|
||||
EditSecret = Guid.NewGuid(),
|
||||
Size = total
|
||||
|
@ -109,8 +109,8 @@ export function FilePreview() {
|
||||
{info ? (
|
||||
<Fragment>
|
||||
<Helmet>
|
||||
<title>void.cat - {info.metadata?.name}</title>
|
||||
<meta name="description" content={info.metadata?.description}/>
|
||||
<title>void.cat - {info.metadata?.name ?? info.id}</title>
|
||||
{info.metadata?.description ? <meta name="description" content={info.metadata?.description}/> : null}
|
||||
{renderOpenGraphTags()}
|
||||
</Helmet>
|
||||
<div className="flex flex-center">
|
||||
|
Loading…
x
Reference in New Issue
Block a user