Showing
7 changed files
with
83 additions
and
10 deletions
This diff is collapsed. Click to expand it.
| ... | @@ -14,6 +14,7 @@ var mytoons = require('./routes/mytoons'); | ... | @@ -14,6 +14,7 @@ var mytoons = require('./routes/mytoons'); |
| 14 | var passport = require('passport'); | 14 | var passport = require('passport'); |
| 15 | var setting = require('./routes/setting'); | 15 | var setting = require('./routes/setting'); |
| 16 | var session = require('express-session'); | 16 | var session = require('express-session'); |
| 17 | +var toonviewer = require('./routes/toonviewer') | ||
| 17 | 18 | ||
| 18 | passport.serializeUser(function(user, done) { | 19 | passport.serializeUser(function(user, done) { |
| 19 | console.log('serialized'); | 20 | console.log('serialized'); |
| ... | @@ -58,6 +59,7 @@ app.use('/', index); | ... | @@ -58,6 +59,7 @@ app.use('/', index); |
| 58 | app.use('/users', users); | 59 | app.use('/users', users); |
| 59 | app.use('/mytoons', mytoons); | 60 | app.use('/mytoons', mytoons); |
| 60 | app.use('/setting', setting); | 61 | app.use('/setting', setting); |
| 62 | +app.use('/toonviewer', toonviewer); | ||
| 61 | 63 | ||
| 62 | //app.use(express.static('views')); | 64 | //app.use(express.static('views')); |
| 63 | 65 | ... | ... |
| ... | @@ -32,7 +32,7 @@ function getUpdatedToons(cb){ | ... | @@ -32,7 +32,7 @@ function getUpdatedToons(cb){ |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | function getMyToons(id,cb){ | 34 | function getMyToons(id,cb){ |
| 35 | - 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;'; | 35 | + 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;'; |
| 36 | var mylist = new Array(); | 36 | var mylist = new Array(); |
| 37 | connection.query(sqlquery,id,function(err,rows,result){ | 37 | connection.query(sqlquery,id,function(err,rows,result){ |
| 38 | if(!err){ | 38 | if(!err){ |
| ... | @@ -40,7 +40,7 @@ function getMyToons(id,cb){ | ... | @@ -40,7 +40,7 @@ function getMyToons(id,cb){ |
| 40 | cb(mylist); | 40 | cb(mylist); |
| 41 | }else{ | 41 | }else{ |
| 42 | console.log("내 웹툰 리스트 가져오는데 실패했습니다!"); | 42 | console.log("내 웹툰 리스트 가져오는데 실패했습니다!"); |
| 43 | - throw err; | 43 | + //throw err; |
| 44 | } | 44 | } |
| 45 | }); | 45 | }); |
| 46 | } | 46 | } | ... | ... |
routes/toonviewer.js
0 → 100644
| 1 | +var express = require('express'); | ||
| 2 | +var router = express.Router(); | ||
| 3 | +var request = require('request'); | ||
| 4 | +var cheerio = require('cheerio'); | ||
| 5 | +var async = require('async'); | ||
| 6 | + | ||
| 7 | +function updateLastWebtoon(toon_index, user_id, num,cb){ | ||
| 8 | + var sql_query = "UPDATE user_toon_relation SET last=? WHERE user_id=? && toon_index=?"; | ||
| 9 | + connection.query(sql_query,[num, user_id,toon_index],function(err){ | ||
| 10 | + if(!err){ | ||
| 11 | + cb(); | ||
| 12 | + } | ||
| 13 | + }); | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +function getToonImages(toon_index, num, cb){ | ||
| 17 | + var imageList = []; | ||
| 18 | + var toonUrl = "http://comic.naver.com/webtoon/detail.nhn?titleId=" + toon_index + "&no=" + num; | ||
| 19 | + | ||
| 20 | + request(toonUrl, function(err, res, html){ | ||
| 21 | + if(!err){ | ||
| 22 | + var $ = cheerio.load(html); | ||
| 23 | + var p = Promise.resolve(); | ||
| 24 | + var eachs = $("div.wt_viewer > img").each(function(index, element) { | ||
| 25 | + p = p.then(function() { | ||
| 26 | + var toonHref = $(element).attr('src'); | ||
| 27 | + imageList.push(toonHref); | ||
| 28 | + }); | ||
| 29 | + }); | ||
| 30 | + p.then(function(){ | ||
| 31 | + cb(imageList); | ||
| 32 | + }); | ||
| 33 | + }else{ | ||
| 34 | + console.log("웹툰 이미지 못가져왔습니다."); | ||
| 35 | + } | ||
| 36 | + }); | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +router.get('/:toon_index/:num',function(req,res){ | ||
| 40 | + if(!req.isAuthenticated()){ | ||
| 41 | + res.redirect('/'); | ||
| 42 | + return; | ||
| 43 | + } | ||
| 44 | + updateLastWebtoon(req.params.toon_index, req.user.user_id, req.params.num, function(){ | ||
| 45 | + var toonUrl = "http://comic.naver.com/webtoon/detail.nhn?titleId=" + req.params.toon_index + "&no=" + req.params.num; | ||
| 46 | + res.redirect(toonUrl); | ||
| 47 | + /* | ||
| 48 | + getToonImages(req.params.toon_index, req.params.num, function(imageList){ | ||
| 49 | + res.render('toonviewer',{ | ||
| 50 | + title: "zzz", | ||
| 51 | + images: imageList | ||
| 52 | + }); | ||
| 53 | + }); | ||
| 54 | + */ | ||
| 55 | + }) | ||
| 56 | +}); | ||
| 57 | + | ||
| 58 | +module.exports = router; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -27,11 +27,8 @@ | ... | @@ -27,11 +27,8 @@ |
| 27 | </head> | 27 | </head> |
| 28 | <h1>내툰</h1> | 28 | <h1>내툰</h1> |
| 29 | <p>추가한 리스트</p> | 29 | <p>추가한 리스트</p> |
| 30 | - | ||
| 31 | <a href="/auth/logout/kakao">로그아웃</a> | 30 | <a href="/auth/logout/kakao">로그아웃</a> |
| 32 | <a href="/setting/">세팅</a> | 31 | <a href="/setting/">세팅</a> |
| 33 | -</br> | ||
| 34 | - | ||
| 35 | <table> | 32 | <table> |
| 36 | <tr> | 33 | <tr> |
| 37 | <th>썸네일</th> | 34 | <th>썸네일</th> |
| ... | @@ -44,11 +41,10 @@ | ... | @@ -44,11 +41,10 @@ |
| 44 | %><tr> | 41 | %><tr> |
| 45 | <td class="toon_thumbnail"><image src="<%= mytoons[i].thum_link%>"/></td> | 42 | <td class="toon_thumbnail"><image src="<%= mytoons[i].thum_link%>"/></td> |
| 46 | <td class="toon_name"><%= mytoons[i].name %></td> | 43 | <td class="toon_name"><%= mytoons[i].name %></td> |
| 47 | - <td class="toon_last"><%= mytoons[i].last %>화</td> | 44 | + <td class="toon_last"><a href="/toonviewer/<%= mytoons[i].toon_index %>/<%= mytoons[i].last %>"><%= mytoons[i].last %>화</a></td> |
| 48 | - <td class="toon_next"><%= mytoons[i].last +1 %>화</td> | 45 | + <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> |
| 49 | - <td class="toon_latest"><%= mytoons[i].latest %>화</td> | 46 | + <td class="toon_latest"><a href="/toonviewer/<%= mytoons[i].toon_index %>/<%= mytoons[i].latest %>"><%= mytoons[i].latest %>화</a></td> |
| 50 | </tr> | 47 | </tr> |
| 51 | - <br> | ||
| 52 | <% } %> | 48 | <% } %> |
| 53 | </table> | 49 | </table> |
| 54 | 50 | ... | ... |
views/toonviewer.ejs
0 → 100644
| 1 | +<!DOCTYPE html> | ||
| 2 | +<html lang="en"> | ||
| 3 | +<head> | ||
| 4 | + <meta charset="UTF-8"> | ||
| 5 | + <title><%= title %></title> | ||
| 6 | +</head> | ||
| 7 | +<body> | ||
| 8 | +<% | ||
| 9 | +for(image in images){ | ||
| 10 | +%> | ||
| 11 | +<img src="<%= images[image] %>" alt=""/> | ||
| 12 | +<% | ||
| 13 | +} | ||
| 14 | + %> | ||
| 15 | + | ||
| 16 | +</body> | ||
| 17 | +</html> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment