mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-03-29 16:01:43 +01:00
Include legacy uploader format from metadata
This commit is contained in:
parent
863f14e25f
commit
0d83281a60
@ -83,7 +83,7 @@ namespace VoidCat.Controllers
|
||||
// attach file upload to user
|
||||
if (uid.HasValue)
|
||||
{
|
||||
await _userUploads.AddFile(uid!.Value, vf);
|
||||
await _userUploads.AddFile(uid!.Value, vf.Id);
|
||||
}
|
||||
|
||||
if (cli)
|
||||
|
@ -19,9 +19,9 @@ public interface IUserUploadsStore
|
||||
/// Assign a file upload to a user
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="voidFile"></param>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
ValueTask AddFile(Guid user, PrivateVoidFile voidFile);
|
||||
ValueTask AddFile(Guid user, Guid file);
|
||||
|
||||
/// <summary>
|
||||
/// Get the uploader of a single file
|
||||
|
@ -12,7 +12,7 @@ public static class FileStorageStartup
|
||||
|
||||
if (settings.CloudStorage != default)
|
||||
{
|
||||
services.AddTransient<IUserUploadsStore, UserUploadStore>();
|
||||
services.AddTransient<IUserUploadsStore, CacheUserUploadStore>();
|
||||
|
||||
// cloud storage
|
||||
if (settings.CloudStorage.S3 != default)
|
||||
@ -29,7 +29,7 @@ public static class FileStorageStartup
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddTransient<IUserUploadsStore, UserUploadStore>();
|
||||
services.AddTransient<IUserUploadsStore, CacheUserUploadStore>();
|
||||
services.AddTransient<IFileStore, LocalDiskFileStore>();
|
||||
services.AddTransient<IFileMetadataStore, LocalDiskFileMetadataStore>();
|
||||
}
|
||||
|
@ -15,9 +15,10 @@ public class MigrateToPostgres : IMigration
|
||||
private readonly ICache _cache;
|
||||
private readonly IPaywallStore _paywallStore;
|
||||
private readonly IUserStore _userStore;
|
||||
private readonly IUserUploadsStore _userUploads;
|
||||
|
||||
public MigrateToPostgres(VoidSettings settings, ILogger<MigrateToPostgres> logger, IFileMetadataStore fileMetadata,
|
||||
ICache cache, IPaywallStore paywallStore, IUserStore userStore)
|
||||
ICache cache, IPaywallStore paywallStore, IUserStore userStore, IUserUploadsStore userUploads)
|
||||
{
|
||||
_logger = logger;
|
||||
_settings = settings;
|
||||
@ -25,6 +26,7 @@ public class MigrateToPostgres : IMigration
|
||||
_cache = cache;
|
||||
_paywallStore = paywallStore;
|
||||
_userStore = userStore;
|
||||
_userUploads = userUploads;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -56,13 +58,17 @@ public class MigrateToPostgres : IMigration
|
||||
var localDiskMetaStore =
|
||||
new LocalDiskFileMetadataStore(_settings);
|
||||
|
||||
var files = await localDiskMetaStore.ListFiles<SecretVoidFileMeta>(new(0, int.MaxValue));
|
||||
var files = await localDiskMetaStore.ListFiles<UploaderSecretVoidFileMeta>(new(0, int.MaxValue));
|
||||
await foreach (var file in files.Results)
|
||||
{
|
||||
try
|
||||
{
|
||||
file.MimeType ??= "application/octet-stream";
|
||||
await _fileMetadata.Set(file.Id, file);
|
||||
if (file.Uploader.HasValue)
|
||||
{
|
||||
await _userUploads.AddFile(file.Uploader.Value, file.Id);
|
||||
}
|
||||
await localDiskMetaStore.Delete(file.Id);
|
||||
_logger.LogInformation("Migrated file metadata for {File}", file.Id);
|
||||
}
|
||||
@ -134,4 +140,9 @@ public class MigrateToPostgres : IMigration
|
||||
public string? PasswordHash { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
|
||||
private record UploaderSecretVoidFileMeta : SecretVoidFileMeta
|
||||
{
|
||||
public Guid? Uploader { get; set; }
|
||||
}
|
||||
}
|
@ -4,11 +4,11 @@ using VoidCat.Services.Abstractions;
|
||||
namespace VoidCat.Services.Users;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class UserUploadStore : IUserUploadsStore
|
||||
public class CacheUserUploadStore : IUserUploadsStore
|
||||
{
|
||||
private readonly ICache _cache;
|
||||
|
||||
public UserUploadStore(ICache cache)
|
||||
public CacheUserUploadStore(ICache cache)
|
||||
{
|
||||
_cache = cache;
|
||||
}
|
||||
@ -43,10 +43,10 @@ public class UserUploadStore : IUserUploadsStore
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask AddFile(Guid user, PrivateVoidFile voidFile)
|
||||
public async ValueTask AddFile(Guid user, Guid file)
|
||||
{
|
||||
await _cache.AddToList(MapKey(user), voidFile.Id.ToString());
|
||||
await _cache.Set(MapUploader(voidFile.Id), user);
|
||||
await _cache.AddToList(MapKey(user), file.ToString());
|
||||
await _cache.Set(MapUploader(file), user);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
@ -60,12 +60,12 @@ and uf.""File"" = f.""Id""";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask AddFile(Guid user, PrivateVoidFile voidFile)
|
||||
public async ValueTask AddFile(Guid user, Guid file)
|
||||
{
|
||||
await using var conn = await _connection.Get();
|
||||
await conn.ExecuteAsync(@"insert into ""UserFiles""(""File"", ""User"") values(:file, :user)", new
|
||||
{
|
||||
file = voidFile.Id,
|
||||
file,
|
||||
user
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user