entities.rs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. use crate::errors::ErrorCode;
  2. use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
  3. use std::convert::TryInto;
  4. #[derive(PartialEq, Eq, Debug, ProtoBuf_Enum, Clone)]
  5. pub enum ExportType {
  6. Text = 0,
  7. Markdown = 1,
  8. Link = 2,
  9. }
  10. impl Default for ExportType {
  11. fn default() -> Self {
  12. ExportType::Text
  13. }
  14. }
  15. impl From<i32> for ExportType {
  16. fn from(val: i32) -> Self {
  17. match val {
  18. 0 => ExportType::Text,
  19. 1 => ExportType::Markdown,
  20. 2 => ExportType::Link,
  21. _ => {
  22. tracing::error!("Invalid export type: {}", val);
  23. ExportType::Text
  24. }
  25. }
  26. }
  27. }
  28. #[derive(Default, ProtoBuf)]
  29. pub struct EditPayloadPB {
  30. #[pb(index = 1)]
  31. pub doc_id: String,
  32. // Encode in JSON format
  33. #[pb(index = 2)]
  34. pub operations: String,
  35. }
  36. #[derive(Default)]
  37. pub struct EditParams {
  38. pub doc_id: String,
  39. // Encode in JSON format
  40. pub operations: String,
  41. }
  42. impl TryInto<EditParams> for EditPayloadPB {
  43. type Error = ErrorCode;
  44. fn try_into(self) -> Result<EditParams, Self::Error> {
  45. Ok(EditParams {
  46. doc_id: self.doc_id,
  47. operations: self.operations,
  48. })
  49. }
  50. }
  51. #[derive(Default, ProtoBuf)]
  52. pub struct DocumentDataPB {
  53. #[pb(index = 1)]
  54. pub doc_id: String,
  55. /// Encode in JSON format
  56. #[pb(index = 2)]
  57. pub content: String,
  58. }
  59. #[derive(Default, ProtoBuf)]
  60. pub struct ExportPayloadPB {
  61. #[pb(index = 1)]
  62. pub view_id: String,
  63. #[pb(index = 2)]
  64. pub export_type: ExportType,
  65. #[pb(index = 3)]
  66. pub document_version: DocumentVersionPB,
  67. }
  68. #[derive(PartialEq, Eq, Debug, ProtoBuf_Enum, Clone)]
  69. pub enum DocumentVersionPB {
  70. /// this version's content of the document is build from `Delta`. It uses
  71. /// `DeltaDocumentEditor`.
  72. V0 = 0,
  73. /// this version's content of the document is build from `NodeTree`. It uses
  74. /// `AppFlowyDocumentEditor`
  75. V1 = 1,
  76. }
  77. impl std::default::Default for DocumentVersionPB {
  78. fn default() -> Self {
  79. Self::V0
  80. }
  81. }
  82. #[derive(Default, ProtoBuf)]
  83. pub struct OpenDocumentPayloadPB {
  84. #[pb(index = 1)]
  85. pub document_id: String,
  86. #[pb(index = 2)]
  87. pub version: DocumentVersionPB,
  88. }
  89. #[derive(Default, Debug)]
  90. pub struct ExportParams {
  91. pub view_id: String,
  92. pub export_type: ExportType,
  93. pub document_version: DocumentVersionPB,
  94. }
  95. impl TryInto<ExportParams> for ExportPayloadPB {
  96. type Error = ErrorCode;
  97. fn try_into(self) -> Result<ExportParams, Self::Error> {
  98. Ok(ExportParams {
  99. view_id: self.view_id,
  100. export_type: self.export_type,
  101. document_version: self.document_version,
  102. })
  103. }
  104. }
  105. #[derive(Default, ProtoBuf)]
  106. pub struct ExportDataPB {
  107. #[pb(index = 1)]
  108. pub data: String,
  109. #[pb(index = 2)]
  110. pub export_type: ExportType,
  111. }