refactor retrieve_ng_bootstrap

pull/19/head
Niko PLP 1 year ago
parent 51f1de5ac3
commit bfe5bd2f02
  1. 2
      ng-app/package.json
  2. 2
      ng-app/src/App.svelte
  3. 1
      ngaccount/web/src/routes/Create.svelte
  4. 47
      p2p-net/src/utils.rs

@ -6,7 +6,7 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"webdev": "cross-env NG_APP_WEB=1 TAURI_DEBUG=1 vite", "webdev": "cross-env NG_APP_WEB=1 TAURI_DEBUG=1 vite",
"webbuild": "cross-env NG_APP_WEB=1 vite build && rm -f ./dist-web/assets/*.svg", "webbuild": "cross-env NG_APP_WEB=1 vite build && rm -f ./dist-web/assets/*.svg && tar --exclude .DS_Store -zcvf dist-web.tar.gz dist-web",
"webfilebuild": "cross-env NG_APP_WEB=1 NG_APP_FILE=1 vite build && node prepare-app-file.cjs && rm -rf ./dist-file/assets && tar --exclude .DS_Store -zcvf dist-file.tar.gz dist-file", "webfilebuild": "cross-env NG_APP_WEB=1 NG_APP_FILE=1 vite build && node prepare-app-file.cjs && rm -rf ./dist-file/assets && tar --exclude .DS_Store -zcvf dist-file.tar.gz dist-file",
"webfilebuilddebug": "cross-env NG_APP_WEB=1 NG_APP_FILE=1 TAURI_DEBUG=1 vite build -m debug", "webfilebuilddebug": "cross-env NG_APP_WEB=1 NG_APP_FILE=1 TAURI_DEBUG=1 vite build -m debug",
"build": "vite build && rm -f ./dist/assets/*.svg", "build": "vite build && rm -f ./dist/assets/*.svg",

@ -11,7 +11,7 @@
<script lang="ts"> <script lang="ts">
// this line is needed to have the SDK working when compiling for a single file bundle (pnpm webfilebuild) // this line is needed to have the SDK working when compiling for a single file bundle (pnpm webfilebuild)
import * as api from "ng-sdk-js"; //import * as api from "ng-sdk-js";
import { push, default as Router } from "svelte-spa-router"; import { push, default as Router } from "svelte-spa-router";
import { onMount, tick, onDestroy } from "svelte"; import { onMount, tick, onDestroy } from "svelte";
import { import {

@ -16,7 +16,6 @@
// @ts-ignore // @ts-ignore
import Logo from "../assets/nextgraph.svg?component"; import Logo from "../assets/nextgraph.svg?component";
import { link, querystring } from "svelte-spa-router"; import { link, querystring } from "svelte-spa-router";
import { tauri, event } from "@tauri-apps/api";
import { onMount } from "svelte"; import { onMount } from "svelte";
let domain = import.meta.env.NG_ACCOUNT_DOMAIN; let domain = import.meta.env.NG_ACCOUNT_DOMAIN;

@ -115,17 +115,32 @@ pub fn check_is_local_url(bootstrap: &BrokerServerV0, location: &String) -> Opti
} }
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
pub async fn retrieve_local_url(location: String) -> Option<String> { async fn retrieve_ng_bootstrap(location: &String) -> Option<BootstrapContent> {
let bootstraps: BootstrapContent = { let prefix = if (APP_PREFIX == "") {
let resp = reqwest::get(format!("{}{}", APP_PREFIX, NG_BOOTSTRAP_LOCAL_PATH)).await; let url = Url::parse(location).unwrap();
url.origin().unicode_serialization()
} else {
APP_PREFIX.to_string()
};
let url = format!("{}{}", prefix, NG_BOOTSTRAP_LOCAL_PATH);
//log_info!("url {}", url);
let resp = reqwest::get(url).await;
if resp.is_ok() { if resp.is_ok() {
let resp = resp.unwrap().json::<BootstrapContent>().await; let resp = resp.unwrap().json::<BootstrapContent>().await;
resp.unwrap() return Some(resp.unwrap());
} else { } else {
//log_info!("err {}", resp.unwrap_err());
return None; return None;
} }
}; }
for bootstrap in bootstraps.servers() {
#[cfg(target_arch = "wasm32")]
pub async fn retrieve_local_url(location: String) -> Option<String> {
let bootstraps = retrieve_ng_bootstrap(&location).await;
if bootstraps.is_none() {
return None;
}
for bootstrap in bootstraps.unwrap().servers() {
let res = check_is_local_url(bootstrap, &location); let res = check_is_local_url(bootstrap, &location);
if res.is_some() { if res.is_some() {
return res; return res;
@ -134,6 +149,7 @@ pub async fn retrieve_local_url(location: String) -> Option<String> {
None None
} }
#[cfg(target_arch = "wasm32")]
pub async fn retrieve_local_bootstrap( pub async fn retrieve_local_bootstrap(
location_string: String, location_string: String,
invite_string: Option<String>, invite_string: Option<String>,
@ -149,19 +165,14 @@ pub async fn retrieve_local_bootstrap(
log_debug!("invite_String {:?} invite1{:?}", invite_string, invite1); log_debug!("invite_String {:?} invite1{:?}", invite_string, invite1);
let invite2: Option<Invitation> = { let invite2: Option<Invitation> = {
// let resp = reqwest::get(format!("{}{}", APP_PREFIX, NG_BOOTSTRAP_LOCAL_PATH)).await; let bootstraps = retrieve_ng_bootstrap(&location_string).await;
// if resp.is_ok() { if bootstraps.is_none() {
// let resp = resp.unwrap().json::<BootstrapContent>().await;
// if resp.is_ok() {
// let mut inv: Invitation = resp.unwrap().into();
// inv.set_url(BROKER.read().await.get_registration_url());
// Some(inv)
// } else {
// None
// }
// } else {
None None
//} } else {
let mut inv: Invitation = bootstraps.unwrap().into();
inv.set_url(BROKER.read().await.get_registration_url());
Some(inv)
}
}; };
let res = if invite1.is_none() { let res = if invite1.is_none() {

Loading…
Cancel
Save