From f2038843ede65ba0bff6da8cb9432b88a49f8b69 Mon Sep 17 00:00:00 2001 From: Ionite Date: Sun, 19 Nov 2023 00:56:12 -0500 Subject: [PATCH] Add GetDownload apis --- StabilityMatrix.Core/Api/ILykosAuthApi.cs | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/StabilityMatrix.Core/Api/ILykosAuthApi.cs b/StabilityMatrix.Core/Api/ILykosAuthApi.cs index 2ca76415..2d543244 100644 --- a/StabilityMatrix.Core/Api/ILykosAuthApi.cs +++ b/StabilityMatrix.Core/Api/ILykosAuthApi.cs @@ -63,4 +63,30 @@ public interface ILykosAuthApi [Headers("Authorization: Bearer")] [Delete("/api/oauth/patreon")] Task DeletePatreonOAuth(CancellationToken cancellationToken = default); + + [Headers("Authorization: Bearer")] + [Get("/api/files/download")] + Task GetDownloadRedirect( + string path, + CancellationToken cancellationToken = default + ); + + public async Task GetDownloadUrl( + string path, + CancellationToken cancellationToken = default + ) + { + var result = await GetDownloadRedirect(path, cancellationToken).ConfigureAwait(false); + + if (result.StatusCode != HttpStatusCode.Redirect) + { + result.EnsureSuccessStatusCode(); + throw new InvalidOperationException( + $"Expected a redirect 302 response, got {result.StatusCode}" + ); + } + + return result.Headers.Location?.ToString() + ?? throw new InvalidOperationException("Expected a redirect URL, but got none"); + } }