강현태

웹툰 보기 링크 추가.

This diff is collapsed. Click to expand it.
......@@ -14,6 +14,7 @@ var mytoons = require('./routes/mytoons');
var passport = require('passport');
var setting = require('./routes/setting');
var session = require('express-session');
var toonviewer = require('./routes/toonviewer')
passport.serializeUser(function(user, done) {
console.log('serialized');
......@@ -58,6 +59,7 @@ app.use('/', index);
app.use('/users', users);
app.use('/mytoons', mytoons);
app.use('/setting', setting);
app.use('/toonviewer', toonviewer);
//app.use(express.static('views'));
......
......@@ -32,7 +32,7 @@ function getUpdatedToons(cb){
}
function getMyToons(id,cb){
var sqlquery = 'SELECT name, thum_link, webtoon_link, week, last, latest FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;';
var sqlquery = 'SELECT name, thum_link, webtoon_link, week, last, latest, t.toon_index AS toon_index FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;';
var mylist = new Array();
connection.query(sqlquery,id,function(err,rows,result){
if(!err){
......@@ -40,7 +40,7 @@ function getMyToons(id,cb){
cb(mylist);
}else{
console.log("내 웹툰 리스트 가져오는데 실패했습니다!");
throw err;
//throw err;
}
});
}
......
var express = require('express');
var router = express.Router();
var request = require('request');
var cheerio = require('cheerio');
var async = require('async');
function updateLastWebtoon(toon_index, user_id, num,cb){
var sql_query = "UPDATE user_toon_relation SET last=? WHERE user_id=? && toon_index=?";
connection.query(sql_query,[num, user_id,toon_index],function(err){
if(!err){
cb();
}
});
}
function getToonImages(toon_index, num, cb){
var imageList = [];
var toonUrl = "http://comic.naver.com/webtoon/detail.nhn?titleId=" + toon_index + "&no=" + num;
request(toonUrl, function(err, res, html){
if(!err){
var $ = cheerio.load(html);
var p = Promise.resolve();
var eachs = $("div.wt_viewer > img").each(function(index, element) {
p = p.then(function() {
var toonHref = $(element).attr('src');
imageList.push(toonHref);
});
});
p.then(function(){
cb(imageList);
});
}else{
console.log("웹툰 이미지 못가져왔습니다.");
}
});
}
router.get('/:toon_index/:num',function(req,res){
if(!req.isAuthenticated()){
res.redirect('/');
return;
}
updateLastWebtoon(req.params.toon_index, req.user.user_id, req.params.num, function(){
var toonUrl = "http://comic.naver.com/webtoon/detail.nhn?titleId=" + req.params.toon_index + "&no=" + req.params.num;
res.redirect(toonUrl);
/*
getToonImages(req.params.toon_index, req.params.num, function(imageList){
res.render('toonviewer',{
title: "zzz",
images: imageList
});
});
*/
})
});
module.exports = router;
\ No newline at end of file
......@@ -27,11 +27,8 @@
</head>
<h1>내툰</h1>
<p>추가한 리스트</p>
<a href="/auth/logout/kakao">로그아웃</a>
<a href="/setting/">세팅</a>
</br>
<table>
<tr>
<th>썸네일</th>
......@@ -44,11 +41,10 @@
%><tr>
<td class="toon_thumbnail"><image src="<%= mytoons[i].thum_link%>"/></td>
<td class="toon_name"><%= mytoons[i].name %></td>
<td class="toon_last"><%= mytoons[i].last %>화</td>
<td class="toon_next"><%= mytoons[i].last +1 %>화</td>
<td class="toon_latest"><%= mytoons[i].latest %>화</td>
<td class="toon_last"><a href="/toonviewer/<%= mytoons[i].toon_index %>/<%= mytoons[i].last %>"><%= mytoons[i].last %>화</a></td>
<td class="toon_next"><% if(mytoons[i].last+1 <= mytoons[i].latest){ %> <a href="/toonviewer/<%= mytoons[i].toon_index %>/<%= mytoons[i].last+1 %>"><%= mytoons[i].last +1 %>화</a><% } %></td>
<td class="toon_latest"><a href="/toonviewer/<%= mytoons[i].toon_index %>/<%= mytoons[i].latest %>"><%= mytoons[i].latest %>화</a></td>
</tr>
<br>
<% } %>
</table>
......
......@@ -11,7 +11,7 @@
</head>
<h1>내툰</h1>
<p>추가하거나 제거할 웹툰을 선택해주세요.</p>
<a href="/mytoons">뒤로</a>
<table>
<%
var current = "";
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><%= title %></title>
</head>
<body>
<%
for(image in images){
%>
<img src="<%= images[image] %>" alt=""/>
<%
}
%>
</body>
</html>
\ No newline at end of file