Skip to content

Commit

Permalink
chore: Add AWS SDK dependencies for S3 and STS storage operations
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Mar 3, 2025
1 parent 965ee62 commit 5f715d3
Show file tree
Hide file tree
Showing 5 changed files with 434 additions and 28 deletions.
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"typecheck": "tsc --pretty"
},
"dependencies": {
"@aws-sdk/client-sts": "^3.758.0",
"@hey/data": "workspace:*",
"@hey/db": "workspace:*",
"@hey/helpers": "workspace:*",
Expand Down
57 changes: 57 additions & 0 deletions apps/api/src/routes/sts/token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { AssumeRoleCommand, STSClient } from "@aws-sdk/client-sts";
import { EVER_API, EVER_BUCKET, EVER_REGION } from "@hey/data/constants";
import logger from "@hey/helpers/logger";
import type { Request, Response } from "express";
import catchedError from "src/helpers/catchedError";
import { rateLimiter } from "src/helpers/middlewares/rateLimiter";

const params = {
DurationSeconds: 900,
Policy: `{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:AbortMultipartUpload"
],
"Resource": [
"arn:aws:s3:::${EVER_BUCKET}/*"
]
}
]
}`
};

export const get = [
rateLimiter({ requests: 50, within: 1 }),
async (_: Request, res: Response) => {
try {
const accessKeyId = process.env.EVER_ACCESS_KEY as string;
const secretAccessKey = process.env.EVER_ACCESS_SECRET as string;
const stsClient = new STSClient({
credentials: { accessKeyId, secretAccessKey },
endpoint: EVER_API,
region: EVER_REGION
});
const command = new AssumeRoleCommand({
...params,
RoleArn: undefined,
RoleSessionName: undefined
});
const { Credentials: credentials } = await stsClient.send(command);
logger.info("STS token generated");

return res.status(200).json({
accessKeyId: credentials?.AccessKeyId,
secretAccessKey: credentials?.SecretAccessKey,
sessionToken: credentials?.SessionToken,
success: true
});
} catch (error) {
return catchedError(res, error);
}
}
];
2 changes: 2 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
},
"dependencies": {
"@apollo/client": "^3.13.1",
"@aws-sdk/client-s3": "^3.758.0",
"@aws-sdk/lib-storage": "^3.758.0",
"@headlessui/react": "2.2.0",
"@heroicons/react": "^2.2.0",
"@hey/data": "workspace:*",
Expand Down
8 changes: 7 additions & 1 deletion packages/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ export const STATIC_ASSETS_URL = "https://static.hey.xyz";
export const STATIC_IMAGES_URL = `${STATIC_ASSETS_URL}/images`;
export const LENS_MEDIA_SNAPSHOT_URL =
"https://ik.imagekit.io/lens/media-snapshot";
export const STORAGE_NODE_URL = "https://api.grove.storage";
export const DEFAULT_OG = `${STATIC_IMAGES_URL}/og/cover.png`;
export const DEFAULT_AVATAR = `${STATIC_IMAGES_URL}/default.png`;
export const PLACEHOLDER_IMAGE = `${STATIC_IMAGES_URL}/placeholder.webp`;
export const BLOCK_EXPLORER_URL = IS_MAINNET
? "https://block-explorer.lens.dev"
: "https://block-explorer.testnet.lens.dev";

// Storage
export const STORAGE_NODE_URL = "https://api.grove.storage";
export const IPFS_GATEWAY = "https://gw.ipfs-lens.dev/ipfs";
export const EVER_API = "https://endpoint.4everland.co";
export const EVER_REGION = "4EVERLAND";
export const EVER_BUCKET = "hey-media";

// Tokens / Keys
export const WALLETCONNECT_PROJECT_ID = "cd542acc70c2b548030f9901a52e70c8";
export const GIPHY_KEY = "yNwCXMKkiBrxyyFduF56xCbSuJJM8cMd";
Expand Down
Loading

0 comments on commit 5f715d3

Please sign in to comment.