diff --git a/api/handler/short_link.go b/api/handler/short_link.go
index 1d82b42..de00e49 100644
--- a/api/handler/short_link.go
+++ b/api/handler/short_link.go
@@ -70,7 +70,30 @@ func ShortLinkGenHandler(c *gin.Context) {
c.String(200, hash)
}
-func ShortLinkGetHandler(c *gin.Context) {
+func ShortLinkGetUrlHandler(c *gin.Context) {
+ var params validator.ShortLinkGetValidator
+ if err := c.ShouldBindQuery(¶ms); err != nil {
+ c.String(400, "参数错误: "+err.Error())
+ return
+ }
+ if strings.TrimSpace(params.Hash) == "" {
+ c.String(400, "参数错误")
+ return
+ }
+ var shortLink model.ShortLink
+ result := database.FindShortLinkByHash(params.Hash, &shortLink)
+ if result.Error != nil {
+ c.String(404, "未找到短链接")
+ return
+ }
+ if shortLink.Password != "" && shortLink.Password != params.Password {
+ c.String(403, "密码错误")
+ return
+ }
+ c.String(200, shortLink.Url)
+}
+
+func ShortLinkGetConfigHandler(c *gin.Context) {
// 获取动态路由
hash := c.Param("hash")
password := c.Query("password")
diff --git a/api/route.go b/api/route.go
index 4c02550..6d5c940 100644
--- a/api/route.go
+++ b/api/route.go
@@ -53,14 +53,18 @@ func SetRoute(r *gin.Engine) {
handler.SubHandler(c)
},
)
- r.POST(
- "/short", func(c *gin.Context) {
- handler.ShortLinkGenHandler(c)
+ r.GET(
+ "/s/:hash", func(c *gin.Context) {
+ handler.ShortLinkGetConfigHandler(c)
},
)
r.GET(
- "/s/:hash", func(c *gin.Context) {
- handler.ShortLinkGetHandler(c)
+ "/short", func(c *gin.Context) {
+ handler.ShortLinkGetUrlHandler(c)
+ })
+ r.POST(
+ "/short", func(c *gin.Context) {
+ handler.ShortLinkGenHandler(c)
},
)
r.PUT(
diff --git a/api/static/index.html b/api/static/index.html
index 68fb48f..27d6d65 100644
--- a/api/static/index.html
+++ b/api/static/index.html
@@ -13,7 +13,6 @@
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js">
-