+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ aide = { version = "0.11.0", features = ["axum"] }
tokio = { version = "1.29.1", features = ["full"] }
axum-jsonschema = { version = "0.6.0", features = ["aide"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
tower-http = { version = "0.4.1", features = ["validate-request", "auth"] }

[build-dependencies]
chrono = "0.4.26"
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ mod similarity;

#[tokio::main]
async fn main() -> Result<()> {
let api_key : &str = option_env!("API_KEY").unwrap_or("");
if api_key == "" {
println!("Running in open mode, no API_KEY set");
}

tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer().with_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| "tinyvector=info".into()),
Expand Down
17 changes: 14 additions & 3 deletions src/routes/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use aide::axum::{
};
use axum::{extract::Path, http::StatusCode, Extension};
use axum_jsonschema::Json;
use tower_http::validate_request::ValidateRequestHeaderLayer;
use schemars::JsonSchema;
use std::time::Instant;

Expand All @@ -13,16 +14,26 @@ use crate::{
similarity::Distance,
};

const API_KEY: Option<&str> = option_env!("API_KEY");

pub fn handler() -> ApiRouter {
ApiRouter::new().nest(
let api_key_layer = ValidateRequestHeaderLayer::bearer(API_KEY.unwrap_or(""));

let route = ApiRouter::new().nest(
"/collections",
ApiRouter::new()
.api_route("/:collection_name", put(create_collection))
.api_route("/:collection_name", post(query_collection))
.api_route("/:collection_name", get(get_collection_info))
.api_route("/:collection_name", delete(delete_collection))
.api_route("/:collection_name/insert", post(insert_into_collection)),
)
.api_route("/:collection_name/insert", post(insert_into_collection))
);

if API_KEY.is_some() {
route.layer(api_key_layer)
} else {
route
}
}

/// Create a new collection
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载