mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-13 01:30:37 +00:00
add RustService method for sharing files via native share sheet
This commit is contained in:
parent
ff93f98625
commit
5a0e522620
45
app/MindWork AI Studio/Tools/Services/RustService.Share.cs
Normal file
45
app/MindWork AI Studio/Tools/Services/RustService.Share.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
namespace AIStudio.Tools.Services;
|
||||||
|
|
||||||
|
public sealed partial class RustService
|
||||||
|
{
|
||||||
|
public async Task<bool> ShareFile(string filePath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var response = await this.http.PostAsJsonAsync(
|
||||||
|
"/share/file",
|
||||||
|
new ShareFileRequest(filePath),
|
||||||
|
this.jsonRustSerializerOptions);
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
this.logger?.LogError($"The Rust runtime rejected the share request: {response.StatusCode}.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await response.Content.ReadFromJsonAsync<ShareFileResponse>(this.jsonRustSerializerOptions);
|
||||||
|
if (result?.Success == true)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
this.logger?.LogError($"The native share sheet could not be opened: {result?.Issue ?? "Unknown error"}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (HttpRequestException exception)
|
||||||
|
{
|
||||||
|
this.logger?.LogWarning(exception, "Failed to reach the Rust runtime share endpoint.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (TaskCanceledException exception)
|
||||||
|
{
|
||||||
|
this.logger?.LogWarning(exception, "Timed out while reaching the Rust runtime share endpoint.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
this.logger?.LogError(exception, "Failed to process the Rust runtime share response.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed record ShareFileRequest(string FilePath);
|
||||||
|
private sealed record ShareFileResponse(bool Success, string Issue);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user