From 17b50f3e25977b4d2f4680a4711a87bd9503f905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= Date: Sun, 13 Sep 2015 18:06:27 +0200 Subject: [PATCH] shortcuts imported; note import completed --- src/storage.js | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/storage.js b/src/storage.js index 1066fea..6d426f7 100644 --- a/src/storage.js +++ b/src/storage.js @@ -28,7 +28,7 @@ var Shortcut = sequelize.define('Shortcut', { params: Sequelize.STRING }); -//Note.hasMany(Shortcut); +Note.hasMany(Shortcut); Shortcut.belongsTo(Note); sequelize.sync().then(function () { @@ -56,30 +56,36 @@ sequelize.sync().then(function () { edited: !isNaN(edited[id]) && edited[id] && new Date(edited[id] * 1000) || null, views: views[id], }).then(note => { - - links.forEach(shortcutId => { - client.hget("short-url", shortcutId, function (err, result){ - - Shortcut.create({ - id: shortcutId, - params: result - }).then(shortcut => { - - debugger - shortcut.setNote(note); - - }) - - }); - }); - - }); - + links.forEach(shortcutId => { + client.hget("short-url", shortcutId, function (err, result) { + + result = result.replace(/:([\w_-]+)\s/g, '"$1":'); + var obj = {}; + try { + obj = JSON.parse(result); + delete obj.title; + delete obj.day; + delete obj.year; + delete obj.month; + } catch (e) { + return console.log("PARSE ERROR FOR", result) + } + Shortcut.create({ + id: shortcutId, + params: Object.keys(obj).length == 0 ? null : JSON.stringify(obj) + }).then(shortcut => { + shortcut.setNote(note); + note.addShortcut(shortcut); + + }) + }); + }); + }); }) }); });