2 Commits

Author SHA1 Message Date
3dca408356 Cleanup potential memory leaks
Some checks failed
Build and Push Image / build-and-push (push) Has been cancelled
2025-07-23 15:45:35 -04:00
1655e342b7 Removed avif + heif support 2025-07-17 20:02:41 -04:00
4 changed files with 14 additions and 17 deletions

View File

@@ -8,9 +8,7 @@
<ItemGroup>
<PackageReference Include="FFMpegCore" Version="5.2.0" />
<PackageReference Include="HeyRed.ImageSharp.Heif" Version="2.1.3" />
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
<PackageReference Include="LibHeif.Native" Version="1.15.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.7" />
<PackageReference Include="MaybeError" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.7" />

View File

@@ -79,6 +79,10 @@ public class AobaService(IMongoDatabase db)
{
return ex;
}
finally
{
data.Dispose();
}
}
public async Task<MaybeEx<GridFSDownloadStream, GridFSException>> GetFileStreamAsync(ObjectId mediaId, bool seekable = false, CancellationToken cancellationToken = default)

View File

@@ -3,8 +3,6 @@
using FFMpegCore;
using FFMpegCore.Pipes;
using HeyRed.ImageSharp.Heif.Formats.Avif;
using HeyRed.ImageSharp.Heif.Formats.Heif;
using MaybeError.Errors;
@@ -102,26 +100,22 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
};
}
private static Image LoadImageAsync(Stream stream, string ext)
private static Maybe<Image> LoadImage(Stream stream, string ext)
{
if (ext is ".heif" or ".avif")
{
var decoderOptions = new DecoderOptions()
{
Configuration = new Configuration(
new AvifConfigurationModule(),
new HeifConfigurationModule())
};
return Image.Load(decoderOptions, stream);
return new Error("Unsupported image type");
}
else
return Image.Load(stream);
}
public static async Task<Stream> GenerateImageThumbnailAsync(Stream stream, ThumbnailSize size, string ext, CancellationToken cancellationToken = default)
public static async Task<Maybe<Stream>> GenerateImageThumbnailAsync(Stream stream, ThumbnailSize size, string ext, CancellationToken cancellationToken = default)
{
var img = LoadImageAsync(stream, ext);
img.Mutate(o =>
var img = LoadImage(stream, ext);
if (img.HasError)
return img.Error;
img.Value.Mutate(o =>
{
var size =
o.Resize(new ResizeOptions
@@ -131,8 +125,9 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
Size = new Size(300, 300)
});
});
img.Value.Dispose();
var result = new MemoryStream();
await img.SaveAsWebpAsync(result, cancellationToken);
await img.Value.SaveAsWebpAsync(result, cancellationToken);
result.Position = 0;
return result;
}