Remove ThumbHasher from Property
This commit is contained in:
@ -376,45 +376,7 @@ public partial class DlibDotNet
|
||||
List<Tuple<string, DateTime>> subFileTuples = new();
|
||||
List<KeyValuePair<string, string>> metadataCollection;
|
||||
FileHolder resizedFileHolder = _Resize.GetResizedFileHolder(item);
|
||||
if (item.Property is not null && item.Property.Id is not null && resizedFileHolder.Exists && item.Property.ThumbHashBytes is null)
|
||||
{
|
||||
(string aResultsFullGroupDirectory, _) = GetResultsFullGroupDirectories();
|
||||
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, "{}");
|
||||
string[] files = Directory.GetFiles(aPropertySingletonDirectory, $"{item.Property.Id.Value}*", SearchOption.AllDirectories);
|
||||
if (files.Length == 1)
|
||||
{
|
||||
string matchFile = files.First();
|
||||
string json = File.ReadAllText(matchFile);
|
||||
string find = "\"CreationTime\":";
|
||||
if (!json.Contains(find))
|
||||
throw new NotImplementedException();
|
||||
byte[]? thumbHashBytes = _IThumbHasher.Encode(resizedFileHolder.FullName);
|
||||
string thumbHashJson = JsonSerializer.Serialize(thumbHashBytes);
|
||||
json = json.Replace(find, $"\"{nameof(property.ThumbHashBytes)}\": {thumbHashJson}, {find}");
|
||||
property = JsonSerializer.Deserialize<Shared.Models.Property>(json);
|
||||
if (property is null || property.ThumbHashBytes is null)
|
||||
throw new NullReferenceException(nameof(property));
|
||||
json = JsonSerializer.Serialize(property, new JsonSerializerOptions { WriteIndented = true });
|
||||
if (thumbHashBytes is null || thumbHashBytes.Length != property.ThumbHashBytes.Length)
|
||||
throw new Exception(nameof(property.ThumbHashBytes));
|
||||
for (int i = 0; i < thumbHashBytes.Length; i++)
|
||||
{
|
||||
if (thumbHashBytes[i] != property.ThumbHashBytes[i])
|
||||
throw new Exception(nameof(property.ThumbHashBytes));
|
||||
}
|
||||
thumbHashBytes = JsonSerializer.Deserialize<byte[]>(thumbHashJson);
|
||||
if (thumbHashBytes is null || thumbHashBytes.Length != property.ThumbHashBytes.Length)
|
||||
throw new Exception(nameof(property.ThumbHashBytes));
|
||||
for (int i = 0; i < thumbHashBytes.Length; i++)
|
||||
{
|
||||
if (thumbHashBytes[i] != property.ThumbHashBytes[i])
|
||||
throw new Exception(nameof(property.ThumbHashBytes));
|
||||
}
|
||||
File.WriteAllText(matchFile, json);
|
||||
File.SetLastWriteTime(matchFile, item.Property.LastWriteTime);
|
||||
}
|
||||
}
|
||||
if (item.Property is not null && item.Property.Id is not null && resizedFileHolder.Exists && item.Property.Width is not null && item.Property.Height is not null && item.Property.ThumbHashBytes is not null)
|
||||
if (item.Property is not null && item.Property.Id is not null && resizedFileHolder.Exists && item.Property.Width is not null && item.Property.Height is not null)
|
||||
{
|
||||
string fileName;
|
||||
string c2ThumbHasherContentDirectory = Path.Combine(c2ResultsFullGroupDirectory, "()");
|
||||
@ -423,13 +385,13 @@ public partial class DlibDotNet
|
||||
_ = Directory.CreateDirectory(c2ThumbHasherContentDirectory);
|
||||
if (!Directory.Exists(c2ThumbHasherSingletonDirectory))
|
||||
_ = Directory.CreateDirectory(c2ThumbHasherSingletonDirectory);
|
||||
MemoryStream memoryStream = _IThumbHasher.GetMemoryStream(item.Property.ThumbHashBytes, item.Property.Width.Value, item.Property.Height.Value);
|
||||
string thumbHashJson = JsonSerializer.Serialize(item.Property.ThumbHashBytes)[1..^1];
|
||||
MemoryStream memoryStream = _IThumbHasher.GetMemoryStream(Array.Empty<byte>(), item.Property.Width.Value, item.Property.Height.Value);
|
||||
string thumbHashJson = JsonSerializer.Serialize(Array.Empty<byte>())[1..^1];
|
||||
if (!Regex.Matches(thumbHashJson, @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]").Any())
|
||||
fileName = Path.Combine(c2ThumbHasherSingletonDirectory, $"{thumbHashJson}.png");
|
||||
else
|
||||
{
|
||||
// string thumbHash = BitConverter.ToString(item.Property.ThumbHashBytes).Replace("-", string.Empty);
|
||||
// string thumbHash = BitConverter.ToString(Array.Empty<byte>()).Replace("-", string.Empty);
|
||||
// fileName = Path.Combine(c2ThumbHasherContentDirectory, $"{thumbHash}.png");
|
||||
fileName = Path.Combine(c2ThumbHasherContentDirectory, $"{resizedFileHolder.NameWithoutExtension}.png");
|
||||
}
|
||||
@ -467,7 +429,7 @@ public partial class DlibDotNet
|
||||
_Log.Information(string.Concat("LastWriteTimeChanged <", item.ImageFileHolder.FullName, '>'));
|
||||
else if (item.Moved.HasValue && item.Moved.Value)
|
||||
_Log.Information(string.Concat("Moved <", item.ImageFileHolder.FullName, '>'));
|
||||
property = propertyLogic.GetProperty(_IThumbHasher, item, subFileTuples, parseExceptions);
|
||||
property = propertyLogic.GetProperty(item, subFileTuples, parseExceptions);
|
||||
item.Update(property);
|
||||
if (propertyHashCode is null)
|
||||
{
|
||||
|
Reference in New Issue
Block a user