From de33a19498b38dcb8254654fb94bba3b7142a153 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 17 Oct 2016 20:59:54 -0700 Subject: [PATCH] WIP --- ext/bg/js/ankiweb.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ext/bg/js/ankiweb.js b/ext/bg/js/ankiweb.js index 17b5525e..35f4858e 100644 --- a/ext/bg/js/ankiweb.js +++ b/ext/bg/js/ankiweb.js @@ -24,7 +24,26 @@ class AnkiWeb { } addNote(note) { - return Promise.resolve(true); + return this.retrieve().then(info => { + const model = info.models.find(m => m.name === note.modelName); + if (!model) { + return Promise.reject('invalid model'); + } + + const fields = []; + for (const field of model.fields) { + fields.push(note.fields[field]); + } + + const form = new FormData(); + form.append('data', [fields, note.tags.join(' ')]); + form.append('mid', model.id); + form.append('deck', note.deckname); + + return AnkiWeb.loadAccountPage('https://ankiweb.net/edit/save', 'POST', form, this.username, this.password); + }).then(response => { + return true; + }); } canAddNotes(notes) {