@@ -1497,14 +1497,15 @@ class SocketData {
14971497 this . $opened = false
14981498 this . $key = 1
14991499 this . $callback = { }
1500+ this . $creating = false
15001501 this . create_ws ( )
15011502 }
15021503 }
15031504 send_http ( namespace , data ) {
15041505 return new Promise ( async ( resolve , reject ) => {
15051506 const resp = await fetch ( `${ this . $url } ?namespace=${ encodeURIComponent ( namespace ) } ` , {
15061507 method : "POST" ,
1507- data : data
1508+ body : JSON . stringify ( data )
15081509 } )
15091510 var resp_data = [ null , null ]
15101511 if ( resp . ok ) {
@@ -1522,9 +1523,9 @@ class SocketData {
15221523 resolve ( resp_data )
15231524 } )
15241525 }
1525- create_ws ( ) {
1526+ async create_ws ( ) {
15261527 if ( ! this . $support ) throw "Unable to send websocket data."
1527- if ( this . $ws == null ) this . $ws = new WebSocketClient ( "ws" + ( this . $url . slice ( 4 ) ) , {
1528+ if ( this . $ws == null && ! this . $creating ) this . $ws = new WebSocketClient ( "ws" + ( this . $url . slice ( 4 ) ) , {
15281529 "onmessage" : ( msg ) => {
15291530 var data = JSON . parse ( msg . data )
15301531 this . recv (
@@ -1546,6 +1547,7 @@ class SocketData {
15461547 }
15471548 this . $cache = { }
15481549 window . dispatchEvent ( new Event ( "mainsocket_connect" ) )
1550+ this . $creating = false
15491551 } ,
15501552 "onclose" : ( ) => {
15511553 this . $opened = false
@@ -2394,14 +2396,16 @@ class Authentication {
23942396 this . _main = [ ]
23952397 this . _input = {
23962398 username : app . createElement ( "input" ) ,
2397- password : app . createElement ( "input" ) ,
2399+ password : app . createElement ( "input" ) . setAttribute ( "type" , "password" ) ,
23982400 captcha : {
23992401 image : app . createElement ( "img" ) ,
24002402 input : app . createElement ( "input" )
24012403 } ,
24022404 label : app . createElement ( "p" ) ,
2403- auth : app . createElement ( "button" ) . setI18N ( "dashboard.auth.login" ) ,
2404- forever : app . createElement ( "button" ) . setAttribute ( "type" , "checkbox" )
2405+ auth : app . createElement ( "button" ) . class ( "submit" ) . setI18N ( "dashboard.auth.login" ) . event ( "click" , async ( ) => {
2406+ await this . login ( "a" , "a" , false )
2407+ } ) ,
2408+ forever : app . createElement ( "input" ) . setAttribute ( "type" , "checkbox" )
24052409 }
24062410 this . _captcha = app . createElement ( "div" )
24072411 this . _container = app . createElement ( "div" ) . class ( "panel-auth" ) . append (
@@ -2410,7 +2414,10 @@ class Authentication {
24102414 this . _captcha ,
24112415 this . _input . label ,
24122416 this . _input . auth ,
2413- this . _input . forever ,
2417+ /*app.createElement("div").class("flex", "panel-auth-root").append(
2418+ app.createElement("span").setText("Forever"),
2419+ this._input.forever,
2420+ ),*/
24142421 )
24152422 this . _Styles = {
24162423 ".panel-auth" : `
@@ -2419,6 +2426,10 @@ class Authentication {
24192426 justify-content: center;
24202427 align-items: stretch;
24212428 ` ,
2429+ '.panel-auth-root' : [
2430+ 'margin: 8px' ,
2431+ 'padding: 8px'
2432+ ] ,
24222433 '.panel-auth input, .panel-auth button' : [
24232434 'margin: 4px' ,
24242435 'padding: 8px'
@@ -2443,7 +2454,7 @@ class Authentication {
24432454 margin: 0px;
24442455 color: var(--color);
24452456 -webkit-tap-highlight-color: transparent;
2446- width: 100 %;
2457+ width: 98 %;
24472458 padding: 8.5px 0px 8.5px 14px;`
24482459 ] ,
24492460 '.panel-auth .label-input label' : [
@@ -2481,14 +2492,13 @@ class Authentication {
24812492 border-width: 1px;
24822493 overflow: hidden;
24832494 color: var(--color);
2484- border-color: var(--shadow );`
2495+ border-color: var(--dark-color );`
24852496 ] ,
24862497 '.panel-auth .label-input:hover fieldset' : [
24872498 'border-color: var(--main-shadow)'
24882499 ] ,
24892500 '.panel-auth .label-input.active fieldset' : [
24902501 'border-color: var(--none-color-shadow)' ,
2491- 'border-width: 1.25px;'
24922502 ] ,
24932503 '.panel-auth .label-input legend' : [
24942504 `float: unset;
@@ -2516,6 +2526,27 @@ class Authentication {
25162526 `font-size: 0.75em;
25172527 visibility: visible;
25182528 white-space: nowrap;`
2529+ ] ,
2530+ '.panel-auth .submit' : [
2531+ `background-color: transparent;
2532+ border: none;
2533+ border-radius: 100px;
2534+ color: var(--color);
2535+ margin: 8px;
2536+ padding: 8px;
2537+ transition: background-color 0.3s ease, color 0.3s ease;
2538+ `
2539+ ] ,
2540+ '.panel-auth .submit::before' : [
2541+ `filter: blur(10px);`
2542+ ] ,
2543+ '.panel-auth .submit:hover' : [
2544+ `background-color: var(--main-shadow);
2545+ transition: background-color 0.3s ease, color 0.3s ease;`
2546+ ] ,
2547+ '.panel-auth .submit:active' : [
2548+ `background-color: var(--main-color);
2549+ transition: background-color 0.3s ease, color 0.3s ease;`
25192550 ]
25202551 }
25212552 this . refreshToken = $config . get ( "refreshToken" ) || null
@@ -2563,14 +2594,16 @@ class Authentication {
25632594 async login ( username , password , forever = false ) {
25642595 var [ err , ack ] = await $MainSocket . send ( "auth" , {
25652596 "username" : username ,
2566- "password" : atob ( password )
2567- } )
2597+ "password" : btoa ( password )
2598+ } , true )
25682599 if ( ack && ack . success ) {
25692600 this . username = ack . username
25702601 this . avatar = ack . avatar
25712602 this . token = ack . token
25722603 this . refreshToken = ack . refreshToken
2604+ return true
25732605 }
2606+ return false
25742607 }
25752608 open ( ) {
25762609 modal . title_i18n ( "dashboard.auth" ) . open ( ) . setConfirm ( false ) . body (
@@ -3796,9 +3829,7 @@ app.$Menu.add("dashboard", new class {
37963829 window . addEventListener ( "lang" , refresh )
37973830 await $MainSocket . send ( "status" , ( new Date ( ) . valueOf ( ) ) ) . then ( ( data ) => {
37983831 var [ err , ack ] = data
3799- var ping = ( new Date ( ) . valueOf ( ) ) - ack . timestamp || ack . time . current * 1000
3800- console . log ( ack )
3801- this . uptime = ack . uptime - ping / 1000 + ( ( new Date ( ) . valueOf ( ) ) - ack . time . current * 1000 ) / 1000
3832+ this . uptime = ack . uptime + ( ack . time . current - ( new Date ( ) . valueOf ( ) / 1000.0 ) )
38023833 this . status = ack
38033834 } )
38043835 await $MainSocket . send ( "statistics" , ( this . storages [ this . switch_storage . selected - 1 ] ) ) . then ( ( data ) => {
@@ -3817,7 +3848,7 @@ app.$Menu.add("dashboard", new class {
38173848 window . addEventListener ( "mainsocket_status" , ( data ) => {
38183849 var [ err , ack ] = data . detail
38193850 this . status = ack
3820- this . uptime = ack . uptime + ( ( new Date ( ) . valueOf ( ) ) - ack . time . current * 1000 ) / 1000
3851+ this . uptime = ack . uptime + ( ack . time . current - ( new Date ( ) . valueOf ( ) ) / 1000.0 )
38213852 this . setStatus ( )
38223853 } )
38233854 } else {
@@ -3826,7 +3857,7 @@ app.$Menu.add("dashboard", new class {
38263857 $MainSocket . send ( "status" , ( new Date ( ) . valueOf ( ) ) ) . then ( ( data ) => {
38273858 var [ err , ack ] = data
38283859 var ping = ( new Date ( ) . valueOf ( ) ) - ack . timestamp || ack . time . current * 1000
3829- this . uptime = ack . uptime - ping / 1000 + ( ( new Date ( ) . valueOf ( ) ) - ack . time . current * 1000 ) / 1000
3860+ this . uptime = ack . uptime + ( ack . time . current - ( new Date ( ) . valueOf ( ) ) / 1000.0 )
38303861 this . status = ack
38313862 this . setStatus ( )
38323863 } )
@@ -3835,6 +3866,13 @@ app.$Menu.add("dashboard", new class {
38353866 window . addEventListener ( "mainsocket_disconnect" , ( data ) => {
38363867 this . uptime = null
38373868 } )
3869+ window . addEventListener ( "mainsocket_connect" , ( ) => {
3870+ $MainSocket . send ( "status" , ( new Date ( ) . valueOf ( ) ) ) . then ( ( data ) => {
3871+ var [ err , ack ] = data
3872+ this . uptime = ack . uptime + ( ack . time . current - ( new Date ( ) . valueOf ( ) / 1000.0 ) )
3873+ this . status = ack
3874+ } )
3875+ } )
38383876 this . initBasic ( )
38393877 this . switch . select ( 0 )
38403878 }
0 commit comments