Showing
6 changed files
with
27 additions
and
99 deletions
This diff is collapsed. Click to expand it.
... | @@ -62,36 +62,6 @@ router.get('/auth/logout/kakao',function (req,res) { | ... | @@ -62,36 +62,6 @@ router.get('/auth/logout/kakao',function (req,res) { |
62 | allWebtoons = new Array(); | 62 | allWebtoons = new Array(); |
63 | 63 | ||
64 | function getLatestToon(titleid, day ,cb) { | 64 | function getLatestToon(titleid, day ,cb) { |
65 | - /*var url = "http://comic.naver.com/webtoon/list.nhn?titleId=" + titleid+ "&weekday="+day; | ||
66 | - console.log(url); | ||
67 | - request(url, function (err, res, html) { | ||
68 | - if (!err) { | ||
69 | - var $ = cheerio.load(html); | ||
70 | - var latestLink = 'http://comic.naver.com'; | ||
71 | - var latest; | ||
72 | - var t = $('#content > table > tbody > tr > td.title > a').first().each(function () { | ||
73 | - latestLink += $(this).attr('href'); | ||
74 | - setTimeout(function () {},100); | ||
75 | - latest = latestLink.split('?')[1].split('&')[1].split('=')[1]; | ||
76 | - }); | ||
77 | - | ||
78 | - var latestImage; | ||
79 | - $('#content > table > tbody > tr > td > a > img').first().each(function () { | ||
80 | - latestImage = $(this).attr('src'); | ||
81 | - setTimeout(function () {},100); | ||
82 | - }); | ||
83 | - | ||
84 | - cb({ | ||
85 | - latest: latest, | ||
86 | - latestLink: latestLink, | ||
87 | - latestImage: latestImage | ||
88 | - }); | ||
89 | - | ||
90 | - } else { | ||
91 | - console.log("최신화 못가져왔습니다."); | ||
92 | - //throw err; | ||
93 | - } | ||
94 | - });*/ | ||
95 | } | 65 | } |
96 | 66 | ||
97 | function getAllToons() { | 67 | function getAllToons() { |
... | @@ -287,10 +257,6 @@ function getAllToons() { | ... | @@ -287,10 +257,6 @@ function getAllToons() { |
287 | p.then(function() { | 257 | p.then(function() { |
288 | i = 0; | 258 | i = 0; |
289 | allWebtoonList.forEach(function (webtoon) { | 259 | allWebtoonList.forEach(function (webtoon) { |
290 | - // getLatestToon(webtoon.toon_index, webtoon.week, function (latest_toon) { | ||
291 | - // webtoon.latest = latest_toon.latest; | ||
292 | - //i++; | ||
293 | - //console.log(i + " = " + webtoon.name + " : " + webtoon.latest); | ||
294 | var sql= "INSERT INTO `toon` (toon_index, name, thum_link, webtoon_link, week, site, latest) VALUES(?) ON DUPLICATE KEY UPDATE latest=latest"; | 260 | var sql= "INSERT INTO `toon` (toon_index, name, thum_link, webtoon_link, week, site, latest) VALUES(?) ON DUPLICATE KEY UPDATE latest=latest"; |
295 | var values=[webtoon.toon_index, webtoon.name, webtoon.thum_link, webtoon.webtoon_link,webtoon.week, webtoon.site, webtoon.latest]; | 261 | var values=[webtoon.toon_index, webtoon.name, webtoon.thum_link, webtoon.webtoon_link,webtoon.week, webtoon.site, webtoon.latest]; |
296 | connection.query(sql,[values],function(err,result){ | 262 | connection.query(sql,[values],function(err,result){ |
... | @@ -299,11 +265,6 @@ function getAllToons() { | ... | @@ -299,11 +265,6 @@ function getAllToons() { |
299 | } else { | 265 | } else { |
300 | console.log("웹툰 DB처리 완료!"); | 266 | console.log("웹툰 DB처리 완료!"); |
301 | } | 267 | } |
302 | - //[webtoon,webtoon.latest], function () { | ||
303 | - // if (err) { | ||
304 | - // console.log("웹툰 갱신중 에러!"); | ||
305 | - //} | ||
306 | - // } | ||
307 | }); | 268 | }); |
308 | //}); | 269 | //}); |
309 | }) | 270 | }) | ... | ... |
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | var cheerio = require('cheerio'); | 2 | var cheerio = require('cheerio'); |
3 | - | ||
4 | var request = require('request'); | 3 | var request = require('request'); |
5 | var async = require('async'); | 4 | var async = require('async'); |
6 | var router = express.Router(); | 5 | var router = express.Router(); |
7 | 6 | ||
8 | function getUpdatedToons(cb){ | 7 | function getUpdatedToons(cb){ |
9 | - var allToons = new Array(); | ||
10 | - var allToonsUrl = "http://comic.naver.com/webtoon/weekday.nhn"; | ||
11 | - | ||
12 | - request(allToonsUrl, function(err, res, html){ | ||
13 | - if(!err){ | ||
14 | - var $ = cheerio.load(html); | ||
15 | - var p = Promise.resolve(); | ||
16 | - var eachs = $(".thumb").has('.ico_updt').next().each(function() { | ||
17 | - p = p.then(function() { | ||
18 | - var link = $(this); | ||
19 | - var toonName = link.text(); | ||
20 | - var toonHref = link.attr('href'); | ||
21 | - | ||
22 | - allToons[toonName] = toonHref; | ||
23 | - }); | ||
24 | - }); | ||
25 | - p.then(function(){ | ||
26 | - cb(allToons); | ||
27 | - }); | ||
28 | - }else{ | ||
29 | - console.log("업데이트 웹툰 못가져왔습니다."); | ||
30 | - throw err; | ||
31 | - } | ||
32 | - }); | ||
33 | } | 8 | } |
34 | 9 | ||
35 | function getMyToons(id,cb){ | 10 | function getMyToons(id,cb){ |
36 | - //var sql = "INSERT INTO `user` (id) VALUES (?)"; | 11 | + //id 값을 가진 user가 저장한 웹툰들 가져오기 |
37 | - //var kid=[profile._json.id]; | 12 | + var sqlquery = "SELECT t.toon_index, t.name, t.thum_link, t.webtoon_link, t.week, t.site FROM user u, user_toon_relation ur, toon t WHERE u.id = '"+id+"' && u.id=ur.user_id && t.toon_index=ur.toon_index;"; |
38 | - //connection.query(sql,kid,function(err,result){ | ||
39 | - var sqlquery = "SELECT name, thum_link, webtoon_link, week, last, 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;"; | ||
40 | - //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;"; | ||
41 | var mylist = new Array(); | 13 | var mylist = new Array(); |
42 | connection.query(sqlquery,id,function(err,rows,result){ | 14 | connection.query(sqlquery,id,function(err,rows,result){ |
43 | if(!err){ | 15 | if(!err){ |
44 | mylist=rows; | 16 | mylist=rows; |
45 | cb(mylist); | 17 | cb(mylist); |
18 | + console.log(mylist); | ||
46 | }else{ | 19 | }else{ |
47 | console.log("내 웹툰 리스트 가져오는데 실패했습니다!"); | 20 | console.log("내 웹툰 리스트 가져오는데 실패했습니다!"); |
48 | //throw err; | 21 | //throw err; | ... | ... |
... | @@ -3,35 +3,34 @@ var router = express.Router(); | ... | @@ -3,35 +3,34 @@ var router = express.Router(); |
3 | 3 | ||
4 | function addMyToons(id,index,cb){ | 4 | function addMyToons(id,index,cb){ |
5 | connection.query("INSERT INTO user_toon_relation SET ?;", | 5 | connection.query("INSERT INTO user_toon_relation SET ?;", |
6 | - {user_id : id,toon_index : index, last : 1},function (err) { | 6 | + {user_id : id,toon_index : index},function (err) { |
7 | if(err) { | 7 | if(err) { |
8 | throw err; | 8 | throw err; |
9 | console.log("내 웹툰 추가중 에러!") | 9 | console.log("내 웹툰 추가중 에러!") |
10 | } else{ | 10 | } else{ |
11 | - //alert("추가되었습니다.") | 11 | + // alert("추가되었습니다.") |
12 | cb(); | 12 | cb(); |
13 | } | 13 | } |
14 | }); | 14 | }); |
15 | } | 15 | } |
16 | - | 16 | +//내툰 수정하기 |
17 | router.post('/toggle_toon',function(req,res,next){ | 17 | router.post('/toggle_toon',function(req,res,next){ |
18 | var index = req.body.toon_index; | 18 | var index = req.body.toon_index; |
19 | var id = req.user.user_id; | 19 | var id = req.user.user_id; |
20 | - | 20 | + connection.query("SELECT COUNT(*) FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"'", |
21 | - connection.query("SELECT COUNT(*) FROM user_toon_relation WHERE user_id=? && toon_index=?", | ||
22 | [id,index], function (err, rows,result) { | 21 | [id,index], function (err, rows,result) { |
23 | if(err){ | 22 | if(err){ |
24 | console.log("내웹툰 등록중 에러!"); | 23 | console.log("내웹툰 등록중 에러!"); |
25 | }else{ | 24 | }else{ |
26 | var count = rows[0]["COUNT(*)"]; | 25 | var count = rows[0]["COUNT(*)"]; |
27 | if(count>0){//이미 등록되어 있는 것이라면, | 26 | if(count>0){//이미 등록되어 있는 것이라면, |
28 | - connection.query("DELETE FROM user_toon_relation WHERE user_id=? && toon_index=?;", | 27 | + connection.query("DELETE FROM user_toon_relation WHERE user_id='"+id+"' && toon_index='"+index+"';", |
29 | [id, index],function (err, rows, result) { | 28 | [id, index],function (err, rows, result) { |
30 | if(err) { | 29 | if(err) { |
31 | console.log("내 웹툰 제거중 에러!"); | 30 | console.log("내 웹툰 제거중 에러!"); |
32 | throw err; | 31 | throw err; |
33 | }else{ | 32 | }else{ |
34 | - //alert("제거되었습니다.") | 33 | + // alert("제거되었습니다.") |
35 | res.redirect('/setting'); | 34 | res.redirect('/setting'); |
36 | } | 35 | } |
37 | }); | 36 | }); |
... | @@ -45,13 +44,15 @@ router.post('/toggle_toon',function(req,res,next){ | ... | @@ -45,13 +44,15 @@ router.post('/toggle_toon',function(req,res,next){ |
45 | }); | 44 | }); |
46 | 45 | ||
47 | function getMyToons(id,cb){ | 46 | function getMyToons(id,cb){ |
48 | - var sqlquery = 'SELECT name, thum_link, webtoon_link, week, last FROM user u, user_toon_relation ur, toon t WHERE u.id=? && u.id=ur.user_id && t.toon_index=ur.toon_index;'; | 47 | + //mysql5.7 syntax에 맞게 수정 => 로그인한 유저의 |
48 | + var sqlquery = "SELECT t.toon_index, t.name, t.thum_link, t.webtoon_link, t.week, t.site FROM user u, user_toon_relation ur, toon t WHERE u.id = '"+id+"' && u.id=ur.user_id && t.toon_index=ur.toon_index;"; | ||
49 | var mylist = new Array(); | 49 | var mylist = new Array(); |
50 | connection.query(sqlquery,id,function(err,rows,result){ | 50 | connection.query(sqlquery,id,function(err,rows,result){ |
51 | if(!err){ | 51 | if(!err){ |
52 | mylist=rows; | 52 | mylist=rows; |
53 | cb(mylist); | 53 | cb(mylist); |
54 | }else{ | 54 | }else{ |
55 | + router.get('/') | ||
55 | console.log("내 웹툰 리스트 가져오는데 실패했습니다!"); | 56 | console.log("내 웹툰 리스트 가져오는데 실패했습니다!"); |
56 | //throw err; | 57 | //throw err; |
57 | } | 58 | } | ... | ... |
... | @@ -4,15 +4,6 @@ var request = require('request'); | ... | @@ -4,15 +4,6 @@ var request = require('request'); |
4 | var cheerio = require('cheerio'); | 4 | var cheerio = require('cheerio'); |
5 | var async = require('async'); | 5 | var async = require('async'); |
6 | 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){ | 7 | function getToonImages(toon_index, num, cb){ |
17 | var imageList = []; | 8 | var imageList = []; |
18 | var toonUrl = "http://comic.naver.com/webtoon/detail.nhn?titleId=" + toon_index + "&no=" + num; | 9 | var toonUrl = "http://comic.naver.com/webtoon/detail.nhn?titleId=" + toon_index + "&no=" + num; |
... | @@ -41,10 +32,6 @@ router.get('/:toon_index/:num',function(req,res){ | ... | @@ -41,10 +32,6 @@ router.get('/:toon_index/:num',function(req,res){ |
41 | res.redirect('/'); | 32 | res.redirect('/'); |
42 | return; | 33 | return; |
43 | } | 34 | } |
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){ | 35 | getToonImages(req.params.toon_index, req.params.num, function(imageList){ |
49 | res.render('toonviewer',{ | 36 | res.render('toonviewer',{ |
50 | title: "zzz", | 37 | title: "zzz", |
... | @@ -52,7 +39,7 @@ router.get('/:toon_index/:num',function(req,res){ | ... | @@ -52,7 +39,7 @@ router.get('/:toon_index/:num',function(req,res){ |
52 | }); | 39 | }); |
53 | }); | 40 | }); |
54 | 41 | ||
55 | - }) | 42 | + // }) |
56 | }); | 43 | }); |
57 | 44 | ||
58 | module.exports = router; | 45 | module.exports = router; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
4 | <title>내툰</title> | 4 | <title>내툰</title> |
5 | <link rel='stylesheet' href='/stylesheets/style.css' /> | 5 | <link rel='stylesheet' href='/stylesheets/style.css' /> |
6 | <style> | 6 | <style> |
7 | - .toon_latest,.toon_next,.toon_last,.toon_name,.toon_thumbnail{ | 7 | + .toon_name,.toon_thumbnail{ |
8 | width:10%; | 8 | width:10%; |
9 | } | 9 | } |
10 | 10 | ||
... | @@ -28,24 +28,30 @@ | ... | @@ -28,24 +28,30 @@ |
28 | <h1>내툰</h1> | 28 | <h1>내툰</h1> |
29 | <p>추가한 리스트</p> | 29 | <p>추가한 리스트</p> |
30 | <a href="/auth/logout/kakao">로그아웃</a> | 30 | <a href="/auth/logout/kakao">로그아웃</a> |
31 | -<a href="/setting/">세팅</a> | 31 | +<a href="/setting/">수정하기</a> |
32 | <table> | 32 | <table> |
33 | <tr> | 33 | <tr> |
34 | <th>썸네일</th> | 34 | <th>썸네일</th> |
35 | <th>웹툰명</th> | 35 | <th>웹툰명</th> |
36 | - <th>최근에 본 화</th> | 36 | + <th>요일</th> |
37 | - <th>다음화</th> | 37 | + <th>사이트</th> |
38 | - <th>최신화</th> | 38 | + <th>바로가기</th> |
39 | </tr> | 39 | </tr> |
40 | + <!--로그인한 회원이 내툰에 웹툰이 없을시--> | ||
41 | + <%if (mytoons.length==0){ | ||
42 | + %> | ||
43 | + <th>내툰리스트에 웹툰이 없습니다! 수정하기 버튼을 눌러서 추가하세요!</th> | ||
44 | + <%}%> | ||
40 | <% for(i=0;i<mytoons.length; i++){ | 45 | <% for(i=0;i<mytoons.length; i++){ |
41 | %><tr> | 46 | %><tr> |
42 | <td class="toon_thumbnail"><image src="<%= mytoons[i].thum_link%>"/></td> | 47 | <td class="toon_thumbnail"><image src="<%= mytoons[i].thum_link%>"/></td> |
43 | <td class="toon_name"><%= mytoons[i].name %></td> | 48 | <td class="toon_name"><%= mytoons[i].name %></td> |
44 | - <td class="toon_last"><a href="/toonviewer/<%= mytoons[i].toon_index %>/<%= mytoons[i].last %>"><%= mytoons[i].last %>화</a></td> | 49 | + <td class="week"><%= mytoons[i].week.toLowerCase() %></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> | 50 | + <td class="site"><%= mytoons[i].site %></td> |
46 | - <td class="toon_latest"><a href="/toonviewer/<%= mytoons[i].toon_index %>/<%= mytoons[i].latest %>"><%= mytoons[i].latest %>화</a></td> | 51 | + <td class="webtoon_link"><a href="<%=mytoons[i].webtoon_link%>">바로가기</a></td> |
47 | </tr> | 52 | </tr> |
48 | <% } %> | 53 | <% } %> |
54 | + | ||
49 | </table> | 55 | </table> |
50 | 56 | ||
51 | </br> | 57 | </br> | ... | ... |
-
Please register or login to post a comment