26
26
import cn .hutool .core .io .IoUtil ;
27
27
import cn .hutool .core .io .resource .ResourceUtil ;
28
28
import cn .hutool .core .lang .Tuple ;
29
+ import cn .hutool .core .util .BooleanUtil ;
29
30
import cn .hutool .core .util .StrUtil ;
30
31
import cn .hutool .core .util .URLUtil ;
31
32
import com .alibaba .fastjson2 .JSONObject ;
40
41
import io .jpom .permission .MethodFeature ;
41
42
import io .jpom .permission .SystemPermission ;
42
43
import io .jpom .service .dblog .BackupInfoService ;
44
+ import io .jpom .service .system .SystemParametersServer ;
43
45
import io .jpom .system .ServerConfig ;
44
46
import lombok .Lombok ;
47
+ import lombok .extern .slf4j .Slf4j ;
48
+ import org .springframework .context .ApplicationContext ;
45
49
import org .springframework .http .MediaType ;
46
50
import org .springframework .util .Assert ;
47
51
import org .springframework .web .bind .annotation .GetMapping ;
69
73
@ RequestMapping (value = "system" )
70
74
@ Feature (cls = ClassFeature .SYSTEM_UPGRADE )
71
75
@ SystemPermission (superUser = true )
72
- public class SystemUpdateController extends BaseServerController {
76
+ @ Slf4j
77
+ public class SystemUpdateController extends BaseServerController implements ILoadEvent {
78
+
79
+ private static final String JOIN_JPOM_BETA_RELEASE = "JOIN_JPOM_BETA_RELEASE" ;
73
80
74
81
private final BackupInfoService backupInfoService ;
75
82
private final ServerConfig serverConfig ;
83
+ private final SystemParametersServer systemParametersServer ;
76
84
77
85
public SystemUpdateController (BackupInfoService backupInfoService ,
78
- ServerConfig serverConfig ) {
86
+ ServerConfig serverConfig ,
87
+ SystemParametersServer systemParametersServer ) {
79
88
this .backupInfoService = backupInfoService ;
80
89
this .serverConfig = serverConfig ;
90
+ this .systemParametersServer = systemParametersServer ;
81
91
}
82
92
83
93
@ PostMapping (value = "info" , produces = MediaType .APPLICATION_JSON_VALUE )
@@ -91,10 +101,26 @@ public JsonMessage<JSONObject> info(HttpServletRequest request, String machineId
91
101
JSONObject jsonObject = new JSONObject ();
92
102
jsonObject .put ("manifest" , instance );
93
103
jsonObject .put ("remoteVersion" , remoteVersion );
104
+ jsonObject .put ("joinBetaRelease" , RemoteVersion .betaRelease ());
94
105
return JsonMessage .success ("" , jsonObject );
95
106
});
96
107
}
97
108
109
+ @ GetMapping (value = "change-beta-release" , produces = MediaType .APPLICATION_JSON_VALUE )
110
+ @ Feature (method = MethodFeature .LIST )
111
+ public JsonMessage <String > changeBetaRelease (String beta ) {
112
+ boolean betaBool = this .changeBetaRelease2 (beta );
113
+ RemoteVersion .loadRemoteInfo ();
114
+ return JsonMessage .success (betaBool ? "成功加入 beta 计划" : "关闭 beta 计划成功" );
115
+ }
116
+
117
+ private boolean changeBetaRelease2 (String beta ) {
118
+ boolean betaBool = BooleanUtil .toBoolean (beta );
119
+ systemParametersServer .upsert (JOIN_JPOM_BETA_RELEASE , String .valueOf (betaBool ), "是否加入 beta 计划" );
120
+ RemoteVersion .changeBetaRelease (String .valueOf (betaBool ));
121
+ return betaBool ;
122
+ }
123
+
98
124
/**
99
125
* 更新日志
100
126
*
@@ -213,4 +239,11 @@ public JsonMessage<String> upgrade(HttpServletRequest request,
213
239
return JsonMessage .success (Const .UPGRADE_MSG );
214
240
});
215
241
}
242
+
243
+ @ Override
244
+ public void afterPropertiesSet (ApplicationContext applicationContext ) throws Exception {
245
+ String config = systemParametersServer .getConfig (JOIN_JPOM_BETA_RELEASE , String .class );
246
+ boolean release2 = this .changeBetaRelease2 (config );
247
+ log .debug ("beta plan:{}" , release2 );
248
+ }
216
249
}
0 commit comments