mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-04-08 18:18:03 +02:00
Fix size
This commit is contained in:
parent
9fc77e883a
commit
991a6c7713
@ -132,6 +132,7 @@ services.AddAuthorization((opt) =>
|
||||
services.AddTransient<RazorPartialToStringRenderer>();
|
||||
services.AddTransient<IMigration, PopulateMetadataId>();
|
||||
services.AddTransient<IMigration, MigrateToPostgres>();
|
||||
services.AddTransient<IMigration, FixSize>();
|
||||
|
||||
// file storage
|
||||
services.AddStorage(voidSettings);
|
||||
|
38
VoidCat/Services/Migrations/FixSize.cs
Normal file
38
VoidCat/Services/Migrations/FixSize.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using VoidCat.Model;
|
||||
using VoidCat.Services.Abstractions;
|
||||
|
||||
namespace VoidCat.Services.Migrations;
|
||||
|
||||
public class FixSize : IMigration
|
||||
{
|
||||
private readonly ILogger<FixSize> _logger;
|
||||
private readonly IFileMetadataStore _fileMetadata;
|
||||
private readonly IFileStore _fileStore;
|
||||
|
||||
public FixSize(ILogger<FixSize> logger, IFileMetadataStore fileMetadata, IFileStore fileStore)
|
||||
{
|
||||
_logger = logger;
|
||||
_fileMetadata = fileMetadata;
|
||||
_fileStore = fileStore;
|
||||
}
|
||||
|
||||
public async ValueTask<IMigration.MigrationResult> Migrate(string[] args)
|
||||
{
|
||||
var files = await _fileMetadata.ListFiles<SecretVoidFileMeta>(new(0, int.MaxValue));
|
||||
await foreach (var file in files.Results)
|
||||
{
|
||||
var fs = await _fileStore.Open(new(file.Id, Enumerable.Empty<RangeRequest>()), CancellationToken.None);
|
||||
if (file.Size != (ulong) fs.Length)
|
||||
{
|
||||
_logger.LogInformation("Updating file size {Id} to {Size}", file.Id, fs.Length);
|
||||
var newFile = file with
|
||||
{
|
||||
Size = (ulong) fs.Length
|
||||
};
|
||||
await _fileMetadata.Set(newFile.Id, newFile);
|
||||
}
|
||||
}
|
||||
|
||||
return IMigration.MigrationResult.Completed;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user