Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: s3 presigned url #61

Merged
merged 2 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ DATABASE_URL=
DIRECT_URL=

# Supabase db service_role token
SUPABASE_SERVICE_ROLE=
SUPABASE_SERVICE_ROLE=

# MinIO Creds
MINIO_ENDPOINT=
MINIO_ACCESSKEY=
MINIO_SECRETKEY=
Binary file modified backend/bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"bignumber.js": "^9.1.2",
"elysia": "latest",
"lucia": "^3.2.0",
"minio": "^8.0.1",
"pino-pretty": "^11.2.1",
"pm2": "^5.4.1"
},
Expand Down
13 changes: 13 additions & 0 deletions backend/src/libs/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Client } from 'minio';

const minioClient = new Client({
port: 9000,
region: process.env.MINIO_ENDPOINT!,
endPoint: process.env.MINIO_ENDPOINT!,
accessKey: process.env.MINIO_ACCESSKEY!,
secretKey: process.env.MINIO_SECRETKEY!,
})

const bucketName = process.env.MINIO_BUCKET!;

export { minioClient, bucketName };
2 changes: 2 additions & 0 deletions backend/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Elysia } from "elysia";
import authRoutes from "@/routes/auth";
import machineRoutes from "@/routes/machine";
import storeRoutes from "@/routes/store";
import paymentRoutes from "@/routes/payment";

const routes = new Elysia();
Expand All @@ -9,6 +10,7 @@ routes
.get("/", () => "Hello from Elysia!")
.group("/auth", (routes) => routes.use(authRoutes))
.group("/machine", (routes) => routes.use(machineRoutes))
.group("/store", (routes) => routes.use(storeRoutes))
.group("/payment", (routes) => routes.use(paymentRoutes));

export default routes;
22 changes: 22 additions & 0 deletions backend/src/routes/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Elysia, t } from "elysia";
import storeController from "@/routes/store/store.controller";

const storeRoutes = new Elysia();

storeRoutes
.get("/presigned-url", storeController.GenPresignedUrl, {
query: t.Object(
{
name: t.String()
},
{
description: "Expected name of the object",
},
),
detail: {
summary: "Gen Presigned url",
tags: ["store"],
},
});

export default storeRoutes;
17 changes: 17 additions & 0 deletions backend/src/routes/store/store.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { minioClient, bucketName } from "@/libs/store";

const GenPresignedUrl = async ({ query: { name }, set, log }) => {
try {
const url = minioClient.presignedPutObject(bucketName, name, 24 * 60 * 60);
set.status = 201;
return url;
} catch (err) {
log.error(err);
set.status = 500;
return { message: "Internal Server Error" };
}
};

export default {
GenPresignedUrl
};
Loading