mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
* chore: rename service * refactor: upload * chore: save upload meta data * chore: add sql test * chore: uploader * chore: fix upload * chore: cache file and remove after finish * chore: retry upload * chore: pause when netowork unreachable * chore: add event test * chore: add test * chore: clippy * chore: update client-api commit id * chore: fix flutter test
54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
use crate::chunked_byte::ChunkedBytes;
|
|
use async_trait::async_trait;
|
|
pub use client_api_entity::{CompletedPartRequest, CreateUploadResponse, UploadPartResponse};
|
|
use flowy_error::{FlowyError, FlowyResult};
|
|
use lib_infra::box_any::BoxAny;
|
|
use lib_infra::future::FutureResult;
|
|
|
|
#[async_trait]
|
|
pub trait StorageService: Send + Sync {
|
|
fn upload_object(
|
|
&self,
|
|
workspace_id: &str,
|
|
local_file_path: &str,
|
|
) -> FutureResult<String, FlowyError>;
|
|
|
|
fn delete_object(&self, url: String, local_file_path: String) -> FlowyResult<()>;
|
|
|
|
fn download_object(&self, url: String, local_file_path: String) -> FlowyResult<()>;
|
|
|
|
fn create_upload(
|
|
&self,
|
|
workspace_id: &str,
|
|
parent_dir: &str,
|
|
local_file_path: &str,
|
|
) -> FutureResult<CreatedUpload, FlowyError>;
|
|
|
|
async fn start_upload(&self, chunks: &ChunkedBytes, record: &BoxAny) -> Result<(), FlowyError>;
|
|
|
|
async fn resume_upload(
|
|
&self,
|
|
workspace_id: &str,
|
|
parent_dir: &str,
|
|
file_id: &str,
|
|
) -> Result<(), FlowyError>;
|
|
}
|
|
|
|
pub struct CreatedUpload {
|
|
pub url: String,
|
|
pub file_id: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct UploadResult {
|
|
pub file_id: String,
|
|
pub status: UploadStatus,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
pub enum UploadStatus {
|
|
Finish,
|
|
Failed,
|
|
InProgress,
|
|
}
|