mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Update
This commit is contained in:
@@ -34,7 +34,7 @@ impl Service<Request<Body>> for PixivDownloaderSvc {
|
||||
fn call(&mut self, req: Request<Body>) -> Self::Future {
|
||||
match self.routes.match_route(&req) {
|
||||
Some(route) => Box::pin(async move {
|
||||
match route.response(req) {
|
||||
match route.response(req).await {
|
||||
Ok(data) => Ok(data),
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
|
||||
@@ -9,20 +9,24 @@ pub trait MatchRoute<T, R> {
|
||||
fn match_route(&self, req: &Request<T>) -> bool;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait ResponseFor<T, R> {
|
||||
fn response(&self, req: Request<T>) -> Result<Response<R>, PixivDownloaderError>;
|
||||
async fn response(&self, req: Request<T>) -> Result<Response<R>, PixivDownloaderError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait ResponseJsonFor<T> {
|
||||
fn response_json(&self, req: Request<T>) -> Result<JsonValue, PixivDownloaderError>;
|
||||
async fn response_json(&self, req: Request<T>) -> Result<JsonValue, PixivDownloaderError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T, U> ResponseFor<T, Body> for U
|
||||
where
|
||||
U: ResponseJsonFor<T>,
|
||||
U: ResponseJsonFor<T> + Sync + Send,
|
||||
T: Sync + Send + 'static,
|
||||
{
|
||||
fn response(&self, req: Request<T>) -> Result<Response<Body>, PixivDownloaderError> {
|
||||
let re = self.response_json(req)?;
|
||||
async fn response(&self, req: Request<T>) -> Result<Response<Body>, PixivDownloaderError> {
|
||||
let re = self.response_json(req).await?;
|
||||
Ok(Response::new(Body::from(re.to_string())))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ impl VersionContext {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ResponseJsonFor<Body> for VersionContext {
|
||||
fn response_json(&self, _req: Request<Body>) -> Result<JsonValue, PixivDownloaderError> {
|
||||
async fn response_json(&self, _req: Request<Body>) -> Result<JsonValue, PixivDownloaderError> {
|
||||
Ok(json::object! {"version": [0, 0, 1, 0]})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user