feat: 添加授权数据目录忽略和数据库查询功能
- 添加 authorize_data/ 目录到 .gitignore 文件中以忽略该目录的版本控制 - 更新授权数据库文件内容 - 添加通过项目和设备ID查询数据库存在的功能,并将InsertArgs结构体设为公共可见。 - 添加创建令牌时检查项目和设备ID是否已存在的逻辑,并返回相应的状态信息。
This commit is contained in:
20
src/db.rs
20
src/db.rs
@@ -14,7 +14,7 @@ pub struct Authorize {
|
||||
pub insert_time: String,
|
||||
}
|
||||
|
||||
pub(crate) struct InsertArgs {
|
||||
pub struct InsertArgs {
|
||||
pub project: String,
|
||||
pub token: String,
|
||||
pub device_id: String,
|
||||
@@ -64,6 +64,24 @@ impl Db {
|
||||
Ok(Db { client })
|
||||
}
|
||||
|
||||
/// 通过project和device_id查询是否存在数据库
|
||||
pub async fn exists_project(
|
||||
&self,
|
||||
project: &str,
|
||||
device_id: &str,
|
||||
) -> Result<Option<Authorize>, Box<dyn std::error::Error>> {
|
||||
let row = Authorize::all()
|
||||
.where_col(|a| a.project.equal(project))
|
||||
.where_col(|a| a.device_id.equal(device_id))
|
||||
.limit(1)
|
||||
.run(&self.client)
|
||||
.await?
|
||||
.into_inners()
|
||||
.into_iter()
|
||||
.next();
|
||||
Ok(row)
|
||||
}
|
||||
|
||||
/// 判断 token 是否存在
|
||||
pub async fn verify_token(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user