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 19, 2024
1 parent d8b3023 commit 05819ec
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 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;
}
7 changes: 4 additions & 3 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 @@ -348,7 +349,7 @@ impl Db {
pub fn register_endpoint(&mut self, endpoint: Endpoint) -> AtomicResult<()> {
let mut resource = endpoint.to_resource(self)?;
let endpoints_collection = self.get_server_url().set_route(Routes::Endpoints);
resource.set_propval(
resource.set(
urls::PARENT.into(),
Value::AtomicUrl(endpoints_collection.to_string()),
self,
Expand Down Expand Up @@ -715,7 +716,7 @@ impl Storelike for Db {
)
}

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

Expand Down
2 changes: 1 addition & 1 deletion lib/src/plugins/add_pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn handle_confirm_add_pubkey(context: HandleGetContext) -> AtomicResult<Reso

// Add the key to the agent
let mut agent = store.get_resource(&confirmation.agent)?;
agent.push_propval(urls::ACTIVE_KEYS, pubkey.into(), true)?;
agent.push(urls::ACTIVE_KEYS, pubkey.into(), true)?;
agent.save(store)?;

return_success()
Expand Down
3 changes: 2 additions & 1 deletion lib/src/populate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,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 @@ -386,5 +386,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 @@ -375,7 +375,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 @@ -41,8 +41,8 @@ sanitize-filename = "0.5"
serde_json = "1"
serde_with = "3.3.0"
simple-server-timing-header = "0.1.0"
static-files = "0.2"
tantivy = "0.21"
static-files = "0.2.3"
tracing = "0.1"
tracing-actix-web = "0.7"
tracing-chrome = "0.7"
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 @@ -65,11 +64,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 @@ -94,7 +88,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 05819ec

Please sign in to comment.