Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(cli): run automations after screenshot record and upload

Richie McIlroyaac1a5c646d3
diff --git a/apps/cli/src/record.rs b/apps/cli/src/record.rs
index 2ae52a02a..fff1ae7a5 100644
--- a/apps/cli/src/record.rs
+++ b/apps/cli/src/record.rs
@@ -228,9 +228,21 @@ async fn foreground_inner(params: RecordParams, format: OutputFormat) -> Result<
}
let completed = finalize(actor, params.duration, interactive, None).await?;
+ crate::automation::run_recording_finished(
+ completed.project_path(),
+ automation_mode(params.mode),
+ )
+ .await;
emit_stopped(format, &completed)
}
+fn automation_mode(mode: RecordMode) -> cap_automation::AutomationRecordingMode {
+ match mode {
+ RecordMode::Studio => cap_automation::AutomationRecordingMode::Studio,
+ RecordMode::Instant => cap_automation::AutomationRecordingMode::Instant,
+ }
+}
+
async fn run_detached(params: RecordParams, format: OutputFormat) -> Result<(), String> {
match detached_inner(params, format).await {
Ok(()) => Ok(()),
@@ -432,6 +444,11 @@ async fn session_worker(params: RecordParams, recording_id: &str) -> Result<(),
let stop_path = session::stop_file(recording_id)?;
let completed = finalize(actor, params.duration, false, Some(&stop_path)).await?;
+ crate::automation::run_recording_finished(
+ completed.project_path(),
+ automation_mode(params.mode),
+ )
+ .await;
let recording_meta_exists = completed
.project_path()
.join("recording-meta.json")
diff --git a/apps/cli/src/screenshot.rs b/apps/cli/src/screenshot.rs
index 118d58ea9..3dcc8a137 100644
--- a/apps/cli/src/screenshot.rs
+++ b/apps/cli/src/screenshot.rs
@@ -57,6 +57,8 @@ impl Screenshot {
}
};
+ let automation_target = target.clone();
+
let image = capture_screenshot(target)
.await
.map_err(|e| format!("Screenshot failed: {e}"))?;
@@ -65,6 +67,8 @@ impl Screenshot {
.save(&self.path)
.map_err(|e| format!("Failed to write screenshot to {}: {e}", self.path.display()))?;
+ crate::automation::run_screenshot(&self.path, &automation_target).await;
+
match format {
OutputFormat::Json => write_json(&ScreenshotResult {
path: self.path,
diff --git a/apps/cli/src/upload.rs b/apps/cli/src/upload.rs
index 5187ff0ca..8c4c818a4 100644
--- a/apps/cli/src/upload.rs
+++ b/apps/cli/src/upload.rs
@@ -81,6 +81,16 @@ impl UploadArgs {
upload_file(&http, &put_url, &file_path).await?;
let link = format!("{server}/s/{video_id}");
+
+ let is_project = self.file.is_dir()
+ || self
+ .file
+ .extension()
+ .is_some_and(|ext| ext.eq_ignore_ascii_case("cap"));
+ if is_project {
+ crate::automation::run_upload_completed(&self.file, &link, &video_id).await;
+ }
+
match format {
OutputFormat::Json => write_json(&UploadEvent::Uploaded {
id: &video_id,
@@ -133,6 +143,30 @@ impl UploadArgs {
}
}
+/// Upload an existing MP4 video file and return its shareable link. Reuses the same credential
+/// resolution and signed-upload flow as `cap upload`, so automation-driven uploads behave identically.
+pub async fn upload_video_path(file_path: &Path, name: Option<String>) -> Result<String, String> {
+ if !is_mp4(file_path) {
+ return Err(format!(
+ "Automation upload only supports MP4 files; {} is not an .mp4",
+ file_path.display()
+ ));
+ }
+
+ let creds = credentials::resolve()?;
+ let server = creds.server.clone();
+ let meta = probe_video_meta(file_path)?;
+
+ let http = Client::new();
+ let auth = format!("Bearer {}", creds.api_key);
+
+ let video_id = create_video(&http, &server, &auth, &name, None, &meta).await?;
+ let put_url = presign_put(&http, &server, &auth, &video_id, &meta).await?;
+ upload_file(&http, &put_url, file_path).await?;
+
+ Ok(format!("{server}/s/{video_id}"))
+}
+
fn probe_video_meta(path: &Path) -> Result<VideoMeta, String> {
ffmpeg::init().map_err(|e| format!("Failed to initialise FFmpeg: {e}"))?;