Skip to content

Commit

Permalink
Merge pull request #91 from AVtheking/popular_search
Browse files Browse the repository at this point in the history
allowed more file extension
  • Loading branch information
AVtheking authored Nov 25, 2023
2 parents 6d14f5a + e331d01 commit 6b96aea
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 73 deletions.
140 changes: 70 additions & 70 deletions controllers/teacher_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ const teacherCtrl = {
fs.unlinkSync(videoFilePath);
return next(new ErrorHandler(400, "You are not the creater of course"));
}
if (course.isPublished) {
if (noteFilePath != null) {
fs.unlinkSync(noteFilePath);
}
fs.unlinkSync(videoFilePath);
return next(new ErrorHandler(400, "Course is already published"));
}
// if (course.isPublished) {
// if (noteFilePath != null) {
// fs.unlinkSync(noteFilePath);
// }
// fs.unlinkSync(videoFilePath);
// return next(new ErrorHandler(400, "Course is already published"));
// }


//Video Conversion using worker threads
Expand Down Expand Up @@ -450,69 +450,69 @@ const teacherCtrl = {
next(e);
}
},
addlecture: async (req, res, next) => {
let videoFilePath, inputFilePath, inputFileName;
try {
const courseId = req.params.courseId;
if (!req.file) {
return next(new ErrorHandler(400, "Please upload a video file"));
}
const result = await videoSchema.validateAsync(req.body);
const videoTitle = result.videoTitle;
videoFilePath = "public/course_videos" + "/" + req.file.filename;
let course = await Course.findById(courseId);
if (!course) {
fs.unlinkSync(videoFilePath);
return next(new ErrorHandler(404, "Course not found"));
}
if (!course.createdBy.equals(req.user._id)) {
fs.unlinkSync(videoFilePath);
return next(
new ErrorHandler(400, "You are not the creater of the course")
);
}
const conversionPromise = resolutions.map((resolution) => {
inputFilePath = videoFilePath;
inputFileName = path.basename(
inputFilePath,
path.extname(inputFilePath)
);
const outputPath = `public/course_videos/${inputFileName}-${
resolution.name
}${path.extname(inputFilePath)}`;
return createConversionWorker(resolution, inputFilePath, outputPath);
});
await Promise.all(conversionPromise);
console.log("Video conversion completed");
const du = await getVideoDurationInSeconds(videoFilePath);
let video = new Video({
videoTitle,
videoUrl: videoFilePath,
videoUrl_144p: `public/course_videos/${inputFileName}-144p${path.extname(
inputFilePath
)}`,
videoUrl_360p: `public/course_videos/${inputFileName}-360p${path.extname(
inputFilePath
)}`,
videoUrl_720p: `public/course_videos/${inputFileName}-720p${path.extname(
inputFilePath
)}`,
videoDuration: du,
});
video = await video.save();
course.videos.push(video._id);
course = await course.save();
res.json({
success: true,
message: "Lecture added successfully",
});
} catch (e) {
if (videoFilePath) {
fs.unlinkSync(videoFilePath);
}
next(e);
}
},
// addlecture: async (req, res, next) => {
// let videoFilePath, inputFilePath, inputFileName;
// try {
// const courseId = req.params.courseId;
// if (!req.file) {
// return next(new ErrorHandler(400, "Please upload a video file"));
// }
// const result = await videoSchema.validateAsync(req.body);
// const videoTitle = result.videoTitle;
// videoFilePath = "public/course_videos" + "/" + req.file.filename;
// let course = await Course.findById(courseId);
// if (!course) {
// fs.unlinkSync(videoFilePath);
// return next(new ErrorHandler(404, "Course not found"));
// }
// if (!course.createdBy.equals(req.user._id)) {
// fs.unlinkSync(videoFilePath);
// return next(
// new ErrorHandler(400, "You are not the creater of the course")
// );
// }
// const conversionPromise = resolutions.map((resolution) => {
// inputFilePath = videoFilePath;
// inputFileName = path.basename(
// inputFilePath,
// path.extname(inputFilePath)
// );
// const outputPath = `public/course_videos/${inputFileName}-${
// resolution.name
// }${path.extname(inputFilePath)}`;
// return createConversionWorker(resolution, inputFilePath, outputPath);
// });
// await Promise.all(conversionPromise);
// console.log("Video conversion completed");
// const du = await getVideoDurationInSeconds(videoFilePath);
// let video = new Video({
// videoTitle,
// videoUrl: videoFilePath,
// videoUrl_144p: `public/course_videos/${inputFileName}-144p${path.extname(
// inputFilePath
// )}`,
// videoUrl_360p: `public/course_videos/${inputFileName}-360p${path.extname(
// inputFilePath
// )}`,
// videoUrl_720p: `public/course_videos/${inputFileName}-720p${path.extname(
// inputFilePath
// )}`,
// videoDuration: du,
// });
// video = await video.save();
// course.videos.push(video._id);
// course = await course.save();
// res.json({
// success: true,
// message: "Lecture added successfully",
// });
// } catch (e) {
// if (videoFilePath) {
// fs.unlinkSync(videoFilePath);
// }
// next(e);
// }
// },
removeLecture: async (req, res, next) => {
try {
const courseId = req.params.courseId;
Expand Down
3 changes: 1 addition & 2 deletions middlewares/uploadNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ if (!fs.existsSync(Videodirectory)) {
fs.mkdirSync(Videodirectory);
}


if (!fs.existsSync(NotesDirectory)) {
fs.mkdirSync(NotesDirectory);
}
Expand Down Expand Up @@ -42,7 +41,7 @@ const upload = multer({
fileFilter: (req, file, cb) => {
if (file.originalname.match(/\.(mp4|MPEG-4|mkv)$/)) {
cb(null, true);
} else if (file.originalname.match(/\.(pdf)$/)) {
} else if (file.originalname.match(/\.(pdf|ppt|jpeg|png|word|pptx)$/i)) {
cb(null, true);
} else {
cb(new ErrorHandler(400, "Invalid file type"), false);
Expand Down
Binary file added public/course_notes/notes-1700922068338.pptx
Binary file not shown.
Binary file added public/course_videos/video-1700922068277-144p.mp4
Binary file not shown.
Binary file added public/course_videos/video-1700922068277-360p.mp4
Binary file not shown.
Binary file added public/course_videos/video-1700922068277-720p.mp4
Binary file not shown.
Binary file added public/course_videos/video-1700922068277.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion routes/teacherRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {auth,uploadVideo, uploadImage, uploadNotes} = require("../middlewares");

teacherRouter.patch("/become-instructor", auth, teacherCtrl.becomeTeacher);
teacherRouter.patch("/become-student", auth, teacherCtrl.becomeStudent);
teacherRouter.patch("/add-lecture/:courseId", auth, uploadVideo, teacherCtrl.addlecture)
// teacherRouter.patch("/add-lecture/:courseId", auth, uploadVideo, teacherCtrl.addlecture)
teacherRouter.patch("/change-thumbnail/:courseId", auth, uploadImage, teacherCtrl.changeThumbnail)
teacherRouter.patch("/update-course/:courseId", auth, uploadImage, teacherCtrl.updateCourse)

Expand Down

0 comments on commit 6b96aea

Please sign in to comment.