Skip to content

Commit c7b232f

Browse files
authored
Remove dev stuff
1 parent 7c623ae commit c7b232f

File tree

1 file changed

+0
-109
lines changed

1 file changed

+0
-109
lines changed

StabilityMatrix.Avalonia/Services/ModelImportService.cs

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -183,115 +183,6 @@ public async Task DoImport(
183183

184184
await trackedDownloadService.TryStartDownload(download);
185185
}
186-
public Task DoOpenModelDbImport(
187-
OpenModelDbKeyedModel model,
188-
OpenModelDbResource resource,
189-
DirectoryPath downloadFolder,
190-
Action<TrackedDownload>? configureDownload = null
191-
)
192-
{
193-
// todo: maybe can get actual filename from url?
194-
ArgumentException.ThrowIfNullOrEmpty(model.Id, nameof(model));
195-
ArgumentException.ThrowIfNullOrEmpty(resource.Type, nameof(resource));
196-
var modelFileName = $"{model.Id}.{resource.Type}";
197-
198-
var modelUris = resource.Urls?.Select(u => new Uri(u, UriKind.Absolute)).ToArray();
199-
if (modelUris is null || modelUris.Length == 0)
200-
{
201-
notificationService.Show(
202-
new Notification(
203-
"Model has no download links",
204-
"This model has no download links available",
205-
NotificationType.Warning
206-
)
207-
);
208-
return Task.CompletedTask;
209-
}
210-
211-
return DoCustomImport(
212-
modelUris,
213-
modelFileName,
214-
downloadFolder,
215-
model.Images?.SelectImageAbsoluteUris().FirstOrDefault(),
216-
configureDownload: configureDownload,
217-
connectedModelInfo: new ConnectedModelInfo(model, resource, DateTimeOffset.Now)
218-
);
219-
}
220-
221-
public async Task DoCustomImport(
222-
IEnumerable<Uri> modelUris,
223-
string modelFileName,
224-
DirectoryPath downloadFolder,
225-
Uri? previewImageUri = null,
226-
string? previewImageFileExtension = null,
227-
ConnectedModelInfo? connectedModelInfo = null,
228-
Action<TrackedDownload>? configureDownload = null
229-
)
230-
{
231-
// Folders might be missing if user didn't install any packages yet
232-
downloadFolder.Create();
233-
234-
// Fix invalid chars in FileName
235-
var modelBaseFileName = Path.GetFileNameWithoutExtension(modelFileName);
236-
modelBaseFileName = Path.GetInvalidFileNameChars()
237-
.Aggregate(modelBaseFileName, (current, c) => current.Replace(c, '_'));
238-
var modelFileExtension = Path.GetExtension(modelFileName);
239-
240-
var downloadPath = downloadFolder.JoinFile(modelBaseFileName + modelFileExtension);
241-
242-
// Save model info and preview image first if available
243-
var cleanupFilePaths = new List<string>();
244-
if (connectedModelInfo is not null)
245-
{
246-
await connectedModelInfo.SaveJsonToDirectory(downloadFolder, modelBaseFileName);
247-
cleanupFilePaths.Add(
248-
downloadFolder.JoinFile(modelBaseFileName + ConnectedModelInfo.FileExtension)
249-
);
250-
}
251-
if (previewImageUri is not null)
252-
{
253-
if (previewImageFileExtension is null)
254-
{
255-
previewImageFileExtension = Path.GetExtension(previewImageUri.LocalPath);
256-
if (string.IsNullOrEmpty(previewImageFileExtension))
257-
{
258-
throw new InvalidOperationException(
259-
"Unable to get preview image file extension from from Uri, and no file extension provided"
260-
);
261-
}
262-
}
263-
264-
var previewImageDownloadPath = downloadFolder.JoinFile(
265-
modelBaseFileName + ".preview" + previewImageFileExtension
266-
);
267-
268-
await notificationService.TryAsync(
269-
downloadService.DownloadToFileAsync(previewImageUri.ToString(), previewImageDownloadPath),
270-
"Could not download preview image"
271-
);
272-
273-
cleanupFilePaths.Add(previewImageDownloadPath);
274-
}
275-
276-
// Create tracked download
277-
// todo: support multiple uris
278-
var modelUri = modelUris.First();
279-
var download = trackedDownloadService.NewDownload(modelUri, downloadPath);
280-
281-
// Add hash info
282-
// download.ExpectedHashSha256 = modelFile.Hashes.SHA256;
283-
284-
// Add files to cleanup list
285-
download.ExtraCleanupFileNames.AddRange(cleanupFilePaths);
286-
287-
// Configure
288-
configureDownload?.Invoke(download);
289-
290-
// Add hash context action
291-
// download.ContextAction = CivitPostDownloadContextAction.FromCivitFile(modelFile);
292-
293-
await trackedDownloadService.TryStartDownload(download);
294-
}
295186

296187
private string GenerateUniqueFileName(string folder, string fileName)
297188
{

0 commit comments

Comments
 (0)