feat: 引入 InsertArgs 聚合授权数据并开放 /create API
- 引入 InsertArgs 结构体并替换 insert_authorize 的多参数列表,改用入参聚合方式传递授权数据。 - 启动提供 /create 接口的 API 服务并用数据库保存生成的令牌
This commit is contained in:
24
src/db.rs
24
src/db.rs
@@ -15,6 +15,14 @@ pub struct Authorize {
|
||||
pub insert_time: String,
|
||||
}
|
||||
|
||||
pub(crate) struct InsertArgs {
|
||||
pub project: String,
|
||||
pub key: String,
|
||||
pub device_id: String,
|
||||
pub expire: String,
|
||||
pub insert_time: String,
|
||||
}
|
||||
|
||||
/// 包装类,内部持有 SQLite 连接
|
||||
pub struct Db {
|
||||
client: SqliteClient,
|
||||
@@ -92,18 +100,14 @@ impl Db {
|
||||
/// 插入新的授权数据
|
||||
pub async fn insert_authorize(
|
||||
&self,
|
||||
project: &str,
|
||||
key: &str,
|
||||
device_id: &str,
|
||||
expire: &str,
|
||||
insert_time: &str,
|
||||
args: InsertArgs,
|
||||
) -> Result<i32, Box<dyn std::error::Error>> {
|
||||
let mut auth = Authorize::new();
|
||||
auth.project = project.to_string();
|
||||
auth.key = key.to_string();
|
||||
auth.device_id = device_id.to_string();
|
||||
auth.expire = expire.to_string();
|
||||
auth.insert_time = insert_time.to_string();
|
||||
auth.project = args.project.to_string();
|
||||
auth.key = args.key.to_string();
|
||||
auth.device_id = args.device_id.to_string();
|
||||
auth.expire = args.expire.to_string();
|
||||
auth.insert_time = args.insert_time.to_string();
|
||||
|
||||
let _created = auth.save(&self.client).await?;
|
||||
Ok(auth.id)
|
||||
|
||||
Reference in New Issue
Block a user