@@ -2,9 +2,6 @@ package main
22
33import (
44 "bytes"
5- "encoding/json"
6- "io"
7- "net/http"
85 "net/url"
96 "os"
107 "path"
@@ -13,9 +10,8 @@ import (
1310)
1411
1512const (
16- CACHE_DIR = "./.cache/bdsdown"
17- VERSION_QUERY_URL = "https://www.minecraft.net/en-us/download/server/bedrock"
18- DEFAULT_MIRROR_HOST = "mcdl.bibk.top"
13+ CACHE_DIR = "./.cache/bdsdown"
14+ VERSION_QUERY_URL = "https://www.minecraft.net/en-us/download/server/bedrock"
1915)
2016
2117var VERSION_TEMPLATE = map [string ]* template.Template {
@@ -41,18 +37,13 @@ func main() {
4137 _ , f := path .Split (u .Path )
4238 f = path .Join (CACHE_DIR , f )
4339 mirrorEnv := os .Getenv ("BDSDOWN_MIRROR_URL" )
44- if mirrorEnv != "" || needUseMirror () {
45- if mirrorEnv == "" {
46- u .Host = DEFAULT_MIRROR_HOST
40+ if mirrorEnv != "" {
41+ mirrorUrl , err := url .Parse (mirrorEnv )
42+ if err != nil {
43+ log .Error ("failed to parse BDSDOWN_MIRROR_URL, download from official site" )
4744 } else {
48- mirrorUrl , err := url .Parse (mirrorEnv )
49- if err != nil {
50- log .Error ("failed to parse BDSDOWN_MIRROR_URL, use default mirror instead" )
51- u .Host = DEFAULT_MIRROR_HOST
52- } else {
53- u .Scheme = mirrorUrl .Scheme
54- u .Host = mirrorUrl .Host
55- }
45+ u .Scheme = mirrorUrl .Scheme
46+ u .Host = mirrorUrl .Host
5647 }
5748 log .Info ("trying download from mirror" )
5849 }
@@ -108,40 +99,3 @@ func main() {
10899 }
109100
110101}
111-
112- func needUseMirror () bool {
113- resp , err := http .Get ("http://ip-api.com/json/" )
114- if err != nil {
115- log .Warningf ("failed to get IP location: %v, use mirror by default." , err )
116- return true
117- }
118- defer resp .Body .Close ()
119- body , err := io .ReadAll (resp .Body )
120- if err != nil {
121- log .Warningf ("failed to get IP location: %v, use mirror by default." , err )
122- return true
123- }
124- type IPData struct {
125- Status string
126- Country string
127- CountryCode string
128- Region string
129- RegionName string
130- City string
131- Zip string
132- Lat float32
133- Lon float32
134- Timezone string
135- Isp string
136- Org string
137- As string
138- Query string
139- }
140- var data IPData
141- err = json .Unmarshal (body , & data )
142- if err != nil {
143- log .Warningf ("failed to get IP location: %v, use mirror by default." , err )
144- return true
145- }
146- return data .CountryCode == "CN"
147- }
0 commit comments