Skip to content
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
2 changes: 2 additions & 0 deletions apps/core-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"license": "ISC",
"packageManager": "pnpm@10.27.0",
"dependencies": {
"@aws-sdk/client-s3": "^3.1006.0",
"@aws-sdk/s3-request-presigner": "^3.1006.0",
"amqplib": "^0.10.9",
"bcrypt": "^6.0.0",
"cookie-parser": "^1.4.7",
Expand Down
28 changes: 28 additions & 0 deletions apps/core-api/src/controllers/media.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Request, Response, NextFunction } from "express";

import { generateUploadUrlService } from "../services/media.service.js";

export const generateUploadUrlController = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {

const { fileName, fileType, folder } = req.body;

const result = await generateUploadUrlService(
folder,
fileName,
fileType
);

res.status(200).json({
success: true,
data: result
});

} catch (error) {
next(error);
}
};
9 changes: 9 additions & 0 deletions apps/core-api/src/lib/s3.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { S3Client } from "@aws-sdk/client-s3";

export const s3Client = new S3Client({
region: process.env.AWS_REGION!,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!
}
});
6 changes: 5 additions & 1 deletion apps/core-api/src/models/brand.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IBrandProfile extends Document {

isProfileComplete: boolean;
isVerified: boolean;
profileImageUrl?: string,
}

const BrandProfileSchema = new Schema<IBrandProfile>(
Expand Down Expand Up @@ -65,7 +66,10 @@ const BrandProfileSchema = new Schema<IBrandProfile>(
type: [String], // store S3 keys
default: [],
},

profileImageUrl: {
type: String,
default: ""
},
isProfileComplete: {
type: Boolean,
default: false,
Expand Down
5 changes: 5 additions & 0 deletions apps/core-api/src/models/influencer.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface IInfluencerProfile extends Document {

isProfileComplete: boolean;
isVerified: boolean;
profileImageUrl?: string,
}

const InfluencerProfileSchema = new Schema<IInfluencerProfile>(
Expand Down Expand Up @@ -50,6 +51,10 @@ const InfluencerProfileSchema = new Schema<IInfluencerProfile>(
type: String,
maxlength: 500,
},
profileImageUrl: {
type: String,
default: ""
},

instagramUrl: String,
youtubeUrl: String,
Expand Down
5 changes: 4 additions & 1 deletion apps/core-api/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Router } from "express";
import { Router } from "express";

import mediaRoutes from "../routes/media.routes.js";

import userRoutes from "./users.routes.js";
import authRoutes from "./auth.routes.js";
Expand All @@ -24,5 +26,6 @@ router.use("/bookings", bookingRoutes);
router.use("/orders", orderRoutes);
router.use("/payments", paymentRoutes);
router.use("/search", searchRoutes);
router.use("/media", mediaRoutes);

export default router
14 changes: 14 additions & 0 deletions apps/core-api/src/routes/media.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Router } from "express";

import { generateUploadUrlController } from "../controllers/media.controller.js";
import { authenticate } from "../middlewares/auth.middleware.js";

const router:Router = Router();

router.post(
"/upload-url",
authenticate,
generateUploadUrlController
);

export default router;
33 changes: 33 additions & 0 deletions apps/core-api/src/services/media.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { PutObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";

import { s3Client } from "../lib/s3.client.js";

export const generateUploadUrlService = async (
folder: string,
fileName: string,
fileType: string
) => {

const uniqueFileName = `${Date.now()}-${fileName}`;

const key = `${folder}/${uniqueFileName}`;

const command = new PutObjectCommand({
Bucket: process.env.AWS_BUCKET_NAME!,
Key: key,
ContentType: fileType
});

const uploadUrl = await getSignedUrl(s3Client, command, {
expiresIn: 300
});

const fileUrl =
`https://${process.env.AWS_BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${key}`;

return {
uploadUrl,
fileUrl
};
};
Loading
Loading