2022-10-22 13:57:44 +00:00
|
|
|
use crate::entities::{
|
2023-02-13 01:29:49 +00:00
|
|
|
DocumentDataPB, EditParams, EditPayloadPB, ExportDataPB, ExportParams, ExportPayloadPB,
|
|
|
|
OpenDocumentPayloadPB,
|
2022-10-22 13:57:44 +00:00
|
|
|
};
|
2022-10-13 15:29:37 +00:00
|
|
|
use crate::DocumentManager;
|
|
|
|
use flowy_error::FlowyError;
|
2022-10-22 13:57:44 +00:00
|
|
|
|
2022-12-01 00:35:50 +00:00
|
|
|
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
|
2022-10-13 15:29:37 +00:00
|
|
|
use std::convert::TryInto;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
pub(crate) async fn get_document_handler(
|
2023-02-13 01:29:49 +00:00
|
|
|
data: AFPluginData<OpenDocumentPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<DocumentManager>>,
|
2023-02-10 14:24:34 +00:00
|
|
|
) -> DataResult<DocumentDataPB, FlowyError> {
|
2023-02-13 01:29:49 +00:00
|
|
|
let context: OpenDocumentPayloadPB = data.into_inner();
|
|
|
|
let editor = manager.open_document_editor(&context.document_id).await?;
|
|
|
|
let document_data = editor.export().await?;
|
|
|
|
data_result(DocumentDataPB {
|
|
|
|
doc_id: context.document_id,
|
|
|
|
content: document_data,
|
|
|
|
})
|
2022-10-13 15:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) async fn apply_edit_handler(
|
2023-02-13 01:29:49 +00:00
|
|
|
data: AFPluginData<EditPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<DocumentManager>>,
|
2022-10-13 15:29:37 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2023-02-13 01:29:49 +00:00
|
|
|
let params: EditParams = data.into_inner().try_into()?;
|
|
|
|
manager.apply_edit(params).await?;
|
|
|
|
Ok(())
|
2022-10-13 15:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn export_handler(
|
2023-02-13 01:29:49 +00:00
|
|
|
data: AFPluginData<ExportPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<DocumentManager>>,
|
2022-10-13 15:29:37 +00:00
|
|
|
) -> DataResult<ExportDataPB, FlowyError> {
|
2023-02-13 01:29:49 +00:00
|
|
|
let params: ExportParams = data.into_inner().try_into()?;
|
|
|
|
let editor = manager.open_document_editor(¶ms.view_id).await?;
|
|
|
|
let document_data = editor.export().await?;
|
|
|
|
data_result(ExportDataPB {
|
|
|
|
data: document_data,
|
|
|
|
export_type: params.export_type,
|
|
|
|
})
|
2022-10-13 15:29:37 +00:00
|
|
|
}
|