Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 1 addition & 1 deletion components/Launcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
watch(
() => infra_store.is_captcha_validated,
(value, oldValue) => {
if (value && !oldValue && process.client) {
if (value && !oldValue && import.meta.client) {
infra_store.create_backend()
}
},
Expand Down
9 changes: 0 additions & 9 deletions components/Recaptcha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
site_key: { type: String, required: true },
})

onMounted(() => {
if (process.client) {
const config = useRuntimeConfig()
if (config.public.NODE_ENV !== "production" || !infra_store.is_cloud) {
infra_store.$patch({ is_captcha_validated: true })
}
}
})

async function submit_recaptcha(token) {
try {
const response = await $fetch.raw(
Expand Down
2 changes: 1 addition & 1 deletion components/RemoteRenderingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
}

onMounted(async () => {
if (process.client) {
if (import.meta.client) {
window.addEventListener("resize", resize)
await nextTick()
view.setContainer(viewer.value.$el)
Expand Down
5 changes: 5 additions & 0 deletions composables/api_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export function api_fetch(
const { valid, error } = validate_schema(schema, body)

if (!valid) {
if (process.env.NODE_ENV === "development") {
console.log("Bad request", error, schema, params)
console.log("schema", schema)
console.log("params", params)
}
feedback_store.add_error(400, schema.$id, "Bad request", error)
throw new Error(schema.$id.concat(": ", error))
}
Expand Down
5 changes: 5 additions & 0 deletions composables/viewer_call.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export function viewer_call(
const { valid, error } = validate_schema(schema, params)

if (!valid) {
if (process.env.NODE_ENV === "development") {
console.log("Bad request", error, schema, params)
console.log("schema", schema)
console.log("params", params)
}
feedback_store.add_error(400, schema.route, "Bad request", error)
throw new Error(schema.route.concat(": ", error))
}
Expand Down
4 changes: 3 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export default defineNuxtConfig({
SITE_BRANCH:
process.env.NODE_ENV === "production" ? process.env.SITE_BRANCH : "",
PROJECT: process.env.NODE_ENV === "production" ? process.env.PROJECT : "",
NODE_ENV: process.env.NODE_ENV,
BROWSER: process.env.BROWSER || false,
GEODE_PORT: process.env.GEODE_PORT || "",
VIEWER_PORT: process.env.VIEWER_PORT || "",
},
},

Expand Down
9 changes: 6 additions & 3 deletions stores/geode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ export const use_geode_store = defineStore("geode", {
}),
getters: {
protocol() {
if (use_infra_store().is_cloud) {
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
return "https"
}
return "http"
},
port() {
if (use_infra_store().is_cloud) {
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
return "443"
}
if (useRuntimeConfig().public.GEODE_PORT) {
return useRuntimeConfig().public.GEODE_PORT
}
return this.default_local_port
},
base_url() {
const infra_store = use_infra_store()
let geode_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
if (infra_store.is_cloud) {
if (infra_store.app_mode == appMode.appMode.CLOUD) {
if (infra_store.ID == "") {
throw new Error("ID must not be empty in cloud mode")
}
Expand Down
32 changes: 15 additions & 17 deletions stores/infra.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { useStorage } from "@vueuse/core"
import isElectron from "is-electron"
import Status from "@ogw_f/utils/status.js"

export const use_infra_store = defineStore("infra", {
state: () => ({
app_mode: getAppMode(),
ID: useStorage("ID", ""),
is_captcha_validated: false,
is_captcha_validated: true,
status: Status.NOT_CREATED,
}),
getters: {
is_cloud() {
return (
!isElectron() && useRuntimeConfig().public.NODE_ENV === "production"
)
},
domain_name() {
if (this.is_cloud) {
if (this.app_mode == appMode.appMode.CLOUD) {
return useRuntimeConfig().public.API_URL
} else {
return "localhost"
}
return "localhost"
},
lambda_url() {
const geode_store = use_geode_store()
Expand Down Expand Up @@ -47,27 +41,30 @@ export const use_infra_store = defineStore("infra", {
},
actions: {
async create_backend() {
console.log("create_backend this.app_mode", this.app_mode)
if (this.status === Status.CREATED) return
return navigator.locks.request("infra.create_backend", async (lock) => {
this.status = Status.CREATING
if (this.status === Status.CREATED) return
console.log("LOCK GRANTED !", lock)
const geode_store = use_geode_store()
const viewer_store = use_viewer_store()
const feedback_store = use_feedback_store()
if (isElectron()) {
const back_port = await window.electronAPI.run_back(geode_store.port)
if (this.app_mode == appMode.appMode.DESKTOP) {
const viewer_store = use_viewer_store()
const geode_store = use_geode_store()
const back_port = await window.electronAPI.run_back(
geode_store.default_local_port,
)
geode_store.$patch({ default_local_port: back_port })
const viewer_port = await window.electronAPI.run_viewer(
viewer_store.port,
viewer_store.default_local_port,
)
viewer_store.$patch({ default_local_port: viewer_port })
} else {
} else if (this.app_mode == appMode.appMode.CLOUD) {
const { data, error } = await useFetch(this.lambda_url, {
method: "POST",
})
if (error.value || !data.value) {
this.status = Status.NOT_CREATED
const feedback_store = use_feedback_store()
feedback_store.server_error = true
return
}
Expand All @@ -79,6 +76,7 @@ export const use_infra_store = defineStore("infra", {
})
},
async create_connection() {
console.log("create_connection")
await use_viewer_store().ws_connect()
await use_geode_store().do_ping()
return
Expand Down
13 changes: 8 additions & 5 deletions stores/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import vtkWSLinkClient from "@kitware/vtk.js/IO/Core/WSLinkClient"
import "@kitware/vtk.js/Rendering/OpenGL/Profiles/Geometry"
import schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"
import Status from "@ogw_f/utils/status.js"
import { useRuntimeConfig } from "nuxt/app"

export const use_viewer_store = defineStore("viewer", {
state: () => ({
Expand All @@ -16,23 +17,25 @@ export const use_viewer_store = defineStore("viewer", {
}),
getters: {
protocol() {
if (use_infra_store().is_cloud) {
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
return "wss"
} else {
return "ws"
}
},
port() {
if (use_infra_store().is_cloud) {
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
return "443"
} else {
return this.default_local_port
}
if (useRuntimeConfig().public.VIEWER_PORT) {
return useRuntimeConfig().public.VIEWER_PORT
}
return this.default_local_port
},
base_url() {
const infra_store = use_infra_store()
let viewer_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
if (infra_store.is_cloud) {
if (infra_store.app_mode == appMode.appMode.CLOUD) {
if (infra_store.ID == "") {
throw new Error("ID must not be empty in cloud mode")
}
Expand Down
39 changes: 23 additions & 16 deletions test/stores/Geode.nuxt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,50 +30,57 @@ describe("Geode Store", () => {

describe("getters", () => {
describe("protocol", () => {
test("test is_cloud true", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD", () => {
infra_store.app_mode = appMode.appMode.CLOUD
expect(geode_store.protocol).toBe("https")
})

test("test is_cloud false", () => {
infra_store.is_cloud = false
test("test app_mode BROWSER", () => {
infra_store.app_mode = appMode.appMode.BROWSER
expect(geode_store.protocol).toBe("http")
})
test("test app_mode DESKTOP", () => {
infra_store.app_mode = appMode.appMode.DESKTOP
expect(geode_store.protocol).toBe("http")
})
})

describe("port", () => {
test("test is_cloud true", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD", () => {
infra_store.app_mode = appMode.appMode.CLOUD
expect(geode_store.port).toBe("443")
})
test("test is_cloud false", () => {
infra_store.is_cloud = false
test("test app_mode BROWSER", () => {
infra_store.app_mode = appMode.appMode.BROWSER
expect(geode_store.port).toBe(geode_store.default_local_port)
})
test("test app_mode DESKTOP", () => {
infra_store.app_mode = appMode.appMode.DESKTOP
expect(geode_store.port).toBe(geode_store.default_local_port)
})

test("test override default_local_port", () => {
infra_store.is_cloud = false
infra_store.app_mode = appMode.appMode.DESKTOP
geode_store.default_local_port = "12"
expect(geode_store.port).toBe("12")
})
})

describe("base_url", () => {
test("test is_cloud false", () => {
infra_store.is_cloud = false
test("test app_mode BROWSER", () => {
infra_store.app_mode = appMode.appMode.BROWSER
infra_store.domain_name = "localhost"
expect(geode_store.base_url).toBe("http://localhost:5000")
})
test("test is_cloud true", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD", () => {
infra_store.app_mode = appMode.appMode.CLOUD
infra_store.ID = "123456"
infra_store.domain_name = "example.com"
expect(geode_store.base_url).toBe(
"https://example.com:443/123456/geode",
)
})
test("test is_cloud true, ID empty", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD, ID empty", () => {
infra_store.app_mode = appMode.appMode.CLOUD
infra_store.ID = ""
infra_store.domain_name = "example.com"
expect(() => geode_store.base_url).toThrowError(
Expand Down
19 changes: 10 additions & 9 deletions test/stores/Infra.nuxt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,23 @@ describe("Infra Store", () => {
})
})
describe("getters", () => {
describe("is_cloud", () => {
describe("app_mode", () => {
test("test type", () => {
expectTypeOf(infra_store.is_cloud).toBeBoolean()
expectTypeOf(infra_store.app_mode).toBeString()
})
})

describe("domain_name", () => {
test("test type", () => {
expectTypeOf(infra_store.is_cloud).toBeString()
test("test app_mode BROWSER", () => {
infra_store.app_mode = appMode.appMode.BROWSER
expect(infra_store.domain_name).toBe("localhost")
})
test("test is_cloud false", () => {
infra_store.is_cloud = false
test("test app_mode DESKTOP", () => {
infra_store.app_mode = appMode.appMode.DESKTOP
expect(infra_store.domain_name).toBe("localhost")
})
test("test is_cloud false", () => {
infra_store.is_cloud = true
test("test app_mode CLOUD", () => {
infra_store.app_mode = appMode.appMode.CLOUD
expect(infra_store.domain_name).toBe("api.geode-solutions.com")
})
})
Expand All @@ -64,7 +65,7 @@ describe("Infra Store", () => {
test("test is cloud true", () => {
useRuntimeConfig().public.SITE_BRANCH = "/test"
useRuntimeConfig().public.PROJECT = "/project"
infra_store.is_cloud = true
infra_store.app_mode = appMode.appMode.CLOUD
expect(infra_store.lambda_url).toBe(
"https://api.geode-solutions.com:443/test/project/createbackend",
)
Expand Down
Loading
Loading