Browse Source

shortcuts imported; note import completed

master
Christian Müller 10 years ago
parent
commit
17b50f3e25
  1. 28
      src/storage.js

28
src/storage.js

@ -28,7 +28,7 @@ var Shortcut = sequelize.define('Shortcut', {
params: Sequelize.STRING params: Sequelize.STRING
}); });
//Note.hasMany(Shortcut); Note.hasMany(Shortcut);
Shortcut.belongsTo(Note); Shortcut.belongsTo(Note);
sequelize.sync().then(function () { sequelize.sync().then(function () {
@ -60,26 +60,32 @@ sequelize.sync().then(function () {
links.forEach(shortcutId => { links.forEach(shortcutId => {
client.hget("short-url", shortcutId, function (err, result) { 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({ Shortcut.create({
id: shortcutId, id: shortcutId,
params: result params: Object.keys(obj).length == 0 ? null : JSON.stringify(obj)
}).then(shortcut => { }).then(shortcut => {
debugger
shortcut.setNote(note); shortcut.setNote(note);
note.addShortcut(shortcut);
}) })
}); });
}); });
}); });
}) })
}); });
}); });

Loading…
Cancel
Save