1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 06:54:41 -05:00

🐛 Parse short link

This commit is contained in:
Nite07 2024-05-09 12:58:33 +08:00
parent 3e720ec14d
commit 036907fba4
3 changed files with 28 additions and 1 deletions

2
.vscode/launch.json vendored
View File

@ -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'"
}

View File

@ -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)
}

View File

@ -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)
}