Skip to content

Commit

Permalink
Merge branch 'main' into 9-database_support
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertshelley committed Mar 1, 2024
2 parents da594be + f53f43f commit 3d35442
Show file tree
Hide file tree
Showing 34 changed files with 592 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ homepage = "https://github.com/hubertshelley/silent"
license = "Apache-2.0"
readme = "./readme.md"
repository = "https://github.com/hubertshelley/silent"
version = "1.0.9"
version = "1.1.1"
14 changes: 7 additions & 7 deletions examples/candle_whisper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ cuda = ["candle-core/cuda", "candle-nn/cuda", "candle-transformers/cuda", "dep:b

[build-dependencies]
anyhow = { version = "1", features = ["backtrace"] }
bindgen_cuda = { version = "0.1.1", optional = true }
bindgen_cuda = { version = "0.1.4", optional = true }


[dependencies]
clap = { version = "4.2.4", features = ["derive"] }
clap = { version = "4.5.1", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
silent = { path = "../../silent", features = ["full"] }
symphonia = { version = "0.5.3", features = ["all"] }
anyhow = "1.0.79"
tokio = { version = "1.35.1", features = ["full"] }
symphonia = { version = "0.5.4", features = ["all"] }
anyhow = "1.0.80"
tokio = { version = "1.36.0", features = ["full"] }

#candle-core = { version = "0.3.2" }
#candle-nn = { version = "0.3.2" }
Expand All @@ -36,7 +36,7 @@ candle-core = { git = "https://github.com/huggingface/candle" }
candle-nn = { git = "https://github.com/huggingface/candle" }
candle-transformers = { git = "https://github.com/huggingface/candle" }

tokenizers = { version = "0.15.0", features = ["onig"] }
tokenizers = { version = "0.15.2", features = ["onig"] }
rand = "0.8.5"
serde_json = "1.0.109"
serde_json = "1.0.114"
byteorder = "1.5.0"
2 changes: 1 addition & 1 deletion examples/configs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
async-trait = "0.1.76"
async-trait = "0.1.77"
2 changes: 1 addition & 1 deletion examples/custom_handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
async-trait = "0.1.76"
async-trait = "0.1.77"
4 changes: 2 additions & 2 deletions examples/custom_tokio_listener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent", features = ["full"] }
async-trait = "0.1.76"
tokio = { version = "1.35.1", features = ["full"] }
async-trait = "0.1.77"
tokio = { version = "1.36.0", features = ["full"] }
4 changes: 2 additions & 2 deletions examples/custom_tokio_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent", features = ["full"] }
async-trait = "0.1.76"
tokio = { version = "1.35.1", features = ["full"] }
async-trait = "0.1.77"
tokio = { version = "1.36.0", features = ["full"] }
2 changes: 1 addition & 1 deletion examples/exception_handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent", features = ["full"] }
serde = { version = "1.0.193", features = ["derive"] }
serde = { version = "1.0.197", features = ["derive"] }
2 changes: 1 addition & 1 deletion examples/form/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
serde = { version = "1.0.193", features = ["derive"] }
serde = { version = "1.0.197", features = ["derive"] }
6 changes: 3 additions & 3 deletions examples/llma_chat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.76"
async-trait = "0.1.77"
llm = "0.1.1"
once_cell = "1.19.0"
rand = "0.8.5"
serde = { version = "1.0.193", features = ["derive"] }
serde = { version = "1.0.197", features = ["derive"] }
silent = { path = "../../silent", features = ["ws"] }
tokio = { version = "1.35.1", features = ["full"] }
tokio = { version = "1.36.0", features = ["full"] }
2 changes: 1 addition & 1 deletion examples/middleware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.76"
async-trait = "0.1.77"
silent = { path = "../../silent" }
2 changes: 1 addition & 1 deletion examples/multer_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ version.workspace = true
bytes = "1.5.0"
futures-util = "0.3.30"
multer = "3.0.0"
tokio = { version = "1.35.1", features = ["full"] }
tokio = { version = "1.36.0", features = ["full"] }
2 changes: 1 addition & 1 deletion examples/multipart-form/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
serde = { version = "1.0.193", features = ["derive"] }
serde = { version = "1.0.197", features = ["derive"] }
7 changes: 7 additions & 0 deletions examples/scheduler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/scheduler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "example-scheduler"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = "0.4"
silent = { path = "../../silent", features = ["scheduler"] }
24 changes: 24 additions & 0 deletions examples/scheduler/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use chrono::Utc;
use silent::prelude::*;
use std::sync::Arc;

fn main() {
logger::fmt().with_max_level(Level::INFO).init();
let route = Route::new("").get(|req| async move {
let process_time = Utc::now() + chrono::Duration::seconds(5);
let task = Task::create_with_action_async(
"task_id".to_string(),
process_time.try_into().unwrap(),
"task description".to_string(),
Arc::new(|| {
Box::pin(async {
println!("task run: {:?}", Utc::now());
Ok(())
})
}),
);
req.scheduler().lock().await.add_task(task)?;
Ok("hello world")
});
Server::new().run(route);
}
2 changes: 1 addition & 1 deletion examples/sse-chat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ once_cell = "1"
parking_lot = "0.12"
tokio = { version = "1", features = ["macros"] }
tokio-stream = { version = "0.1", features = ["net"] }
serde = { version = "1.0.193", features = ["derive"] }
serde = { version = "1.0.197", features = ["derive"] }
2 changes: 1 addition & 1 deletion examples/templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.193", features = ["derive"] }
serde = { version = "1.0.197", features = ["derive"] }
silent = { path = "../../silent", features = ["template"] }
6 changes: 3 additions & 3 deletions examples/todo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"

[dependencies]
silent = { path = "../../silent" }
serde = { version = "1.0.193", features = ["derive"] }
uuid = { version = "1.6.1", features = ["serde", "v4"] }
async-trait = "0.1.76"
serde = { version = "1.0.197", features = ["derive"] }
uuid = { version = "1.7.0", features = ["serde", "v4"] }
async-trait = "0.1.77"
4 changes: 2 additions & 2 deletions examples/tokenizer_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokenizers = { version = "0.15.0", features = ["onig"] }
anyhow = "1.0.79"
tokenizers = { version = "0.15.2", features = ["onig"] }
anyhow = "1.0.80"
tracing-subscriber = "0.3.18"
tracing = "0.1.40"
2 changes: 1 addition & 1 deletion examples/tokio-tungstenite_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ version.workspace = true
[dependencies]
futures-channel = "0.3.30"
futures-util = "0.3.30"
tokio = { version = "1.35.1", features = ["full"] }
tokio = { version = "1.36.0", features = ["full"] }
tokio-tungstenite = "0.21.0"
2 changes: 1 addition & 1 deletion examples/websocket-chat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false

[dependencies]
silent = { path = "../../silent", features = ["ws"] }
tokio = { version = "1.35.1", features = ["full"] }
tokio = { version = "1.36.0", features = ["full"] }
tokio-stream = { version = "0.1.14", features = ["net"] }
futures-util = { version = "0.3.30", default-features = false }
once_cell = "1.19.0"
4 changes: 2 additions & 2 deletions examples/websocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.76"
async-trait = "0.1.77"
silent = { path = "../../silent", features = ["ws"] }
tokio = { version = "1.35.1", features = ["full"] }
tokio = { version = "1.36.0", features = ["full"] }
tokio-tungstenite = "0.21.0"
futures-util = "0.3.30"
backtrace = "0.3.69"
Expand Down
25 changes: 14 additions & 11 deletions silent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["server", "test", "static"]
full = ["admin", "server", "multipart", "ws", "sse", "security", "static", "session", "cookie", "template", "test"]
full = ["admin", "server", "multipart", "ws", "sse", "security", "static", "session", "cookie", "template", "test", "scheduler"]
admin = ["server", "sse", "template", "session"]
server = ["tokio/fs", "tokio/net", "tokio/rt-multi-thread", "tokio/signal"]
ws = []
Expand All @@ -29,35 +29,36 @@ cookie = []
template = []
#wasi = ["tokio/sync"]
test = ["tokio/macros", "tokio/rt"]
scheduler = []

[dependencies]
thiserror = "1.0.53"
hyper = { version = "1.1.0", features = ["full"] }
tokio = { version = "1.35.1", optional = true }
thiserror = "1.0.57"
hyper = { version = "1.2.0", features = ["full"] }
tokio = { version = "1.36.0", optional = true }
bytes = "1.5.0"
http-body-util = "0.1.0"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
async-trait = "0.1.76"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.109"
uuid = "1.6.1"
async-trait = "0.1.77"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
uuid = "1.7.0"
url = "2.5.0"
serde_urlencoded = "0.7.1"
multimap = { version = "0.10.0", features = ["serde"] }
mime = "0.3.17"
tempfile = "3.9.0"
tempfile = "3.10.1"
textnonce = "1.0.0"
multer = "3.0.0"
#silent-multer = "0.1.0"
futures-util = "0.3.30"
chrono = { version = "0.4.31", default-features = false, features = ["clock"] }
chrono = { version = "0.4.34", default-features = false, features = ["clock"] }
tokio-tungstenite = "0.21.0"
#silent-tokio-tungstenite = "0.1.0"
headers = "0.4.0"
tokio-stream = { version = "0.1.14", features = ["net"] }
pin-project = "1.1"
argon2 = "0.5.2"
argon2 = "0.5.3"
pbkdf2 = { version = "0.12", features = ["simple"] }
aes-gcm = "0.10.3"
aes = "0.8"
Expand All @@ -71,3 +72,5 @@ http = "1.0.0"
http-body = "1.0.0"
futures = "0.3.30"
tokio-util = "0.7.10"
anyhow = "1.0.80"
cron = "0.12.1"
12 changes: 12 additions & 0 deletions silent/src/core/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::core::req_body::ReqBody;
#[cfg(feature = "multipart")]
use crate::core::serde::from_str_multi_val;
use crate::header::CONTENT_TYPE;
#[cfg(feature = "scheduler")]
use crate::Scheduler;
use crate::{Configs, SilentError};
#[cfg(feature = "cookie")]
use cookie::{Cookie, CookieJar};
Expand All @@ -17,6 +19,10 @@ use serde::Deserialize;
use serde_json::Value;
use std::collections::HashMap;
use std::net::IpAddr;
#[cfg(feature = "scheduler")]
use std::sync::Arc;
#[cfg(feature = "scheduler")]
use tokio::sync::Mutex;
use tokio::sync::OnceCell;
use url::form_urlencoded;

Expand Down Expand Up @@ -346,4 +352,10 @@ impl Request {
{
self.cookies.get(name.as_ref())
}
#[cfg(feature = "scheduler")]
#[inline]
/// Get `Scheduler` from extensions.
pub fn scheduler(&self) -> &Arc<Mutex<Scheduler>> {
self.extensions().get().unwrap()
}
}
5 changes: 4 additions & 1 deletion silent/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum SilentError {
HyperError(#[from] hyper::Error),
/// 上传文件读取 错误
#[error("upload file read error `{0}`")]
FileEmpty(#[from] crate::multer::Error),
FileEmpty(#[from] multer::Error),
/// Body为空 错误
#[error("body is empty")]
BodyEmpty,
Expand All @@ -56,6 +56,9 @@ pub enum SilentError {
/// websocket错误
#[error("websocket error: {0}")]
WsError(String),
/// anyhow错误
#[error("{0}")]
AnyhowError(#[from] anyhow::Error),
/// 业务错误
#[error("business error: {msg} ({code})")]
BusinessError {
Expand Down
7 changes: 7 additions & 0 deletions silent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub mod middleware;
mod route;
#[cfg(feature = "server")]
mod rt;
#[cfg(feature = "scheduler")]
mod scheduler;
#[cfg(feature = "security")]
mod security;
#[cfg(feature = "server")]
Expand All @@ -25,6 +27,7 @@ mod templates;
mod ws;

// use silent_multer as multer;
#[allow(unused_imports)]
#[allow(clippy::single_component_path_imports)]
use multer;
// use silent_tokio_tungstenite as tokio_tungstenite;
Expand All @@ -40,6 +43,8 @@ pub use handler::Handler;
pub use handler::HandlerWrapper;
pub use headers;
pub use hyper::{header, Method, StatusCode};
#[cfg(feature = "scheduler")]
pub use scheduler::{ProcessTime, Scheduler, Task};

pub mod prelude {
pub use crate::configs::Configs;
Expand All @@ -60,6 +65,8 @@ pub mod prelude {
pub use crate::route::handler_append::WSHandlerAppend;
pub use crate::route::handler_append::{HandlerAppend, HandlerGetter};
pub use crate::route::{Route, RouteService};
#[cfg(feature = "scheduler")]
pub use crate::scheduler::Task;
#[cfg(feature = "security")]
pub use crate::security::{argon2, pbkdf2};
#[cfg(feature = "server")]
Expand Down
Loading

0 comments on commit 3d35442

Please sign in to comment.