Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: CloudFront invalidation for reupload. + misc changes

Richie McIlroy638ddaeb386e
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index a194f6c33..94f790452 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -2005,7 +2005,28 @@ pub async fn run() {
.expect("error while running tauri application")
.run(|handle, event| match event {
#[cfg(target_os = "macos")]
- tauri::RunEvent::Reopen { .. } => open_main_window(handle.clone()),
+ tauri::RunEvent::Reopen { .. } => {
+ // Check if any editor window is open
+ let has_editor = handle
+ .webview_windows()
+ .iter()
+ .any(|(label, _)| label.starts_with("editor-"));
+
+ if has_editor {
+ // Find and focus the editor window
+ if let Some(editor_window) = handle
+ .webview_windows()
+ .iter()
+ .find(|(label, _)| label.starts_with("editor-"))
+ .map(|(_, window)| window.clone())
+ {
+ editor_window.set_focus().ok();
+ }
+ } else {
+ // No editor window open, show main window
+ open_main_window(handle.clone());
+ }
+ }
_ => {}
});
}
diff --git a/apps/web/app/api/upload/signed/route.ts b/apps/web/app/api/upload/signed/route.ts
index 95046e27c..a0f53d8d5 100644
--- a/apps/web/app/api/upload/signed/route.ts
+++ b/apps/web/app/api/upload/signed/route.ts
@@ -3,13 +3,13 @@ import {
createPresignedPost,
type PresignedPost,
} from "@aws-sdk/s3-presigned-post";
+import { CloudFrontClient, CreateInvalidationCommand } from "@aws-sdk/client-cloudfront";
import { db } from "@cap/database";
import { getCurrentUser } from "@cap/database/auth/session";
import { s3Buckets } from "@cap/database/schema";
import { eq } from "drizzle-orm";
import { cookies } from "next/headers";
import type { NextRequest } from "next/server";
-import { decrypt } from "@cap/database/crypto";
export async function POST(request: NextRequest) {
try {
@@ -66,6 +66,41 @@ export async function POST(request: NextRequest) {
secretAccessKey: bucket.secretAccessKey,
} : null;
+ if (!bucket || !s3Config || bucket.bucketName !== process.env.CAP_S3_BUCKET) {
+ const distributionId = process.env.CAP_CLOUDFRONT_DISTRIBUTION_ID;
+ if (distributionId) {
+ console.log("Creating CloudFront invalidation for", fileKey);
+
+ const cloudfront = new CloudFrontClient({
+ region: process.env.NEXT_PUBLIC_CAP_AWS_REGION || "us-east-1",
+ credentials: {
+ accessKeyId: process.env.CAP_AWS_ACCESS_KEY || "",
+ secretAccessKey: process.env.CAP_AWS_SECRET_KEY || "",
+ }
+ });
+
+ const pathToInvalidate = "/" + fileKey;
+
+ try {
+ const invalidation = await cloudfront.send(
+ new CreateInvalidationCommand({
+ DistributionId: distributionId,
+ InvalidationBatch: {
+ CallerReference: `${Date.now()}`,
+ Paths: {
+ Quantity: 1,
+ Items: [pathToInvalidate],
+ },
+ },
+ })
+ );
+ console.log("CloudFront invalidation created:", invalidation);
+ } catch (error) {
+ console.error("Failed to create CloudFront invalidation:", error);
+ }
+ }
+ }
+
console.log("Creating S3 client with config:", {
hasEndpoint: !!s3Config?.endpoint,
hasRegion: !!s3Config?.region,
@@ -98,7 +133,6 @@ export async function POST(request: NextRequest) {
};
const bucketName = await getS3Bucket(bucket);
- console.log("Using bucket:", bucketName);
const presignedPostData: PresignedPost = await createPresignedPost(
s3Client,
diff --git a/crates/flags/src/lib.rs b/crates/flags/src/lib.rs
index 3732488a4..550e9a808 100644
--- a/crates/flags/src/lib.rs
+++ b/crates/flags/src/lib.rs
@@ -13,5 +13,5 @@ pub const FLAGS: Flags = Flags {
split: false, // cfg!(debug_assertions),
pause_resume: false, // cfg!(debug_assertions),
zoom: false, // cfg!(debug_assertions),
- custom_s3: false,
+ custom_s3: true,
};