diff --git a/sqlx-data.json b/sqlx-data.json index 295d3dae..e749d0b1 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -52,21 +52,6 @@ }, "query": "UPDATE mcaptcha_users set name = $1\n WHERE name = $2" }, - "238569a64d7dbd252e3b27204f207e8a8548109717b89495ddf8f9a870c7c75d": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Varchar", - "Int4", - "Text", - "Text" - ] - } - }, - "query": "UPDATE mcaptcha_config SET name = $1, duration = $2 \n WHERE user_id = (SELECT ID FROM mcaptcha_users WHERE name = $3)\n AND key = $4" - }, "2b319a202bb983d5f28979d1e371f399125da1122fbda36a5a55b75b9c743451": { "describe": { "columns": [], @@ -265,6 +250,21 @@ }, "query": "UPDATE mcaptcha_config SET key = $1 \n WHERE key = $2 AND user_id = (SELECT ID FROM mcaptcha_users WHERE name = $3)" }, + "570c22f19fe0b97d78086038c8ef82509dce0bae704d80f9f031c1c47e6a6572": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Varchar", + "Int4", + "Text", + "Text" + ] + } + }, + "query": "UPDATE mcaptcha_config SET name = $1, duration = $2\n WHERE user_id = (SELECT ID FROM mcaptcha_users WHERE name = $3)\n AND key = $4" + }, "60081afa71dca3d10b372aabfdbc809f0cf62b33994a3bb43ea444159c6544fe": { "describe": { "columns": [], diff --git a/src/api/v1/mcaptcha/update.rs b/src/api/v1/mcaptcha/update.rs index 18997c9c..d2be34a3 100644 --- a/src/api/v1/mcaptcha/update.rs +++ b/src/api/v1/mcaptcha/update.rs @@ -22,6 +22,8 @@ use libmcaptcha::defense::Level; use libmcaptcha::master::messages::RenameBuilder; use serde::{Deserialize, Serialize}; +use db_core::CreateCaptcha; + use super::create::MCaptchaDetails; use super::get_random; use crate::errors::*; @@ -131,38 +133,21 @@ pub mod runner { // still, needs to be benchmarked defense.build()?; - let mut futs = Vec::with_capacity(payload.levels.len() + 2); - sqlx::query!( - "DELETE FROM mcaptcha_levels - WHERE config_id = ( - SELECT config_id FROM mcaptcha_config where key = ($1) - AND user_id = ( - SELECT ID from mcaptcha_users WHERE name = $2 - ) - )", - &payload.key, - &username - ) - .execute(&data.db) - .await?; + data.dblib + .delete_captcha_levels(username, &payload.key) + .await?; - let update_fut = sqlx::query!( - "UPDATE mcaptcha_config SET name = $1, duration = $2 - WHERE user_id = (SELECT ID FROM mcaptcha_users WHERE name = $3) - AND key = $4", - &payload.description, - payload.duration as i32, - &username, - &payload.key, - ) - .execute(&data.db); + let m = CreateCaptcha { + key: &payload.key, + duration: payload.duration as i32, + description: &payload.description, + }; - futs.push(update_fut); + data.dblib.update_captcha_metadata(&username, &m).await?; data.dblib .add_captcha_levels(username, &payload.key, &payload.levels) .await?; - try_join_all(futs).await?; if let Err(ServiceError::CaptchaError(e)) = data .captcha .remove(RemoveCaptcha(payload.key.clone()))