1
+ /* Copyright (C) 2021-2025 sirpdboy herboy2008@gmail.com https://github.com/sirpdboy/luci-app-netspeedtest */
1
2
'use strict' ;
2
3
'require view' ;
3
4
'require poll' ;
@@ -17,7 +18,7 @@ return view.extend({
17
18
// handleSaveApply: null,
18
19
// handleSave: null,
19
20
// handleReset: null,
20
- load : function ( ) {
21
+ load ( ) {
21
22
return Promise . all ( [
22
23
L . resolveDefault ( fs . stat ( SpeedtestCli ) , { } ) ,
23
24
L . resolveDefault ( fs . read ( ResultFile ) , null ) ,
@@ -26,76 +27,94 @@ return view.extend({
26
27
] ) ;
27
28
} ,
28
29
29
- poll_status : function ( nodes , res ) {
30
- var has_ookla = res [ 0 ] . path ,
30
+ poll_status ( nodes , res ) {
31
+ var has_ookla = res [ 0 ] . path ,
31
32
result_content = res [ 1 ] ? res [ 1 ] . trim ( ) . split ( "\n" ) : [ ] ;
32
- var ookla_stat = nodes . querySelector ( '#ookla_status' ) ,
33
+ var ookla_stat = nodes . querySelector ( '#ookla_status' ) ,
33
34
result_stat = nodes . querySelector ( '#speedtest_result' ) ;
34
35
35
- // Update status indicators
36
- ookla_stat . style . color = has_ookla ? 'green' : 'red' ;
37
- dom . content ( ookla_stat , [ _ ( has_ookla ? 'Installed' : 'Not Installed' ) ] ) ;
38
-
39
- // Update result display
40
- if ( result_content . length ) {
41
- if ( result_content [ 0 ] == 'Testing' ) {
42
- result_stat . innerHTML = "<span style='color:green;font-weight:bold'>" +
43
- "<img src='/luci-static/resources/icons/loading.gif' height='17' style='vertical-align:middle'/> " +
44
- _ ( 'Testing in progress...' ) +
45
- "</span>" ;
46
- } else if ( result_content [ 0 ] . match ( / h t t p s ? : \S + / ) ) {
47
- result_stat . innerHTML = "<div style='max-width:500px'><a href='" +
48
- result_content [ 0 ] + "' target='_blank'><img src='" +
49
- result_content [ 0 ] + '.png' + "' style='max-width:100%'></a></div>" ;
50
- } else if ( result_content [ 0 ] == 'Test failed' ) {
51
- result_stat . innerHTML = "<span style='color:red;font-weight:bold'>" +
52
- _ ( 'Test failed.' ) + "</span>" ;
53
- }
54
- } else {
55
- result_stat . innerHTML = "<span style='color:gray'>" +
56
- _ ( 'No test results yet.' ) + "</span>" ;
36
+ // 获取版本号(新增部分)
37
+ var version_info = '' ;
38
+ if ( has_ookla ) {
39
+ fs . exec_direct ( '/usr/bin/speedtest' , [ '--version' ] )
40
+ . then ( function ( res ) {
41
+ if ( res . stdout ) {
42
+ var version_match = res . stdout . match ( / S p e e d t e s t ( \d + \. \d + \. \d + ) / ) ;
43
+ if ( version_match ) {
44
+ version_info = ' ver:' + version_match [ 1 ] ;
45
+ }
46
+ }
47
+ // 更新状态显示(包含版本号)
48
+ ookla_stat . style . color = 'green' ;
49
+ dom . content ( ookla_stat , [ _ ( has_ookla ? 'Installed' + version_info : 'Not Installed' ) ] ) ;
50
+ } )
51
+ . catch ( function ( ) {
52
+ // 如果获取版本失败,仍显示基本状态
53
+ ookla_stat . style . color = has_ookla ? 'green' : 'red' ;
54
+ dom . content ( ookla_stat , [ _ ( has_ookla ? 'Installed' : 'Not Installed' ) ] ) ;
55
+ } ) ;
56
+ } else {
57
+ // 未安装时的显示保持不变
58
+ ookla_stat . style . color = 'red' ;
59
+ dom . content ( ookla_stat , [ _ ( 'Not Installed' ) ] ) ;
60
+ }
61
+ if ( result_content . length ) {
62
+ if ( result_content [ 0 ] == 'Testing' ) {
63
+ result_stat . innerHTML = "<span style='color:green;font-weight:bold'>" +
64
+ "<img src='/luci-static/resources/icons/loading.gif' height='17' style='vertical-align:middle ;margin-left:20px'/> " +
65
+ _ ( 'SpeedTesting in progress...' ) +
66
+ "</span>" ;
67
+ } else if ( result_content [ 0 ] . match ( / h t t p s ? : \S + / ) ) {
68
+ result_stat . innerHTML = "<div style='max-width:500px'><a href='" +
69
+ result_content [ 0 ] + "' target='_blank'><img src='" +
70
+ result_content [ 0 ] + '.png' + "' style='max-width:100%;margin-left:20px'></a></div>" ;
71
+ } else if ( result_content [ 0 ] == 'Test failed' ) {
72
+ result_stat . innerHTML = "<span style='color:red;font-weight:bold;margin-left:20px'>" +
73
+ _ ( 'Test failed.' ) + "</span>" ;
57
74
}
58
- } ,
75
+ } else {
76
+ result_stat . innerHTML = "<span style='color:gray;margin-left:20px'>" +
77
+ _ ( 'No test results yet.' ) + "</span>" ;
78
+ }
79
+ } ,
59
80
60
- render : function ( res ) {
81
+ render ( res ) {
61
82
var has_ookla = res [ 0 ] . path ,
62
83
result_content = res [ 1 ] ? res [ 1 ] . trim ( ) . split ( "\n" ) : [ ] ,
63
84
result_mtime = res [ 2 ] ? res [ 2 ] . mtime * 1000 : 0 ,
64
85
date = new Date ( ) ;
65
86
66
87
var m , s , o ;
67
- m = new form . Map ( 'netspeedtest' , _ ( 'WAN Ookla SpeedTest' ) ) ;
88
+ m = new form . Map ( 'netspeedtest' , _ ( 'Wan Ookla SpeedTest' ) ) ;
68
89
69
90
// Result display section
70
91
s = m . section ( form . TypedSection , '_result' ) ;
71
92
s . anonymous = true ;
72
- s . render = function ( ) {
73
- var content ;
74
- if ( result_content . length ) {
75
- if ( result_content [ 0 ] == 'Testing' ) {
76
- content = E ( 'span' , { style : 'color:green;font-weight:bold' } , [
77
- E ( 'img' , { src : '/luci-static/resources/icons/loading.gif' , height : '20' } ) ,
78
- ' ' , _ ( 'Testing in progress...' )
79
- ] ) ;
80
- } else if ( result_content [ 0 ] . match ( / h t t p s ? : \S + / ) ) {
81
- content = E ( 'div' , { style : 'max-width:500px' } , [
82
- E ( 'a' , { href : result_content [ 0 ] , target : '_blank' } , [
83
- E ( 'img' , { src : result_content [ 0 ] + '.png' , style : 'max-width:100%' } )
84
- ] )
85
- ] ) ;
86
- } else {
87
- content = E ( 'span' , { style : 'color:red;font-weight:bold' } ,
88
- _ ( 'Test failed.' ) ) ;
89
- }
90
- } else {
91
- content = E ( 'span' , { style : 'color:gray' } ,
92
- _ ( 'No test results yet.' ) ) ;
93
- }
94
- return E ( 'div' , { id : 'speedtest_result' } , content ) ;
95
- } ;
93
+ s . render = function ( section_id ) {
94
+ if ( result_content . length ) {
95
+ if ( result_content [ 0 ] == 'Testing' ) {
96
+ return E ( 'div' , { 'id' : 'speedtest_result' } , [ E ( 'span' , { 'style' : 'color:yellow;font-weight:bold' } , [
97
+ E ( 'img' , { 'src' : L . resource ( [ 'icons/loading.gif' ] ) , 'height' : '20' , 'style' : 'vertical-align:middle' } , [ ] ) ,
98
+ _ ( 'Testing in progress...' )
99
+ ] ) ] )
100
+ } ;
101
+ if ( result_content [ 0 ] . match ( / h t t p s ? : \S + / ) ) {
102
+ return E ( 'div' , { 'id' : 'speedtest_result' } , [ E ( 'div' , { 'style' : 'max-width:500px' } , [
103
+ E ( 'a' , { 'href' : result_content [ 0 ] , 'target' : '_blank' } , [
104
+ E ( 'img' , { 'src' : result_content [ 0 ] + '.png' , 'style' : 'max-width:100%;max-height:100%;vertical-align:middle' } , [ ] )
105
+ ] ) ] ) ] )
106
+ } ;
107
+ if ( result_content [ 0 ] == 'Test failed' ) {
108
+ return E ( 'div' , { 'id' : 'speedtest_result' } , [ E ( 'span' , { 'style' : 'color:red;font-weight:bold' } , [ _ ( 'Test failed.' ) ] ) ] )
109
+ }
110
+ } else {
111
+ return E ( 'div' , { 'id' : 'speedtest_result' } , [ E ( 'span' , { 'style' : 'color:red;font-weight:bold;display:none' } , [ _ ( 'No result.' ) ] ) ] )
112
+ }
113
+ } ;
96
114
97
115
// Configuration section
98
116
s = m . section ( form . NamedSection , 'config' , 'netspeedtest' ) ;
117
+ s . anonymous = true ;
99
118
100
119
// Start test button
101
120
o = s . option ( form . Button , '_start' , _ ( 'Start Ookla SpeedTest' ) ) ;
0 commit comments