using LiteDB;
namespace StabilityMatrix.Core.Models.Database;
///
/// Represents a locally indexed model file.
///
public class LocalModelFile
{
///
/// Relative path to the file from the root model directory.
///
[BsonId]
public required string RelativePath { get; set; }
///
/// Type of the model file.
///
public required SharedFolderType SharedFolderType { get; set; }
///
/// Optional connected model information.
///
public ConnectedModelInfo? ConnectedModelInfo { get; set; }
///
/// Optional preview image relative path.
///
public string? PreviewImageRelativePath { get; set; }
///
/// File name of the relative path.
///
public string FileName => Path.GetFileName(RelativePath);
///
/// File name of the relative path without extension.
///
public string FileNameWithoutExtension => Path.GetFileNameWithoutExtension(RelativePath);
public string GetFullPath(string rootModelDirectory)
{
return Path.Combine(rootModelDirectory, RelativePath);
}
public string? GetPreviewImageFullPath(string rootModelDirectory)
{
return PreviewImageRelativePath == null
? null
: Path.Combine(rootModelDirectory, PreviewImageRelativePath);
}
public string FullPathGlobal => GetFullPath(GlobalConfig.LibraryDir.JoinDir("Models"));
public string? PreviewImageFullPathGlobal =>
GetPreviewImageFullPath(GlobalConfig.LibraryDir.JoinDir("Models"));
protected bool Equals(LocalModelFile other)
{
return RelativePath == other.RelativePath;
}
///
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != this.GetType())
return false;
return Equals((LocalModelFile)obj);
}
///
public override int GetHashCode()
{
return RelativePath.GetHashCode();
}
public static readonly HashSet SupportedCheckpointExtensions =
new() { ".safetensors", ".pt", ".ckpt", ".pth", ".bin" };
public static readonly HashSet SupportedImageExtensions =
new() { ".png", ".jpg", ".jpeg" };
public static readonly HashSet SupportedMetadataExtensions = new() { ".json" };
}