From c4418abf5e42fed47da26c39c8d08af2d6d9b5e1 Mon Sep 17 00:00:00 2001 From: luchenqun Date: Mon, 20 Feb 2017 22:16:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8D=A1=E7=89=87=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E9=83=A8=E5=88=86=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- database/db.js | 27 ++++++++++-------- package.json | 3 +- public/css/style.css | 17 +++++++---- .../controllers/bookmarks-controller.js | 4 +-- .../scripts/directives/js-init-directive.js | 12 ++++++++ public/views/bookmarks.html | 22 +++++++++++++-- public/views/search.html | 2 +- public/views/tags.html | 2 +- routes/api.js | 28 ++++++++++++++++++- 10 files changed, 94 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 780103f..39c8249 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ jspm_packages .node_repl_history # Upload File -uploads \ No newline at end of file +uploads +/public/images/shot/ \ No newline at end of file diff --git a/database/db.js b/database/db.js index e7e09b0..365a4e0 100644 --- a/database/db.js +++ b/database/db.js @@ -52,15 +52,15 @@ Date.prototype.format = function(fmt) { //author: meizz // update delete 返回影响的行数 var db = { - } - // var sql = "SELECT * FROM `users` WHERE `username` = 'luchenqun'"; - // client.query(sql, (err, result) => { - // if (err) { - // console.log(err); - // } else { - // console.log(result); - // } - // }); +} +// var sql = "SELECT * FROM `users` WHERE `username` = 'luchenqun'"; +// client.query(sql, (err, result) => { +// if (err) { +// console.log(err); +// } else { +// console.log(result); +// } +// }); db.addBookmark = function(user_id, bookmark) { var insertSql = "INSERT INTO `bookmarks` (`user_id`, `title`, `description`, `url`, `public`, `click_count`) VALUES ('" + user_id + "', '" + bookmark.title + "', '" + bookmark.description + "', '" + bookmark.url + "', '" + bookmark.public + "', '1')"; @@ -413,9 +413,14 @@ db.getBookmarksTable = function(params) { var sql = "SELECT id, user_id, title, description, url, public, click_count, DATE_FORMAT(created_at, '%Y-%m-%d') as created_at, DATE_FORMAT(last_click, '%Y-%m-%d') as last_click FROM `bookmarks` WHERE 1=1"; if (user_id) { - sql += " AND `user_id` = '" + user_id + "' ORDER BY click_count DESC" + sql += " AND `user_id` = '" + user_id + "'"; + if (params.showStyle == 'card') { + sql += " ORDER BY created_at DESC"; + } else { + sql += " ORDER BY click_count DESC"; + } } - + console.log(sql); return new Promise(function(resolve, reject) { client.query(sql, (err, result) => { if (err) { diff --git a/package.json b/package.json index 282331d..9e48a0a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "mysql": "^2.11.1", "node-readability": "^2.2.0", "serve-favicon": "~2.3.0", - "supervisor": "^0.11.0" + "supervisor": "^0.11.0", + "webshot": "^0.18.0" } } diff --git a/public/css/style.css b/public/css/style.css index 14fc086..5d34d06 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1,8 +1,8 @@ body { - background-image: url('../images/bg.png'); - background-repeat: repeat; - background-position: top left; - background-attachment: scroll; + background-image: url('../images/bg.png'); + background-repeat: repeat; + background-position: top left; + background-attachment: scroll; padding: 50px; font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; } @@ -10,7 +10,7 @@ code { background-color: rgba(0, 0, 0, 0.08); border-radius: 3px; display: inline-block; - font-family: "Monaco","Menlo","Ubuntu Mono","Consolas","source-code-pro",monospace; + font-family: "Monaco", "Menlo", "Ubuntu Mono", "Consolas", "source-code-pro", monospace; font-size: 0.875em; font-weight: bold; padding: 1px 6px; @@ -24,6 +24,13 @@ code { color: #212121; border: 1px solid transparent; } +.bookmarkTitle { + text-overflow: ellipsis; + overflow: hidden; + display: -webkit-box; + -webkit-box-orient: vertical; + height: 40px; +} .bookmarkNormalHover { white-space: nowrap; text-overflow: ellipsis; diff --git a/public/scripts/controllers/bookmarks-controller.js b/public/scripts/controllers/bookmarks-controller.js index 6d098b0..e87a284 100644 --- a/public/scripts/controllers/bookmarks-controller.js +++ b/public/scripts/controllers/bookmarks-controller.js @@ -4,7 +4,7 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', ' $scope.showSearch = false; // 搜索对话框 $scope.bookmarkNormalHover = false; $scope.bookmarkEditHover = false; - $scope.showStyle = ($stateParams && $stateParams.showStyle) || 'navigate'; // 显示风格'navigate', 'card', 'table' + $scope.showStyle = 'card' //($stateParams && $stateParams.showStyle) || 'card'; // 显示风格'navigate', 'card', 'table' $('.js-radio-' + $scope.showStyle).checkbox('set checked'); $scope.edit = false; const perPageItems = 20; @@ -102,7 +102,7 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', ' function getBookmarks(params) { if (params.showStyle != 'navigate') { params.currentPage = $scope.currentPage; - params.perPageItems = perPageItems; + params.perPageItems = params.showStyle == 'table' ? perPageItems : perPageItems * 3; } bookmarkService.getBookmarks(params) .then((data) => { diff --git a/public/scripts/directives/js-init-directive.js b/public/scripts/directives/js-init-directive.js index 14f5696..183ecc4 100644 --- a/public/scripts/directives/js-init-directive.js +++ b/public/scripts/directives/js-init-directive.js @@ -162,3 +162,15 @@ app.directive('jsMenuInit', function($compile) { }, }; }); + +app.directive('errSrc', function() { + return { + link: function(scope, element, attrs) { + element.bind('error', function() { + if (attrs.src != attrs.errSrc) { + attrs.$set('src', attrs.errSrc); + } + }); + } + } +}); diff --git a/public/views/bookmarks.html b/public/views/bookmarks.html index baa13f0..26ef4fa 100644 --- a/public/views/bookmarks.html +++ b/public/views/bookmarks.html @@ -30,7 +30,7 @@ id="{{bookmark.id}}"> - + {{ bookmark.title}}
@@ -59,7 +59,7 @@ - + {{ bookmark.title }} @@ -91,4 +91,20 @@ -
正在开发中,尽请期待。。。。。。
+
+
+ +
+
diff --git a/public/views/search.html b/public/views/search.html index 87b5fad..1157175 100644 --- a/public/views/search.html +++ b/public/views/search.html @@ -128,7 +128,7 @@ - + {{ bookmark.title }} diff --git a/public/views/tags.html b/public/views/tags.html index bf21142..5e8d979 100644 --- a/public/views/tags.html +++ b/public/views/tags.html @@ -28,7 +28,7 @@ - + {{ bookmark.title }} diff --git a/routes/api.js b/routes/api.js index e9f7c3d..0a74281 100644 --- a/routes/api.js +++ b/routes/api.js @@ -5,6 +5,15 @@ var read = require('node-readability'); var db = require('../database/db.js'); var parseHtml = require('../common/parse_html.js'); var multer = require('multer'); +var webshot = require('webshot'); +var fs = require('fs'); + +var webshotOptions = { + shotSize: { + width: 320, + height: 320 + }, +}; var storage = multer.diskStorage({ destination: function(req, file, cb) { @@ -285,6 +294,7 @@ api.get('/bookmarks', function(req, res) { var data = []; // 获取每个书签的所有分类标签 bookmarks.forEach(function(bookmark) { + getWebshot(bookmark.id, bookmark.url); var bookmarkTags = []; tagsBookmarks.forEach(function(tb) { if (tb.bookmark_id == bookmark.id) { @@ -566,7 +576,10 @@ api.post('/addBookmark', function(req, res) { db.delBookmarkTags(bookmark_id); // 不管3721,先删掉旧的分类 return bookmark_id; }) // 将之前所有的书签分类信息删掉 - .then((bookmark_id) => db.addTagsBookmarks(tags, bookmark_id)) // 插入分类 + .then((bookmark_id) => { + getWebshot(bookmark_id, bookmark.url); + return db.addTagsBookmarks(tags, bookmark_id) + }) // 插入分类 .then(() => db.updateLastUseTags(userId, tags)) // 更新最新使用的分类 .then(() => res.json({})) // 运气不错 .catch((err) => console.log('addBookmark err', err)); // oops! @@ -620,4 +633,17 @@ function md5(str) { .digest('hex'); }; +function getWebshot(id, url) { + var finePath = './public/images/shot/' + id + '.png' + fs.exists(finePath, function(exists) { + if (!exists) { + webshot(url, finePath, webshotOptions, function(err) { + if (err) { + console.log(id + " webshot fail", err); + } + }); + } + }); +} + module.exports = api;