Return token on upload (required by JM Web)
This commit is contained in:
parent
b191626ad9
commit
6e51ece84c
4 changed files with 4 additions and 5 deletions
|
@ -82,6 +82,7 @@ pub struct UploadResponse {
|
|||
pub status: i32,
|
||||
pub error: Option<String>,
|
||||
pub files: Option<Vec<String>>,
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
|
|
@ -130,7 +130,7 @@ async fn upload(
|
|||
|
||||
let token = token.ok_or_else(|| APIError::Unauthorized("Missing token".to_string()))?;
|
||||
let category = category.ok_or_else(|| APIError::BadRequest("Missing category".to_string()))?;
|
||||
let user = User::check_token(token, &db_pool)
|
||||
let user = User::check_token(&token, &db_pool)
|
||||
.await?
|
||||
.ok_or_else(|| APIError::Forbidden("token not existing".to_string()))?;
|
||||
let total = (user.dayuploads as isize) + (files.len() as isize);
|
||||
|
@ -167,12 +167,11 @@ async fn upload(
|
|||
status: 201,
|
||||
error: None,
|
||||
files: Some(links),
|
||||
token,
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
//TODO: Implement upload endpoint
|
||||
|
||||
pub fn routes() -> Router<BoxRoute> {
|
||||
Router::new()
|
||||
.route("/meme", get(meme))
|
||||
|
|
|
@ -157,7 +157,7 @@ impl User {
|
|||
Ok(q)
|
||||
}
|
||||
|
||||
pub async fn check_token(token: String, pool: &MySqlPool) -> Result<Option<Self>> {
|
||||
pub async fn check_token(token: &String, pool: &MySqlPool) -> Result<Option<Self>> {
|
||||
let q: Option<User> = sqlx::query("SELECT id, name, MD5(token) AS hash, uploads FROM (SELECT id, name, IFNULL(count.uploads, 0) AS uploads FROM users LEFT JOIN (SELECT user, COUNT(*) AS uploads FROM memes WHERE DATE(timestamp) = CURDATE() GROUP BY (user)) AS count ON users.id = count.user) AS users, token WHERE users.id = token.uid AND token = ?")
|
||||
.bind(token)
|
||||
.map(|row: MySqlRow| Self {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
|
Loading…
Reference in a new issue