Feat/ssad 0099/azure blobe storage#108
Conversation
… to fetch non-existent blobs
…etcode-Server-January-2026 into feat/SSAD-0099/azure-blobe-storage # Conflicts: # Streetcode/Streetcode.Resources/Messages.resx
DrFaust555
left a comment
There was a problem hiding this comment.
- Problem: missing else/continue in ~7 handlers
Repeats in GetAllAudiosHandler, GetAllImagesHandler, GetImageByStreetcodeIdHandler, GetStreetcodeArtByStreetcodeIdHandler, GetAllCategoriesHandler, GetCategoriesByStreetcodeIdHandler, GetArtsByStreetcodeIdHandler:
var audioBase64 = await _blobService.FindFileInStorageAsBase64(audio.BlobName);
if (audioBase64 is not null)
{
audio.Base64 = audioBase64;
}
// BUG: this code is ALWAYS executed — even when the blob is found!
var errorNotFoundMsg = Messages.Error_MediaBlobNotFound.Format(...);
_logger.LogError(request, errorNotFoundMsg);
return Result.Fail(new Error(errorNotFoundMsg));
There is no else or continue after if — the handler always returns Fail, even when the blob is found successfully. GetAllNewsHandler and SortedByDateTimeHandler have the correct continue — this is a copy-paste error where continue was forgotten to be added in the rest.
Other inaccuracies:
- Program.cs hardcodes AzureBlobService in RecurringJob:
RecurringJob.AddOrUpdate(...)
In Local environment AzureBlobService is not registered — will fail. IBlobService is required. - AzureBlobService.FindFileInStorageAsBytes returns null! — null-forgiving operator hides potential NullReferenceException. Return type should be Task<byte[]?>.
- BlobService.SaveFileInStorageBase64 is broken — the result of FileService.EncryptFile() is discarded, unencrypted bytes are written to disk.
- UpdateNewsHandler — Delete(newsEntity.Image) without null-check — if newsEntity.Image is also null, there will be a NullReferenceException.
- AzureBlobService uses Console.WriteLine instead of ILogger for logging.
- CleanBlobStorage loads ALL images and audios into memory via GetAllAsync() — a problem with large data.
Design issues
8. 0% tests on AzureBlobService and FileService — new 200+ lines of production code without coverage.
9. 9.9% duplication — blob-not-found pattern copy-pasted in 20 handlers. Should be moved to helper.
…etcode-Server-January-2026 into feat/SSAD-0099/azure-blobe-storage
- Optimize AzureBlobService.CleanBlobStorage with batching and logging; delete only unreferenced blobs - Use EncryptBytes/DecryptBytes for clearer encryption logic - Add early continue in MediatR handlers after successful Base64 retrieval - Update UpdateNewsHandler to avoid deleting images linked to Facts - Improve and expand unit tests for blob and news update logic - Register blob cleanup Hangfire job via IBlobService interface - Add StyleCop suppressions and enhance logging throughout blob services #99
|


Added azure blob storage
Moved Encryption/Decryption logic to a separate shared service
Added blob existence validation logic
Added unit tests for new logic
#99