This commit is contained in:
Kieran 2022-07-06 22:38:18 +01:00
parent ffa540f8fd
commit 72f98f5013
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
5 changed files with 33 additions and 4 deletions

View File

@ -65,6 +65,11 @@ public record VoidFileMeta : IVoidFileMeta
/// Url to download the file /// Url to download the file
/// </summary> /// </summary>
public Uri? Url { get; set; } public Uri? Url { get; set; }
/// <summary>
/// Time when the file will expire and be deleted
/// </summary>
public DateTimeOffset? Expires { get; set; }
} }
/// <summary> /// <summary>

View File

@ -52,6 +52,7 @@ public class LocalDiskFileMetadataStore : IFileMetadataStore
oldMeta.Description = meta.Description ?? oldMeta.Description; oldMeta.Description = meta.Description ?? oldMeta.Description;
oldMeta.Name = meta.Name ?? oldMeta.Name; oldMeta.Name = meta.Name ?? oldMeta.Name;
oldMeta.MimeType = meta.MimeType ?? oldMeta.MimeType; oldMeta.MimeType = meta.MimeType ?? oldMeta.MimeType;
oldMeta.Expires = meta.Expires ?? oldMeta.Expires;
await Set(id, oldMeta); await Set(id, oldMeta);
} }

View File

@ -32,9 +32,10 @@ public class PostgresFileMetadataStore : IFileMetadataStore
await using var conn = await _connection.Get(); await using var conn = await _connection.Get();
await conn.ExecuteAsync( await conn.ExecuteAsync(
@"insert into @"insert into
""Files""(""Id"", ""Name"", ""Size"", ""Uploaded"", ""Description"", ""MimeType"", ""Digest"", ""EditSecret"") ""Files""(""Id"", ""Name"", ""Size"", ""Uploaded"", ""Description"", ""MimeType"", ""Digest"", ""EditSecret"", ""Expires"")
values(:id, :name, :size, :uploaded, :description, :mimeType, :digest, :editSecret) values(:id, :name, :size, :uploaded, :description, :mimeType, :digest, :editSecret, :expires)
on conflict (""Id"") do update set ""Name"" = :name, ""Description"" = :description, ""MimeType"" = :mimeType", new on conflict (""Id"") do update set ""Name"" = :name, ""Description"" = :description, ""MimeType"" = :mimeType, ""Expires"" = :expires",
new
{ {
id, id,
name = obj.Name, name = obj.Name,
@ -43,7 +44,8 @@ on conflict (""Id"") do update set ""Name"" = :name, ""Description"" = :descript
description = obj.Description, description = obj.Description,
mimeType = obj.MimeType, mimeType = obj.MimeType,
digest = obj.Digest, digest = obj.Digest,
editSecret = obj.EditSecret editSecret = obj.EditSecret,
expires = obj.Expires
}); });
} }
@ -79,6 +81,7 @@ on conflict (""Id"") do update set ""Name"" = :name, ""Description"" = :descript
oldMeta.Description = meta.Description ?? oldMeta.Description; oldMeta.Description = meta.Description ?? oldMeta.Description;
oldMeta.Name = meta.Name ?? oldMeta.Name; oldMeta.Name = meta.Name ?? oldMeta.Name;
oldMeta.MimeType = meta.MimeType ?? oldMeta.MimeType; oldMeta.MimeType = meta.MimeType ?? oldMeta.MimeType;
oldMeta.Expires = meta.Expires ?? oldMeta.Expires;
await Set(id, oldMeta); await Set(id, oldMeta);
} }

View File

@ -52,6 +52,7 @@ public class S3FileMetadataStore : IFileMetadataStore
oldMeta.Description = meta.Description ?? oldMeta.Description; oldMeta.Description = meta.Description ?? oldMeta.Description;
oldMeta.Name = meta.Name ?? oldMeta.Name; oldMeta.Name = meta.Name ?? oldMeta.Name;
oldMeta.MimeType = meta.MimeType ?? oldMeta.MimeType; oldMeta.MimeType = meta.MimeType ?? oldMeta.MimeType;
oldMeta.Expires = meta.Expires ?? oldMeta.Expires;
await Set(id, oldMeta); await Set(id, oldMeta);
} }

View File

@ -0,0 +1,19 @@
using FluentMigrator;
namespace VoidCat.Services.Migrations.Database;
[Migration(20220615_2238)]
public class FileExpiry : Migration {
public override void Up()
{
Create.Column("Expires")
.OnTable("Files")
.AsDateTimeOffset().Nullable().Indexed();
}
public override void Down()
{
Delete.Column("Expires")
.FromTable("Files");
}
}