From e3c0aa7349517632214bfb1cdceb716ad646a27d Mon Sep 17 00:00:00 2001 From: luchenqun Date: Tue, 6 Aug 2019 11:25:27 +0800 Subject: [PATCH] import bookmark add create_at --- common/parse_html.js | 2 +- database/db.js | 3 +++ routes/api.js | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/parse_html.js b/common/parse_html.js index cd09dfd..ced88a4 100644 --- a/common/parse_html.js +++ b/common/parse_html.js @@ -18,7 +18,7 @@ var parsehtml = function (file, callback) { var add_date, name, bookmark, tags, url; url = $(e).attr("href"); name = $(e).text() || "无标题"; - add_date = $(e).attr("add_date"); + add_date = parseInt($(e).attr("add_date")) * 1000; // 只允许用一个标签 // 只允许用一个标签 diff --git a/database/db.js b/database/db.js index 929ac47..62906d8 100644 --- a/database/db.js +++ b/database/db.js @@ -63,6 +63,9 @@ db.getBookmarkbyUrl = function(user_id, url) { db.addBookmark = function(user_id, bookmark) { var sql = "INSERT INTO `bookmarks` (`user_id`, `title`, `description`, `url`, `public`, `click_count`) VALUES ('" + user_id + "', " + client.escape(bookmark.title) + ", " + client.escape(bookmark.description) + ", " + client.escape(bookmark.url) + ", '" + bookmark.public + "', '1')"; + if (bookmark.created_at) { + sql = "INSERT INTO `bookmarks` (`user_id`, `title`, `description`, `url`, `public`, `created_at`, `click_count`) VALUES ('" + user_id + "', " + client.escape(bookmark.title) + ", " + client.escape(bookmark.description) + ", " + client.escape(bookmark.url) + ", '" + bookmark.public+ "', '" + bookmark.created_at + "', '1')"; + } console.log(sql); return new Promise(function(resolve, reject) { client.query(sql, (err, result) => { diff --git a/routes/api.js b/routes/api.js index 71d08a8..f93061a 100644 --- a/routes/api.js +++ b/routes/api.js @@ -785,6 +785,7 @@ api.post('/uploadBookmarkFile', upload.single('bookmark'), function(req, res) { bookmark.description = ""; bookmark.url = item.url; bookmark.public = '1'; + bookmark.created_at = new Date(item.add_date).format('yyyy-MM-dd hh:mm:ss') if (item.tags.length == 0) { item.tags.push("未分类") } @@ -1551,7 +1552,7 @@ api.get('/download', function(req, res) { db.getExportBookmarksByTag(tag.id) .then((bookmarks) => { bookmarks.forEach((bookmark) => { - $('#' + bookmark.tag_id).append('
' + bookmark.title + '
'); + $('#' + bookmark.tag_id).append('
' + bookmark.title + '
'); }); if (tagIndex == tags.length - 1) { console.log('export bookmarks document construct end...');