Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 5 additions & 10 deletions app/components/Launcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Loading from "@ogw_front/components/Loading";
import Recaptcha from "@ogw_front/components/Recaptcha";
import { Status } from "@ogw_front/utils/status";
import { appMode } from "@ogw_front/utils/local/app_mode";
import { useInfraStore } from "@ogw_front/stores/infra";

const { logo } = defineProps({
Expand All @@ -12,22 +13,16 @@ const { logo } = defineProps({
});

const infraStore = useInfraStore();

watch(
() => infraStore.is_captcha_validated,
(value, oldValue) => {
if (value && !oldValue && import.meta.client) {
infraStore.create_backend();
}
},
);
if (infraStore.app_mode !== appMode.CLOUD) {
infraStore.create_backend();
}
</script>

<template>
<v-container class="justify">
<v-row align-content="center" align="center">
<v-col
v-if="!infraStore.is_captcha_validated"
v-if="!infraStore.status == Status.NOT_CREATED"
class="align"
cols="12"
align-self="center"
Expand Down
30 changes: 5 additions & 25 deletions app/components/Recaptcha.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<script setup>
import { appMode } from "@ogw_front/utils/local/app_mode";
import { useInfraStore } from "@ogw_front/stores/infra";

const RESPONSE_STATUS_OK = 200;

const { button_label, button_color, color } = defineProps({
button_label: {
type: String,
Expand All @@ -20,7 +17,7 @@ const { button_label, button_color, color } = defineProps({
required: false,
},
});
const infraStore = useInfraStore();

const name = ref("");
const email = ref("");
const launch = ref(false);
Expand All @@ -40,26 +37,9 @@ const emailRules = [
},
];

onMounted(() => {
if (
import.meta.client &&
(process.env.NODE_ENV !== "production" || infraStore.app_mode !== appMode.CLOUD)
) {
infraStore.$patch({ is_captcha_validated: true });
}
});
async function submit_recaptcha() {
const response = await $fetch.raw(`/.netlify/functions/recaptcha`, {
method: "POST",
body: {
name: name.value,
email: email.value,
launch: launch.value,
},
});
infraStore.$patch({
is_captcha_validated: response.status === RESPONSE_STATUS_OK,
});
function submit() {
const infraStore = useInfraStore();
return infraStore.create_backend(name.value, email.value, launch.value);
}
</script>

Expand Down Expand Up @@ -89,7 +69,7 @@ async function submit_recaptcha() {
</VRow>
<VRow align="center" justify="center">
<VCol cols="4" class="d-flex justify-center align-center">
<VBtn :text="button_label" :color="color || button_color" @click="submit_recaptcha" />
<VBtn :text="button_label" :color="color || button_color" @click="submit" />
</VCol>
</VRow>
</template>
63 changes: 63 additions & 0 deletions app/stores/cloud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Status } from "@ogw_front/utils/status";
import { useAppStore } from "./app";
import { useFeedbackStore } from "./feedback";
import { useInfraStore } from "./infra";

export const useCloudStore = defineStore("cloud", {
state: () => ({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi pas le faire en setup directement ?

status: Status.NOT_CONNECTED,
}),
actions: {
launch(name, email, launch) {
this.status = Status.CONNECTING;
console.log("[CLOUD] Launching cloud backend...");
const schema = {
$id: "/api/app/run_cloud",
methods: ["POST"],
type: "object",
properties: {
name: { type: "string" },
email: { type: "string" },
launch: { type: "boolean" },
},
required: ["name", "email", "launch"],
additionalProperties: true,
};
const params = {
name,
email,
launch,
};
console.log("[CLOUD] params", params);
const appStore = useAppStore();
const feedbackStore = useFeedbackStore();
return appStore.request(schema, params, {
request_error_function: () => {
feedbackStore.$patch({ server_error: true });
this.status = Status.NOT_CONNECTED;
},
response_function: (response) => {
feedbackStore.$patch({ server_error: false });
console.log(`[CLOUD] Cloud launched on ${response.url}`);
this.status = Status.CONNECTED;
const infraStore = useInfraStore();
infraStore.$patch({
domain_name: response.url,
});
},
response_error_function: () => {
feedbackStore.$patch({ server_error: true });
this.status = Status.NOT_CONNECTED;
},
});
},
connect() {
console.log("[CLOUD] Cloud connected");
this.status = Status.CONNECTED;
return Promise.resolve();
},
},
share: {
omit: ["status"],
},
});
5 changes: 1 addition & 4 deletions app/stores/geode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
const infraStore = useInfraStore();
let geode_url = `${this.protocol}://${infraStore.domain_name}:${this.port}`;
if (infraStore.app_mode === appMode.CLOUD) {
if (infraStore.ID === "") {
throw new Error("ID must not be empty in cloud mode");
}
geode_url += `/${infraStore.ID}/geode`;
geode_url += `/geode`;
}
return geode_url;
},
Expand Down Expand Up @@ -79,7 +76,7 @@
this.request_counter -= 1;
},
launch(args) {
console.log("[GEODE] Launching back microservice...", { args });

Check warning on line 79 in app/stores/geode.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
const appStore = useAppStore();
const { COMMAND_BACK, NUXT_ROOT_PATH } = useRuntimeConfig().public;
const schema = {
Expand All @@ -95,21 +92,21 @@
};
const params = { COMMAND_BACK, NUXT_ROOT_PATH, args };

console.log("[GEODE] params", params);

Check warning on line 95 in app/stores/geode.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
return appStore.request(schema, params, {
response_function: (response) => {
console.log(`[GEODE] Back launched on port ${response.port}`);

Check warning on line 98 in app/stores/geode.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
this.default_local_port = response.port;
},
});
},
connect() {
console.log("[GEODE] Connecting to geode microservice...");

Check warning on line 104 in app/stores/geode.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
this.set_ping();
return Promise.resolve();
},
request(schema, params, callbacks = {}) {
console.log("[GEODE] Request:", schema.$id);

Check warning on line 109 in app/stores/geode.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
const start = Date.now();

return api_fetch(
Expand All @@ -118,7 +115,7 @@
{
...callbacks,
response_function: async (response) => {
console.log(

Check warning on line 118 in app/stores/geode.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
"[GEODE] Request completed:",
schema.$id,
"in",
Expand All @@ -143,7 +140,7 @@
{
...callbacks,
response_function: async (response) => {
console.log("[GEODE] Request completed:", route);

Check warning on line 143 in app/stores/geode.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
if (callbacks.response_function) {
await callbacks.response_function(response);
}
Expand Down
22 changes: 6 additions & 16 deletions app/stores/infra.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@ import { Status } from "@ogw_front/utils/status";
import { appMode } from "@ogw_front/utils/local/app_mode";
import { registerRunningExtensions } from "@ogw_front/utils/extension";
import { useAppStore } from "@ogw_front/stores/app";
import { useLambdaStore } from "@ogw_front/stores/lambda";
import { useCloudStore } from "@ogw_front/stores/cloud";

export const useInfraStore = defineStore("infra", {
state: () => ({
app_mode: useRuntimeConfig().public.MODE,
ID: "",
is_captcha_validated: false,
status: Status.NOT_CREATED,
microservices: [],
domain_name: "localhost",
}),
getters: {
domain_name() {
if (this.app_mode === appMode.CLOUD) {
return useRuntimeConfig().public.API_URL;
}
return "localhost";
},
microservices_connected() {
console.log("microservices", this.microservices);
return this.microservices.every((store) => store.status === Status.CONNECTED);
Expand All @@ -37,7 +30,7 @@ export const useInfraStore = defineStore("infra", {
console.log("[INFRA] Microservice registered:", store_name);
}
},
create_backend() {
create_backend(name, email, launch) {
console.log("[INFRA] Starting create_backend - Mode:", this.app_mode);
console.log(
"[INFRA] Registered microservices:",
Expand All @@ -47,18 +40,15 @@ export const useInfraStore = defineStore("infra", {
return;
}
return navigator.locks.request("infra.create_backend", async () => {
this.status = Status.CREATING;
if (this.status === Status.CREATED) {
return;
}
this.status = Status.CREATING;
console.log("[INFRA] Lock granted for create_backend");
if (this.app_mode === appMode.CLOUD) {
console.log("[INFRA] CLOUD mode - Launching lambda...");
const lambdaStore = useLambdaStore();
this.ID = await lambdaStore.launch();
console.log("[INFRA] Lambda launched successfully");
const cloudStore = useCloudStore();
await cloudStore.launch(name, email, launch);
} else {
console.log(`[INFRA] ${this.app_mode} mode - Launching microservices...`);
const appStore = useAppStore();
await appStore.createProjectFolder();
if (this.app_mode === appMode.DESKTOP) {
Expand Down
57 changes: 0 additions & 57 deletions app/stores/lambda.js

This file was deleted.

5 changes: 1 addition & 4 deletions app/stores/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ export const useViewerStore = defineStore(
const base_url = computed(() => {
let viewer_url = `${protocol.value}://${infraStore.domain_name}:${port.value}`;
if (infraStore.app_mode === appMode.CLOUD) {
if (infraStore.ID === "") {
throw new Error("ID must not be empty in cloud mode");
}
viewer_url += `/${infraStore.ID}/viewer`;
viewer_url += `/viewer`;
}
viewer_url += "/ws";
return viewer_url;
Expand Down
24 changes: 0 additions & 24 deletions app/utils/recaptcha.js

This file was deleted.

3 changes: 1 addition & 2 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ const __dirname = import.meta.dirname;
export default defineNuxtConfig({
runtimeConfig: {
public: {
API_URL: "api.geode-solutions.com",
COMMAND_BACK: "opengeodeweb-back",
COMMAND_VIEWER: "opengeodeweb-viewer",
NUXT_ROOT_PATH: __dirname,
MODE: process.env.MODE || "CLOUD",
PROJECT: package_json.name,
SITE_BRANCH: process.env.NODE_ENV === "production" ? process.env.SITE_BRANCH : "",
},
},

Expand All @@ -27,6 +25,7 @@ export default defineNuxtConfig({
alias: {
"@ogw_front": path.resolve(__dirname, "app"),
"@ogw_internal": path.resolve(__dirname, "internal"),
"@ogw_server": path.resolve(__dirname, "server"),
"@ogw_tests": path.resolve(__dirname, "tests"),
},

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"dependencies": {
"@geode/opengeodeweb-back": "0.0.0",
"@geode/opengeodeweb-viewer": "0.0.0",
"@google-cloud/run": "3.2.0",
"@kitware/vtk.js": "33.3.0",
"@mdi/font": "7.4.47",
"@pinia/nuxt": "0.11.3",
Expand All @@ -48,6 +49,8 @@
"conf": "15.1.0",
"dexie": "4.2.1",
"get-port-please": "3.2.0",
"google-auth-library": "10.6.1",
"googleapis": "171.4.0",
"js-file-download": "0.4.12",
"jszip": "3.10.1",
"node-stream-zip": "1.15.0",
Expand Down
Loading
Loading