Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fixes

Steven Teyae616fe7d138
diff --git a/apps/docs/self-hosting.mdx b/apps/docs/self-hosting.mdx
index 4f2a84b377..5c6942c084 100644
--- a/apps/docs/self-hosting.mdx
+++ b/apps/docs/self-hosting.mdx
@@ -326,8 +326,8 @@ After you create you token, copy the `Access Key ID`, `Secret Access Key` and `E
Once you have your credentials, set them in your `.env` file:
```bash
-STORAGE_ACCESS_KEY={Access Key ID}
-STORAGE_SECRET_KEY={Secret Access Key}
+STORAGE_ACCESS_KEY_ID={Access Key ID}
+STORAGE_SECRET_ACCESS_KEY={Secret Access Key}
STORAGE_ENDPOINT={Storage Endpoint}/{Bucket Name}
```
diff --git a/apps/web/app/api/cron/links/event/route.ts b/apps/web/app/api/cron/links/event/route.ts
index 58242ddb4c..da71b0b7ee 100644
--- a/apps/web/app/api/cron/links/event/route.ts
+++ b/apps/web/app/api/cron/links/event/route.ts
@@ -6,6 +6,7 @@ import { ProjectProps } from "@/lib/types";
import { formatRedisLink, redis } from "@/lib/upstash";
import {
APP_DOMAIN_WITH_NGROK,
+ DUB_THUMBNAIL,
GOOGLE_FAVICON_URL,
getApexDomain,
log,
@@ -80,6 +81,16 @@ export async function POST(req: Request) {
// increment links usage and send alert if needed
if (type === "create" && link.projectId) {
+ if (link.image === DUB_THUMBNAIL) {
+ await prisma.link.update({
+ where: {
+ id: link.id,
+ },
+ data: {
+ image: `https://${process.env.STORAGE_DOMAIN}/images/${link.id}`,
+ },
+ });
+ }
const project = await prisma.project.update({
where: {
id: link.projectId,
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index dc55476c6f..b406474e0c 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -14,6 +14,7 @@ import {
import {
DEFAULT_REDIRECTS,
DUB_DOMAINS,
+ DUB_THUMBNAIL,
SHORT_DOMAIN,
getDomainWithoutWWW,
getParamsFromURL,
@@ -504,8 +505,7 @@ export function combineTagIds({
}
export async function addLink(link: LinkWithTagIdsProps) {
- let { domain, key, url, expiresAt, title, description, image, proxy, geo } =
- link;
+ let { key, url, expiresAt, title, description, image, proxy, geo } = link;
const uploadedImage = image && image.startsWith("data:image") ? true : false;
const combinedTagIds = combineTagIds(link);
@@ -513,11 +513,6 @@ export async function addLink(link: LinkWithTagIdsProps) {
const { utm_source, utm_medium, utm_campaign, utm_term, utm_content } =
getParamsFromURL(url);
- if (proxy && image && uploadedImage) {
- const { url } = await storage.upload(`images/${key}`, image);
- image = url;
- }
-
const { tagId, tagIds, ...rest } = link;
const response = await prisma.link.create({
@@ -526,7 +521,9 @@ export async function addLink(link: LinkWithTagIdsProps) {
key,
title: truncate(title, 120),
description: truncate(description, 240),
- image,
+ // if there's an uploaded image, we put a placeholder image URL
+ // since we'll update this in the callback event after we get the link ID
+ image: uploadedImage ? DUB_THUMBNAIL : image,
utm_source,
utm_medium,
utm_campaign,
@@ -557,6 +554,12 @@ export async function addLink(link: LinkWithTagIdsProps) {
},
});
+ if (proxy && image && uploadedImage) {
+ const { url } = await storage.upload(`images/${response.id}`, image);
+ image = url;
+ console.log("image", image);
+ }
+
const shortLink = linkConstructor({
domain: response.domain,
key: response.key,
@@ -564,6 +567,7 @@ export async function addLink(link: LinkWithTagIdsProps) {
const tags = response.tags.map(({ tag }) => tag);
return {
...response,
+ image, // return the uploaded image URL (instead of the placeholder one)
tagId: tags?.[0]?.id ?? null, // backwards compatibility
tags,
shortLink,
@@ -732,7 +736,7 @@ export async function editLink({
if (proxy && image) {
// only upload image if proxy is true and there's an image
if (uploadedImage) {
- const { url } = await storage.upload(`images/${key}`, image);
+ const { url } = await storage.upload(`images/${id}`, image);
image = url;
}
} else {