add beyond

This commit is contained in:
polv committed 2022-04-27 13:07:04 +07:00
1 parent 49cd39297a
commit 1c362c0c1c
4 files changed
+168 -11

No files matched your search

+20 -10
View File
@@ -41,6 +41,20 @@ async function main() {
);
})
.then((rs) => {
const cardsByTemplateName = {
data: new Map<string, number[]>(),
async get(templateName: string) {
let v = this.data.get(templateName);
if (!v) {
v = await anki.api('findCards', {
query: `deck:${DECK} card:${templateName}`,
});
}
this.data.set(templateName, v);
return v;
},
};
return Promise.all(
rs
.flat()
@@ -51,16 +65,12 @@ async function main() {
})),
)
.map(({ templateName, subdeck, cardIdsSet }) =>
anki
.api('findCards', {
query: `deck:${DECK} card:${templateName}`,
})
.then((cards) =>
anki.api('changeDeck', {
cards: cards.filter((c) => cardIdsSet.has(c)),
deck: `${DECK}::${subdeck}::${templateName}`,
}),
),
cardsByTemplateName.get(templateName).then((cards) =>
anki.api('changeDeck', {
cards: cards.filter((c) => cardIdsSet.has(c)),
deck: `${DECK}::${subdeck}::${templateName}`,
}),
),
),
);
}),