Flare-k

[Modified] Video DB and videoDetail View

...@@ -115,4 +115,5 @@ dist ...@@ -115,4 +115,5 @@ dist
115 .yarn/build-state.yml 115 .yarn/build-state.yml
116 .pnp.* 116 .pnp.*
117 117
118 -package-lock.json
...\ No newline at end of file ...\ No newline at end of file
118 +package-lock.json
119 +uploads
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -13,6 +13,7 @@ const app = express(); ...@@ -13,6 +13,7 @@ const app = express();
13 13
14 app.use(helmet()); 14 app.use(helmet());
15 app.set("view engine", "pug"); 15 app.set("view engine", "pug");
16 +app.use("/uploads", express.static("uploads"));
16 app.use(cookieParser()); 17 app.use(cookieParser());
17 app.use(bodyParser.json()); 18 app.use(bodyParser.json());
18 app.use(bodyParser.urlencoded({ extended: true })); //json, html, text, urlencoded 할 거 없이 다 parser할 수 있도록 설정해줘야 한다. 19 app.use(bodyParser.urlencoded({ extended: true })); //json, html, text, urlencoded 할 거 없이 다 parser할 수 있도록 설정해줘야 한다.
......
...@@ -8,7 +8,7 @@ import Video from "../models/Video"; ...@@ -8,7 +8,7 @@ import Video from "../models/Video";
8 export const home = async(req, res) => { 8 export const home = async(req, res) => {
9 try { 9 try {
10 const videos = await Video.find({}); //모든 비디오를 가져온다. 10 const videos = await Video.find({}); //모든 비디오를 가져온다.
11 - res.render("home", { pageTitle: "Home", videos }); 11 + res.render("home", { pageTitle: "Home", videos }); //render DB에 저장된 video의 내용을 보여준다
12 } catch (error) { 12 } catch (error) {
13 console.log(error); 13 console.log(error);
14 res.render("home", { pageTitle: "Home", videos: [] }); 14 res.render("home", { pageTitle: "Home", videos: [] });
...@@ -44,8 +44,20 @@ export const postUpload = async(req, res) => { ...@@ -44,8 +44,20 @@ export const postUpload = async(req, res) => {
44 //id는 mongoDB가 랜덤하게 만들어준다. 44 //id는 mongoDB가 랜덤하게 만들어준다.
45 }; 45 };
46 46
47 -export const videoDetail = (req, res) => 47 +export const videoDetail = async(req, res) => {
48 - res.render("videoDetail", { pageTitle: "Video Detail" }); 48 + //console.log(req.params); params에 id가 있다는걸 알게 됨
49 + const {
50 + params: { id },
51 + } = req;
52 + try {
53 + const video = await Video.findById(id);
54 + //console.log(video);
55 + res.render("videoDetail", { pageTitle: "Video Detail", video });
56 + } catch (error) {
57 + //console.log(error);
58 + res.redirect(routes.home);
59 + }
60 +};
49 export const editVideo = (req, res) => 61 export const editVideo = (req, res) =>
50 res.render("editVideo", { pageTitle: "Edit Video" }); 62 res.render("editVideo", { pageTitle: "Edit Video" });
51 export const deleteVideo = (req, res) => 63 export const deleteVideo = (req, res) =>
......
1 import multer from "multer"; 1 import multer from "multer";
2 import routes from "./routes"; 2 import routes from "./routes";
3 3
4 -const multerVideo = multer({ dest: "videos/" }); 4 +const multerVideo = multer({ dest: "uploads/videos/" });
5 5
6 export const localsMiddleware = (req, res, next) => { 6 export const localsMiddleware = (req, res, next) => {
7 res.locals.siteName = "my Youtube"; 7 res.locals.siteName = "my Youtube";
......
...@@ -8,5 +8,5 @@ block content ...@@ -8,5 +8,5 @@ block content
8 id: item.id, 8 id: item.id,
9 title : item.title, 9 title : item.title,
10 views: item.views, 10 views: item.views,
11 - videoFile:item.videoFile 11 + videoFile:item.fileUrl
12 }) 12 })
...\ No newline at end of file ...\ No newline at end of file
......
1 extends layouts/main 1 extends layouts/main
2 2
3 block content 3 block content
4 - p Hello This is videoDetail
...\ No newline at end of file ...\ No newline at end of file
4 + .video__player
5 + video(src=`/${video.fileUrl}`)
6 + .video__info
7 + a(href=routes.editVideo) Edit video
8 + h5.video__title=video.title
9 + span.video__views=video.views
10 + p.video__description=video.desription
...\ No newline at end of file ...\ No newline at end of file
......