mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
move InMeilisearchFormat to MeiliSync.cs
This commit is contained in:
parent
505c51923f
commit
d683943eb3
@ -1,4 +1,3 @@
|
||||
using System.Collections;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using static System.Text.Json.JsonNamingPolicy;
|
||||
@ -46,22 +45,7 @@ internal static class FilterExtensionMethods
|
||||
};
|
||||
}
|
||||
|
||||
public static object? InMeilisearchFormat(this object? value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
null => null,
|
||||
string => value,
|
||||
Enum => value.ToString(),
|
||||
IEnumerable enumerable
|
||||
=> enumerable.Cast<object>().Select(InMeilisearchFormat).ToArray(),
|
||||
DateTimeOffset dateTime => dateTime.ToUnixTimeSeconds(),
|
||||
DateOnly date => date.ToUnixTimeSeconds(),
|
||||
_ => value
|
||||
};
|
||||
}
|
||||
|
||||
private static long ToUnixTimeSeconds(this DateOnly date)
|
||||
public static long ToUnixTimeSeconds(this DateOnly date)
|
||||
{
|
||||
return new DateTimeOffset(date.ToDateTime(new TimeOnly())).ToUnixTimeSeconds();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Collections;
|
||||
using System.Dynamic;
|
||||
using System.Reflection;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
@ -62,7 +63,7 @@ public class MeiliSync
|
||||
foreach (PropertyInfo property in item.GetType().GetProperties())
|
||||
dictionary.Add(
|
||||
CamelCase.ConvertName(property.Name),
|
||||
property.GetValue(item).InMeilisearchFormat()
|
||||
ConvertToMeilisearchFormat(property.GetValue(item))
|
||||
);
|
||||
dictionary.Add("ref", $"{kind}-{item.Id}");
|
||||
expando.kind = kind;
|
||||
@ -79,4 +80,19 @@ public class MeiliSync
|
||||
}
|
||||
return _client.Index(index).DeleteOneDocumentAsync(id.ToString());
|
||||
}
|
||||
|
||||
private object? ConvertToMeilisearchFormat(object? value)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
null => null,
|
||||
string => value,
|
||||
Enum => value.ToString(),
|
||||
IEnumerable enumerable
|
||||
=> enumerable.Cast<object>().Select(ConvertToMeilisearchFormat).ToArray(),
|
||||
DateTimeOffset dateTime => dateTime.ToUnixTimeSeconds(),
|
||||
DateOnly date => date.ToUnixTimeSeconds(),
|
||||
_ => value
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user