diff --git a/proto/anki/import_export.proto b/proto/anki/import_export.proto index 595221242..1c2d67b58 100644 --- a/proto/anki/import_export.proto +++ b/proto/anki/import_export.proto @@ -17,7 +17,7 @@ service ImportExportService { returns (generic.Empty); rpc ImportAnkiPackage(ImportAnkiPackageRequest) returns (ImportAnkiPackageResponse); - rpc ExportAnkiPackage(ExportAnkiPackageRequest) returns (generic.Empty); + rpc ExportAnkiPackage(ExportAnkiPackageRequest) returns (generic.UInt32); } message ImportCollectionPackageRequest { @@ -57,7 +57,7 @@ message ExportAnkiPackageRequest { bool with_media = 3; oneof selector { generic.Empty whole_collection = 4; - decks.DeckId deck_id = 5; + int64 deck_id = 5; notes.NoteIds note_ids = 6; } } diff --git a/rslib/src/backend/import_export.rs b/rslib/src/backend/import_export.rs index f9076e9f2..52ad47f3e 100644 --- a/rslib/src/backend/import_export.rs +++ b/rslib/src/backend/import_export.rs @@ -56,7 +56,7 @@ impl ImportExportService for Backend { .map(Into::into) } - fn export_anki_package(&self, input: pb::ExportAnkiPackageRequest) -> Result { + fn export_anki_package(&self, input: pb::ExportAnkiPackageRequest) -> Result { let selector = input .selector .ok_or_else(|| AnkiError::invalid_input("missing oneof"))?; diff --git a/rslib/src/import_export/package/apkg/export.rs b/rslib/src/import_export/package/apkg/export.rs index 43c5c5e32..49df6d786 100644 --- a/rslib/src/import_export/package/apkg/export.rs +++ b/rslib/src/import_export/package/apkg/export.rs @@ -23,6 +23,7 @@ use crate::{ }; impl Collection { + /// Returns number of exported notes. pub fn export_apkg( &mut self, out_path: impl AsRef, @@ -31,24 +32,24 @@ impl Collection { with_media: bool, media_fn: Option) -> MediaIter>>, progress_fn: impl FnMut(usize) -> Result<()>, - progress_fn: impl FnMut(usize), - ) -> Result<()> { + ) -> Result { let temp_apkg = tempfile_in_parent_of(out_path.as_ref())?; let mut temp_col = NamedTempFile::new()?; let temp_col_path = temp_col .path() .to_str() .ok_or_else(|| AnkiError::IoError("tempfile with non-unicode name".into()))?; - let media = self.export_collection_extracting_media( + let data = self.export_collection_extracting_media( temp_col_path, search, with_scheduling, with_media, )?; + let media = if let Some(media_fn) = media_fn { - media_fn(media) + media_fn(data.media_paths) } else { - MediaIter::from_file_list(media, self.media_folder.clone()) + MediaIter::from_file_list(data.media_paths, self.media_folder.clone()) }; let col_size = temp_col.as_file().metadata()?.len() as usize; @@ -61,7 +62,8 @@ impl Collection { &self.tr, progress_fn, )?; - atomic_rename(temp_apkg, out_path.as_ref(), true) + atomic_rename(temp_apkg, out_path.as_ref(), true)?; + Ok(data.notes.len()) } fn export_collection_extracting_media( @@ -70,7 +72,7 @@ impl Collection { search: impl TryIntoSearch, with_scheduling: bool, with_media: bool, - ) -> Result> { + ) -> Result { let mut data = ExchangeData::default(); data.gather_data(self, search, with_scheduling)?; if with_media { @@ -82,7 +84,7 @@ impl Collection { temp_col.set_creation_stamp(self.storage.creation_stamp()?)?; temp_col.close(Some(SchemaVersion::V11))?; - Ok(data.media_paths) + Ok(data) } fn new_minimal(path: impl Into) -> Result {