Support for using a master key (#83)

* Support for using a master key

* Expand scope of PR, add wrapper struct, add files to intitial versions/mods

* Change changelog path, run formatter

* Split file changes into different PR

* Formatting, rename main variable

Co-authored-by: Aeledfyr <aeledfyr@gmail.com>
This commit is contained in:
Geometrically
2020-10-19 14:23:05 -07:00
committed by GitHub
parent e0b972f6d6
commit c886e7949e
8 changed files with 75 additions and 25 deletions

View File

@@ -52,6 +52,12 @@ impl actix_web::ResponseError for SearchError {
}
}
#[derive(Clone)]
pub struct SearchConfig {
pub address: String,
pub key: String,
}
/// A mod document used for uploading mods to meilisearch's indices.
/// This contains some extra data that is not returned by search results.
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -133,9 +139,11 @@ impl Document for ResultSearchMod {
}
}
pub async fn search_for_mod(info: &SearchRequest) -> Result<SearchResults, SearchError> {
let address = &*dotenv::var("MEILISEARCH_ADDR")?;
let client = Client::new(address, "");
pub async fn search_for_mod(
info: &SearchRequest,
config: &SearchConfig,
) -> Result<SearchResults, SearchError> {
let client = Client::new(&*config.key, &*config.address);
let filters: Cow<_> = match (info.filters.as_deref(), info.version.as_deref()) {
(Some(f), Some(v)) => format!("({}) AND ({})", f, v).into(),