This commit is contained in:
Alex Yatskov 2016-10-17 20:59:54 -07:00
parent 9d1756a2a8
commit de33a19498

View File

@ -24,7 +24,26 @@ class AnkiWeb {
} }
addNote(note) { 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) { canAddNotes(notes) {