Files
coop/crates/state/src/blossom.rs
reya 971a82df1b
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m47s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m52s
Rust / build (macos-latest, stable) (push) Has been cancelled
Rust / build (windows-latest, stable) (push) Has been cancelled
Rust / build (macos-latest, stable) (pull_request) Has been cancelled
Rust / build (windows-latest, stable) (pull_request) Has been cancelled
add backup panel
2026-02-25 09:11:23 +07:00

28 lines
748 B
Rust

use std::path::PathBuf;
use anyhow::{anyhow, Error};
use gpui::AsyncApp;
use gpui_tokio::Tokio;
use mime_guess::from_path;
use nostr_blossom::prelude::*;
use nostr_sdk::prelude::*;
pub async fn upload(server: Url, path: PathBuf, cx: &AsyncApp) -> Result<Url, Error> {
let content_type = from_path(&path).first_or_octet_stream().to_string();
let data = smol::fs::read(path).await?;
let keys = Keys::generate();
// Construct the blossom client
let client = BlossomClient::new(server);
Tokio::spawn(cx, async move {
let blob = client
.upload_blob(data, Some(content_type), None, Some(&keys))
.await?;
Ok(blob.url)
})
.await
.map_err(|e| anyhow!("Upload error: {e}"))?
}