entities.rs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. use crate::errors::ErrorCode;
  2. use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
  3. use std::convert::TryInto;
  4. #[derive(PartialEq, Debug, ProtoBuf_Enum, Clone)]
  5. pub enum ExportType {
  6. Text = 0,
  7. Markdown = 1,
  8. Link = 2,
  9. }
  10. impl std::default::Default for ExportType {
  11. fn default() -> Self {
  12. ExportType::Text
  13. }
  14. }
  15. impl std::convert::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. log::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 text_block_id: String,
  32. // Encode in JSON format
  33. #[pb(index = 2)]
  34. pub operations: String,
  35. // Encode in JSON format
  36. #[pb(index = 3)]
  37. pub delta: String,
  38. }
  39. #[derive(Default)]
  40. pub struct EditParams {
  41. pub text_block_id: String,
  42. // Encode in JSON format
  43. pub operations: String,
  44. // Encode in JSON format
  45. pub delta: String,
  46. }
  47. impl TryInto<EditParams> for EditPayloadPB {
  48. type Error = ErrorCode;
  49. fn try_into(self) -> Result<EditParams, Self::Error> {
  50. Ok(EditParams {
  51. text_block_id: self.text_block_id,
  52. operations: self.operations,
  53. delta: self.delta,
  54. })
  55. }
  56. }
  57. #[derive(Default, ProtoBuf)]
  58. pub struct TextBlockPB {
  59. #[pb(index = 1)]
  60. pub text_block_id: String,
  61. /// Encode in JSON format
  62. #[pb(index = 2)]
  63. pub snapshot: String,
  64. }
  65. #[derive(Default, ProtoBuf)]
  66. pub struct ExportPayloadPB {
  67. #[pb(index = 1)]
  68. pub view_id: String,
  69. #[pb(index = 2)]
  70. pub export_type: ExportType,
  71. }
  72. #[derive(Default, Debug)]
  73. pub struct ExportParams {
  74. pub view_id: String,
  75. pub export_type: ExportType,
  76. }
  77. impl TryInto<ExportParams> for ExportPayloadPB {
  78. type Error = ErrorCode;
  79. fn try_into(self) -> Result<ExportParams, Self::Error> {
  80. Ok(ExportParams {
  81. view_id: self.view_id,
  82. export_type: self.export_type,
  83. })
  84. }
  85. }
  86. #[derive(Default, ProtoBuf)]
  87. pub struct ExportDataPB {
  88. #[pb(index = 1)]
  89. pub data: String,
  90. #[pb(index = 2)]
  91. pub export_type: ExportType,
  92. }