diff --git a/pylib/anki/template.py b/pylib/anki/template.py index 248219c4e..1854d71e8 100644 --- a/pylib/anki/template.py +++ b/pylib/anki/template.py @@ -238,7 +238,7 @@ class TemplateRenderContext: def _partially_render(self) -> PartiallyRenderedCard: if self._template: # card layout screen - out = self._col._backend.render_uncommitted_card( + out = self._col._backend.render_uncommitted_card_legacy( note=self._note._to_backend_note(), card_ord=self._card.ord, template=to_json_bytes(self._template), diff --git a/rslib/backend.proto b/rslib/backend.proto index 1bed8f2f7..b89f827bc 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -221,6 +221,8 @@ service CardRenderingService { rpc GetEmptyCards(Empty) returns (EmptyCardsReport); rpc RenderExistingCard(RenderExistingCardIn) returns (RenderCardOut); rpc RenderUncommittedCard(RenderUncommittedCardIn) returns (RenderCardOut); + rpc RenderUncommittedCardLegacy(RenderUncommittedCardLegacyIn) + returns (RenderCardOut); rpc StripAVTags(String) returns (String); rpc RenderMarkdown(RenderMarkdownIn) returns (String); } @@ -686,6 +688,13 @@ message RenderExistingCardIn { } message RenderUncommittedCardIn { + Note note = 1; + uint32 card_ord = 2; + Notetype.Template template = 3; + bool fill_empty = 4; +} + +message RenderUncommittedCardLegacyIn { Note note = 1; uint32 card_ord = 2; bytes template = 3; diff --git a/rslib/src/backend/cardrendering.rs b/rslib/src/backend/cardrendering.rs index a68e3ea7b..b68c8ba9a 100644 --- a/rslib/src/backend/cardrendering.rs +++ b/rslib/src/backend/cardrendering.rs @@ -98,6 +98,23 @@ impl CardRenderingService for Backend { fn render_uncommitted_card( &self, input: pb::RenderUncommittedCardIn, + ) -> Result { + let template = input.template.ok_or(AnkiError::NotFound)?.into(); + let mut note = input + .note + .ok_or_else(|| AnkiError::invalid_input("missing note"))? + .into(); + let ord = input.card_ord as u16; + let fill_empty = input.fill_empty; + self.with_col(|col| { + col.render_uncommitted_card(&mut note, &template, ord, fill_empty) + .map(Into::into) + }) + } + + fn render_uncommitted_card_legacy( + &self, + input: pb::RenderUncommittedCardLegacyIn, ) -> Result { let schema11: CardTemplateSchema11 = serde_json::from_slice(&input.template)?; let template = schema11.into();