Use new API v1 path for uploads

This commit is contained in:
Marcin Kulik
2025-07-09 16:01:54 +02:00
parent 06a0fd81a9
commit e8b3591c10
2 changed files with 8 additions and 8 deletions

View File

@@ -10,7 +10,7 @@ use url::Url;
use crate::config::Config; use crate::config::Config;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct UploadAsciicastResponse { pub struct RecordingResponse {
pub url: String, pub url: String,
pub message: Option<String>, pub message: Option<String>,
} }
@@ -33,11 +33,11 @@ pub fn get_auth_url(config: &Config) -> Result<Url> {
Ok(url) Ok(url)
} }
pub async fn upload_asciicast(path: &str, config: &Config) -> Result<UploadAsciicastResponse> { pub async fn create_recording(path: &str, config: &Config) -> Result<RecordingResponse> {
let server_url = &config.get_server_url()?; let server_url = &config.get_server_url()?;
let install_id = config.get_install_id()?; let install_id = config.get_install_id()?;
let response = upload_request(server_url, path, install_id) let response = create_recording_request(server_url, path, install_id)
.await? .await?
.send() .send()
.await?; .await?;
@@ -48,18 +48,18 @@ pub async fn upload_asciicast(path: &str, config: &Config) -> Result<UploadAscii
response.error_for_status_ref()?; response.error_for_status_ref()?;
Ok(response.json::<UploadAsciicastResponse>().await?) Ok(response.json::<RecordingResponse>().await?)
} }
async fn upload_request( async fn create_recording_request(
server_url: &Url, server_url: &Url,
path: &str, path: &str,
install_id: String, install_id: String,
) -> Result<RequestBuilder> { ) -> Result<RequestBuilder> {
let client = Client::new(); let client = Client::new();
let mut url = server_url.clone(); let mut url = server_url.clone();
url.set_path("api/asciicasts"); url.set_path("api/v1/recordings");
let form = Form::new().file("asciicast", path).await?; let form = Form::new().file("file", path).await?;
Ok(client Ok(client
.post(url) .post(url)

View File

@@ -14,7 +14,7 @@ impl cli::Upload {
async fn do_run(self) -> Result<()> { async fn do_run(self) -> Result<()> {
let config = Config::new(self.server_url.clone())?; let config = Config::new(self.server_url.clone())?;
let _ = asciicast::open_from_path(&self.file)?; let _ = asciicast::open_from_path(&self.file)?;
let response = api::upload_asciicast(&self.file, &config).await?; let response = api::create_recording(&self.file, &config).await?;
println!("{}", response.message.unwrap_or(response.url)); println!("{}", response.message.unwrap_or(response.url));
Ok(()) Ok(())