mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-17 19:22:55 +08:00
format code (#14)
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use actix_web::{get, HttpResponse, post, web};
|
||||
use actix_web::{ get, HttpResponse, post, web };
|
||||
use serde::Serialize;
|
||||
use crate::api::JsonResponse;
|
||||
use crate::AppState;
|
||||
@ -16,18 +16,26 @@ pub struct AddDocs2KbParams {
|
||||
pub kb_id: i64,
|
||||
}
|
||||
#[post("/v1.0/create_kb")]
|
||||
async fn create(model: web::Json<kb_info::Model>, data: web::Data<AppState>) -> Result<HttpResponse, AppError> {
|
||||
let mut docs = Query::find_kb_infos_by_name(&data.conn, model.kb_name.to_owned()).await.unwrap();
|
||||
if docs.len() >0 {
|
||||
async fn create(
|
||||
model: web::Json<kb_info::Model>,
|
||||
data: web::Data<AppState>
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let mut docs = Query::find_kb_infos_by_name(
|
||||
&data.conn,
|
||||
model.kb_name.to_owned()
|
||||
).await.unwrap();
|
||||
if docs.len() > 0 {
|
||||
let json_response = JsonResponse {
|
||||
code: 201,
|
||||
err: "Duplicated name.".to_owned(),
|
||||
data: ()
|
||||
data: (),
|
||||
};
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?))
|
||||
}else{
|
||||
Ok(
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?)
|
||||
)
|
||||
} else {
|
||||
let model = Mutation::create_kb_info(&data.conn, model.into_inner()).await?;
|
||||
|
||||
let mut result = HashMap::new();
|
||||
@ -39,14 +47,19 @@ async fn create(model: web::Json<kb_info::Model>, data: web::Data<AppState>) ->
|
||||
data: result,
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?))
|
||||
Ok(
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[post("/v1.0/add_docs_to_kb")]
|
||||
async fn add_docs_to_kb(param: web::Json<AddDocs2KbParams>, data: web::Data<AppState>) -> Result<HttpResponse, AppError> {
|
||||
async fn add_docs_to_kb(
|
||||
param: web::Json<AddDocs2KbParams>,
|
||||
data: web::Data<AppState>
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let _ = Mutation::add_docs(&data.conn, param.kb_id, param.dids.to_owned()).await?;
|
||||
|
||||
let json_response = JsonResponse {
|
||||
@ -55,13 +68,18 @@ async fn add_docs_to_kb(param: web::Json<AddDocs2KbParams>, data: web::Data<AppS
|
||||
data: (),
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?))
|
||||
Ok(
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?)
|
||||
)
|
||||
}
|
||||
|
||||
#[post("/v1.0/anti_kb_docs")]
|
||||
async fn anti_kb_docs(param: web::Json<AddDocs2KbParams>, data: web::Data<AppState>) -> Result<HttpResponse, AppError> {
|
||||
async fn anti_kb_docs(
|
||||
param: web::Json<AddDocs2KbParams>,
|
||||
data: web::Data<AppState>
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let _ = Mutation::remove_docs(&data.conn, param.dids.to_owned(), Some(param.kb_id)).await?;
|
||||
|
||||
let json_response = JsonResponse {
|
||||
@ -70,12 +88,17 @@ async fn anti_kb_docs(param: web::Json<AddDocs2KbParams>, data: web::Data<AppSta
|
||||
data: (),
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?))
|
||||
Ok(
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?)
|
||||
)
|
||||
}
|
||||
#[get("/v1.0/kbs")]
|
||||
async fn list(model: web::Json<kb_info::Model>, data: web::Data<AppState>) -> Result<HttpResponse, AppError> {
|
||||
async fn list(
|
||||
model: web::Json<kb_info::Model>,
|
||||
data: web::Data<AppState>
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let kbs = Query::find_kb_infos_by_uid(&data.conn, model.uid).await?;
|
||||
|
||||
let mut result = HashMap::new();
|
||||
@ -87,13 +110,18 @@ async fn list(model: web::Json<kb_info::Model>, data: web::Data<AppState>) -> Re
|
||||
data: result,
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?))
|
||||
Ok(
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?)
|
||||
)
|
||||
}
|
||||
|
||||
#[post("/v1.0/delete_kb")]
|
||||
async fn delete(model: web::Json<kb_info::Model>, data: web::Data<AppState>) -> Result<HttpResponse, AppError> {
|
||||
async fn delete(
|
||||
model: web::Json<kb_info::Model>,
|
||||
data: web::Data<AppState>
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let _ = Mutation::delete_kb_info(&data.conn, model.kb_id).await?;
|
||||
|
||||
let json_response = JsonResponse {
|
||||
@ -102,19 +130,24 @@ async fn delete(model: web::Json<kb_info::Model>, data: web::Data<AppState>) ->
|
||||
data: (),
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?))
|
||||
Ok(
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?)
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct DocIdsParams {
|
||||
pub uid: i64,
|
||||
pub dids: Vec<i64>
|
||||
pub dids: Vec<i64>,
|
||||
}
|
||||
|
||||
#[post("/v1.0/all_relevents")]
|
||||
async fn all_relevents(params: web::Json<DocIdsParams>, data: web::Data<AppState>) -> Result<HttpResponse, AppError> {
|
||||
async fn all_relevents(
|
||||
params: web::Json<DocIdsParams>,
|
||||
data: web::Data<AppState>
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let dids = crate::service::doc_info::Query::all_descendent_ids(&data.conn, ¶ms.dids).await?;
|
||||
let mut result = HashMap::new();
|
||||
let kbs = Query::find_kb_by_docs(&data.conn, dids).await?;
|
||||
@ -125,8 +158,9 @@ async fn all_relevents(params: web::Json<DocIdsParams>, data: web::Data<AppState
|
||||
data: result,
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?))
|
||||
|
||||
}
|
||||
Ok(
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(serde_json::to_string(&json_response)?)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user