Skip to content

Commit

Permalink
drop domain that is not visible (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoQuote authored Sep 22, 2023
1 parent 4e4d620 commit a146f55
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions httpRequest/httpRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@ type FlowDetail struct {
Bytes int `json:"bytes"`
}

type BucketInfo struct {
BucketName string `json:"bucket_name,omitempty"`
Type string `json:"type,omitempty"`
BusinessType string `json:"business_type,omitempty"`
Status string `json:"status,omitempty"`
Separator string `json:"separator,omitempty"`
Visible bool `json:"visible,omitempty"`
FormApiSecret string `json:"form_api_secret,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
BucketRemark string `json:"bucket_remark,omitempty"`
ApprovalDomains []string `json:"approval_domains,omitempty"`
DisapprovalDomains []interface{} `json:"disapproval_domains,omitempty"`
ApprovalingDomains []interface{} `json:"approvaling_domains,omitempty"`
PurgeControl int `json:"purge_control,omitempty"`
DefaultDomain struct {
Https bool `json:"https,omitempty"`
ForceHttps bool `json:"force_https,omitempty"`
Domain string `json:"domain,omitempty"`
} `json:"default_domain,omitempty"`
Operators []string `json:"operators,omitempty"`
FusionCdn bool `json:"fusion_cdn,omitempty"`
SecurityCdn bool `json:"security_cdn,omitempty"`
Websocket bool `json:"websocket,omitempty"`
InfrequentAccess bool `json:"infrequent_access,omitempty"`
}

func DoDomainListRequest(token string) []string {
req, err := http.NewRequest("GET", domainListAddress, nil)
if err != nil {
Expand Down Expand Up @@ -121,6 +147,10 @@ func DoDomainListRequest(token string) []string {
}

for _, bucket := range bucketList.Buckets {
bucketInfo := GetBucketInfo(bucket.BucketName, token)
if !bucketInfo.Visible {
continue
}
for _, domain := range bucket.Domains {
if strings.Contains(domain.Domain, "upaiyun") || strings.Contains(domain.Domain, "upcdn") {
continue
Expand All @@ -131,6 +161,41 @@ func DoDomainListRequest(token string) []string {
return domainList
}

func GetBucketInfo(domain string, token string) BucketInfo {
req, err := http.NewRequest("GET", "https://api.upyun.com/buckets/info", nil)
if err != nil {
log.Fatal(err)
}
params := make(url.Values)
params.Add("bucket_name", domain)
req.URL.RawQuery = params.Encode()

req.Header.Set("Authorization", "Bearer "+token)

client := &http.Client{}
response, err := client.Do(req)
defer response.Body.Close()
if err != nil {
log.Fatal("请求失败", err)
}
body, err := io.ReadAll(response.Body)
if err != nil {
log.Fatalf("failed to read response body: %s", err)
}
if response.StatusCode != 200 {
log.Printf("request: %v, response: %v", req, response)
log.Fatalf("get domain info failed, return code not 200, response code: %v, response body: %s", response.StatusCode, string(body))
}

var bucketInfo BucketInfo

err = json.Unmarshal(body, &bucketInfo)
if err != nil {
log.Fatal(err)
}
return bucketInfo
}

func DoHttpBandWidthRequest(domain string, token string, rangeTime int64, delayTime int64) BandWidthList {
timeZone, _ := time.LoadLocation("Asia/Shanghai")
timeNow := time.Now().In(timeZone)
Expand Down

0 comments on commit a146f55

Please sign in to comment.