-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
147 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package constant | ||
|
||
var ( | ||
BaseUrl = "https://api.xiaoyuzhoufm.com" | ||
const ( | ||
BaseUrl = "https://api.xiaoyuzhoufm.com" | ||
UpgradeUrl = "https://api.github.com/repos/ultrazg/xyz/releases/latest" | ||
ReleaseUrl = "https://github.com/ultrazg/xyz/releases" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/ultrazg/xyz/constant" | ||
"io" | ||
"net/http" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type AutoGenerated struct { | ||
URL string `json:"url"` | ||
AssetsURL string `json:"assets_url"` | ||
UploadURL string `json:"upload_url"` | ||
HTMLURL string `json:"html_url"` | ||
ID int `json:"id"` | ||
Author Author `json:"author"` | ||
NodeID string `json:"node_id"` | ||
TagName string `json:"tag_name"` | ||
TargetCommitish string `json:"target_commitish"` | ||
Name string `json:"name"` | ||
Draft bool `json:"draft"` | ||
Prerelease bool `json:"prerelease"` | ||
CreatedAt time.Time `json:"created_at"` | ||
PublishedAt time.Time `json:"published_at"` | ||
Assets []Assets `json:"assets"` | ||
TarballURL string `json:"tarball_url"` | ||
ZipballURL string `json:"zipball_url"` | ||
Body string `json:"body"` | ||
} | ||
type Author struct { | ||
Login string `json:"login"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
AvatarURL string `json:"avatar_url"` | ||
GravatarID string `json:"gravatar_id"` | ||
URL string `json:"url"` | ||
HTMLURL string `json:"html_url"` | ||
FollowersURL string `json:"followers_url"` | ||
FollowingURL string `json:"following_url"` | ||
GistsURL string `json:"gists_url"` | ||
StarredURL string `json:"starred_url"` | ||
SubscriptionsURL string `json:"subscriptions_url"` | ||
OrganizationsURL string `json:"organizations_url"` | ||
ReposURL string `json:"repos_url"` | ||
EventsURL string `json:"events_url"` | ||
ReceivedEventsURL string `json:"received_events_url"` | ||
Type string `json:"type"` | ||
SiteAdmin bool `json:"site_admin"` | ||
} | ||
type Uploader struct { | ||
Login string `json:"login"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
AvatarURL string `json:"avatar_url"` | ||
GravatarID string `json:"gravatar_id"` | ||
URL string `json:"url"` | ||
HTMLURL string `json:"html_url"` | ||
FollowersURL string `json:"followers_url"` | ||
FollowingURL string `json:"following_url"` | ||
GistsURL string `json:"gists_url"` | ||
StarredURL string `json:"starred_url"` | ||
SubscriptionsURL string `json:"subscriptions_url"` | ||
OrganizationsURL string `json:"organizations_url"` | ||
ReposURL string `json:"repos_url"` | ||
EventsURL string `json:"events_url"` | ||
ReceivedEventsURL string `json:"received_events_url"` | ||
Type string `json:"type"` | ||
SiteAdmin bool `json:"site_admin"` | ||
} | ||
type Assets struct { | ||
URL string `json:"url"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
Name string `json:"name"` | ||
Label any `json:"label"` | ||
Uploader Uploader `json:"uploader"` | ||
ContentType string `json:"content_type"` | ||
State string `json:"state"` | ||
Size int `json:"size"` | ||
DownloadCount int `json:"download_count"` | ||
CreatedAt time.Time `json:"created_at"` | ||
UpdatedAt time.Time `json:"updated_at"` | ||
BrowserDownloadURL string `json:"browser_download_url"` | ||
} | ||
|
||
func CheckUpgrade() error { | ||
response, _, err := Request(constant.UpgradeUrl, http.MethodGet, nil, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var data *AutoGenerated | ||
if err := json.Unmarshal(body, &data); err != nil { | ||
return err | ||
} | ||
|
||
remoteVersion := strings.TrimPrefix(data.TagName, "v") | ||
|
||
if constant.Version != remoteVersion { | ||
fmt.Printf("\r\n✨发现新版本\r\n当前版本:%s\r\n最新版本:%s\r\n更新内容:\n%s\r\n%s", constant.Version, remoteVersion, data.Body, constant.ReleaseUrl) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters