Skip to content

Commit 5699cf7

Browse files
committed
google auth added + frontend stuff and fixed some UI
1 parent 975c1b1 commit 5699cf7

File tree

101 files changed

+634
-527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+634
-527
lines changed

app.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const express = require('express');
22
const session = require('express-session');
33
const rateLimit = require('express-rate-limit');
4+
const passport = require("passport")
45

56
const limiter = rateLimit({
67
windowMs: 15 * 60 * 1000, // 15 minutes
@@ -53,6 +54,9 @@ app.use(
5354
})
5455
);
5556

57+
app.use(passport.initialize());
58+
app.use(passport.session());
59+
5660
// Routes
5761
app.use('/', defaultRoute);
5862
app.use('/', uploadRoute);

controllers/multerController.js

+34-23
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
1-
const multer = require('multer');
2-
const path = require('path');
3-
const sharp = require('sharp');
1+
const multer = require("multer");
2+
const path = require("path");
3+
const sharp = require("sharp");
44

55
const storage = multer.diskStorage({
6-
destination: (req, file, cb) => {
7-
const uploadDir = path.join(__dirname, '../images/uploads');
8-
cb(null, uploadDir);
9-
},
10-
filename: (req, file, cb) => {
11-
const uniqueName = `${Date.now()}-${file.originalname.replace(/\s+/g, '_')}`;
12-
cb(null, uniqueName);
13-
}
6+
destination: (req, file, cb) => {
7+
const uploadDir = path.join(__dirname, "../images/uploads");
8+
cb(null, uploadDir);
9+
},
10+
filename: (req, file, cb) => {
11+
const uniqueName = `${Date.now()}-${file.originalname.replace(
12+
/\s+/g,
13+
"_"
14+
)}`;
15+
cb(null, uniqueName);
16+
},
1417
});
1518

1619
const upload = multer({ storage });
1720

1821
async function optimizeImage(filePath, qualityValue, resizeWidth = 800) {
19-
const uploadDir = path.join(__dirname, '..', 'images', 'uploads');
20-
const sanitizedFilename = `optimized-${Date.now()}-${path.basename(filePath).replace(/\s+/g, '_').replace(/[^a-zA-Z0-9.-_]/g, '')}`;
21-
const outputFilePath = path.join(uploadDir, sanitizedFilename);
22+
const uploadDir = path.join(__dirname, "..", "images", "uploads");
23+
const sanitizedFilename = `optimized-${Date.now()}-${path
24+
.basename(filePath)
25+
.replace(/\s+/g, "_")
26+
.replace(/[^a-zA-Z0-9.-_]/g, "")}`;
27+
const outputFilePath = path.join(uploadDir, sanitizedFilename);
2228

23-
await sharp(filePath)
24-
.resize(resizeWidth)
25-
.toFormat('jpeg')
26-
.jpeg({ quality: qualityValue })
27-
.toFile(outputFilePath);
29+
await sharp(filePath)
30+
.resize(resizeWidth)
31+
.toFormat("jpeg")
32+
.jpeg({ quality: qualityValue })
33+
.toFile(outputFilePath);
2834

29-
return sanitizedFilename;
35+
return sanitizedFilename;
3036
}
3137

3238
function sanitizeFileName(filePath) {
33-
const ext = path.extname(filePath).toLowerCase();
34-
const sanitizedFilename = `optimized-${Date.now()}-${Math.random().toString(36).substr(2, 9)}-${path.basename(filePath).replace(/\s+/g, '_').replace(/[^a-zA-Z0-9.-_]/g, '')}`;
35-
return sanitizedFilename;
39+
const ext = path.extname(filePath).toLowerCase();
40+
const sanitizedFilename = `optimized-${Date.now()}-${Math.random()
41+
.toString(36)
42+
.substr(2, 9)}-${path
43+
.basename(filePath)
44+
.replace(/\s+/g, "_")
45+
.replace(/[^a-zA-Z0-9.-_]/g, "")}`;
46+
return sanitizedFilename;
3647
}
3748

3849
module.exports = { upload, optimizeImage, sanitizeFileName };
+20-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
function generateDefaultProfilePicture(username = "User") {
2-
const initials = username
3-
.split(' ')
4-
.map(word => word.charAt(0).toUpperCase())
5-
.join('');
6-
const backgroundColor = '#3498db';
7-
const textColor = '#ffffff';
2+
const initials = username
3+
.split(" ")
4+
.map((word) => word.charAt(0).toUpperCase())
5+
.join("");
6+
const backgroundColor = "#3498db";
7+
const textColor = "#ffffff";
88

9-
return `https://ui-avatars.com/api/?name=${initials}&background=${backgroundColor.replace('#', '')}&color=${textColor.replace('#', '')}`;
9+
return `https://ui-avatars.com/api/?name=${initials}&background=${backgroundColor.replace(
10+
"#",
11+
""
12+
)}&color=${textColor.replace("#", "")}`;
1013
}
1114

1215
const getProfilePicture = (user) => {
13-
const username = user.username || "User";
14-
if (user.profilepicture && typeof user.profilepicture === 'string') {
15-
return `/images/uploads/${user.profilepicture}`;
16-
}
17-
return generateDefaultProfilePicture(username);
16+
if (!user || !user.username) {
17+
// Handle the case when user is null or undefined
18+
return generateDefaultProfilePicture(); // Default profile picture if no user or username is available
19+
}
20+
21+
const username = user.username || "User";
22+
if (user.profilepicture && typeof user.profilepicture === "string") {
23+
return `/images/uploads/${user.profilepicture}`;
24+
}
25+
return generateDefaultProfilePicture(username);
1826
};
1927

2028
module.exports = getProfilePicture;

0 commit comments

Comments
 (0)