mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: calling user event from web (#4535)
* refactor: user manager * refactor: user manager * refactor: session location * refactor: user manager * chore: gen ts files * feat: implement indexeddb persistence * chore: integrate user manager * chore: update * chore: run on web thread * chore: run on web thread * chore: fix test * chore: add test * chore: add test * chore: add user & sign in with password * chore: fix test * chore: update docs * chore: fix warnings * chore: gen files * chore: add user * chore: add files * chore: update config * chore: update scirpt * chore: update scirpt * fix: build * chore: update command * fix: ci * ci: fix * fix: compile * fix: compile * fix: ci * fix: compile * fix: tauri build * chore: fix test * chore: fix test
This commit is contained in:
@ -24,4 +24,4 @@ fxhash = "0.2.1"
|
||||
|
||||
|
||||
[features]
|
||||
wasm_build = ["lib-infra/wasm_build", "flowy-error/wasm_build"]
|
||||
enable_wasm = []
|
@ -1,12 +1,19 @@
|
||||
use std::path::Path;
|
||||
if_native! {
|
||||
mod native;
|
||||
pub use native::*;
|
||||
}
|
||||
|
||||
if_wasm! {
|
||||
mod wasm;
|
||||
pub use wasm::*;
|
||||
}
|
||||
|
||||
use bytes::Bytes;
|
||||
|
||||
use flowy_error::FlowyError;
|
||||
use lib_infra::future::FutureResult;
|
||||
use lib_infra::{if_native, if_wasm};
|
||||
use mime::Mime;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tracing::info;
|
||||
|
||||
pub struct ObjectIdentity {
|
||||
pub workspace_id: String,
|
||||
@ -20,44 +27,6 @@ pub struct ObjectValue {
|
||||
pub mime: Mime,
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub async fn object_from_disk(
|
||||
workspace_id: &str,
|
||||
local_file_path: &str,
|
||||
) -> Result<(ObjectIdentity, ObjectValue), FlowyError> {
|
||||
todo!("object_from_disk is not implemented for wasm32")
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub async fn object_from_disk(
|
||||
workspace_id: &str,
|
||||
local_file_path: &str,
|
||||
) -> Result<(ObjectIdentity, ObjectValue), FlowyError> {
|
||||
let ext = Path::new(local_file_path)
|
||||
.extension()
|
||||
.and_then(std::ffi::OsStr::to_str)
|
||||
.unwrap_or("")
|
||||
.to_owned();
|
||||
let mut file = tokio::fs::File::open(local_file_path).await?;
|
||||
let mut content = Vec::new();
|
||||
let n = file.read_to_end(&mut content).await?;
|
||||
info!("read {} bytes from file: {}", n, local_file_path);
|
||||
let mime = mime_guess::from_path(local_file_path).first_or_octet_stream();
|
||||
let hash = fxhash::hash(&content);
|
||||
|
||||
Ok((
|
||||
ObjectIdentity {
|
||||
workspace_id: workspace_id.to_owned(),
|
||||
file_id: hash.to_string(),
|
||||
ext,
|
||||
},
|
||||
ObjectValue {
|
||||
raw: content.into(),
|
||||
mime,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
/// Provides a service for object storage.
|
||||
///
|
||||
/// The trait includes methods for CRUD operations on storage objects.
|
||||
|
34
frontend/rust-lib/flowy-storage/src/native/mod.rs
Normal file
34
frontend/rust-lib/flowy-storage/src/native/mod.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use crate::{ObjectIdentity, ObjectValue};
|
||||
use flowy_error::FlowyError;
|
||||
use std::path::Path;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tracing::info;
|
||||
|
||||
pub async fn object_from_disk(
|
||||
workspace_id: &str,
|
||||
local_file_path: &str,
|
||||
) -> Result<(ObjectIdentity, ObjectValue), FlowyError> {
|
||||
let ext = Path::new(local_file_path)
|
||||
.extension()
|
||||
.and_then(std::ffi::OsStr::to_str)
|
||||
.unwrap_or("")
|
||||
.to_owned();
|
||||
let mut file = tokio::fs::File::open(local_file_path).await?;
|
||||
let mut content = Vec::new();
|
||||
let n = file.read_to_end(&mut content).await?;
|
||||
info!("read {} bytes from file: {}", n, local_file_path);
|
||||
let mime = mime_guess::from_path(local_file_path).first_or_octet_stream();
|
||||
let hash = fxhash::hash(&content);
|
||||
|
||||
Ok((
|
||||
ObjectIdentity {
|
||||
workspace_id: workspace_id.to_owned(),
|
||||
file_id: hash.to_string(),
|
||||
ext,
|
||||
},
|
||||
ObjectValue {
|
||||
raw: content.into(),
|
||||
mime,
|
||||
},
|
||||
))
|
||||
}
|
12
frontend/rust-lib/flowy-storage/src/wasm/mod.rs
Normal file
12
frontend/rust-lib/flowy-storage/src/wasm/mod.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use crate::{ObjectIdentity, ObjectValue};
|
||||
use flowy_error::FlowyError;
|
||||
|
||||
pub async fn object_from_disk(
|
||||
_workspace_id: &str,
|
||||
_local_file_path: &str,
|
||||
) -> Result<(ObjectIdentity, ObjectValue), FlowyError> {
|
||||
Err(
|
||||
FlowyError::not_support()
|
||||
.with_context(format!("object_from_disk is not implemented for wasm32")),
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user