From 20d38b65cf4367133e582dd8aa1bdc569596e1a2 Mon Sep 17 00:00:00 2001 From: Dominic Ruggiero <dominic@userexe.me> Date: Mon, 29 Apr 2024 18:31:42 -0400 Subject: [PATCH] random file names generated with sqids --- package.json | 1 + pnpm-lock.yaml | 7 +++++++ src/modules/pack.ts | 12 ++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3ab8525..0e7d0fb 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "aws-sdk": "^2.1565.0", "discord.js": "^14.13.0", "express": "^4.18.3", + "sqids": "^0.3.0", "zod": "^3.22.3" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ae3d3ba..d5970c0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ dependencies: express: specifier: ^4.18.3 version: 4.18.3 + sqids: + specifier: ^0.3.0 + version: 0.3.0 zod: specifier: ^3.22.3 version: 3.22.4 @@ -896,6 +899,10 @@ packages: object-inspect: 1.13.1 dev: false + /sqids@0.3.0: + resolution: {integrity: sha512-lOQK1ucVg+W6n3FhRwwSeUijxe93b51Bfz5PMRMihVf1iVkl82ePQG7V5vwrhzB11v0NtsR25PSZRGiSomJaJw==} + dev: false + /statuses@2.0.1: resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==} engines: {node: '>= 0.8'} diff --git a/src/modules/pack.ts b/src/modules/pack.ts index d1b5002..fc0ef6d 100644 --- a/src/modules/pack.ts +++ b/src/modules/pack.ts @@ -20,6 +20,7 @@ import { } from "../utils/kitchenChannels"; import s3 from "./s3"; import handleError from "./sentry"; +import Sqids from "sqids"; // this took way too long to get copilot to spit out it had better work const URL_REGEX = @@ -30,7 +31,7 @@ const ALLOWED_CONTENT_TYPES = [ "image/gif", "video/webm", "video/mp4", - "image/webp" + "image/webp", ]; const ALLOWED_EXTERNAL_SITES = ["https://youtu.be/", "https://wikihow.com/"]; @@ -137,9 +138,12 @@ bot.client.on("messageCreate", async (message) => { await finish(sourceURL); return; } else { - const s3Key = `orders/${order.id}/${ - request.headers.get("content-type")?.split("/")[0] - }.${request.headers.get("content-type")?.split("/")[1].split(";")[0]}`; + const sqids = new Sqids(); + const id = sqids.encode([order.id, Date.now()]); + + const s3Key = `orders/${order.id}/${id}.${ + request.headers.get("content-type")?.split("/")[1].split(";")[0] + }`; const buffer = Buffer.from(await request.arrayBuffer());