2021-11-09 08:00:09 +00:00
|
|
|
use crate::errors::ErrorCode;
|
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
|
|
|
use std::convert::TryInto;
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug, ProtoBuf_Enum, Clone)]
|
|
|
|
pub enum ExportType {
|
2022-01-23 04:14:00 +00:00
|
|
|
Text = 0,
|
2021-11-10 06:46:59 +00:00
|
|
|
Markdown = 1,
|
2022-01-23 04:14:00 +00:00
|
|
|
Link = 2,
|
2021-11-09 08:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl std::default::Default for ExportType {
|
2022-01-23 04:14:00 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
ExportType::Text
|
|
|
|
}
|
2021-11-09 08:00:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<i32> for ExportType {
|
|
|
|
fn from(val: i32) -> Self {
|
|
|
|
match val {
|
|
|
|
0 => ExportType::Text,
|
2021-11-10 06:46:59 +00:00
|
|
|
1 => ExportType::Markdown,
|
|
|
|
2 => ExportType::Link,
|
2021-11-09 08:00:09 +00:00
|
|
|
_ => {
|
|
|
|
log::error!("Invalid export type: {}", val);
|
2021-11-09 08:04:13 +00:00
|
|
|
ExportType::Text
|
2022-01-23 04:14:00 +00:00
|
|
|
}
|
2021-11-09 08:00:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-13 12:23:56 +00:00
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct EditPayloadPB {
|
|
|
|
#[pb(index = 1)]
|
2022-10-13 15:29:37 +00:00
|
|
|
pub doc_id: String,
|
2022-09-13 12:23:56 +00:00
|
|
|
|
|
|
|
// Encode in JSON format
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub operations: String,
|
|
|
|
|
|
|
|
// Encode in JSON format
|
|
|
|
#[pb(index = 3)]
|
2022-10-13 15:29:37 +00:00
|
|
|
pub operations_str: String,
|
2022-09-13 12:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct EditParams {
|
2022-10-13 15:29:37 +00:00
|
|
|
pub doc_id: String,
|
2022-09-13 12:23:56 +00:00
|
|
|
|
|
|
|
// Encode in JSON format
|
|
|
|
pub operations: String,
|
|
|
|
|
|
|
|
// Encode in JSON format
|
2022-10-13 15:29:37 +00:00
|
|
|
pub operations_str: String,
|
2022-09-13 12:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TryInto<EditParams> for EditPayloadPB {
|
|
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<EditParams, Self::Error> {
|
|
|
|
Ok(EditParams {
|
2022-10-13 15:29:37 +00:00
|
|
|
doc_id: self.doc_id,
|
2022-09-13 12:23:56 +00:00
|
|
|
operations: self.operations,
|
2022-10-13 15:29:37 +00:00
|
|
|
operations_str: self.operations_str,
|
2022-09-13 12:23:56 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
2022-10-13 15:29:37 +00:00
|
|
|
pub struct DocumentSnapshotPB {
|
2022-09-13 12:23:56 +00:00
|
|
|
#[pb(index = 1)]
|
2022-10-13 15:29:37 +00:00
|
|
|
pub doc_id: String,
|
2022-09-13 12:23:56 +00:00
|
|
|
|
|
|
|
/// Encode in JSON format
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub snapshot: String,
|
|
|
|
}
|
|
|
|
|
2021-11-09 08:00:09 +00:00
|
|
|
#[derive(Default, ProtoBuf)]
|
2022-07-18 03:58:39 +00:00
|
|
|
pub struct ExportPayloadPB {
|
2021-11-09 08:00:09 +00:00
|
|
|
#[pb(index = 1)]
|
2022-02-25 14:27:44 +00:00
|
|
|
pub view_id: String,
|
2021-11-09 08:00:09 +00:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub export_type: ExportType,
|
|
|
|
}
|
|
|
|
|
2021-11-09 09:50:32 +00:00
|
|
|
#[derive(Default, Debug)]
|
2021-11-09 08:00:09 +00:00
|
|
|
pub struct ExportParams {
|
2022-02-25 14:27:44 +00:00
|
|
|
pub view_id: String,
|
2021-11-09 08:00:09 +00:00
|
|
|
pub export_type: ExportType,
|
|
|
|
}
|
|
|
|
|
2022-07-18 03:58:39 +00:00
|
|
|
impl TryInto<ExportParams> for ExportPayloadPB {
|
2021-11-09 08:00:09 +00:00
|
|
|
type Error = ErrorCode;
|
|
|
|
fn try_into(self) -> Result<ExportParams, Self::Error> {
|
|
|
|
Ok(ExportParams {
|
2022-02-25 14:27:44 +00:00
|
|
|
view_id: self.view_id,
|
2021-11-09 08:00:09 +00:00
|
|
|
export_type: self.export_type,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
2022-07-18 03:58:39 +00:00
|
|
|
pub struct ExportDataPB {
|
2021-11-09 08:00:09 +00:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub data: String,
|
2021-11-10 06:46:59 +00:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub export_type: ExportType,
|
2021-11-09 08:00:09 +00:00
|
|
|
}
|