Compare commits

...

9 Commits

Author SHA1 Message Date
junleea 76d8a23f44 Merge branch 'refs/heads/feat-docker' 2025-07-29 20:56:19 +08:00
junleea 3721ba137d 修复run cid接口问题 2025-07-29 20:49:44 +08:00
junleea 9ef020f229 拦截请求处理 2025-06-13 13:58:47 +08:00
junleea 4e915d02ef 修改请求方式 2025-06-13 13:43:38 +08:00
junleea 6f3495f0f5 添加配置文件输出 2025-06-13 13:28:30 +08:00
junleea 97704ca8d2 修改docker文件挂载及配置文件读取 2025-06-13 13:11:18 +08:00
junleea cf0f656032 修改请求client的证书认证 2025-06-12 20:20:38 +08:00
junleea 13086e55ae 修改docker运行git gi
的配置文件
2025-06-12 19:33:57 +08:00
junleea f11e9ffa61 修改docker运行的配置文件 2025-06-12 19:27:48 +08:00
7 changed files with 60 additions and 24 deletions

View File

@ -18,7 +18,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o
FROM scratch
# 复制配置文件
COPY --from=builder /app/saw-ai.conf /home/saw/saw-ai.conf
COPY --from=builder /app/vp.conf /home/videoplayer/vp.conf
# 复制二进制文件
COPY --from=builder /app/videoplayer /home/videoplayer/videoplayer

12
docker-compose.yml Normal file
View File

@ -0,0 +1,12 @@
version: '3.8'
services:
app:
image: vp-image:latest
container_name: vp-container
ports:
- "8088:8083"
volumes:
- logs:/var/log/vp.log
- /etc/vp-app:/etc/vp-app
- /data/file:/data/file

View File

