/
v2ray_endpoint_download.go
51 lines (39 loc) · 1.23 KB
/
v2ray_endpoint_download.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package controller
import (
"github.com/Luna-CY/v2ray-helper/common/database/model"
"github.com/Luna-CY/v2ray-helper/common/generator"
"github.com/Luna-CY/v2ray-helper/common/http/code"
"github.com/Luna-CY/v2ray-helper/common/http/response"
"github.com/Luna-CY/v2ray-helper/common/logger"
"github.com/Luna-CY/v2ray-helper/dataservice"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type V2rayEndpointDownloadBody struct {
Id uint `json:"id"`
}
func V2rayEndpointDownload(c *gin.Context) {
var body V2rayEndpointDownloadBody
if err := c.ShouldBind(&body); nil != err {
response.Response(c, code.BadRequest, "错误请求", nil)
return
}
if 0 == body.Id {
response.Response(c, code.BadRequest, "无效请求", nil)
return
}
var endpoint model.V2rayEndpoint
if err := dataservice.GetBaseService().GetById(body.Id, &endpoint); nil != err {
if gorm.ErrRecordNotFound != err {
logger.GetLogger().Errorf("查询数据库失败: %v", err)
}
response.Response(c, code.BadRequest, "查询数据失败", nil)
return
}
content, err := generator.GenerateVMessShareLink(endpoint)
if nil != err {
response.Response(c, code.ServerError, err.Error(), nil)
return
}
response.Success(c, code.OK, &gin.H{"content": content})
}