diff --git a/templates/error.html b/templates/error.html
new file mode 100644
index 0000000..9cfc104
--- /dev/null
+++ b/templates/error.html
@@ -0,0 +1,35 @@
+
+
+
+
+
+ {{ block "head.html" . }}{{ end }}
+
+
+
+
+
+
+
+ {{ block "nav.html" . }}{{ end }}
+
+
+
+ 糟糕😱, {{ .Nickname }}
+ 你似乎遇到了什么麻烦
+
+
+
+
+
+ {{ .Error.Title }}
+ {{ .Error.Intro }}
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/utils/map.go b/utils/map.go
index 4aab4db..b5ba087 100644
--- a/utils/map.go
+++ b/utils/map.go
@@ -30,7 +30,11 @@ func GetLocationByName(name string) (location Location) {
return
} else {
log.Info("地点不存在, 查询 API")
- //goland:noinspection HttpUrlsUsage
+ if AppConfig.Map.TokenApi == "" {
+ log.WithField("名称", name).Error("未配置 API Token, 查询取消")
+ location.Name = name
+ return
+ }
resp, err := http.Get("https://api.tianditu.gov.cn/geocoder?ds={\"keyWord\":\"" + name + "\"}&tk=" + AppConfig.Map.TokenApi)
if err != nil {
log.WithError(err).WithField("名称", name).Error("获取地点失败")
diff --git a/web/error.go b/web/error.go
new file mode 100644
index 0000000..f711f57
--- /dev/null
+++ b/web/error.go
@@ -0,0 +1,12 @@
+package web
+
+var (
+ errNoMapTokenWeb = simpleError{
+ Title: "NoMapTokenWeb",
+ Intro: "天地图 浏览器端 API Token 未设置",
+ }
+ errNoMapTokenApi = simpleError{
+ Title: "NoMapTokenApi",
+ Intro: "天地图 服务器端 API Token 未设置",
+ }
+)
diff --git a/web/location.go b/web/location.go
index e71100a..838dd27 100644
--- a/web/location.go
+++ b/web/location.go
@@ -9,6 +9,22 @@ import (
)
func MapPage(c *gin.Context) {
+ if AppConfig.Map.TokenWeb == "" {
+ var data errorPageData
+ data.Title = "日记地图"
+ data.Nickname = AppConfig.Web.Nickname
+ data.Error = errNoMapTokenWeb
+ c.HTML(200, "error.html", data)
+ return
+ }
+ if AppConfig.Map.TokenApi == "" {
+ var data errorPageData
+ data.Title = "日记地图"
+ data.Nickname = AppConfig.Web.Nickname
+ data.Error = errNoMapTokenApi
+ c.HTML(200, "error.html", data)
+ return
+ }
var data locationMapData
timenoteData := loader.LoadLastDataFile()
tempL := utils.GetLocationNotes(timenoteData.Notes)
diff --git a/web/web.go b/web/web.go
index 64d02ae..1f24ac6 100644
--- a/web/web.go
+++ b/web/web.go
@@ -88,3 +88,13 @@ type locationPageData struct {
simpleLocation
Notes []simpleNote `json:"notes"`
}
+
+type simpleError struct {
+ Title string `json:"title"`
+ Intro string `json:"intro"`
+}
+
+type errorPageData struct {
+ basicData
+ Error simpleError `json:"error"`
+}