Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(cli): upload videos without requiring --name

Akshar Patel9734f2c5012b
diff --git a/apps/cli/src/upload.rs b/apps/cli/src/upload.rs
index 0844b4832..e2a95d8b8 100644
--- a/apps/cli/src/upload.rs
+++ b/apps/cli/src/upload.rs
@@ -258,6 +258,27 @@ pub async fn upload_video_path(file_path: &Path, name: Option<String>) -> Result
}
}
+fn agent_upload_payload(
+ file_name: &str,
+ name: Option<&str>,
+ content_length: u64,
+ meta: &VideoMeta,
+) -> serde_json::Value {
+ let mut payload = json!({
+ "fileName": file_name,
+ "contentType": "video/mp4",
+ "contentLength": content_length,
+ "durationSeconds": meta.duration_in_secs,
+ "width": meta.width,
+ "height": meta.height,
+ "fps": meta.fps,
+ });
+ if let Some(name) = name {
+ payload["title"] = json!(name);
+ }
+ payload
+}
+
async fn upload_file_with_agent(
file_path: &Path,
name: Option<&str>,
@@ -276,16 +297,7 @@ async fn upload_file_with_agent(
.mutate_json(
Method::POST,
"/uploads",
- &json!({
- "fileName": file_name,
- "contentType": "video/mp4",
- "contentLength": content_length,
- "durationSeconds": meta.duration_in_secs,
- "width": meta.width,
- "height": meta.height,
- "fps": meta.fps,
- "title": name,
- }),
+ &agent_upload_payload(file_name, name, content_length, meta),
)
.await
.map_err(|error| error.to_string())?;
@@ -529,9 +541,26 @@ async fn upload_file(http: &Client, put_url: &str, path: &Path) -> Result<(), St
#[cfg(test)]
mod tests {
- use super::prefer_agent_upload_sources;
+ use super::{VideoMeta, agent_upload_payload, prefer_agent_upload_sources};
use crate::credentials::{AgentCredentialSource, CredentialSource};
+ #[test]
+ fn agent_upload_payload_only_includes_a_requested_title() {
+ let meta = VideoMeta {
+ duration_in_secs: 1.0,
+ width: 640,
+ height: 360,
+ fps: 30.0,
+ };
+ for name in [None, Some("Demo"), Some("")] {
+ let payload = agent_upload_payload("demo.mp4", name, 1024, &meta);
+ match name {
+ Some(name) => assert_eq!(payload["title"], name),
+ None => assert!(payload.get("title").is_none()),
+ }
+ }
+ }
+
#[test]
fn explicit_agent_environment_credential_has_highest_upload_priority() {
assert!(prefer_agent_upload_sources(