summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2025-01-22 20:51:10 +0800
committerGitHub <noreply@github.com>2025-01-22 20:51:10 +0800
commite0417e8d5bebe25476aaafa22a9ee23d9bd61457 (patch)
tree8edcd3aa9bcd1b012a3a429ad6240e6186caef36 /src/utils
parentdf4440a2a049d26c61a540d3254cd885345fbd6c (diff)
downloadaichat-e0417e8d5bebe25476aaafa22a9ee23d9bd61457.tar.gz
feat: add `--sync-models` cli option (#1114)
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/loader.rs2
-rw-r--r--src/utils/request.rs12
2 files changed, 12 insertions, 2 deletions
diff --git a/src/utils/loader.rs b/src/utils/loader.rs
index 519563c..2ac671d 100644
--- a/src/utils/loader.rs
+++ b/src/utils/loader.rs
@@ -61,7 +61,7 @@ pub async fn load_file(loaders: &HashMap<String, String>, path: &str) -> Result<
}
pub async fn load_url(loaders: &HashMap<String, String>, path: &str) -> Result<LoadedDocument> {
- let (contents, extension) = fetch(loaders, path, false).await?;
+ let (contents, extension) = fetch_with_loaders(loaders, path, false).await?;
let mut metadata: DocumentMetadata = Default::default();
metadata.insert(EXTENSION_METADATA.into(), extension);
Ok(LoadedDocument::new(path.into(), contents, metadata))
diff --git a/src/utils/request.rs b/src/utils/request.rs
index 9f2804b..a479e0e 100644
--- a/src/utils/request.rs
+++ b/src/utils/request.rs
@@ -50,7 +50,17 @@ lazy_static::lazy_static! {
static ref GITHUB_REPO_RE: Regex = Regex::new(r"^https://github\.com/([^/]+)/([^/]+)/tree/([^/]+)").unwrap();
}
-pub async fn fetch(
+pub async fn fetch(url: &str) -> Result<String> {
+ let client = match *CLIENT {
+ Ok(ref client) => client,
+ Err(ref err) => bail!("{err}"),
+ };
+ let res = client.get(url).send().await?;
+ let output = res.text().await?;
+ Ok(output)
+}
+
+pub async fn fetch_with_loaders(
loaders: &HashMap<String, String>,
path: &str,
allow_media: bool,