Toggle navigation
Toggle navigation
This project
Loading...
Sign in
이승윤
/
OpenSource-MyCookBook
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이승윤
2021-05-30 13:01:52 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b723259caafb1c189d93a8712591bbc87be63b45
b723259c
1 parent
24478c91
feat: Home page db 호출 기능
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
54 deletions
app.js
routes/Search.js
routes/Videos.js
app.js
View file @
b723259
...
...
@@ -28,7 +28,7 @@ var categori = require('./routes/categori');
var
accounts
=
require
(
'./routes/accounts'
);
var
auth
=
require
(
'./routes/auth'
);
var
connectMongo
=
require
(
'connect-mongo'
);
var
Search
=
require
(
'./routes/Search
'
);
var
Video
=
require
(
'./routes/Videos
'
);
var
MongoStore
=
connectMongo
(
session
);
app
.
set
(
'views'
,
path
.
join
(
__dirname
,
'views'
));
...
...
@@ -68,7 +68,7 @@ app.use(function (req, res, next) {
});
//routes add
app
.
use
(
'/'
,
Search
);
app
.
use
(
'/'
,
Video
);
app
.
use
(
'/categori'
,
categori
);
app
.
use
(
'/accounts'
,
accounts
);
app
.
use
(
'/auth'
,
auth
);
...
...
routes/Search.js
View file @
b723259
...
...
@@ -9,7 +9,7 @@ var limit = 10; // 출력 갯수
var
video
=
[];
var
test
=
'test'
;
var
count
=
0
;
youtube
.
setKey
(
'AIzaSy
AsKr_oWGZIBbL5tLdIl98Lf9Pzqj8jX4o
'
);
// API 키 입력
youtube
.
setKey
(
'AIzaSy
CAaeW1qMSInEdN1OzU20FZlToIZYkb1bc
'
);
// API 키 입력
youtube
.
addParam
(
'order'
,
'rating'
);
// 평점 순으로 정렬
youtube
.
addParam
(
'type'
,
'video'
);
// 타입 지정
youtube
.
addParam
(
'videoLicense'
,
'creativeCommon'
);
// 크리에이티브 커먼즈 아이템만 불러옴
...
...
@@ -19,9 +19,7 @@ youtube.search(word, limit, function (err, result) {
if
(
err
)
{
console
.
log
(
err
);
}
// 에러일 경우 에러공지하고 빠져나감
//console.log(JSON.stringify(result, null, 2)); // 받아온 전체 리스트 출력
var
items
=
result
[
'items'
];
// 결과 중 items 항목만 가져옴
for
(
var
i
in
items
)
{
var
it
=
items
[
i
];
...
...
routes/Videos.js
View file @
b723259
var
Youtube
=
require
(
'youtube-node'
);
var
youtube
=
new
Youtube
();
var
express
=
require
(
'express'
);
var
CategoriModel
=
require
(
'../models/CategoriModel'
);
var
VideoModel
=
require
(
'../models/VideoModel'
);
var
router
=
express
.
Router
();
var
word
=
'백종원'
;
// 검색어 지정
var
limit
=
10
;
// 출력 갯수
var
video
=
[];
var
test
=
'test'
;
var
count
=
0
;
youtube
.
setKey
(
'AIzaSyAsKr_oWGZIBbL5tLdIl98Lf9Pzqj8jX4o'
);
// API 키 입력
youtube
.
addParam
(
'order'
,
'rating'
);
// 평점 순으로 정렬
youtube
.
addParam
(
'type'
,
'video'
);
// 타입 지정
youtube
.
addParam
(
'videoLicense'
,
'creativeCommon'
);
// 크리에이티브 커먼즈 아이템만 불러옴
youtube
.
search
(
word
,
limit
,
function
(
err
,
result
)
{
// 검색 실행
if
(
err
)
{
console
.
log
(
err
);
}
// 에러일 경우 에러공지하고 빠져나감
//console.log(JSON.stringify(result, null, 2)); // 받아온 전체 리스트 출력
var
items
=
result
[
'items'
];
// 결과 중 items 항목만 가져옴
for
(
var
i
in
items
)
{
var
it
=
items
[
i
];
for
(
var
j
in
it
)
{
if
(
it
[
j
][
'title'
]
!=
null
)
{
var
title
=
it
[
j
][
'title'
];
}
if
(
it
[
j
][
'videoId'
]
!=
null
)
{
var
video_id
=
it
[
j
][
'videoId'
];
}
var
urls
=
'https://www.youtube.com/watch?v='
+
video_id
;
}
var
item
=
{
id
:
count
,
title
:
title
,
video_id
:
video_id
,
urls
:
urls
,
};
count
++
;
video
.
push
(
item
);
}
});
router
.
get
(
'/'
,
function
(
req
,
res
)
{
res
.
render
(
'home'
,
{
videos
:
video
}
// DB에서 받은 videos를 videos변수명으로 내보냄
);
CategoriModel
.
find
(
function
(
err
,
category
)
{
VideoModel
.
find
(
function
(
err
,
video
)
{
var
item
=
[];
// 카테고리별 비디오 목록을 담아두는 배열
for
(
var
i
in
category
)
{
var
videos
=
[];
// 비디오 목록을 담는 임시 배열
for
(
var
j
in
video
)
{
if
(
category
[
i
].
title
==
video
[
j
].
categori
)
{
videos
.
push
(
video
[
j
]);
}
}
if
(
videos
.
length
!=
0
)
{
// 빈 배열 체크
console
.
log
(
videos
);
var
items
=
{
category
:
category
[
i
],
videos
:
videos
,
};
item
.
push
(
items
);
}
}
//console.log(item[2].category.title);
//console.log(item[2].videos);
res
.
render
(
'home'
,
{
video
:
item
,
categories
:
category
}
// DB에서 받은 videos와 category를 videos변수명으로 내보냄
);
});
});
});
module
.
exports
=
router
;
...
...
Please
register
or
login
to post a comment