Skip to content
Open
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-alpine
# Set the working directory in the container
WORKDIR /app
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code to the working directory
COPY . .
# Build the application
EXPOSE 5000
# Set the environment variable for production
CMD [ "npm","start" ]
49 changes: 49 additions & 0 deletions config/accont_verification_templete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export const ACCOUNT_VERIFICATION_HTML_TEMPLETE = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email Verification</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
text-align: center;
}
.container {
background: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
margin: auto;
}
.verify-code {
font-size: 24px;
font-weight: bold;
color: #333;
letter-spacing: 5px;
padding: 10px;
background: #e0e0e0;
border-radius: 5px;
display: inline-block;
}
.footer {
margin-top: 20px;
font-size: 14px;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<h2>Email Verification</h2>
<p>Use the verification code below to confirm your email address.</p>
<div class="verify-code">{{otp}}</div>
<p>If you did not request this, please ignore this email.</p>
<div class="footer">&copy; 2025 AUTH</div>
</div>
</body>
</html>`;
11 changes: 11 additions & 0 deletions config/aws/awsconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import AWS from "aws-sdk";

//configure aws
AWS.config.update({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION,
});
const s3 = new AWS.S3();

export default s3;
File renamed without changes.
16 changes: 16 additions & 0 deletions config/nodemailer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import dotenv from "dotenv";
import nodemailer from "nodemailer";

dotenv.config();
//smtp email transport model
const transporter = nodemailer.createTransport({
host: "smtp-relay.brevo.com",
port: process.env.SMTP_PORT,
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SNTP_PASSWORD,
},
});

export default transporter;
52 changes: 52 additions & 0 deletions config/reset_password_templete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
export const PASSWORD_RESET_TEMPLATE = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Reset OTP</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
text-align: center;
}
.container {
background: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
margin: auto;
}
.otp {
font-size: 24px;
font-weight: bold;
color: #333;
letter-spacing: 5px;
padding: 10px;
background: #e0e0e0;
border-radius: 5px;
display: inline-block;
}
.footer {
margin-top: 20px;
font-size: 14px;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<h2>Password Reset Request</h2>
<p>Use the OTP below to reset your password.</p>
<div class="otp">{{otp}}</div>
<p>If you did not request this, please ignore this email.</p>
<div class="footer">&copy; 2025 AUTH</div>
</div>
</body>
</html>

`;
181 changes: 181 additions & 0 deletions controller/resourcecontroller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import dotenv from "dotenv";
import s3 from "../config/aws/awsconfig.js";
import video from "../models/video.model.js";

dotenv.config();
//s3 bucket
const bucketName = process.env.AWS_BUCKET_NAME;

//cloudfront url
const cloudFront = process.env.CLOUDFRONT_URL;
//get pre singed url
export const getPreSingedUrl = async (req, res) => {
const { userId, fileType, filename } = req.body;
if (!userId || !fileType || !filename) {
return res.status(400).json({ success: false, message: "empty parameter" });
}
try {
const key = `reels/${userId}/${filename}`;
const params = {
Bucket: `${bucketName}`,
Key: key,
ContentType: fileType,
};

const uploadUrl = s3.getSignedUrl("putObject", params);

if (!uploadUrl) {
return res
.status(400)
.json({ success: false, message: "cannot get url" });
}
return res.status(200).json({
success: true,
data: {
uploadUrl: uploadUrl,
videokey: key,
},
});
} catch (err) {
return res.status(500).json({ success: false, message: `${err}` });
}
};
//save metadata
export const saveMetaData = async (req, res) => {
const { userId, videoKey, title } = req.body;
if (!userId || !videoKey || !title) {
return res.status(400).json({ success: false, message: "empty parameter" });
}
try {
const newVideo = new video({
userId,
title,
url: videoKey,
});
const createdVideo = await newVideo.save();
return res.status(200).json({
success: true,
data: {
id: createdVideo._id,
userId: createdVideo.userId,
videokey: createdVideo.url,
},
});
} catch (err) {
return res.status(500).json({ success: false, message: `${err}` });
}
};
//fetch all video data using cloudfront url
export const fetchVideoData = async (req, res) => {
const page = parseInt(req.query.page) || 1;
const limit = parseInt(req.query.limit) || 10;

const skip = (page - 1) * limit;
try {
const videos = await video
.find({})
.sort({ createdAt: -1 })
.limit(limit)
.skip(skip);

if (!videos) {
return res
.status(404)
.json({ success: false, message: "data not found" });
}
const allVideos = videos.map((video) => ({
reelId: video._id,
userId: video.userId,
title: video.title,
url: `${cloudFront}/${video.url}`,
joinedDate: video.createdAt,
updatedDate: video.updatedAt,
processed: video.processed,
weblink: video.weblink,
likes: video.likes,
disLikes: video.disLikes,
comments: video.comments,
tags: video.tags,
}));

return res.status(200).json({ success: true, data: { videos: allVideos } });
} catch (err) {
return res.status(500).json({ success: false, message: `${err}` });
}
};
//like reels
export const likeReels = async (req, res) => {
const { userId, reelId } = req.body;

if (!userId || !reelId) {
return res
.status(400)
.json({ success: false, message: "invalid credientials" });
}

try {
const reel = await video.findById(reelId);
if (!reel) {
return res
.status(404)
.json({ success: false, message: "reel not found" });
}
//check if like or not
const isLiked = reel.likes.includes(userId);
if (isLiked) {
//remove userid if already liked
reel.likes = reel.likes.filter((id) => id !== userId);
} else {
//add new like
reel.likes.push(userId);
}

const updatedReel = await reel.save();``
return res.status(200).json({
success: true,
data: {
reel: updatedReel,
},
});
} catch (err) {
return res.status(500).json({ success: false, message: `${err}` });
}
};
//dislike reels
export const dislikeReels = async (req, res) => {
const { userId, reelId } = req.body;

if (!userId || !reelId) {
return res
.status(400)
.json({ success: false, message: "invalid credientials" });
}

try {
const reel = await video.findById(reelId);
if (!reel) {
return res
.status(404)
.json({ success: false, message: "reel not found" });
}
//check if like or not
const isdisLiked = reel.disLikes.includes(userId);
if (isdisLiked) {
//remove userid if already liked
reel.disLikes = reel.disLikes.filter((id) => id !== userId);
} else {
//add new like
reel.disLikes.push(userId);
}

const updatedReel = await reel.save();
return res.status(200).json({
success: true,
data: {
reel: updatedReel,
},
});
} catch (err) {
return res.status(500).json({ success: false, message: `${err}` });
}
};
Loading