Use stable images ids to prevent duplicated (#452)

This commit is contained in:
Zoe Roux 2024-04-29 22:26:28 +02:00 committed by GitHub
commit 3665070b97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -62,7 +62,7 @@ public class MiscRepository(
}.Select(x => GetSql(x));
string sql = string.Join(" union all ", queries);
IEnumerable<Image?> ret = await database.QueryAsync<Image?>(sql);
return ret.Where(x => x != null).ToArray() as Image[];
return ret.ToArray() as Image[];
}
public async Task DownloadMissingImages()

View File

@ -24,7 +24,6 @@ using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Blurhash.SkiaSharp;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models;
@ -80,7 +79,11 @@ public class ThumbnailsManager(
try
{
if (image.Id == Guid.Empty)
image.Id = Guid.NewGuid();
{
// Ensure stable ids to prevent duplicated images being stored on the fs.
using MD5 md5 = MD5.Create();
image.Id = new Guid(md5.ComputeHash(Encoding.UTF8.GetBytes(image.Source)));
}
logger.LogInformation("Downloading image {What}", what);