Flare-k

[Modified] Video DB and videoDetail View

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