51 行
1.9 KiB
Java
51 行
1.9 KiB
Java
|
|
package com.xuqm.tenant.controller;
|
|||
|
|
|
|||
|
|
import com.xuqm.tenant.config.PrivateDeploymentProperties;
|
|||
|
|
import com.xuqm.tenant.service.SystemUpdateService;
|
|||
|
|
import org.springframework.http.MediaType;
|
|||
|
|
import org.springframework.http.ResponseEntity;
|
|||
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|||
|
|
import org.springframework.web.bind.annotation.RestController;
|
|||
|
|
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
|||
|
|
|
|||
|
|
@RestController
|
|||
|
|
@RequestMapping("/api/system")
|
|||
|
|
public class SystemUpdateController {
|
|||
|
|
|
|||
|
|
private final PrivateDeploymentProperties deployProps;
|
|||
|
|
private final SystemUpdateService updateService;
|
|||
|
|
|
|||
|
|
public SystemUpdateController(PrivateDeploymentProperties deployProps,
|
|||
|
|
SystemUpdateService updateService) {
|
|||
|
|
this.deployProps = deployProps;
|
|||
|
|
this.updateService = updateService;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 触发私有化部署一键升级,以流式文本返回进度日志。
|
|||
|
|
* 仅在 PRIVATE 模式下可用;需要 JWT 认证(租户账号即可)。
|
|||
|
|
*/
|
|||
|
|
@PostMapping(value = "/update", produces = MediaType.TEXT_PLAIN_VALUE)
|
|||
|
|
public ResponseEntity<StreamingResponseBody> update() {
|
|||
|
|
if (!deployProps.isPrivate()) {
|
|||
|
|
return ResponseEntity.status(403)
|
|||
|
|
.contentType(MediaType.TEXT_PLAIN)
|
|||
|
|
.body(out -> out.write("此接口仅在私有化部署可用\n".getBytes()));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
StreamingResponseBody body = outputStream -> {
|
|||
|
|
updateService.runUpdate(line -> {
|
|||
|
|
try {
|
|||
|
|
outputStream.write((line + "\n").getBytes());
|
|||
|
|
outputStream.flush();
|
|||
|
|
} catch (Exception ignored) {}
|
|||
|
|
});
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
return ResponseEntity.ok()
|
|||
|
|
.contentType(MediaType.TEXT_PLAIN)
|
|||
|
|
.body(body);
|
|||
|
|
}
|
|||
|
|
}
|