diff --git a/.gitignore b/.gitignore
index 13cd3c8..19e6832 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,4 +38,5 @@ jspm_packages
# Upload File
uploads
-/public/images/snap/
\ No newline at end of file
+/public/images/snap/
+/public/images/favicon/
\ No newline at end of file
diff --git a/app.js b/app.js
index 7a1173d..d9f392c 100644
--- a/app.js
+++ b/app.js
@@ -75,7 +75,7 @@ app.use(function(err, req, res, next) {
error: {}
});
});
-// api.checkSnapState();
-api.getSnapByTimer();
+// api.checkSnapFaviconState();
+api.getSnapFaviconByTimer();
module.exports = app;
diff --git a/common/download.js b/common/download.js
new file mode 100644
index 0000000..0da3a32
--- /dev/null
+++ b/common/download.js
@@ -0,0 +1,32 @@
+var request = require('request');
+var fs = require('fs');
+
+var download = function(url, dest, cb) {
+ var file = fs.createWriteStream(dest);
+ var sendReq = request.get(url);
+
+ var error = null;
+ sendReq.on('response', function(response) {
+ if (response.statusCode !== 200) {
+ error = 'Response status was ' + response.statusCode;
+ }
+ });
+
+ sendReq.on('error', function(err) {
+ fs.unlink(dest);
+ error = err
+ });
+
+ sendReq.pipe(file);
+
+ file.on('finish', function() {
+ file.close(cb(error));
+ });
+
+ file.on('error', function(err) {
+ fs.unlink(dest);
+ error = err.message;
+ });
+};
+
+module.exports = download;
diff --git a/database/db.js b/database/db.js
index 9d6b684..f2ed244 100644
--- a/database/db.js
+++ b/database/db.js
@@ -696,7 +696,7 @@ db.getBookmarks = function() {
db.getBookmarkWaitSnap = function(today) {
var todayNotSnap = today + 31;
- var sql = "SELECT id, url, snap_state FROM `bookmarks` WHERE `snap_state`>=0 AND `snap_state` <= 64 AND snap_state != " + todayNotSnap + " ORDER BY created_at DESC LIMIT 0, 1";
+ var sql = "SELECT id, url, snap_state, favicon_state FROM `bookmarks` WHERE (`snap_state`>=0 AND `snap_state` <= 64 AND snap_state != " + todayNotSnap + ") OR (`favicon_state`>=0 AND `favicon_state` <= 64 AND favicon_state != " + todayNotSnap + ") ORDER BY created_at DESC LIMIT 0, 1";
return new Promise(function(resolve, reject) {
client.query(sql, (err, result) => {
if (err) {
@@ -722,4 +722,18 @@ db.updateBookmarkSnapState = function(id, snapState) {
});
}
+db.updateBookmarkFaviconState = function(id, faviconState) {
+ console.log("updateBookmarkFaviconState id = " + id + ", faviconState = " + faviconState);
+ var sql = "UPDATE `bookmarks` SET `favicon_state`='" + faviconState + "' WHERE (`id`='" + id + "')";
+ return new Promise(function(resolve, reject) {
+ client.query(sql, (err, result) => {
+ if (err) {
+ reject(err);
+ } else {
+ resolve(result.affectedRows);
+ }
+ });
+ });
+}
+
module.exports = db;
diff --git a/public/scripts/directives/js-init-directive.js b/public/scripts/directives/js-init-directive.js
index 183ecc4..d359528 100644
--- a/public/scripts/directives/js-init-directive.js
+++ b/public/scripts/directives/js-init-directive.js
@@ -174,3 +174,15 @@ app.directive('errSrc', function() {
}
}
});
+
+app.directive('faviconErr', function() {
+ return {
+ link: function(scope, element, attrs) {
+ element.bind('error', function() {
+ if (attrs.src != attrs.faviconErr) {
+ attrs.$set('src', attrs.faviconErr);
+ }
+ });
+ }
+ }
+});
diff --git a/public/views/bookmarks.html b/public/views/bookmarks.html
index f252e1a..0313356 100644
--- a/public/views/bookmarks.html
+++ b/public/views/bookmarks.html
@@ -30,7 +30,7 @@
id="{{bookmark.id}}">
-
+
{{ bookmark.title}}
@@ -56,7 +56,7 @@