108 lines
3 KiB
TypeScript
108 lines
3 KiB
TypeScript
namespace $.$$ {
|
|
$hyoo_crus_yard.masters = [
|
|
$mol_dom_context.document.location.origin +'/',
|
|
]
|
|
|
|
export class $hd_canary_app_monitor extends $.$hd_canary_app_monitor {
|
|
|
|
status_total() {
|
|
return this.home().Sites(null)!.remote_list().every( key => key.last_ping_status()?.val() == true) ? "🟢" : "🔴"
|
|
}
|
|
|
|
target_status( prop: $hd_canary_app_home_site ) {
|
|
return prop.last_ping_status()?.val() ? "🟢" : "🔴"
|
|
}
|
|
target_title(prop: $hd_canary_app_home_site) {
|
|
return prop.title()!.val() as string
|
|
}
|
|
target_url(prop: $hd_canary_app_home_site) {
|
|
return prop.url()!.val() as string;
|
|
}
|
|
target_moment(prop: $hd_canary_app_home_site) {
|
|
return ((prop.last_ping_time()?.val() as $mol_time_moment) ?? "planed ping").toString('YYYY-MM-DD hh:mm:ss')// ?? prop.ref().description! as any
|
|
}
|
|
|
|
target_list() {
|
|
return this.home().Sites(null)!.remote_list().map( key => this.Target( key ) ) ?? []
|
|
}
|
|
|
|
is_valid_http_url(string: string) {
|
|
let url;
|
|
try {
|
|
url = new URL(string);
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
return url.protocol === "http:" || url.protocol === "https:";
|
|
}
|
|
|
|
add_submit() {
|
|
const url = this.add_url().trim()
|
|
if (url == "") throw "Empty url!"
|
|
if (this.is_valid_http_url(url) == false) throw "Not valid url!"
|
|
|
|
|
|
let title = this.add_title().trim()
|
|
if (title == "") title = url.replace(/(^https?:\/\/)|(\/+$)/g, '');
|
|
|
|
this.add_site(url, title)
|
|
|
|
this.add_url('');
|
|
this.add_title('');
|
|
}
|
|
|
|
@$mol_action
|
|
add_site(url: string, title: string) {
|
|
const new_site = this.home().Sites(null)!.make(null)
|
|
new_site.land().give(null, $hyoo_crus_rank_rule)
|
|
|
|
new_site.url(null)!.val(url)
|
|
new_site.title(null)!.val(title)
|
|
}
|
|
|
|
target_remove(prop: $hd_canary_app_home_site) {
|
|
const current = this.home().Sites(null)!.items_vary()
|
|
const new_list = current.filter(item => item != prop.ref())
|
|
this.home().Sites(null)!.items_vary(new_list)
|
|
}
|
|
|
|
// наш id клиента
|
|
my_key() {
|
|
return this.$.$hyoo_crus_auth.current().lord().description!
|
|
}
|
|
|
|
@ $mol_mem
|
|
users() {
|
|
const ref = $hyoo_crus_ref( this.$.$mol_fetch.text( '/join' ) )
|
|
return this.$.$hyoo_crus_glob.Node( ref, $hyoo_crus_dict )
|
|
}
|
|
|
|
@ $mol_mem
|
|
home() {
|
|
// берем свой уголок
|
|
const home = this.$.$hyoo_crus_glob.home( $hd_canary_app_home )
|
|
|
|
|
|
// проверяем есть ли он в базе
|
|
if (this.users().has(this.my_key()) == false) {
|
|
|
|
// даем серверу права на запись
|
|
const ref = $hyoo_crus_ref( this.$.$mol_fetch.text( '/ref' ) )
|
|
home.land().give(ref, $hyoo_crus_rank_post("just"))
|
|
|
|
// и заносим это в глобальную базу
|
|
this.users().dive(this.my_key(), $hyoo_crus_atom_vary, home.ref().description)
|
|
}
|
|
|
|
return home
|
|
}
|
|
|
|
@$mol_action
|
|
bulk_add(sites_input: string) {
|
|
const sites = sites_input.split(/\r?\n/).map( site => site.trim()).filter(site => site != "")
|
|
for (const site of sites) {
|
|
this.add_site(site, site.replace(/(^https?:\/\/)|(\/+$)/g, ''))
|
|
}
|
|
}
|
|
}
|
|
}
|