Skip to content

Commit b1c9199

Browse files
committed
fix qr_code generator
1 parent a373861 commit b1c9199

18 files changed

Lines changed: 68 additions & 46 deletions

File tree

api/src/bin/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use api::{
22
configure::env::get_env_source,
33
constant::ENV_PREFIX,
4-
error::ApiResult,
4+
error::result::ApiResult,
55
server::{worker::GarbageCollectorTask, ApiServer},
66
util::{self, tracing::INIT_SUBSCRIBER},
77
};

api/src/database/file_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::error::{ApiError, ApiResult};
1+
use crate::error::{result::ApiResult, ApiError};
22
use sdk::dto::FileUrlPath;
33
use serde::{Deserialize, Serialize};
44
use sled::IVec;

api/src/database/meta_data_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
error::{ApiError, ApiResult},
2+
error::{result::ApiResult, ApiError},
33
util::secret::SecretHash,
44
};
55
use chrono::{DateTime, Utc};

api/src/database/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
configure::DatabaseConfig,
3-
error::{ApiError, ApiResult},
3+
error::{result::ApiResult, ApiError},
44
};
55
use chrono::{DateTime, Utc};
66
use sled::IVec;

api/src/error/mod.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
use axum::{
2-
http::StatusCode,
3-
response::{IntoResponse, Response},
4-
Json,
5-
};
1+
use axum::http::StatusCode;
62
use sdk::dto::response::BodyResponseError;
73

8-
pub type ApiResult<T = ()> = std::result::Result<T, ApiError>;
4+
pub mod response;
5+
pub mod result;
96

107
#[derive(Debug, thiserror::Error)]
118
pub enum ApiError {
@@ -53,6 +50,8 @@ pub enum ApiError {
5350
MultipartError(#[from] axum::extract::multipart::MultipartError),
5451
#[error(transparent)]
5552
UrlError(#[from] url::ParseError),
53+
#[error(transparent)]
54+
ImageError(#[from] image::ImageError),
5655
#[error("lock error: {0}")]
5756
LockError(String),
5857
#[error("duration out of range error: {0}")]
@@ -155,6 +154,11 @@ impl ApiError {
155154
err.to_string(),
156155
StatusCode::INTERNAL_SERVER_ERROR,
157156
),
157+
ImageError(err) => (
158+
"IMAGE_ERROR",
159+
err.to_string(),
160+
StatusCode::INTERNAL_SERVER_ERROR,
161+
),
158162
UnknownError(err) => (
159163
"UNKNOWN_ERROR",
160164
err.to_string(),
@@ -178,25 +182,8 @@ impl ApiError {
178182
}
179183
}
180184

181-
impl IntoResponse for ApiError {
182-
fn into_response(self) -> Response {
183-
let (body, status_code) = self.response();
184-
(status_code, Json(body)).into_response()
185-
}
186-
}
187-
188185
pub fn invalid_input_error(field: &'static str, message: &'static str) -> ApiError {
189186
let mut report = garde::Report::new();
190187
report.append(garde::Path::new(field), garde::Error::new(message));
191188
ApiError::InvalidInputError(report)
192189
}
193-
194-
pub trait ToApiResult<T> {
195-
fn to_result(self) -> ApiResult<T>;
196-
}
197-
198-
impl<T> ToApiResult<T> for Option<T> {
199-
fn to_result(self) -> ApiResult<T> {
200-
self.ok_or_else(|| ApiError::NotFoundError(format!("{} not found", std::any::type_name::<T>())))
201-
}
202-
}

api/src/error/response.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use axum::{
2+
response::{IntoResponse, Response},
3+
Json,
4+
};
5+
6+
use super::ApiError;
7+
8+
impl IntoResponse for ApiError {
9+
fn into_response(self) -> Response {
10+
let (body, status_code) = self.response();
11+
(status_code, Json(body)).into_response()
12+
}
13+
}

api/src/error/result.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use super::ApiError;
2+
3+
pub type ApiResult<T = ()> = std::result::Result<T, ApiError>;
4+
5+
pub trait ToApiResult<T> {
6+
fn to_result(self) -> ApiResult<T>;
7+
}
8+
9+
impl<T> ToApiResult<T> for Option<T> {
10+
fn to_result(self) -> ApiResult<T> {
11+
self.ok_or_else(|| ApiError::NotFoundError(format!("{} not found", std::any::type_name::<T>())))
12+
}
13+
}

api/src/handler/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tower::ServiceExt;
1515
use tower_http::services::fs::ServeFileSystemResponseBody;
1616

1717
use crate::{
18-
error::ApiResult,
18+
error::result::ApiResult,
1919
server::ApiState,
2020
service::{self},
2121
};

api/src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod worker;
33

44
use crate::configure::{ApiConfig, UrlSchema};
55
use crate::database::Database;
6-
use crate::error::ApiResult;
6+
use crate::error::result::ApiResult;
77
use crate::router::get_router;
88
use std::sync::Arc;
99

api/src/server/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::error::ApiResult;
1+
use crate::error::result::ApiResult;
22

33
use super::ApiState;
44

0 commit comments

Comments
 (0)