Skip to content

Commit

Permalink
fix: fix download fail and release note is nil (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH authored Oct 10, 2023
1 parent e2b8b0a commit ddaaa67
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
21 changes: 13 additions & 8 deletions route/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 28 in route/installer.go

View workflow job for this annotation

GitHub Actions / build

undefined: tag

Check failure on line 28 in route/installer.go

View workflow job for this annotation

GitHub Actions / goreleaser

undefined: 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),
})
}

Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions service/status_serivce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions types/installer_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ddaaa67

Please sign in to comment.