diff options
author | Phie <phie@phie.ovh> | 2020-04-12 15:52:22 +0300 |
---|---|---|
committer | Phie <phie@phie.ovh> | 2020-04-12 15:52:22 +0300 |
commit | 93e95f3bfe2de18bf3034aea03599a9e3f2d4696 (patch) | |
tree | 688683835cfe35926660ce4ad14fcaddbd756a77 /server | |
parent | d2d36a14a95cfe3882dbc13e5e64d788f0d1466b (diff) |
continue working on new importer
Diffstat (limited to 'server')
-rw-r--r-- | server/server.js | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/server/server.js b/server/server.js index a711e06..c8c9fe3 100644 --- a/server/server.js +++ b/server/server.js @@ -16,13 +16,14 @@ var currentcache = {} var media = [] var openedNotePath = undefined var handle = function (method, path, data, callback) { - console.logDebug(method + " " + path) + console.log(method + " " + path) var splitPath = path.split("?") var pathBeforeArgs = splitPath[0] + var args = {} + if (splitPath[1] != undefined) { var argsStr = path.split("?")[1] argsSplit = argsStr.split("&"); - var args = {} for (var arg of argsSplit) { argSplit = arg.split("="); args[decodeURIComponent(argSplit[0])] = decodeURIComponent(argSplit[1]) @@ -366,14 +367,45 @@ var handle = function (method, path, data, callback) { return; } case "/note/import": { - console.log("/note/import") - const path = require('path') + console.logDebug("/note/import") - var notepath = path.join(settingsHelper.getNotePath(), data.files[0].name) + const path = require('path') + var relativeNotePath = data.files[0].name + var notepath = path.join(settingsHelper.getNotePath(), relativeNotePath) fs.writeFile(notepath, data.files[0].data, 'base64', function (err) { - console.log("/note/import finished " + err) - callback(err, "") + console.logDebug("/note/import finished " + err) + if (!err) { + var kactions = [] + var time = new Date().getTime() + if (data.metadata != undefined) { + for (var keyword of data.metadata.keywords) { + kactions.push({ + keyword, + time: time, + action: "add", + path: relativeNotePath + }) + + } + } + new KeywordsDBManager(settingsHelper.getNotePath() + "/quickdoc/keywords/" + settingsHelper.getAppUid()).actionArray(kactions, function () { + if (data.add_to_recent) { + var dbactions = [] + kactions.push({ + time: time, + action: "add", + path: relativeNotePath + }) + new RecentDBManager(settingsHelper.getNotePath() + "/quickdoc/recentdb/" + settingsHelper.getAppUid()).actionArray(dbactions, function () { + callback(false, ""); + }) + } else callback(false, ""); + + }) + + } else + callback(err, "") }) return; } |