mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-04-09 03:38:01 +02:00
Nullable columns
This commit is contained in:
parent
5a424e4d16
commit
7ea99de160
@ -59,7 +59,7 @@ public record VoidFileMeta : IVoidFileMeta
|
||||
/// <summary>
|
||||
/// SHA-256 hash of the file
|
||||
/// </summary>
|
||||
public string? Digest { get; init; }
|
||||
public string? Digest { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Url to download the file
|
||||
|
@ -43,8 +43,8 @@ public class S3FileStore : StreamFileStore, IFileStore
|
||||
}
|
||||
};
|
||||
|
||||
var r = await _client.PutObjectAsync(req, cts);
|
||||
return await HandleCompletedUpload(payload, r.ChecksumSHA256, payload.Meta.Size);
|
||||
await _client.PutObjectAsync(req, cts);
|
||||
return HandleCompletedUpload(payload, payload.Meta.Size);
|
||||
}
|
||||
|
||||
public async ValueTask Egress(EgressRequest request, Stream outStream, CancellationToken cts)
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Buffers;
|
||||
using System.Security.Cryptography;
|
||||
using VoidCat.Model;
|
||||
using VoidCat.Model.Exceptions;
|
||||
using VoidCat.Services.Abstractions;
|
||||
@ -45,16 +44,11 @@ public abstract class StreamFileStore
|
||||
}
|
||||
}
|
||||
|
||||
var (total, hash) = await IngressInternal(id, payload.InStream, outStream, cts);
|
||||
if (payload.Hash != null && !hash.Equals(payload.Hash, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
throw new CryptographicException("Invalid file hash");
|
||||
}
|
||||
|
||||
return await HandleCompletedUpload(payload, hash, total);
|
||||
var total = await IngressInternal(id, payload.InStream, outStream, cts);
|
||||
return HandleCompletedUpload(payload, total);
|
||||
}
|
||||
|
||||
protected async Task<PrivateVoidFile> HandleCompletedUpload(IngressPayload payload, string hash, ulong totalSize)
|
||||
protected PrivateVoidFile HandleCompletedUpload(IngressPayload payload, ulong totalSize)
|
||||
{
|
||||
var meta = payload.Meta;
|
||||
if (payload.IsAppend)
|
||||
@ -68,7 +62,6 @@ public abstract class StreamFileStore
|
||||
{
|
||||
meta = meta! with
|
||||
{
|
||||
Digest = hash,
|
||||
Uploaded = DateTimeOffset.UtcNow,
|
||||
EditSecret = Guid.NewGuid(),
|
||||
Size = totalSize
|
||||
@ -84,13 +77,12 @@ public abstract class StreamFileStore
|
||||
return vf;
|
||||
}
|
||||
|
||||
private async Task<(ulong, string)> IngressInternal(Guid id, Stream ingress, Stream outStream,
|
||||
private async Task<ulong> IngressInternal(Guid id, Stream ingress, Stream outStream,
|
||||
CancellationToken cts)
|
||||
{
|
||||
using var buffer = MemoryPool<byte>.Shared.Rent(BufferSize);
|
||||
var total = 0UL;
|
||||
int readLength = 0, offset = 0;
|
||||
var sha = SHA256.Create();
|
||||
int readLength, offset = 0;
|
||||
while ((readLength = await ingress.ReadAsync(buffer.Memory[offset..], cts)) > 0 || offset != 0)
|
||||
{
|
||||
if (readLength != 0 && offset + readLength < buffer.Memory.Length)
|
||||
@ -104,13 +96,11 @@ public abstract class StreamFileStore
|
||||
var buf = buffer.Memory[..totalRead];
|
||||
await outStream.WriteAsync(buf, cts);
|
||||
await _stats.TrackIngress(id, (ulong) buf.Length);
|
||||
sha.TransformBlock(buf.ToArray(), 0, buf.Length, null, 0);
|
||||
total += (ulong) buf.Length;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
sha.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
|
||||
return (total, sha.Hash!.ToHex());
|
||||
return total;
|
||||
}
|
||||
|
||||
protected async Task EgressFull(Guid id, Stream inStream, Stream outStream,
|
||||
|
@ -21,12 +21,12 @@ public class Init : Migration
|
||||
|
||||
Create.Table("Files")
|
||||
.WithColumn("Id").AsGuid().PrimaryKey()
|
||||
.WithColumn("Name").AsString()
|
||||
.WithColumn("Name").AsString().Nullable()
|
||||
.WithColumn("Size").AsInt64()
|
||||
.WithColumn("Uploaded").AsDateTimeOffset().Indexed().WithDefault(SystemMethods.CurrentUTCDateTime)
|
||||
.WithColumn("Description").AsString().Nullable()
|
||||
.WithColumn("MimeType").AsString().WithDefaultValue("application/octet-stream")
|
||||
.WithColumn("Digest").AsString()
|
||||
.WithColumn("Digest").AsString().Nullable()
|
||||
.WithColumn("EditSecret").AsGuid();
|
||||
|
||||
Create.Table("UserFiles")
|
||||
|
@ -157,8 +157,6 @@ public class MigrateToPostgres : IMigration
|
||||
|
||||
private record UploaderSecretVoidFileMeta : SecretVoidFileMeta
|
||||
{
|
||||
public new string? Digest { get; set; }
|
||||
|
||||
[JsonConverter(typeof(Base58GuidConverter))]
|
||||
public Guid? Uploader { get; set; }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user