Skip to content

Commit 43a49a8

Browse files
committed
Fix CodeQL alerts
1 parent 5c5018f commit 43a49a8

File tree

9 files changed

+3682
-7064
lines changed

9 files changed

+3682
-7064
lines changed

backend/package-lock.json

Lines changed: 3659 additions & 7048 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@babel/preset-env": "^7.15.8",
5252
"chai": "^4.3.4",
5353
"cypress": "^9.2.0",
54-
"eslint": "^8.57.0",
54+
"eslint": "^8.6.0",
5555
"eslint-config-airbnb-base": "^15.0.0",
5656
"eslint-plugin-import": "^2.25.3",
5757
"eslint-plugin-mocha": "^8.0.0",

backend/src/controllers/auth/resetPassword.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const resetPassword = async (req, res) => {
1515
});
1616
}
1717
const user = await User.findOne({
18-
resetToken: token,
18+
resetToken: { $eq: token },
1919
resetTokenExpiry: { $gt: Date.now() },
2020
});
2121
if (!user) {

backend/src/controllers/auth/sso.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const googleCallback = async (req, res) => {
88

99
try {
1010
// Check if the user already exists in the database
11-
let existingUser = await User.findOne({ email: user.email });
11+
let existingUser = await User.findOne({ email: { $eq: user.email } });
1212

1313
if (!existingUser) {
1414
// Create a new user if not found
@@ -39,7 +39,7 @@ const githubCallback = async (req, res) => {
3939
const user = req.user;
4040

4141
try {
42-
let existingUser = await User.findOne({ email: user.email });
42+
let existingUser = await User.findOne({ email: { $eq: user.email } });
4343

4444
if (!existingUser) {
4545
existingUser = new User({
@@ -67,7 +67,7 @@ const facebookCallback = async (req, res) => {
6767
const user = req.user;
6868

6969
try {
70-
let existingUser = await User.findOne({ email: user.email });
70+
let existingUser = await User.findOne({ email: { $eq: user.email } });
7171

7272
if (!existingUser) {
7373
existingUser = new User({

backend/src/controllers/auth/verifyEmail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const verifyEmail = async (req, res) => {
55
const { token } = req.query;
66

77
try {
8-
const user = await User.findOne({ verificationToken: token });
8+
const user = await User.findOne({ verificationToken: { $eq: token } });
99
if (!user) {
1010
return res.status(400).json({ error: "Invalid verification token" });
1111
}

backend/src/controllers/summary/generateAudioSummary.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
const fs = require("fs");
2+
const path = require("path");
23
const textUtils = require("../../utils/text");
34
const audioUtils = require("../../utils/audio");
45

6+
const ROOT_DIR = "src/utils/audio/audios/";
7+
58
const generateAudioSummary = async (req, res) => {
69
try {
710
const { audioData } = req.body;
811

912
// check if valid audioData provided
10-
if (!audioData || !audioData.audioFilePath || !audioData.format) {
13+
if (!audioData || !audioData.audioFileName || !audioData.format) {
1114
return res.status(400).json({ error: "Invalid audio data provided." });
1215
}
1316

@@ -17,13 +20,13 @@ const generateAudioSummary = async (req, res) => {
1720
}
1821

1922
// Check if the audio file exists
20-
if (!fs.existsSync(audioData.audioFilePath)) {
23+
if (!fs.existsSync(path.resolve(ROOT_DIR, audioData.audioFileName))) {
2124
return res.status(400).json({ error: "Audio file not found." });
2225
}
2326

2427
// Convert audio to text asynchronously
2528
const textFromAudio = await audioUtils.convertAudioToText(
26-
audioData.audioFilePath,
29+
audioData.audioFileName,
2730
audioData.format
2831
);
2932

backend/src/models/User.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ userSchema.methods.generateVerificationToken = function () {
5656

5757
// Static method to find by email
5858
userSchema.statics.findByEmail = function (email) {
59-
return this.findOne({ email });
59+
return this.findOne({ email: { $eq: email } });
6060
};
6161

6262
module.exports = mongoose.model("User", userSchema);

backend/src/utils/audio/convertAudioToText.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const DeepSpeech = require("deepspeech");
22
const convertMP3toWAV = require("./convertMP3toWAV");
33
const fs = require("fs");
4+
const path = require("path");
5+
const ROOT_DIR = "src/utils/audio/audios/";
46

57
const wavOutputPath = "src/utils/audio/audios/output.wav";
68

7-
async function convertAudioToText(audioFilePath, audioFormat) {
9+
async function convertAudioToText(audioFileName, audioFormat) {
810
let audioData = Buffer.from("");
911

1012
// Load the DeepSpeech model without specifying model and scorer paths
@@ -13,6 +15,8 @@ async function convertAudioToText(audioFilePath, audioFormat) {
1315
// Load the language model scorer without specifying scorer path
1416
model.enableExternalScorer();
1517

18+
const audioFilePath = path.resolve(ROOT_DIR, audioFileName);
19+
1620
if (audioFormat === "mp3") {
1721
await convertMP3toWAV(audioFilePath, wavOutputPath);
1822
audioData = fs.readFileSync(wavOutputPath);

backend/tests/unit/controllers/summaryController.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("Summary Controller - Audio Content", () => {
3333

3434
it("should return error if audio file not found", async () => {
3535
req.body.audioData = {
36-
audioFilePath: "invalid/path/to/audio.mp3",
36+
audioFileName: "invalid/path/to/audio.mp3",
3737
format: "mp3",
3838
};
3939
sinon.stub(fs, "existsSync").returns(false);
@@ -45,7 +45,7 @@ describe("Summary Controller - Audio Content", () => {
4545

4646
it("should return error if audio format not supported", async () => {
4747
req.body.audioData = {
48-
audioFilePath: "valid/path/to/audio.mp3",
48+
audioFileName: "valid/path/to/audio.mp3",
4949
format: "unsupported_format",
5050
};
5151
sinon.stub(fs, "existsSync").returns(true);
@@ -57,7 +57,7 @@ describe("Summary Controller - Audio Content", () => {
5757

5858
it("should return error if no text found in the audio", async () => {
5959
req.body.audioData = {
60-
audioFilePath: "src/utils/audio/audios/no-speech.mp3",
60+
audioFileName: "no-speech.mp3",
6161
format: "mp3",
6262
};
6363
sinon.stub(fs, "existsSync").returns(true);
@@ -71,7 +71,7 @@ describe("Summary Controller - Audio Content", () => {
7171

7272
it("should generate summary from text", async () => {
7373
req.body.audioData = {
74-
audioFilePath: "valid/path/to/audio.mp3",
74+
audioFileName: "valid/path/to/audio.mp3",
7575
format: "mp3",
7676
};
7777
sinon.stub(fs, "existsSync").returns(true);
@@ -90,7 +90,7 @@ describe("Summary Controller - Audio Content", () => {
9090

9191
it("should handle internal server error", async () => {
9292
req.body.audioData = {
93-
audioFilePath: "valid/path/to/audio.mp3",
93+
audioFileName: "valid/path/to/audio.mp3",
9494
format: "mp3",
9595
};
9696
sinon.stub(fs, "existsSync").returns(true);

0 commit comments

Comments
 (0)