Skip to content

Commit 55311f3

Browse files
committed
refactor: remove default mirror
1 parent fc02c95 commit 55311f3

File tree

3 files changed

+16
-55
lines changed

3 files changed

+16
-55
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.1] - 2025-03-07
9+
10+
### Changed
11+
12+
- Removed default mirror and download from official site by default
13+
814
## [1.1.0] - 2025-03-06
915

1016
### Changed
@@ -100,6 +106,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
100106

101107
- Basic functionality
102108

109+
[1.1.1]: https://github.com/LiteLDev/bdsdown/compare/v1.1.0...v1.1.1
103110
[1.1.0]: https://github.com/LiteLDev/bdsdown/compare/v1.0.5...v1.1.0
104111
[1.0.5]: https://github.com/LiteLDev/bdsdown/compare/v1.0.4...v1.0.5
105112
[1.0.4]: https://github.com/LiteLDev/bdsdown/compare/v1.0.3...v1.0.4

main.go

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package main
22

33
import (
44
"bytes"
5-
"encoding/json"
6-
"io"
7-
"net/http"
85
"net/url"
96
"os"
107
"path"
@@ -13,9 +10,8 @@ import (
1310
)
1411

1512
const (
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

2117
var 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-
}

tooth.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"format_version": 3,
33
"format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d",
44
"tooth": "github.com/LiteLDev/bdsdown",
5-
"version": "1.1.0",
5+
"version": "1.1.1",
66
"info": {
77
"name": "bdsdown",
88
"description": "Downloader for Minecraft BDS",

0 commit comments

Comments
 (0)