Browse Source

Merge branch 'main' into fix-console-generation-progress

pull/14/head
JT 1 year ago committed by GitHub
parent
commit
783e46731b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      StabilityMatrix/CheckpointManagerPage.xaml
  2. 35
      StabilityMatrix/Helper/ModelFinder.cs

5
StabilityMatrix/CheckpointManagerPage.xaml

@ -322,7 +322,10 @@
</DrawingBrush>
</Border.BorderBrush>
</Border>
<VirtualizingStackPanel Orientation="Vertical" VerticalAlignment="Center">
<VirtualizingStackPanel
Margin="0,8"
Orientation="Vertical"
VerticalAlignment="Center">
<TextBlock
Effect="{StaticResource TextDropShadowEffect}"
FontSize="24"

35
StabilityMatrix/Helper/ModelFinder.cs

@ -1,6 +1,8 @@
using System.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using NLog;
using Refit;
using StabilityMatrix.Api;
using StabilityMatrix.Database;
using StabilityMatrix.Models.Api;
@ -41,18 +43,27 @@ public class ModelFinder
public async Task<ModelSearchResult?> RemoteFindModel(string hashBlake3)
{
Logger.Info("Searching Civit API for model version using hash {Hash}", hashBlake3);
var versionResponse = await civitApi.GetModelVersionByHash(hashBlake3);
Logger.Info("Found version {VersionId} with model id {ModelId}",
versionResponse.Id, versionResponse.ModelId);
var model = await civitApi.GetModelById(versionResponse.ModelId);
try
{
var versionResponse = await civitApi.GetModelVersionByHash(hashBlake3);
Logger.Info("Found version {VersionId} with model id {ModelId}",
versionResponse.Id, versionResponse.ModelId);
var model = await civitApi.GetModelById(versionResponse.ModelId);
// VersionResponse is not actually the full data of ModelVersion, so find it again
var version = model.ModelVersions!.First(version => version.Id == versionResponse.Id);
// VersionResponse is not actually the full data of ModelVersion, so find it again
var version = model.ModelVersions!.First(version => version.Id == versionResponse.Id);
var file = versionResponse.Files
.First(file => file.Hashes.BLAKE3?.ToLowerInvariant() == hashBlake3);
var file = versionResponse.Files
.First(file => file.Hashes.BLAKE3?.ToLowerInvariant() == hashBlake3);
return new ModelSearchResult(model, version, file);
return new ModelSearchResult(model, version, file);
}
catch (ApiException e)
{
Logger.Info("Could not find remote model version using hash {Hash}: {Error}",
hashBlake3, e.Message);
return null;
}
}
}

Loading…
Cancel
Save