diff --git a/route/installer.go b/route/installer.go index 175cd8d..ef9b6da 100644 --- a/route/installer.go +++ b/route/installer.go @@ -24,17 +24,20 @@ func (a *api) GetStatus(ctx echo.Context) error { } func (a *api) GetRelease(ctx echo.Context, params codegen.GetReleaseParams) error { + http_trigger_context := context.WithValue(ctx.Request().Context(), types.Trigger, types.HTTP_REQUEST) + release, err := service.InstallerService.GetRelease(http_trigger_context, tag) + status, _ := service.GetStatus() if status.Status == codegen.Downloading { - message := "downloading" - return ctx.JSON(http.StatusOK, &codegen.ResponseOK{ - Message: &message, + return ctx.JSON(http.StatusOK, &codegen.ReleaseOK{ + Data: release, + Upgradable: utils.Ptr(false), }) } if status.Status == codegen.Installing { - message := "downloading" - return ctx.JSON(http.StatusOK, &codegen.ResponseOK{ - Message: &message, + return ctx.JSON(http.StatusOK, &codegen.ReleaseOK{ + Data: release, + Upgradable: utils.Ptr(false), }) } @@ -46,8 +49,10 @@ func (a *api) GetRelease(ctx echo.Context, params codegen.GetReleaseParams) erro tag = *params.Version } - http_trigger_context := context.WithValue(ctx.Request().Context(), types.Trigger, types.HTTP_REQUEST) - release, err := service.InstallerService.GetRelease(http_trigger_context, tag) + // 这里就拿导致拿两次release了 + // 这里不能用request的context,不然会cancel + http_trigger_context = context.WithValue(context.Background(), types.Trigger, types.HTTP_REQUEST) + release, err = service.InstallerService.GetRelease(http_trigger_context, tag) if err != nil { message := err.Error() diff --git a/service/status_serivce.go b/service/status_serivce.go index e92c914..9504542 100644 --- a/service/status_serivce.go +++ b/service/status_serivce.go @@ -28,6 +28,11 @@ func (r *StatusService) Install(release codegen.Release, sysRoot string) error { func (r *StatusService) GetRelease(ctx context.Context, tag string) (*codegen.Release, error) { release := &codegen.Release{} + // 因为更新完进入主页又要拿一次release + if ctx.Value(types.Trigger) == types.HTTP_CHECK { + // 不更新状态 + } + if ctx.Value(types.Trigger) == types.CRON_JOB { UpdateStatusWithMessage(FetchUpdateBegin, "触发更新") defer func() { diff --git a/types/installer_type.go b/types/installer_type.go index 59c76d7..5a6a48a 100644 --- a/types/installer_type.go +++ b/types/installer_type.go @@ -9,6 +9,8 @@ const ( type TriggerType string const ( + HTTP_CHECK TriggerType = "http-request-check" + HTTP_REQUEST TriggerType = "http-request-trigger" CRON_JOB TriggerType = "cron-job-trigger" INSTALL TriggerType = "install-trigger"