chore: replace try_from with from

This commit is contained in:
appflowy
2022-07-19 11:31:04 +08:00
parent 2981b685bc
commit e7c672cb7e
13 changed files with 97 additions and 117 deletions

View File

@ -3,7 +3,7 @@ use crate::{
request::{HttpRequestBuilder, ResponseMiddleware},
};
use flowy_error::FlowyError;
use flowy_sync::entities::text_block::{CreateTextBlockParams, ResetTextBlockParams, TextBlockIdPB, TextBlockInfoPB};
use flowy_sync::entities::text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB};
use flowy_text_block::BlockCloudService;
use http_flowy::response::FlowyResponse;
use lazy_static::lazy_static;
@ -27,7 +27,7 @@ impl BlockCloudService for BlockHttpCloudService {
FutureResult::new(async move { create_document_request(&token, params, &url).await })
}
fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult<Option<TextBlockInfoPB>, FlowyError> {
fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult<Option<DocumentPB>, FlowyError> {
let token = token.to_owned();
let url = self.config.doc_url();
FutureResult::new(async move { read_document_request(&token, params, &url).await })
@ -54,7 +54,7 @@ pub async fn read_document_request(
token: &str,
params: TextBlockIdPB,
url: &str,
) -> Result<Option<TextBlockInfoPB>, FlowyError> {
) -> Result<Option<DocumentPB>, FlowyError> {
let doc = request_builder()
.get(&url.to_owned())
.header(HEADER_TOKEN, token)

View File

@ -1,10 +1,10 @@
use flowy_sync::{
entities::{folder::FolderInfo, text_block::TextBlockInfoPB},
entities::{folder::FolderInfo, text_block::DocumentPB},
errors::CollaborateError,
protobuf::{RepeatedRevision as RepeatedRevisionPB, Revision as RevisionPB},
server_document::*,
server_folder::FolderCloudPersistence,
util::{make_document_info_from_revisions_pb, make_folder_from_revisions_pb},
util::{make_document_from_revision_pbs, make_folder_from_revisions_pb},
};
use lib_infra::future::BoxResultFuture;
use std::{
@ -111,12 +111,12 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence {
}
impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
fn read_text_block(&self, doc_id: &str) -> BoxResultFuture<TextBlockInfoPB, CollaborateError> {
fn read_text_block(&self, doc_id: &str) -> BoxResultFuture<DocumentPB, CollaborateError> {
let storage = self.storage.clone();
let doc_id = doc_id.to_owned();
Box::pin(async move {
let repeated_revision = storage.get_revisions(&doc_id, None).await?;
match make_document_info_from_revisions_pb(&doc_id, repeated_revision)? {
match make_document_from_revision_pbs(&doc_id, repeated_revision)? {
Some(document_info) => Ok(document_info),
None => Err(CollaborateError::record_not_found()),
}
@ -127,12 +127,12 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
&self,
doc_id: &str,
repeated_revision: RepeatedRevisionPB,
) -> BoxResultFuture<Option<TextBlockInfoPB>, CollaborateError> {
) -> BoxResultFuture<Option<DocumentPB>, CollaborateError> {
let doc_id = doc_id.to_owned();
let storage = self.storage.clone();
Box::pin(async move {
let _ = storage.set_revisions(repeated_revision.clone()).await?;
make_document_info_from_revisions_pb(&doc_id, repeated_revision)
make_document_from_revision_pbs(&doc_id, repeated_revision)
})
}

View File

@ -6,7 +6,7 @@ use flowy_folder::event_map::FolderCouldServiceV1;
use flowy_sync::{
client_document::default::initial_quill_delta_string,
entities::{
text_block::{CreateTextBlockParams, ResetTextBlockParams, TextBlockIdPB, TextBlockInfoPB},
text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB},
ws_data::{ClientRevisionWSData, ClientRevisionWSDataType},
},
errors::CollaborateError,
@ -419,8 +419,8 @@ impl BlockCloudService for LocalServer {
FutureResult::new(async { Ok(()) })
}
fn read_block(&self, _token: &str, params: TextBlockIdPB) -> FutureResult<Option<TextBlockInfoPB>, FlowyError> {
let doc = TextBlockInfoPB {
fn read_block(&self, _token: &str, params: TextBlockIdPB) -> FutureResult<Option<DocumentPB>, FlowyError> {
let doc = DocumentPB {
block_id: params.value,
text: initial_quill_delta_string(),
rev_id: 0,