Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Add provider select

Richie McIlroy1cef9e48b231
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/apps/s3-config.tsx b/apps/desktop/src/routes/(window-chrome)/settings/apps/s3-config.tsx
index 346933534..b6a76f3fb 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/apps/s3-config.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/apps/s3-config.tsx
@@ -6,6 +6,7 @@ import { clientEnv } from "~/utils/env";
import { commands } from "~/utils/tauri";
interface S3Config {
+ provider: string;
accessKeyId: string;
secretAccessKey: string;
endpoint: string;
@@ -14,6 +15,7 @@ interface S3Config {
}
export default function S3ConfigPage() {
+ const [provider, setProvider] = createSignal("aws");
const [accessKeyId, setAccessKeyId] = createSignal("");
const [secretAccessKey, setSecretAccessKey] = createSignal("");
const [endpoint, setEndpoint] = createSignal("https://s3.amazonaws.com");
@@ -51,6 +53,7 @@ export default function S3ConfigPage() {
const data = await response.json();
if (data.config) {
const config = data.config as S3Config;
+ setProvider(config.provider || "aws");
setAccessKeyId(config.accessKeyId);
setSecretAccessKey(config.secretAccessKey);
setEndpoint(config.endpoint || "https://s3.amazonaws.com");
@@ -86,6 +89,7 @@ export default function S3ConfigPage() {
Authorization: `Bearer ${auth.token}`,
},
body: JSON.stringify({
+ provider: provider(),
accessKeyId: accessKeyId(),
secretAccessKey: secretAccessKey(),
endpoint: endpoint(),
@@ -122,18 +126,48 @@ export default function S3ConfigPage() {
<div class="space-y-4">
<div>
<p class="text-gray-400 text-sm">
- It should take under 10 minutes to set up and connect your S3
- bucket to Cap. View the{" "}
+ It should take under 10 minutes to set up and connect your
+ storage bucket to Cap. View the{" "}
<a
href="https://cap.so/docs/s3-config"
target="_blank"
class="text-gray-500 font-semibold underline"
>
- S3 Config Guide
+ Storage Config Guide
</a>{" "}
to get started.
</p>
</div>
+
+ <div>
+ <label class="text-gray-500 text-sm">Storage Provider</label>
+ <div class="relative">
+ <select
+ value={provider()}
+ onChange={(e) => setProvider(e.currentTarget.value)}
+ class="w-full px-3 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 appearance-none bg-white pr-10"
+ >
+ <option value="aws">AWS S3</option>
+ <option value="cloudflare">Cloudflare R2</option>
+ <option value="other">Other S3-Compatible</option>
+ </select>
+ <div class="absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none">
+ <svg
+ class="w-4 h-4 text-gray-400"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
+ clip-rule="evenodd"
+ />
+ </svg>
+ </div>
+ </div>
+ </div>
+
<div>
<label class="text-gray-500 text-sm">Access Key ID</label>
<input
diff --git a/apps/web/app/api/desktop/s3/config/get/route.ts b/apps/web/app/api/desktop/s3/config/get/route.ts
index 787f7d782..a516c1192 100644
--- a/apps/web/app/api/desktop/s3/config/get/route.ts
+++ b/apps/web/app/api/desktop/s3/config/get/route.ts
@@ -73,6 +73,7 @@ export async function GET(request: NextRequest) {
const encryptedConfig = await db
.select({
+ provider: s3Buckets.provider,
accessKeyId: s3Buckets.accessKeyId,
secretAccessKey: s3Buckets.secretAccessKey,
endpoint: s3Buckets.endpoint,
@@ -82,8 +83,8 @@ export async function GET(request: NextRequest) {
.from(s3Buckets)
.where(eq(s3Buckets.ownerId, user.id));
- // Decrypt the config before sending
const config = encryptedConfig[0] ? {
+ provider: encryptedConfig[0].provider,
accessKeyId: decrypt(encryptedConfig[0].accessKeyId),
secretAccessKey: decrypt(encryptedConfig[0].secretAccessKey),
endpoint: encryptedConfig[0].endpoint ? decrypt(encryptedConfig[0].endpoint) : null,
diff --git a/apps/web/app/api/desktop/s3/config/route.ts b/apps/web/app/api/desktop/s3/config/route.ts
index c0f2431d5..afe7af81e 100644
--- a/apps/web/app/api/desktop/s3/config/route.ts
+++ b/apps/web/app/api/desktop/s3/config/route.ts
@@ -55,10 +55,11 @@ export async function POST(request: NextRequest) {
console.log("[S3 Config] User authenticated", { userId: user.id });
- const { accessKeyId, secretAccessKey, endpoint, bucketName, region } =
+ const { provider, accessKeyId, secretAccessKey, endpoint, bucketName, region } =
await request.json();
console.log("[S3 Config] Received S3 config data", {
+ provider,
hasAccessKeyId: !!accessKeyId,
hasSecretKey: !!secretAccessKey,
endpoint,
@@ -77,6 +78,7 @@ export async function POST(request: NextRequest) {
// Encrypt sensitive data before storing
const encryptedData = {
id: existingBucket[0]?.id || nanoId(),
+ provider,
accessKeyId: encrypt(accessKeyId),
secretAccessKey: encrypt(secretAccessKey),
endpoint: endpoint ? encrypt(endpoint) : null,
@@ -92,6 +94,7 @@ export async function POST(request: NextRequest) {
.values(encryptedData)
.onDuplicateKeyUpdate({
set: {
+ provider: encryptedData.provider,
accessKeyId: encryptedData.accessKeyId,
secretAccessKey: encryptedData.secretAccessKey,
endpoint: encryptedData.endpoint,
diff --git a/apps/web/utils/s3.ts b/apps/web/utils/s3.ts
index 7bcfe842c..17853d54d 100644
--- a/apps/web/utils/s3.ts
+++ b/apps/web/utils/s3.ts
@@ -38,6 +38,7 @@ export function getS3Config(config?: S3Config) {
}
return {
+ forcePathStyle: true,
endpoint: config.endpoint ? tryDecrypt(config.endpoint) : process.env.NEXT_PUBLIC_CAP_AWS_ENDPOINT,
region: tryDecrypt(config.region) ?? process.env.NEXT_PUBLIC_CAP_AWS_REGION,
credentials: {
diff --git a/packages/database/schema.ts b/packages/database/schema.ts
index d2c1b3117..2f3521af5 100644
--- a/packages/database/schema.ts
+++ b/packages/database/schema.ts
@@ -271,6 +271,7 @@ export const s3Buckets = mysqlTable("s3_buckets", {
bucketName: encryptedText("bucketName").notNull(),
accessKeyId: encryptedText("accessKeyId").notNull(),
secretAccessKey: encryptedText("secretAccessKey").notNull(),
+ provider: text("provider").notNull().default("aws"),
});
export const commentsRelations = relations(comments, ({ one }) => ({