Skip to content

Commit a586779

Browse files
authored
Merge pull request #60 from 4darsh-Dev/prof-work
changed multer profile pic upload logic
2 parents 56e3e22 + db2daf1 commit a586779

File tree

6 files changed

+2072
-68
lines changed

6 files changed

+2072
-68
lines changed

client/src/js/config.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Development configuration
2-
export const CONFIG = {
3-
API_ENDPOINT: 'http://localhost:5000'
4-
}
2+
// export const CONFIG = {
3+
// API_ENDPOINT: 'http://localhost:5000'
4+
// }
55

66

77
// Production configuration
8-
// export const CONFIG = {
9-
// API_ENDPOINT: 'https://student-zynergy.vercel.app'
10-
// }
8+
export const CONFIG = {
9+
API_ENDPOINT: 'https://student-zynergy.vercel.app'
10+
}

client/src/pages/login.html

+14-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ <h1 class="input-box-heading">Login</h1>
3535
</span>
3636
<p>Email</p>
3737
</div>
38-
<input class="input-box" name="email" autocomplete="off" />
38+
<input
39+
class="input-box"
40+
type="email"
41+
name="email"
42+
autocomplete="off"
43+
required
44+
/>
3945
</div>
4046
<div class="input-box-div">
41-
<input class="input-box" name="password" autocomplete="off" />
47+
<input
48+
class="input-box"
49+
type="password"
50+
name="password"
51+
autocomplete="off"
52+
required
53+
/>
4254
<div class="input-box-text-div">
4355
<span class="material-symbols-outlined login-form-icon">
4456
lock

server/controllers/authController.js

+25-30
Original file line numberDiff line numberDiff line change
@@ -93,45 +93,40 @@ const token = (req, res) => {
9393
}
9494

9595
// profile pic upload
96-
9796
const multer = require('multer');
98-
const path = require('path');
99-
100-
// Set storage engine
101-
const storage = multer.diskStorage({
102-
destination: './uploads/profile_pics',
103-
filename: (req, file, cb) => {
104-
cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
105-
}
97+
const multerS3 = require('multer-s3');
98+
const AWS = require('aws-sdk');
99+
100+
// Configure AWS S3
101+
const s3 = new AWS.S3({
102+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
103+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
104+
region: process.env.AWS_REGION,
106105
});
107106

108-
// Init upload
107+
// Set up Multer to use S3 for storage
109108
const upload = multer({
110-
storage: storage,
111-
limits: { fileSize: 1000000 }, // Limit file size to 1MB
112-
fileFilter: (req, file, cb) => {
113-
checkFileType(file, cb);
114-
}
115-
}).single('profileImage');
116-
117-
// Check file type
118-
function checkFileType(file, cb) {
119-
const filetypes = /jpeg|jpg|png|gif/;
120-
const extname = filetypes.test(path.extname(file.originalname).toLowerCase());
121-
const mimetype = filetypes.test(file.mimetype);
122-
123-
if (mimetype && extname) {
124-
return cb(null, true);
125-
} else {
126-
cb('Error: Images Only!');
127-
}
128-
}
109+
storage: multerS3({
110+
s3: s3,
111+
bucket: 'your-s3-bucket-name',
112+
metadata: (req, file, cb) => {
113+
cb(null, { fieldName: file.fieldname });
114+
},
115+
key: (req, file, cb) => {
116+
cb(null, Date.now().toString() + '-' + file.originalname);
117+
},
118+
}),
119+
});
120+
121+
122+
129123

130124

131125

132126

133127
module.exports = {
134128
register,
135129
login,
136-
token
130+
token,
131+
upload
137132
}

0 commit comments

Comments
 (0)