Skip to content

Commit

Permalink
random file names generated with sqids
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhappyma committed Apr 29, 2024
1 parent b83bba5 commit 20d38b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/modules/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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/"];

Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 20d38b6

Please sign in to comment.