Skip to content

Commit

Permalink
#502-wildcard-subdomain:
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Jul 31, 2023
1 parent 6157632 commit 7dac7b6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
7 changes: 6 additions & 1 deletion browser/data-browser/src/components/RegisterSignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export function RegisterSignIn({
if (agent) {
return <>{children}</>;
} else if (!emailRegister) {
return <SettingsAgent />;
return (
<>
<SettingsAgent />
<ErrorLook>No e-mail support on this server...</ErrorLook>
</>
);
}

return (
Expand Down
5 changes: 3 additions & 2 deletions browser/react/src/useServerSupports.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ServerSupports, useStore } from './index.js';
import { ServerSupports, useServerURL, useStore } from './index.js';
import { useEffect, useState } from 'react';

export function useServerSupports(): ServerSupports {
const store = useStore();
const serverURL = useServerURL();
const [supports, setSupports] = useState<ServerSupports>({
emailRegister: false,
});
Expand All @@ -14,7 +15,7 @@ export function useServerSupports(): ServerSupports {
}

check();
}, [store]);
}, [store, serverURL]);

return supports;
}
5 changes: 3 additions & 2 deletions lib/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Db {
pub fn init_temp(id: &str) -> AtomicResult<Db> {
let tmp_dir_path = format!(".temp/db/{}", id);
let _try_remove_existing = std::fs::remove_dir_all(&tmp_dir_path);
let store = Db::init(std::path::Path::new(&tmp_dir_path), "https://localhost")?;
let mut store = Db::init(std::path::Path::new(&tmp_dir_path), "https://localhost")?;
let agent = store.create_agent(None)?;
store.set_default_agent(agent);
store.populate()?;
Expand Down Expand Up @@ -233,6 +233,7 @@ impl Db {
let mut endpoints = build_default_endpoints();

if self.smtp_client.is_some() {
tracing::info!("SMTP client is set, adding register endpoints");
endpoints.push(plugins::register::register_endpoint());
endpoints.push(plugins::register::confirm_email_endpoint());
}
Expand Down Expand Up @@ -645,7 +646,7 @@ impl Storelike for Db {
)
}

fn populate(&self) -> AtomicResult<()> {
fn populate(&mut self) -> AtomicResult<()> {
crate::populate::populate_all(self)
}

Expand Down
3 changes: 2 additions & 1 deletion lib/src/populate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub fn populate_sidebar_items(store: &crate::Db) -> AtomicResult<()> {

/// Runs all populate commands. Optionally runs index (blocking), which can be slow!
#[cfg(feature = "db")]
pub fn populate_all(store: &crate::Db) -> AtomicResult<()> {
pub fn populate_all(store: &mut crate::Db) -> AtomicResult<()> {
// populate_base_models should be run in init, instead of here, since it will result in infinite loops without
populate_default_store(store)
.map_err(|e| format!("Failed to populate default store. {}", e))?;
Expand All @@ -295,5 +295,6 @@ pub fn populate_all(store: &crate::Db) -> AtomicResult<()> {
populate_collections(store).map_err(|e| format!("Failed to populate collections. {}", e))?;
populate_sidebar_items(store)
.map_err(|e| format!("Failed to populate sidebar items. {}", e))?;
store.register_default_endpoints()?;
Ok(())
}
2 changes: 1 addition & 1 deletion lib/src/storelike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ pub trait Storelike: Sized {
}

/// Loads the default store. For DBs it also adds default Collections and Endpoints.
fn populate(&self) -> AtomicResult<()> {
fn populate(&mut self) -> AtomicResult<()> {
crate::populate::populate_base_models(self)?;
crate::populate::populate_default_store(self)
}
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ rustls-pemfile = "1"
sanitize-filename = "0.4"
serde_json = "1"
simple-server-timing-header = "0.1.0"
static-files = "0.2"
static-files = "0.2.3"
tantivy = "0.19"
tracing = "0.1"
tracing-actix-web = "0.6"
Expand Down
12 changes: 4 additions & 8 deletions server/src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ pub struct AppState {

/// Initializes the Store and sets the default agent.
pub fn init_store(config: &Config) -> AtomicServerResult<Db> {
let mut store = atomic_lib::Db::init(&config.store_path, &config.server_url)?;
let store = atomic_lib::Db::init(&config.store_path, &config.server_url)?;

tracing::info!("Setting default agent");
set_default_agent(config, &store)?;
store.register_default_endpoints()?;

Ok(store)
}
Expand Down Expand Up @@ -66,11 +65,6 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
};

let should_init = !&config.store_path.exists() || config.initialize;
if should_init {
tracing::info!("Initialize: creating and populating new Database...");
atomic_lib::populate::populate_default_store(&store)
.map_err(|e| format!("Failed to populate default store. {}", e))?;
}

// Initialize search constructs
tracing::info!("Starting search service");
Expand All @@ -95,7 +89,9 @@ pub async fn init(config: Config) -> AtomicServerResult<AppState> {
// If the user changes their server_url, the drive will not exist.
// In this situation, we should re-build a new drive from scratch.
if should_init {
atomic_lib::populate::populate_all(&store)?;
tracing::info!("Initialize: creating and populating new Database...");

atomic_lib::populate::populate_all(&mut store)?;
// Building the index here is needed to perform Queries on imported resources
let store_clone = store.clone();
std::thread::spawn(move || {
Expand Down

0 comments on commit 7dac7b6

Please sign in to comment.