Skip to content

Commit

Permalink
feat: add timeout to add appstore (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH authored May 29, 2024
1 parent 70b0349 commit f012d13
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions service/appstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/IceWhaleTech/CasaOS-AppManagement/codegen"
"github.com/IceWhaleTech/CasaOS-AppManagement/common"
Expand Down Expand Up @@ -77,16 +78,20 @@ func (s *appStore) UpdateCatalog() error {
// check wether the zip package size change
// if not, skip the update
{
// timeout 5s
http.DefaultClient.Timeout = 5 * time.Second
res, err := http.Head(s.url)
if err != nil {
return err
}
if res.StatusCode != http.StatusOK {
return fmt.Errorf("failed to get appstore size, status code: %d", res.StatusCode)
}
if res.ContentLength == s.lastAPPStoreSize {
logger.Info("appstore size not changed", zap.String("url", s.url))
return nil
} else {
logger.Info("appstore size changed, update app store", zap.String("url", s.url))
}
logger.Info("appstore size changed, update app store", zap.String("url", s.url))

defer func() {
if isSuccessful {
Expand Down

0 comments on commit f012d13

Please sign in to comment.