The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
small fixes
Steven Teyd8af3c860e58
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tsindex 17b2d9bdb0..1b9f9a1506 100644--- a/apps/web/app/api/links/[linkId]/route.ts+++ b/apps/web/app/api/links/[linkId]/route.ts@@ -110,14 +110,7 @@ export const PUT = withAuth(async ({ req, headers, project, link }) => {// DELETE /api/links/[linkId] – delete a linkexport const DELETE = withAuth(async ({ headers, link }) => {- if (!link) {- throw new DubApiError({- code: "not_found",- message: "Link not found.",- });- }- const response = await deleteLink(link.id);-+ const response = await deleteLink(link!.id);return NextResponse.json(response[0], {headers,});diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.tsindex 9a9bf864f0..876b08e479 100644--- a/apps/web/lib/api/links.ts+++ b/apps/web/lib/api/links.ts@@ -832,12 +832,7 @@ export async function deleteLink(linkId: string) {tags: true,},});- return await Promise.all([- prisma.link.delete({- where: {- id: link.id,- },- }),+ return await Promise.allSettled([link.proxy && link.image && storage.delete(`images/${link.id}`),redis.hdel(link.domain, link.key.toLowerCase()),recordLink({ link, deleted: true }),diff --git a/apps/web/lib/storage.ts b/apps/web/lib/storage.tsindex 427826c45c..f3145c902e 100644--- a/apps/web/lib/storage.ts+++ b/apps/web/lib/storage.ts@@ -1,65 +1,74 @@-import { AwsClient } from 'aws4fetch';+import { AwsClient } from "aws4fetch";class StorageClient {- private client: AwsClient;+ private client: AwsClient;- constructor() {- this.client = new AwsClient({- accessKeyId: process.env.STORAGE_ACCESS_KEY_ID || '',- secretAccessKey: process.env.STORAGE_SECRET_ACCESS_KEY || '',- service: 's3',- region: 'auto',- });- }+ constructor() {+ this.client = new AwsClient({+ accessKeyId: process.env.STORAGE_ACCESS_KEY_ID || "",+ secretAccessKey: process.env.STORAGE_SECRET_ACCESS_KEY || "",+ service: "s3",+ region: "auto",+ });+ }- async upload(key: string, body: Blob | Buffer | string, contentType?: string) {- let uploadBody;-- if (typeof body === 'string') {- try {- uploadBody = this.base64ToArrayBuffer(body);- } catch (error) {- throw new Error(`Invalid base64 string: ${error.message}`);- }- } else {- uploadBody = body;- }-- const headers = {- 'Content-Length': uploadBody.size.toString()- };- if (contentType) headers['Content-Type'] = contentType;-- await this.client.fetch(`${process.env.STORAGE_ENDPOINT}/${key}`, {- method: 'PUT',- headers,- body: uploadBody,- });+ async upload(+ key: string,+ body: Blob | Buffer | string,+ contentType?: string,+ ) {+ let uploadBody;- return {- url: `${process.env.STORAGE_DOMAIN}/${key}`,+ if (typeof body === "string") {+ try {+ uploadBody = this.base64ToArrayBuffer(body);+ } catch (error) {+ throw new Error(`Invalid base64 string: ${error.message}`);}+ } else {+ uploadBody = body;+ }++ const headers = {+ "Content-Length": uploadBody.size.toString(),+ };+ if (contentType) headers["Content-Type"] = contentType;++ await this.client.fetch(`${process.env.STORAGE_ENDPOINT}/${key}`, {+ method: "PUT",+ headers,+ body: uploadBody,+ });++ return {+ url: `${process.env.STORAGE_DOMAIN}/${key}`,+ };}- async delete(key: string) {- await this.client.fetch(`${process.env.STORAGE_ENDPOINT}/${key}`, {- method: 'DELETE',- });- }+ async delete(key: string) {+ await this.client.fetch(`${process.env.STORAGE_ENDPOINT}/${key}`, {+ method: "DELETE",+ });++ return { success: true };+ }- private base64ToArrayBuffer(base64: string, contentType?: string) {- const base64Data = base64.replace(/^data:.+;base64,/, '');- const paddedBase64Data = base64Data.padEnd(base64Data.length + (4 - base64Data.length % 4) % 4, '=');+ private base64ToArrayBuffer(base64: string, contentType?: string) {+ const base64Data = base64.replace(/^data:.+;base64,/, "");+ const paddedBase64Data = base64Data.padEnd(+ base64Data.length + ((4 - (base64Data.length % 4)) % 4),+ "=",+ );- const binaryString = atob(paddedBase64Data);- const byteArray = new Uint8Array(binaryString.length);- for (let i = 0; i < binaryString.length; i++) {- byteArray[i] = binaryString.charCodeAt(i);- }- const opts = {}- if (contentType) opts['type'] = contentType;- return new Blob([byteArray], opts);+ const binaryString = atob(paddedBase64Data);+ const byteArray = new Uint8Array(binaryString.length);+ for (let i = 0; i < binaryString.length; i++) {+ byteArray[i] = binaryString.charCodeAt(i);}+ const opts = {};+ if (contentType) opts["type"] = contentType;+ return new Blob([byteArray], opts);+ }}-export const storage = new StorageClient();\ No newline at end of file+export const storage = new StorageClient();