diff --git a/.env.sample b/.env.sample index fce81663bb..eb57ad85c6 100644 --- a/.env.sample +++ b/.env.sample @@ -189,6 +189,10 @@ SLACK_VERIFICATION_TOKEN=your_token SLACK_APP_ID=A0XXXXXXX SLACK_MESSAGE_ACTIONS=true +# For Dropbox integration, follow these instructions to get the key https://www.dropbox.com/developers/embedder#setup +# and do not forget to whitelist your domain name in the app settings +DROPBOX_APP_KEY= + # Optionally enable Sentry (sentry.io) to track errors and performance, # and optionally add a Sentry proxy tunnel for bypassing ad blockers in the UI: # https://docs.sentry.io/platforms/javascript/troubleshooting/#using-the-tunnel-option) diff --git a/public/images/dropbox.png b/public/images/dropbox.png new file mode 100644 index 0000000000..8f1744c0d9 Binary files /dev/null and b/public/images/dropbox.png differ diff --git a/server/env.ts b/server/env.ts index c6ffdd2c2f..84ac65f70f 100644 --- a/server/env.ts +++ b/server/env.ts @@ -348,6 +348,13 @@ export class Environment { */ public SMTP_SECURE = this.toBoolean(environment.SMTP_SECURE ?? "true"); + /** + * Dropbox app key for embedding Dropbox files + */ + @Public + @IsOptional() + public DROPBOX_APP_KEY = this.toOptionalString(environment.DROPBOX_APP_KEY); + /** * Sentry DSN for capturing errors and frontend performance. */ diff --git a/server/routes/embeds.ts b/server/routes/embeds.ts index 6a175d7516..15359823c6 100644 --- a/server/routes/embeds.ts +++ b/server/routes/embeds.ts @@ -1,5 +1,6 @@ import escape from "escape-html"; import { Context, Next } from "koa"; +import env from "@server/env"; /** * Resize observer script that sends a message to the parent window when content is resized. Inject @@ -117,5 +118,38 @@ ${resizeObserverScript(ctx)} return; } + if ( + parsed.host === "www.dropbox.com" && + parsed.protocol === "https:" && + ctx.path === "/embeds/dropbox" + ) { + const dropboxJs = "https://www.dropbox.com/static/api/2/dropins.js"; + const csp = ctx.response.get("Content-Security-Policy"); + + // Inject Dropbox domain into the script-src directive + ctx.set( + "Content-Security-Policy", + csp.replace("script-src", "script-src www.dropbox.com") + ); + ctx.set("X-Frame-Options", "sameorigin"); + + ctx.type = "html"; + ctx.body = ` + +
+ +
,
}),
+ ...(env.DROPBOX_APP_KEY
+ ? [
+ new EmbedDescriptor({
+ title: "Dropbox",
+ keywords: "file document",
+ regexMatch: [
+ new RegExp("^https?://(www.)?dropbox.com/(s|scl)/(.*)$"),
+ ],
+ icon:
,
+ component: Dropbox,
+ }),
+ ]
+ : []),
new EmbedDescriptor({
title: "Figma",
keywords: "design svg vector",