Compare commits
2 Commits
v1.1.33
...
3dca408356
| Author | SHA1 | Date | |
|---|---|---|---|
| 3dca408356 | |||
| 1655e342b7 |
@@ -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" />
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user