|
|
@ -1,9 +1,8 @@ |
|
|
|
<template> |
|
|
|
|
|
|
|
<span |
|
|
|
v-if="!store.tasks.isActive || store.tasks.getActiveSlug === this.taskSlug" |
|
|
|
class="text-white lg:text-sm mr-2 ml-2 mt-1.5 text-xs"> |
|
|
|
|
|
|
|
v-if="(!store.tasks.isActive || store.tasks.getActiveSlug === this.taskSlug) && !this.isSingle" |
|
|
|
class="mt-0.5 inline"> |
|
|
|
<span class="text-white lg:text-sm mr-2 ml-2 mt-1 text-xs"> |
|
|
|
<span v-if="!store.tasks.isProcessing(this.taskSlug)">Checked {{ sinceLast }} ago</span> |
|
|
|
<span v-if="store.tasks.isProcessing(this.taskSlug)" class="italic lg:pr-9"> |
|
|
|
<svg class="animate-spin mr-1 -mt-0.5 h-4 w-5 text-white inline" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"> |
|
|
@ -13,8 +12,8 @@ |
|
|
|
{{ this.store.tasks.getProcessed(this.taskSlug).length }}/{{ this.relays.length }} Relays Checked |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
<span class="text-white text-sm mr-2 mt-1.5" v-if="!store.tasks.isProcessing(this.taskSlug)">-</span> |
|
|
|
<span class="text-white text-sm mr-2 mt-1.5" v-if="store.prefs.refresh && !store.tasks.isProcessing(this.taskSlug)"> |
|
|
|
<span class="text-white lg:text-sm mr-2 ml-2 text-xs" v-if="!store.tasks.isProcessing(this.taskSlug)">-</span> |
|
|
|
<span class="text-white lg:text-sm mr-2 ml-2 text-xs" v-if="store.prefs.refresh && !store.tasks.isProcessing(this.taskSlug)"> |
|
|
|
Next check in: {{ untilNext }} |
|
|
|
</span> |
|
|
|
<button |
|
|
@ -24,6 +23,14 @@ |
|
|
|
@click="refreshNow()"> |
|
|
|
Check{{ relay ? ` ${relay}` : "" }} Now |
|
|
|
</button> |
|
|
|
</span> |
|
|
|
|
|
|
|
<span |
|
|
|
v-if="(store.tasks.getActiveSlug === this.taskSlug) && this.isSingle" |
|
|
|
class="text-white lg:text-sm mr-2 ml-2 mt-1.5 text-xs"> |
|
|
|
Loading {{ relayFromUrl }} |
|
|
|
</span> |
|
|
|
|
|
|
|
</template> |
|
|
|
|
|
|
|
<style scoped> |
|
|
@ -35,11 +42,9 @@ import { defineComponent, toRefs } from 'vue' |
|
|
|
|
|
|
|
import { setupStore } from '@/store' |
|
|
|
import RelaysLib from '@/shared/relays-lib.js' |
|
|
|
// import History from '@/shared/history.js' |
|
|
|
import SharedComputed from '@/shared/computed.js' |
|
|
|
|
|
|
|
import { Inspector } from 'nostr-relay-inspector' |
|
|
|
// import sizeof from 'object-sizeof' |
|
|
|
|
|
|
|
import { relays } from '../../../../relays.yaml' |
|
|
|
import { geo } from '../../../../cache/geo.yaml' |
|
|
@ -107,11 +112,9 @@ const localMethods = { |
|
|
|
}, |
|
|
|
|
|
|
|
invalidate: async function(force, single){ |
|
|
|
// console.log('expired', !this.store.tasks.getLastUpdate(this.taskSlug), Date.now() - this.store.tasks.getLastUpdate(this.taskSlug) > this.store.prefs.expireAfter) |
|
|
|
if( (!this.isExpired(this.taskSlug) && !force) ) |
|
|
|
return |
|
|
|
|
|
|
|
// console.log('windowActive', this.windowActive) |
|
|
|
if(!this.windowActive) |
|
|
|
return |
|
|
|
|
|
|
@ -123,6 +126,8 @@ const localMethods = { |
|
|
|
|
|
|
|
if(single) { |
|
|
|
await this.check(single) |
|
|
|
.then((result) => this.completeRelay(single, result) ) |
|
|
|
.catch( () => this.completeRelay(single) ) |
|
|
|
} |
|
|
|
else { |
|
|
|
for(let index = 0; index < relays.length; index++) { |
|
|
@ -130,16 +135,11 @@ const localMethods = { |
|
|
|
const relay = relays[index] |
|
|
|
this.check(relay) |
|
|
|
.then((result) => this.completeRelay(relay, result) ) |
|
|
|
// .then( async () => { |
|
|
|
// // this.history = await History() |
|
|
|
// }) |
|
|
|
.catch( () => this.completeRelay(relay) ) |
|
|
|
.catch( () => this.completeRelay(relay) ) //wait, what? TODO: fix |
|
|
|
} |
|
|
|
} |
|
|
|
}, true) |
|
|
|
|
|
|
|
// console.log('queue', this.store.tasks.getActive) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
completeRelay: function(relay, result){ |
|
|
@ -152,20 +152,18 @@ const localMethods = { |
|
|
|
this.results[relay] = result |
|
|
|
this.setCache(result) |
|
|
|
} |
|
|
|
|
|
|
|
if(this.store.tasks.getProcessed(this.taskSlug).length >= this.relays.length) |
|
|
|
if(this.isSingle) |
|
|
|
this.completeAll() |
|
|
|
else if(this.store.tasks.getProcessed(this.taskSlug).length >= this.relays.length) |
|
|
|
this.completeAll() |
|
|
|
}, |
|
|
|
|
|
|
|
completeAll: function(){ |
|
|
|
//console.log('completed') |
|
|
|
this.store.tasks.completeJob() |
|
|
|
// this.store.tasks.finishProcessing(this.taskSlug) |
|
|
|
this.store.tasks.updateNow(this.taskSlug) |
|
|
|
this.store.relays.setAggregateCache('public', Object.keys(this.results).filter( result => this.results[result].aggregate === 'public' )) |
|
|
|
this.store.relays.setAggregateCache('restricted', Object.keys(this.results).filter( result => this.results[result].aggregate === 'restricted' )) |
|
|
|
this.store.relays.setAggregateCache('offline', Object.keys(this.results).filter( result => this.results[result].aggregate === 'offline' )) |
|
|
|
//console.log('all are complete?', !this.store.tasks.isProcessing) |
|
|
|
this.setAverageLatency() |
|
|
|
}, |
|
|
|
|
|
|
@ -195,15 +193,6 @@ const localMethods = { |
|
|
|
resolve(instance.result) |
|
|
|
}) |
|
|
|
.run() |
|
|
|
// .on('close', () => { |
|
|
|
// //console.log(`${relay.url} has closed`) |
|
|
|
// // reject() |
|
|
|
// }) |
|
|
|
// .on('error', () => { |
|
|
|
// // console.log(result) |
|
|
|
// // reject() |
|
|
|
// }) |
|
|
|
|
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
@ -231,8 +220,11 @@ const localMethods = { |
|
|
|
} |
|
|
|
|
|
|
|
export default defineComponent({ |
|
|
|
|
|
|
|
name: 'RefreshComponent', |
|
|
|
|
|
|
|
components: {}, |
|
|
|
|
|
|
|
setup(props){ |
|
|
|
const {resultsProp: results} = toRefs(props) |
|
|
|
return { |
|
|
@ -240,6 +232,7 @@ export default defineComponent({ |
|
|
|
results: results |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
data() { |
|
|
|
return { |
|
|
|
relay: "", |
|
|
@ -256,26 +249,16 @@ export default defineComponent({ |
|
|
|
// history: null |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
created(){ |
|
|
|
clearInterval(this.interval) |
|
|
|
// document.addEventListener("visibilitychange", () => { |
|
|
|
// if(document.visibilityState == 'visible') |
|
|
|
// this.store.layout.setActiveTab(this.$tabid) |
|
|
|
// // if |
|
|
|
|
|
|
|
// // document.title = document.hidden ? "I'm away" : "I'm here"; |
|
|
|
// }); |
|
|
|
document.body.onfocus = () => { |
|
|
|
// alert('tab focused') |
|
|
|
//console.log(`tab #${this.$tabId} is active`) |
|
|
|
|
|
|
|
} |
|
|
|
document.addEventListener('visibilitychange', this.handleVisibility, false) |
|
|
|
}, |
|
|
|
|
|
|
|
unmounted(){ |
|
|
|
clearInterval(this.interval) |
|
|
|
// document.removeEventListener("visibilitychange", this.handleVisibility, false); |
|
|
|
}, |
|
|
|
|
|
|
|
beforeMount(){ |
|
|
|
this.lastUpdate = this.store.tasks.getLastUpdate(this.taskSlug) |
|
|
|
this.untilNext = this.timeUntilRefresh() |
|
|
@ -285,35 +268,39 @@ export default defineComponent({ |
|
|
|
this.store.relays.setRelays(relays) |
|
|
|
this.store.relays.setGeo(geo) |
|
|
|
|
|
|
|
//console.log('total relays', this.relays, this.relays.length) |
|
|
|
|
|
|
|
for(let ri=0;ri-this.relays.length;ri++){ |
|
|
|
const relay = this.relays[ri], |
|
|
|
cache = this.getCache(relay) |
|
|
|
this.results[relay] = cache |
|
|
|
// //console.log('result', 'from result', this.results[relay], 'from cache', cache) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
mounted(){ |
|
|
|
this.migrateLegacy() |
|
|
|
|
|
|
|
// console.log('is processing', this.store.tasks.isProcessing(this.taskSlug)) |
|
|
|
|
|
|
|
if( this.isSingle ){ |
|
|
|
this.taskSlug = 'relays/single' |
|
|
|
this.invalidate(true, this.relayFromUrl) |
|
|
|
} else { |
|
|
|
if(this.store.tasks.isProcessing(this.taskSlug)) |
|
|
|
this.invalidate(true) |
|
|
|
else |
|
|
|
this.invalidate() |
|
|
|
|
|
|
|
} |
|
|
|
this.setRefreshInterval() |
|
|
|
}, |
|
|
|
|
|
|
|
updated(){}, |
|
|
|
|
|
|
|
computed: Object.assign(SharedComputed, { |
|
|
|
getDynamicTimeout: function(){ |
|
|
|
const calculated = this.averageLatency*this.relays.length |
|
|
|
return calculated > 10000 ? calculated : 10000 |
|
|
|
}, |
|
|
|
}), |
|
|
|
|
|
|
|
methods: Object.assign(localMethods, RelaysLib), |
|
|
|
|
|
|
|
props: { |
|
|
|
resultsProp: { |
|
|
|
type: Object, |
|
|
@ -322,6 +309,7 @@ export default defineComponent({ |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
}) |
|
|
|
</script> |
|
|
|
|
|
|
|