Update configuration and enhance media processing: add stream token TTL and timeout settings in .env.example, improve error handling in media endpoints, and refactor command handlers for asynchronous operations. Update documentation to reflect current application state and features.
This commit is contained in:
+21
-8
@@ -27,15 +27,28 @@ public sealed class RegisterMediaAssetCommandHandler(IAppDbContext dbContext, IM
|
||||
var extension = Path.GetExtension(command.OriginalFileName).ToLowerInvariant();
|
||||
var asset = MediaAsset.Register(command.OriginalFileName, extension, command.Source);
|
||||
|
||||
await storage.PromoteToOriginalAsync(
|
||||
command.Source,
|
||||
command.SourceToken,
|
||||
asset.Id,
|
||||
extension,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
// Сначала фиксируем ассет в БД, затем переносим файл в originals/. Если перенос не удался —
|
||||
// откатываем регистрацию, чтобы не оставить orphan (либо есть и строка БД, и файл, либо нет ни
|
||||
// того, ни другого). Обратный порядок оставлял бы перемещённый файл без строки БД при сбое save.
|
||||
dbContext.MediaAssets.Add(asset);
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
try
|
||||
{
|
||||
await storage.PromoteToOriginalAsync(
|
||||
command.Source,
|
||||
command.SourceToken,
|
||||
asset.Id,
|
||||
extension,
|
||||
cancellationToken
|
||||
);
|
||||
}
|
||||
catch
|
||||
{
|
||||
dbContext.MediaAssets.Remove(asset);
|
||||
await dbContext.SaveChangesAsync(cancellationToken);
|
||||
throw;
|
||||
}
|
||||
|
||||
return Result.Success(asset.Id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user