versione 1.2.14 :
- aggiornati i file di configurazione, ENV e script non funzionanti., package. - corretto custom-service-worker.js con CORS - ottimizzato il server, la chiamata Load iniziale (senza promise, con async/await).
This commit is contained in:
@@ -117,12 +117,14 @@ async function Request(type: string, path: string, payload: any, responsedata?:
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const baseURL = globalStore.getServerHost()
|
||||
|
||||
|
||||
try {
|
||||
if (tools.isDebug()) console.log('Axios Request', path, type, tools.notshowPwd(payload))
|
||||
let response: AxiosResponse
|
||||
const config: AxiosRequestConfig = {
|
||||
baseURL: globalStore.getServerHost(),
|
||||
baseURL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-auth': userStore.x_auth_token,
|
||||
@@ -216,7 +218,7 @@ async function Request(type: string, path: string, payload: any, responsedata?:
|
||||
} else if (type === 'get' || type === 'delete') {
|
||||
// @ts-ignore
|
||||
response = await axiosInstance[type](path, {
|
||||
baseURL: globalStore.getServerHost(),
|
||||
baseURL,
|
||||
params: payload,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -230,7 +232,7 @@ async function Request(type: string, path: string, payload: any, responsedata?:
|
||||
} else if (type === 'postFormData') {
|
||||
console.log('postFormData', payload)
|
||||
response = await axiosInstance.post(path, payload, {
|
||||
baseURL: globalStore.getServerHost(),
|
||||
baseURL,
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
'x-auth': userStore.x_auth_token,
|
||||
|
||||
@@ -111,24 +111,26 @@ async function sendSwMsgIfAvailable() {
|
||||
|
||||
const count = await checkPendingMsg()
|
||||
if (count) {
|
||||
return navigator.serviceWorker.ready
|
||||
.then(() => globalroutines('readall', 'swmsg')
|
||||
.then((arr_recmsg) => {
|
||||
if (arr_recmsg.length > 0) {
|
||||
console.log('---------------------- 2) navigator (2) .serviceWorker.ready')
|
||||
let promiseChain = Promise.resolve()
|
||||
if (useServiceWorker()) {
|
||||
return navigator.serviceWorker.ready
|
||||
.then(() => globalroutines('readall', 'swmsg')
|
||||
.then((arr_recmsg) => {
|
||||
if (arr_recmsg.length > 0) {
|
||||
console.log('---------------------- 2) navigator (2) .serviceWorker.ready')
|
||||
let promiseChain = Promise.resolve()
|
||||
|
||||
for (const rec of arr_recmsg) {
|
||||
// #Alternative to SyncManager
|
||||
promiseChain = promiseChain.then(() => Api.syncAlternative(rec._id)
|
||||
.then(() => {
|
||||
//++Todo conv: something = true
|
||||
}))
|
||||
for (const rec of arr_recmsg) {
|
||||
// #Alternative to SyncManager
|
||||
promiseChain = promiseChain.then(() => Api.syncAlternative(rec._id)
|
||||
.then(() => {
|
||||
//++Todo conv: something = true
|
||||
}))
|
||||
}
|
||||
return promiseChain
|
||||
}
|
||||
return promiseChain
|
||||
}
|
||||
return null
|
||||
}))
|
||||
return null
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5406,7 +5406,7 @@ export const tools = {
|
||||
isVerified(): boolean {
|
||||
const globalStore = useGlobalStore()
|
||||
const site = globalStore.site
|
||||
if (site.confpages.enableRegMultiChoice) {
|
||||
if (site.confpages?.enableRegMultiChoice) {
|
||||
return this.TelegVerificato() || this.isEmailVerified()
|
||||
}
|
||||
|
||||
@@ -5441,7 +5441,7 @@ export const tools = {
|
||||
getLinkUserTelegramByUser(userprofile: IUserFields) {
|
||||
|
||||
if (userprofile) {
|
||||
if (userprofile.profile.username_telegram) {
|
||||
if (userprofile.profile?.username_telegram) {
|
||||
return 'https://t.me/' + userprofile.profile.username_telegram
|
||||
}
|
||||
} else {
|
||||
@@ -7960,7 +7960,11 @@ export const tools = {
|
||||
return config[name]*/
|
||||
|
||||
try {
|
||||
return name ? import.meta.env[name] : ''
|
||||
let myenv = name ? import.meta.env[name] : ''
|
||||
|
||||
// console.log('--- ENV: ', name, myenv)
|
||||
|
||||
return myenv
|
||||
} catch (e) {
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -721,11 +721,11 @@ export const useUserStore = defineStore('UserStore', {
|
||||
isUserOk(): boolean {
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
if (globalStore.site.confpages && globalStore.site.confpages.enableRegMultiChoice) {
|
||||
if (globalStore.site.confpages && globalStore.site.confpages?.enableRegMultiChoice) {
|
||||
return ((this.isTelegIdOk() && this.isUsernameTelegOk()) || this.my.verified_email!) && this.my.verified_by_aportador!
|
||||
} else {
|
||||
//if (tools.getAskToVerifyReg()) {
|
||||
if (globalStore.site.confpages && globalStore.site.confpages.enabledRegNeedTelegram) {
|
||||
if (globalStore.site.confpages && globalStore.site.confpages?.enabledRegNeedTelegram) {
|
||||
return this.isTelegIdOk() && this.my.verified_by_aportador! && this.isUsernameTelegOk()
|
||||
} else {
|
||||
return this.my.verified_email!
|
||||
@@ -735,7 +735,7 @@ export const useUserStore = defineStore('UserStore', {
|
||||
},
|
||||
|
||||
isUserWaitingVerifAportador(): boolean {
|
||||
return tools.isLogged() && !this.my.verified_by_aportador
|
||||
return tools.isLogged() && !this.my.verified_by_aportador && this.getAportadorSolidario()
|
||||
},
|
||||
|
||||
isOldRegNotFinished(): boolean {
|
||||
@@ -1557,7 +1557,7 @@ export const useUserStore = defineStore('UserStore', {
|
||||
if (globalStore.site.confpages && globalStore.site.confpages.enableTodos)
|
||||
await todos.dbLoad({ checkPending: true })
|
||||
|
||||
if (globalStore.site.confpages.enableProj)
|
||||
if (globalStore.site.confpages?.enableProj)
|
||||
await projects.dbLoad({ checkPending: true, onlyiffirsttime: true })
|
||||
|
||||
globalStore.addDynamicPages(router)
|
||||
@@ -1599,7 +1599,7 @@ export const useUserStore = defineStore('UserStore', {
|
||||
|
||||
if (token) {
|
||||
this.setAuth(token, refreshToken)
|
||||
if (globalStore.site.confpages.enableTokenExpired) {
|
||||
if (globalStore.site.confpages?.enableTokenExpired) {
|
||||
if (token && refreshToken) {
|
||||
isLogged = true
|
||||
} else {
|
||||
@@ -2132,7 +2132,7 @@ export const useUserStore = defineStore('UserStore', {
|
||||
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
if (globalStore.site && (!globalStore.site.confpages.showCoins && !globalStore.site.confpages.showRIS)) {
|
||||
if (globalStore.site && (!globalStore.site.confpages?.showCoins && !globalStore.site.confpages?.showRIS)) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -864,36 +864,38 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
|
||||
let reg: any
|
||||
const mykey = import.meta.env.VITE_PUBLICKEY_PUSH
|
||||
return navigator.serviceWorker.ready
|
||||
.then((swreg) => {
|
||||
reg = swreg
|
||||
return swreg.pushManager.getSubscription()
|
||||
})
|
||||
.then((subscription) => {
|
||||
console.log('!!!!!!!! subscription = ', subscription)
|
||||
if (navigator.serviceWorker) {
|
||||
return navigator.serviceWorker.ready
|
||||
.then((swreg) => {
|
||||
reg = swreg
|
||||
return swreg.pushManager.getSubscription()
|
||||
})
|
||||
.then((subscription) => {
|
||||
console.log('!!!!!!!! subscription = ', subscription)
|
||||
|
||||
this.wasAlreadySubscribed = !(subscription === null)
|
||||
this.wasAlreadySubscribed = !(subscription === null)
|
||||
|
||||
if (this.wasAlreadySubscribed) {
|
||||
// console.log('User is already SAVED Subscribe on DB!')
|
||||
// return null
|
||||
return subscription
|
||||
} else {
|
||||
// Create a new subscription
|
||||
console.log('#### Create a new subscription !!!')
|
||||
const convertedVapidPublicKey = urlBase64ToUint8Array(mykey)
|
||||
return reg.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: convertedVapidPublicKey,
|
||||
})
|
||||
}
|
||||
})
|
||||
.then((newSub) => {
|
||||
this.saveNewSubscriptionToServer(newSub)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('ERR createPushSubscription:', err)
|
||||
})
|
||||
if (this.wasAlreadySubscribed) {
|
||||
// console.log('User is already SAVED Subscribe on DB!')
|
||||
// return null
|
||||
return subscription
|
||||
} else {
|
||||
// Create a new subscription
|
||||
console.log('#### Create a new subscription !!!')
|
||||
const convertedVapidPublicKey = urlBase64ToUint8Array(mykey)
|
||||
return reg.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: convertedVapidPublicKey,
|
||||
})
|
||||
}
|
||||
})
|
||||
.then((newSub) => {
|
||||
this.saveNewSubscriptionToServer(newSub)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('ERR createPushSubscription:', err)
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// Calling the Server to Save in the MongoDB the Subscriber
|
||||
@@ -985,23 +987,25 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
if ('serviceWorker' in navigator) {
|
||||
// REMOVE ALL SUBSCRIPTION
|
||||
console.log('REMOVE ALL SUBSCRIPTION...')
|
||||
navigator.serviceWorker.ready
|
||||
.then((reg) => {
|
||||
console.log('... Ready')
|
||||
reg.pushManager.getSubscription().then((subscription) => {
|
||||
console.log(' Found Subscription...')
|
||||
if (subscription) {
|
||||
subscription.unsubscribe().then((successful) => {
|
||||
// You've successfully unsubscribed
|
||||
console.log('You\'ve successfully unsubscribed')
|
||||
}).catch((e) => {
|
||||
// Unsubscription failed
|
||||
})
|
||||
}
|
||||
if (navigator.serviceWorker) {
|
||||
navigator.serviceWorker.ready
|
||||
.then((reg) => {
|
||||
console.log('... Ready')
|
||||
reg.pushManager.getSubscription().then((subscription) => {
|
||||
console.log(' Found Subscription...')
|
||||
if (subscription) {
|
||||
subscription.unsubscribe().then((successful) => {
|
||||
// You've successfully unsubscribed
|
||||
console.log('You\'ve successfully unsubscribed')
|
||||
}).catch((e) => {
|
||||
// Unsubscription failed
|
||||
})
|
||||
}
|
||||
})
|
||||
}).catch((err) => {
|
||||
console.error('err ready service worker', err)
|
||||
})
|
||||
}).catch((err) => {
|
||||
console.error('err ready service worker', err)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1838,8 +1842,17 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
// const isLogged = localStorage.getItem(toolsext.localStorage.username)
|
||||
// console.log('isLogged', isLogged)
|
||||
|
||||
let myidapp = ''
|
||||
try {
|
||||
if (res.data?.myuser) {
|
||||
myidapp = res.data?.myuser?.idapp
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
// calendarStore.editable = userStore.isAdmin || userStore.isManager || userStore.isFacilitatore
|
||||
if (res.data.myuser === null || (res.data.myuser.idapp !== tools.getEnv('VITE_APP_ID'))) {
|
||||
if (!myidapp || (myidapp !== tools.getEnv('VITE_APP_ID'))) {
|
||||
if (isLogged) {
|
||||
// Fai Logout
|
||||
// console.log('Fai Logout', 'isLogged', isLogged)
|
||||
|
||||
Reference in New Issue
Block a user