mirror of
https://github.com/nitezs/sub2clash.git
synced 2024-12-23 11:24:42 -05:00
🐛 Parse short link
This commit is contained in:
parent
3e720ec14d
commit
036907fba4
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -5,7 +5,7 @@
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"program": "${workspaceFolder}/main.go",
|
||||
"program": "${workspaceFolder}",
|
||||
"output": "${workspaceFolder}/dist/main.exe",
|
||||
"buildFlags": "-ldflags '-X sub2clash/constant.Version=dev'"
|
||||
}
|
||||
|
@ -135,3 +135,29 @@ func GetRawConfHandler(c *gin.Context) {
|
||||
// 返回响应内容
|
||||
c.String(http.StatusOK, string(all))
|
||||
}
|
||||
|
||||
func GetRawConfUriHandler(c *gin.Context) {
|
||||
// 获取动态路由参数
|
||||
hash := c.Query("hash")
|
||||
password := c.Query("password")
|
||||
|
||||
if strings.TrimSpace(hash) == "" {
|
||||
c.String(http.StatusBadRequest, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
// 查询数据库中的短链接
|
||||
shortLink, err := database.FindShortLinkByHash(hash)
|
||||
if err != nil {
|
||||
c.String(http.StatusNotFound, "未找到短链接或密码错误")
|
||||
return
|
||||
}
|
||||
|
||||
// 校验密码
|
||||
if shortLink.Password != "" && shortLink.Password != password {
|
||||
c.String(http.StatusNotFound, "未找到短链接或密码错误")
|
||||
return
|
||||
}
|
||||
|
||||
c.String(http.StatusOK, shortLink.Url)
|
||||
}
|
||||
|
@ -44,4 +44,5 @@ func SetRoute(r *gin.Engine) {
|
||||
r.GET("/s/:hash", handler.GetRawConfHandler)
|
||||
r.POST("/short", handler.GenerateLinkHandler)
|
||||
r.PUT("/short", handler.UpdateLinkHandler)
|
||||
r.GET("/short", handler.GetRawConfUriHandler)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user