-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
134 lines (112 loc) · 2.47 KB
/
server.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package server
import (
"github.com/gin-gonic/gin"
"log"
"net/http"
"strings"
"violet/api"
)
func Test(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "OK",
})
}
func Video2Text(ctx *gin.Context) {
var data map[string]string
err := ctx.ShouldBind(&data)
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "error parsing JSON",
"error": err.Error(),
})
return
}
if len(data["url"]) == 0 {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "参数为空",
"error": "error parsing JSON",
})
return
}
var finalUrl, title string
if strings.Contains(data["url"], "douyin.com") {
f, t, err := api.GetDouYinInfo(data["url"])
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "视频链接解析失败,请检查链接是否合法",
"error": err.Error(),
})
return
}
finalUrl = f
title = t
} else {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "未知的视频链接,请检查链接是否合法",
"error": "The URL is wrong, please check",
})
return
}
err, d := api.VideoSlice(finalUrl)
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "未知错误,请重试",
"error": err.Error(),
})
return
}
ctx.JSON(http.StatusOK, gin.H{
"message": "success",
"data": gin.H{
"url": finalUrl,
"title": title,
"content": d,
},
})
log.Println("[Info] - done")
}
func RemoveWatermark(ctx *gin.Context) {
var data map[string]string
err := ctx.ShouldBind(&data)
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "error parsing JSON",
"error": err.Error(),
})
return
}
if len(data["url"]) == 0 {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "参数为空",
"error": "error parsing JSON",
})
return
}
var finalUrl, title string
if strings.Contains(data["url"], "douyin.com") {
f, t, err := api.GetDouYinInfo(data["url"])
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "视频链接解析失败,请检查链接是否合法",
"error": err.Error(),
})
return
}
finalUrl = f
title = t
} else {
ctx.JSON(http.StatusBadRequest, gin.H{
"message": "未知的视频链接,请检查链接是否合法",
"error": "The URL is wrong, please check",
})
return
}
ctx.JSON(http.StatusOK, gin.H{
"message": "success",
"data": gin.H{
"url": finalUrl,
"title": title,
},
})
log.Println("[Info] - done")
}