-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(document): add web document for preset / custom docs (#2898)
* add web document change Signed-off-by: xxs-wallace <[email protected]> * [autofix.ci] apply automated fixes * add to schema.sql Signed-off-by: xxs-wallace <[email protected]> * move to new file Signed-off-by: xxs-wallace <[email protected]> * update schema.sql * update * commit suggestion Signed-off-by: xxs-wallace <[email protected]> * refactor(document): add web document service api (#2904) * add api Signed-off-by: xxs-wallace <[email protected]> * fmt Signed-off-by: xxs-wallace <[email protected]> * refactor some name Signed-off-by: xxs-wallace <[email protected]> * fix generate example Signed-off-by: xxs-wallace <[email protected]> * fmt Signed-off-by: xxs-wallace <[email protected]> * rename Signed-off-by: xxs-wallace <[email protected]> * fix method Signed-off-by: xxs-wallace <[email protected]> * add updated at field Signed-off-by: xxs-wallace <[email protected]> * add regex Signed-off-by: xxs-wallace <[email protected]> * Update ee/tabby-schema/src/schema/web_documents.rs * fix doc Signed-off-by: xxs-wallace <[email protected]> * add test Signed-off-by: xxs-wallace <[email protected]> * fix space Signed-off-by: xxs-wallace <[email protected]> --------- Signed-off-by: xxs-wallace <[email protected]> Co-authored-by: Meng Zhang <[email protected]> * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * feat(document): support crawl preset document (#2907) * finish api Signed-off-by: xxs-wallace <[email protected]> * fix delete by id Signed-off-by: xxs-wallace <[email protected]> * fix active Signed-off-by: xxs-wallace <[email protected]> * fix name Signed-off-by: xxs-wallace <[email protected]> * fix api Signed-off-by: xxs-wallace <[email protected]> * add ut Signed-off-by: xxs-wallace <[email protected]> --------- Signed-off-by: xxs-wallace <[email protected]> * add more test Signed-off-by: xxs-wallace <[email protected]> --------- Signed-off-by: xxs-wallace <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Meng Zhang <[email protected]>
- Loading branch information
1 parent
d2962ed
commit 593f1a6
Showing
14 changed files
with
1,049 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE web_documents; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE web_documents( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
name VARCHAR(255) NOT NULL, | ||
url TEXT NOT NULL, | ||
is_preset BOOLEAN NOT NULL DEFAULT FALSE, | ||
created_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')), | ||
updated_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')), | ||
CONSTRAINT idx_name UNIQUE(name), | ||
CONSTRAINT idx_url UNIQUE(url) | ||
); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use anyhow::{anyhow, Result}; | ||
use chrono::{DateTime, Utc}; | ||
use sqlx::{prelude::FromRow, query}; | ||
use tabby_db_macros::query_paged_as; | ||
|
||
use crate::DbConn; | ||
|
||
#[allow(unused)] | ||
#[derive(FromRow)] | ||
pub struct WebDocumentDAO { | ||
pub id: i64, | ||
pub name: String, | ||
pub url: String, | ||
pub is_preset: bool, | ||
pub created_at: DateTime<Utc>, | ||
pub updated_at: DateTime<Utc>, | ||
} | ||
|
||
impl DbConn { | ||
pub async fn list_web_documents( | ||
&self, | ||
limit: Option<usize>, | ||
skip_id: Option<i32>, | ||
backwards: bool, | ||
is_preset: bool, | ||
) -> Result<Vec<WebDocumentDAO>> { | ||
let condition = Some(format!("is_preset={}", is_preset)); | ||
|
||
let urls = query_paged_as!( | ||
WebDocumentDAO, | ||
"web_documents", | ||
["id", "name", "url", "is_preset", "created_at" as "created_at!: DateTime<Utc>", "updated_at" as "updated_at!: DateTime<Utc>"], | ||
limit, | ||
skip_id, | ||
backwards, | ||
condition | ||
).fetch_all(&self.pool) | ||
.await?; | ||
|
||
Ok(urls) | ||
} | ||
|
||
pub async fn create_web_document( | ||
&self, | ||
name: String, | ||
url: String, | ||
is_preset: bool, | ||
) -> Result<i64> { | ||
let res = query!( | ||
"INSERT INTO web_documents(name, url, is_preset) VALUES (?,?,?);", | ||
name, | ||
url, | ||
is_preset | ||
) | ||
.execute(&self.pool) | ||
.await?; | ||
|
||
Ok(res.last_insert_rowid()) | ||
} | ||
|
||
pub async fn deactivate_preset_web_document(&self, name: String) -> Result<()> { | ||
let res = query!("DELETE FROM web_documents WHERE name = ?;", name) | ||
.execute(&self.pool) | ||
.await?; | ||
if res.rows_affected() != 1 { | ||
return Err(anyhow!("No preset web document to deactivate")); | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub async fn delete_web_document(&self, id: i64) -> Result<()> { | ||
query!("DELETE FROM web_documents WHERE id = ?;", id) | ||
.execute(&self.pool) | ||
.await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.