1+ const LINE_BREAK = " " ;
2+
3+ async function updateConsoleIfNeeded ( ) {
4+ let serverGuid = localStorage . getItem ( "activeServerGuid" ) ;
5+
6+ if ( serverGuid == null ) {
7+ return ;
8+ }
9+
10+ let lines = $ ( '#serverConsole' ) . val ( ) . split ( '\n' ) ;
11+ let length = lines . length - 1 ;
12+
13+ let secondLastLine = lines [ length - 1 ] ;
14+ let lastLine = lines [ length ] ;
15+
16+ await axios . post ( `/api/server/console/outdated` , { "Guid" : serverGuid , "SecondLastLine" : secondLastLine , "LastLine" : lastLine } , {
17+ headers : { "Authorization" : `Bearer ${ token } ` }
18+
19+ } ) . then ( ( response ) => {
20+
21+ if ( response . data ) {
22+ loadConsole ( serverGuid )
23+ }
24+ }
25+ ) . catch ( ( err ) => console . error ( err ) )
26+ }
27+
128async function loadConsole ( serverGuid ) {
2- $ ( "#serverConsole" ) . text ( "" ) ;
29+ clearConsole ( ) ;
330
431 await axios . post ( `/api/server/console` , { "Guid" : serverGuid , "AmountOfLines" : 50 , "Reversed" : false } , {
532 headers : { "Authorization" : `Bearer ${ token } ` }
633
734 } ) . then ( ( response ) => {
835
936 response . data . forEach ( line => {
10- $ ( "#serverConsole" ) . append ( line + " " ) ;
37+ $ ( "#serverConsole" ) . append ( LINE_BREAK + line ) ;
1138 } ) ;
1239 scrollToBottom ( ) ;
1340 }
@@ -31,6 +58,10 @@ async function sendCommand(serverGuid) {
3158 loadConsole ( serverGuid ) ;
3259}
3360
61+ function clearConsole ( ) {
62+ $ ( "#serverConsole" ) . text ( "" ) ;
63+ }
64+
3465function scrollToBottom ( ) {
3566 $ ( "#serverConsole" ) . scrollTop ( $ ( "#serverConsole" ) [ 0 ] . scrollHeight ) ;
3667}
0 commit comments