Flare-k

[Add] Speed Test

/* eslint-disable no-console */
import routes from "../routes";
import File from "../models/File";
import performance from "perf_hooks";
export const home = async (req, res) => {
try {
......@@ -13,18 +14,20 @@ export const home = async (req, res) => {
};
export const search = async (req, res) => {
const {
query: { term: searchingBy },
} = req; // == const searchingBy = req.query.term;
let files = [];
try {
files = await File.find({
title: { $regex: searchingBy, $options: "i" }, // i를 옵션으로 추가하면 insensitive.. 대소문자 구분 안함.
});
} catch (error) {
console.log(error);
}
res.render("search", { pageTitle: "Search", searchingBy, files });
console.time("SearchFunction");
const {
query: { term: searchingBy },
} = req; // == const searchingBy = req.query.term;
let files = [];
try {
files = await File.find({
title: { $regex: searchingBy, $options: "i" }, // i를 옵션으로 추가하면 insensitive.. 대소문자 구분 안함.
});
console.timeEnd("SearchFunction");
} catch (error) {
console.log(error);
}
res.render("search", { pageTitle: "Search", searchingBy, files });
};
......@@ -35,6 +38,7 @@ export const getUpload = (req, res) =>
export const postUpload = async (req, res) => {
// const {} 를 통해 body를 받아와 요청하는 정보들을 확인한다.
// 이는 pug와 db.js를 확인해야하는 듯 하다.
console.time("UploadFunction");
const {
body: { title },
file: { path }, // path로 할때는 로컬의 경로. S3는 location
......@@ -45,10 +49,9 @@ export const postUpload = async (req, res) => {
title,
// 여기있는 fileUrl, title은 fileDB의 속성이다.
});
console.log(newFile);
console.timeEnd("UploadFunction");
res.redirect(routes.home);
};
export const fileDetail = async (req, res) => {
......@@ -57,10 +60,8 @@ export const fileDetail = async (req, res) => {
params: { id },
} = req;
try {
const video = await Video.findById(id)
.populate("creator")
.populate("comments");
res.render("videoDetail", { pageTitle: video.title, video });
const file = await File.findById(id);
res.render("fileDetail", { pageTitle: file.title, file });
} catch (error) {
res.redirect(routes.home);
}
......
......@@ -6832,6 +6832,11 @@
"sha.js": "^2.4.8"
}
},
"perf_hooks": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/perf_hooks/-/perf_hooks-0.0.1.tgz",
"integrity": "sha512-qG/D9iA4KDme+KF4vCObJy6Bouu3BlQnmJ8jPydVPm32NJBD9ZK1ZNgXSYaZKHkVC1sKSqUiLgFvAZPUiIEnBw=="
},
"performance-now": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
......
......@@ -47,6 +47,7 @@
"passport-github": "^1.1.0",
"passport-local": "^1.0.0",
"passport-local-mongoose": "^6.0.1",
"perf_hooks": "0.0.1",
"postcss-loader": "^3.0.0",
"pug": "^2.0.4",
"sass-loader": "^8.0.2",
......
extends layouts/main
block content
.file-detail__container
.file__info
h5.file__title=file.title
\ No newline at end of file
extends layouts/main
include mixins/videoBlock
include mixins/fileBlock
block content
.search__header
h3 Searching for: #{searchingBy}
.search__videos
if videos.length === 0
h5 No Videos Found
each item in videos
+videoBlock({
if files.length === 0
h5 No Files Found
each item in files
+fileBlock({
title : item.title,
views: item.views,
videoFile:item.videoFile,
id: item.id
})
\ No newline at end of file
......