Showing
5 changed files
with
36 additions
and
25 deletions
| 1 | /* eslint-disable no-console */ | 1 | /* eslint-disable no-console */ |
| 2 | import routes from "../routes"; | 2 | import routes from "../routes"; |
| 3 | import File from "../models/File"; | 3 | import File from "../models/File"; |
| 4 | +import performance from "perf_hooks"; | ||
| 4 | 5 | ||
| 5 | export const home = async (req, res) => { | 6 | export const home = async (req, res) => { |
| 6 | try { | 7 | try { |
| ... | @@ -13,18 +14,20 @@ export const home = async (req, res) => { | ... | @@ -13,18 +14,20 @@ export const home = async (req, res) => { |
| 13 | }; | 14 | }; |
| 14 | 15 | ||
| 15 | export const search = async (req, res) => { | 16 | export const search = async (req, res) => { |
| 16 | - const { | 17 | + console.time("SearchFunction"); |
| 17 | - query: { term: searchingBy }, | 18 | + const { |
| 18 | - } = req; // == const searchingBy = req.query.term; | 19 | + query: { term: searchingBy }, |
| 19 | - let files = []; | 20 | + } = req; // == const searchingBy = req.query.term; |
| 20 | - try { | 21 | + let files = []; |
| 21 | - files = await File.find({ | 22 | + try { |
| 22 | - title: { $regex: searchingBy, $options: "i" }, // i를 옵션으로 추가하면 insensitive.. 대소문자 구분 안함. | 23 | + files = await File.find({ |
| 23 | - }); | 24 | + title: { $regex: searchingBy, $options: "i" }, // i를 옵션으로 추가하면 insensitive.. 대소문자 구분 안함. |
| 24 | - } catch (error) { | 25 | + }); |
| 25 | - console.log(error); | 26 | + console.timeEnd("SearchFunction"); |
| 26 | - } | 27 | + } catch (error) { |
| 27 | - res.render("search", { pageTitle: "Search", searchingBy, files }); | 28 | + console.log(error); |
| 29 | + } | ||
| 30 | + res.render("search", { pageTitle: "Search", searchingBy, files }); | ||
| 28 | }; | 31 | }; |
| 29 | 32 | ||
| 30 | 33 | ||
| ... | @@ -35,6 +38,7 @@ export const getUpload = (req, res) => | ... | @@ -35,6 +38,7 @@ export const getUpload = (req, res) => |
| 35 | export const postUpload = async (req, res) => { | 38 | export const postUpload = async (req, res) => { |
| 36 | // const {} 를 통해 body를 받아와 요청하는 정보들을 확인한다. | 39 | // const {} 를 통해 body를 받아와 요청하는 정보들을 확인한다. |
| 37 | // 이는 pug와 db.js를 확인해야하는 듯 하다. | 40 | // 이는 pug와 db.js를 확인해야하는 듯 하다. |
| 41 | + console.time("UploadFunction"); | ||
| 38 | const { | 42 | const { |
| 39 | body: { title }, | 43 | body: { title }, |
| 40 | file: { path }, // path로 할때는 로컬의 경로. S3는 location | 44 | file: { path }, // path로 할때는 로컬의 경로. S3는 location |
| ... | @@ -45,10 +49,9 @@ export const postUpload = async (req, res) => { | ... | @@ -45,10 +49,9 @@ export const postUpload = async (req, res) => { |
| 45 | title, | 49 | title, |
| 46 | // 여기있는 fileUrl, title은 fileDB의 속성이다. | 50 | // 여기있는 fileUrl, title은 fileDB의 속성이다. |
| 47 | }); | 51 | }); |
| 48 | - | ||
| 49 | console.log(newFile); | 52 | console.log(newFile); |
| 53 | + console.timeEnd("UploadFunction"); | ||
| 50 | res.redirect(routes.home); | 54 | res.redirect(routes.home); |
| 51 | - | ||
| 52 | }; | 55 | }; |
| 53 | 56 | ||
| 54 | export const fileDetail = async (req, res) => { | 57 | export const fileDetail = async (req, res) => { |
| ... | @@ -57,10 +60,8 @@ export const fileDetail = async (req, res) => { | ... | @@ -57,10 +60,8 @@ export const fileDetail = async (req, res) => { |
| 57 | params: { id }, | 60 | params: { id }, |
| 58 | } = req; | 61 | } = req; |
| 59 | try { | 62 | try { |
| 60 | - const video = await Video.findById(id) | 63 | + const file = await File.findById(id); |
| 61 | - .populate("creator") | 64 | + res.render("fileDetail", { pageTitle: file.title, file }); |
| 62 | - .populate("comments"); | ||
| 63 | - res.render("videoDetail", { pageTitle: video.title, video }); | ||
| 64 | } catch (error) { | 65 | } catch (error) { |
| 65 | res.redirect(routes.home); | 66 | res.redirect(routes.home); |
| 66 | } | 67 | } | ... | ... |
| ... | @@ -6832,6 +6832,11 @@ | ... | @@ -6832,6 +6832,11 @@ |
| 6832 | "sha.js": "^2.4.8" | 6832 | "sha.js": "^2.4.8" |
| 6833 | } | 6833 | } |
| 6834 | }, | 6834 | }, |
| 6835 | + "perf_hooks": { | ||
| 6836 | + "version": "0.0.1", | ||
| 6837 | + "resolved": "https://registry.npmjs.org/perf_hooks/-/perf_hooks-0.0.1.tgz", | ||
| 6838 | + "integrity": "sha512-qG/D9iA4KDme+KF4vCObJy6Bouu3BlQnmJ8jPydVPm32NJBD9ZK1ZNgXSYaZKHkVC1sKSqUiLgFvAZPUiIEnBw==" | ||
| 6839 | + }, | ||
| 6835 | "performance-now": { | 6840 | "performance-now": { |
| 6836 | "version": "2.1.0", | 6841 | "version": "2.1.0", |
| 6837 | "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", | 6842 | "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", | ... | ... |
| ... | @@ -47,6 +47,7 @@ | ... | @@ -47,6 +47,7 @@ |
| 47 | "passport-github": "^1.1.0", | 47 | "passport-github": "^1.1.0", |
| 48 | "passport-local": "^1.0.0", | 48 | "passport-local": "^1.0.0", |
| 49 | "passport-local-mongoose": "^6.0.1", | 49 | "passport-local-mongoose": "^6.0.1", |
| 50 | + "perf_hooks": "0.0.1", | ||
| 50 | "postcss-loader": "^3.0.0", | 51 | "postcss-loader": "^3.0.0", |
| 51 | "pug": "^2.0.4", | 52 | "pug": "^2.0.4", |
| 52 | "sass-loader": "^8.0.2", | 53 | "sass-loader": "^8.0.2", | ... | ... |
Project/views/fileDetail.pug
0 → 100644
| 1 | extends layouts/main | 1 | extends layouts/main |
| 2 | -include mixins/videoBlock | 2 | +include mixins/fileBlock |
| 3 | 3 | ||
| 4 | block content | 4 | block content |
| 5 | .search__header | 5 | .search__header |
| 6 | h3 Searching for: #{searchingBy} | 6 | h3 Searching for: #{searchingBy} |
| 7 | .search__videos | 7 | .search__videos |
| 8 | - if videos.length === 0 | 8 | + if files.length === 0 |
| 9 | - h5 No Videos Found | 9 | + h5 No Files Found |
| 10 | - each item in videos | 10 | + each item in files |
| 11 | - +videoBlock({ | 11 | + +fileBlock({ |
| 12 | title : item.title, | 12 | title : item.title, |
| 13 | - views: item.views, | ||
| 14 | - videoFile:item.videoFile, | ||
| 15 | id: item.id | 13 | id: item.id |
| 16 | }) | 14 | }) |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment