1- import { defineStore } from 'pinia'
21import { useStorage } from '@vueuse/core'
32
43export const use_cloud_store = defineStore ( 'cloud' , {
54 state : ( ) => ( {
65 ID : useStorage ( 'ID' , '' ) ,
76 is_captcha_validated : false ,
8- is_cloud_running : false ,
97 is_connexion_launched : false ,
10- request_counter : 0
118 } ) ,
129 getters : {
13- geode_url : ( state ) => {
14- const public_runtime_config = useRuntimeConfig ( ) . public
15- var geode_url = `${ public_runtime_config . GEODE_PROTOCOL } ://${ public_runtime_config . API_URL } :${ public_runtime_config . GEODE_PORT } `
16- if ( process . env . NODE_ENV == 'production' ) {
17- geode_url = geode_url + `/${ state . ID } /geode`
18- }
19- return geode_url
20- } ,
21- viewer_url : ( state ) => {
22- const public_runtime_config = useRuntimeConfig ( ) . public
23- var viewer_url = `${ public_runtime_config . VIEWER_PROTOCOL } ://${ public_runtime_config . API_URL } :${ public_runtime_config . VIEWER_PORT } `
24- if ( process . env . NODE_ENV == 'production' ) {
25- viewer_url = viewer_url + `/${ state . ID } /viewer`
26- }
27- viewer_url = viewer_url + '/ws'
28- return viewer_url
10+ is_running : ( ) => {
11+ return use_geode_store ( ) . is_running && use_websocket_store ( ) . is_running
2912 } ,
13+ is_busy : ( ) => {
14+ return use_geode_store ( ) . is_busy || use_websocket_store ( ) . is_busy
15+ }
16+
3017 } ,
3118 actions : {
3219 async create_connexion ( ) {
20+ const geode_store = use_geode_store ( )
3321 if ( this . is_connexion_launched ) { return }
3422 this . is_connexion_launched = true
3523 if ( this . ID === '' || this . ID === null || typeof this . ID === 'undefined' ) {
@@ -38,50 +26,28 @@ export const use_cloud_store = defineStore('cloud', {
3826 const { data, error } = await useFetch ( `${ this . geode_url } /ping` , { method : 'POST' } )
3927 console . log ( "error" , error )
4028 if ( data . value !== null ) {
41- this . is_cloud_running = true
42- return this . ping_task ( )
29+ geode_store . is_running = true
30+ return geode_store . ping_task ( )
4331 } else {
4432 return this . create_backend ( )
4533 }
4634 }
4735 } ,
4836 async create_backend ( ) {
37+ const geode_store = use_geode_store ( )
4938 const errors_store = use_errors_store ( )
5039 const config = useRuntimeConfig ( )
5140 const public_runtime_config = config . public
5241 const { data, error } = await useFetch ( `${ public_runtime_config . GEODE_PROTOCOL } ://${ public_runtime_config . API_URL } :${ public_runtime_config . GEODE_PORT } ${ public_runtime_config . SITE_BRANCH } /${ public_runtime_config . PROJECT } /createbackend` , { method : 'POST' } )
5342 if ( data . value !== null ) {
5443 this . ID = data . value . ID
5544 localStorage . setItem ( 'ID' , data . value . ID )
56- this . is_cloud_running = true
57- return this . ping_task ( )
45+ geode_store . is_running = true
46+ return geode_store . ping_task ( )
5847 } else {
5948 console . log ( "error : " , error )
6049 errors_store . server_error = true
6150 }
6251 } ,
63-
64- ping_task ( ) {
65- setInterval ( ( ) => this . do_ping ( ) , 10 * 1000 )
66- } ,
67- async do_ping ( ) {
68- const errors_store = use_errors_store ( )
69- const { data, error } = await useFetch ( `${ this . geode_url } /ping` , { method : 'POST' } )
70- if ( data . value !== null ) {
71- this . is_cloud_running = true
72- } else {
73- errors_store . server_error = true
74- console . log ( "error : " , error )
75- }
76- } ,
77-
78- mutations : {
79- start_request ( state ) {
80- state . request_counter ++
81- } ,
82- stop_request ( state ) {
83- state . request_counter --
84- }
85- }
8652 }
8753} )
0 commit comments