@ -72,13 +72,13 @@ func RunCID(c *gin.Context) {
if err := c.ShouldBind(&req); err == nil {
// 获取用户ID
username, _ := c.Get("username")
//username, _ := c.Get("username")
cid := dao.FindCIDByID(req.ID, authID)
if cid.ID == 0 {
c.JSON(200, gin.H{"error": "CID not found", "code": proto.OperationFailed, "message": "failed"})
return
} else {
go RunShell(username.(string), cid.Url, cid.Script, req.ID, authID)
go RunShell("", cid.Url, cid.Script, req.ID, authID)
c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": "success"})
}
} else {

View File

@ -62,7 +62,8 @@ func init() {
os.MkdirAll(proto.CID_BASE_DIR+"workspace", os.ModePerm)
//读取配置文件
//文件地址/home/videoplayer/vp.conf
configPath := "/home/videoplayer/vp.conf"
//configPath := "/home/videoplayer/vp.conf"
configPath := "/etc/vp-app/vp.conf"
//读取配置文件
err := proto.ReadConfig(configPath)
if err != nil {
@ -177,7 +178,9 @@ func JWTAuthMiddleware() gin.HandlerFunc {
// 将用户信息添加到上下文中
id := token.Claims.(jwt.MapClaims)["id"]
username := token.Claims.(jwt.MapClaims)["username"]
c.Set("id", id)
c.Set("username", username)
c.Set("user_id", int(id.(float64)))
if UserFuncIntercept(int(id.(float64)), c.Request.URL.Path) {

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"gorm.io/gorm"
"log"
"os"
)
@ -124,6 +125,12 @@ func ReadConfig(path string) error {
Config.SERVER_PORT = "8083" // 默认端口
}
}
configJson, cErr := json.Marshal(Config)
if cErr != nil {
log.Println("ReadConfig Error encoding config,err :", cErr)
} else {
log.Println("ReadConfig configJson:", string(configJson))
}
SigningKey = []byte(Config.TOKEN_SECRET)
return err
}

View File

@ -2,11 +2,11 @@
"db":0,
"mysql_dsn":"vp-db:ZcxsP7s7kaBxxDPc@tcp(tx.ljsea.top:3306)/vp-db?charset=utf8mb4&parseTime=True&loc=Local",
"pg_dsn":"host=localhost user=video_t2 dbname=video_t2 password=2t2SKHmWEYj2xFKF port=5432 TimeZone=Asia/Shanghai",
"redis_addr":"host.docker.internal:6379",
"redis_addr":"tx.ljsea.top:6379",
"redis_db":2,
"redis_user_pw":true,
"token_use_redis":false,
"redis_password":"lj502138",
"redis_password":"vbgyfea87423wear",
"token_secret":"mfjurnc_32ndj9dfhj",
"cid_base_dir":"/home/lijun/cid/",
"file_base_dir":"/home/lijun/file/",

View File

@ -2,6 +2,7 @@ package worker
import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"io"
@ -20,7 +21,23 @@ var client *http.Client
// 初始化
func InitReq() {
client = &http.Client{}
client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // 设置为true将跳过证书验证
},
},
}
}
func InitReqClient() {
client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // 设置为true将跳过证书验证
},
},
}
}
// 发起post请求
@ -104,9 +121,8 @@ func SyncDataFromMasterReq(url string, token string) proto.UserSync {
m["device"] = ""
if client == nil {
client = &http.Client{}
InitReqClient()
}
client = &http.Client{}
//获取数据
resp, err := client.Do(req)
if err != nil {
@ -173,7 +189,7 @@ func SyncDataFromMasterReq2(url string, data proto.SyncUserReq) (proto.UserSync,
req.Header.Set("Content-Type", "application/json")
//传输数据
if client == nil {
client = &http.Client{}
InitReqClient()
}
//获取数据
resp, err := client.Do(req)
@ -218,7 +234,7 @@ func SyncDataFromMasterShellReq2(url string, data proto.SyncUserShellReq) ([]dao
req.Header.Set("token", data.Token)
//传输数据
if client == nil {
client = &http.Client{}
InitReqClient()
}
//获取数据
resp, err := client.Do(req)
@ -262,7 +278,7 @@ func SyncDataFromMasterShellReq3(url string, data proto.SyncUserShellResp) ([]pr
req.Header.Set("token", data.Token)
//传输数据
if client == nil {
client = &http.Client{}
InitReqClient()
}
//获取数据
resp, err := client.Do(req)
@ -285,7 +301,6 @@ func SyncDataFromMasterShellReq3(url string, data proto.SyncUserShellResp) ([]pr
}
func DoPostRequestJSON(url string, jsonData []byte, headers map[string]string) (error, []byte) {
httpClient := &http.Client{}
defer func() {
if r := recover(); r != nil {
fmt.Println("SyncDataFromMasterReq2 error:", r)
@ -304,11 +319,12 @@ func DoPostRequestJSON(url string, jsonData []byte, headers map[string]string) (
req.Header.Set(k, v)
}
//传输数据
if httpClient == nil {
httpClient = &http.Client{}
if client == nil {
InitReqClient()
client = client
}
//获取数据
resp, err := httpClient.Do(req)
resp, err := client.Do(req)
if err != nil {
return err, nil
}
@ -322,7 +338,6 @@ func DoPostRequestJSON(url string, jsonData []byte, headers map[string]string) (
}
func DoPostRequestForm(url string, jsonData []byte, headers map[string]string) (error, []byte) {
httpClient := &http.Client{}
defer func() {
if r := recover(); r != nil {
fmt.Println("SyncDataFromMasterReq2 error:", r)
@ -382,7 +397,7 @@ func DoPostRequestForm(url string, jsonData []byte, headers map[string]string) (
}
// 发送请求
resp, err := httpClient.Do(req)
resp, err := client.Do(req)
if err != nil {
return err, nil
}
@ -398,7 +413,6 @@ func DoPostRequestForm(url string, jsonData []byte, headers map[string]string) (
}
func DoPostRequestFormUrlEncoded(url_ string, jsonData []byte, headers map[string]string) (error, []byte) {
httpClient := &http.Client{}
defer func() {
if r := recover(); r != nil {
log.Println("SyncDataFromMasterReq2 error:", r)
@ -449,7 +463,7 @@ func DoPostRequestFormUrlEncoded(url_ string, jsonData []byte, headers map[strin
}
// 发送请求
resp, err := httpClient.Do(req)
resp, err := client.Do(req)
if err != nil {
return err, nil
}
@ -465,7 +479,6 @@ func DoPostRequestFormUrlEncoded(url_ string, jsonData []byte, headers map[strin
}
func DoGetRequest(url string, headers map[string]string) (error, []byte) {
httpClient := &http.Client{}
defer func() {
if r := recover(); r != nil {
fmt.Println("SyncDataFromMasterReq2 error:", r)
@ -483,11 +496,12 @@ func DoGetRequest(url string, headers map[string]string) (error, []byte) {
req.Header.Set(k, v)
}
//传输数据
if httpClient == nil {
httpClient = &http.Client{}
if client == nil {
InitReqClient()
client = client
}
//获取数据
resp, err := httpClient.Do(req)
resp, err := client.Do(req)
if err != nil {
return err, nil
}