Commit 1f76f5f0 authored by supundileepa00's avatar supundileepa00

feat: Video upload backend development

parent f04ec589
import multer from "multer";
import videoService from "../service/videoService.js";
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "uploads/");
},
filename: function (req, file, cb) {
cb(null, Date.now() + "-" + file.originalname);
},
});
const upload = multer({ storage: storage }).single("video");
export function uploadVideo(req, res) {
upload(req, res, function (err) {
if (err) {
console.error(err);
return res
.status(500)
.send("An error occurred while uploading the video");
}
if (!req.file) {
return res.status(400).send("No video file provided");
}
res.status(200).send({
status: true,
message: "Translated Text",
data: "ආආආආආආආආආ",
});
// videoService
// .processVideo(req.file)
// .then(() => res.status(200).send("Video uploaded successfully"))
// .catch((error) => {
// console.error(error);
// res.status(500).send("An error occurred while processing the video");
// });
});
}
......@@ -18,6 +18,7 @@
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0",
"mongoose": "^7.1.1",
"multer": "^1.4.5-lts.1",
"nodemailer": "^6.9.1",
"nodemon": "^2.0.22",
"uuid": "^9.0.0"
......
import express from "express";
import { uploadVideo } from "../controllers/translate.controller.js";
const router = express.Router();
router.post("/upload", uploadVideo);
export default router;
......@@ -6,6 +6,7 @@ import mongoose from "mongoose";
//import routes
import userRoutes from "./routes/user.routes.js";
import translateRoutes from "./routes/translate.routes.js";
dotenv.config();
const app = express();
......@@ -21,6 +22,7 @@ app.get("/", (req, res) => {
//implement routes
app.use("/rest_node/user", userRoutes);
app.use("/rest_node/ssl", translateRoutes);
const CONNECTION_URL = `mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@cluster0.dmza8yi.mongodb.net/?retryWrites=true&w=majority`;
const PORT = process.env.PORT || 5000;
......@@ -42,5 +44,5 @@ mongoose
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Internal Server Error');
res.status(500).send("Internal Server Error");
});
export default function processVideo(videoFile) {
return new Promise((resolve, reject) => {
// Perform video processing tasks here
// Example: store videoFile in a database, generate thumbnails, etc.
// Simulating asynchronous processing
setTimeout(() => {
// Resolve the promise to indicate successful processing
resolve();
}, 2000);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment