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 @@ ...@@ -18,6 +18,7 @@
"express": "^4.18.2", "express": "^4.18.2",
"jsonwebtoken": "^9.0.0", "jsonwebtoken": "^9.0.0",
"mongoose": "^7.1.1", "mongoose": "^7.1.1",
"multer": "^1.4.5-lts.1",
"nodemailer": "^6.9.1", "nodemailer": "^6.9.1",
"nodemon": "^2.0.22", "nodemon": "^2.0.22",
"uuid": "^9.0.0" "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;
...@@ -4,8 +4,9 @@ import dotenv from "dotenv"; ...@@ -4,8 +4,9 @@ import dotenv from "dotenv";
import express from "express"; import express from "express";
import mongoose from "mongoose"; import mongoose from "mongoose";
//import routes //import routes
import userRoutes from "./routes/user.routes.js"; import userRoutes from "./routes/user.routes.js";
import translateRoutes from "./routes/translate.routes.js";
dotenv.config(); dotenv.config();
const app = express(); const app = express();
...@@ -16,31 +17,32 @@ app.use(cors()); ...@@ -16,31 +17,32 @@ app.use(cors());
//end //end
app.get("/", (req, res) => { app.get("/", (req, res) => {
res.json({ message: "Welcome to Server Node" }); res.json({ message: "Welcome to Server Node" });
}); });
//implement routes //implement routes
app.use("/rest_node/user", userRoutes); 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 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; const PORT = process.env.PORT || 5000;
mongoose mongoose
.connect(CONNECTION_URL, { .connect(CONNECTION_URL, {
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: true, useUnifiedTopology: true,
}) })
.then(() => { .then(() => {
app.listen(PORT, () => app.listen(PORT, () =>
console.log(`Server Running on port :http://localhost:${PORT}`) console.log(`Server Running on port :http://localhost:${PORT}`)
); );
}) })
.catch((error) => { .catch((error) => {
console.error(error); console.error(error);
process.exit(1); process.exit(1);
}); });
app.use((err, req, res, next) => { app.use((err, req, res, next) => {
console.error(err.stack); console.error(err.stack);
res.status(500).send('Internal Server Error'); res.status(500).send("Internal Server Error");
}); });
\ No newline at end of file
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