封装res-proc项目新增任务接口
This commit is contained in:
parent
6f5e1aa47c
commit
1744de3d86
30
services/res-proc/client.go
Normal file
30
services/res-proc/client.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package mkt2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
VERSION = "2026-02-03"
|
||||||
|
)
|
||||||
|
|
||||||
|
var HOST = requests.Host{
|
||||||
|
Default: "res-proc",
|
||||||
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
sdk.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClient() (client *Client, err error) {
|
||||||
|
client = new(Client)
|
||||||
|
err = client.Init()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) AddTask(request *AddTaskRequest) (response *AddTaskResponse, err error) {
|
||||||
|
response = CreateAddTaskResponse()
|
||||||
|
err = c.DoAction(request, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
31
services/res-proc/client_test.go
Normal file
31
services/res-proc/client_test.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package mkt2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils/random"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestAddResourceToVdbTask 添加素材上传向量库逻辑
|
||||||
|
func TestAddResourceToVdbTask(t *testing.T) {
|
||||||
|
client, err := NewClient()
|
||||||
|
if err != nil {
|
||||||
|
t.Error("NewClient error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
request := CreateResourceToVdbTaskRequest(ResourceToVdbTaskParam{
|
||||||
|
MaxRetry: 0,
|
||||||
|
TraceId: random.StrRandom(10),
|
||||||
|
Payload: ResourceToVdbPayload{
|
||||||
|
ResourceURL: "https://resouce-mkt.gaore.com/material/video/2021-09/01/2124474664246343/6eb5621f8ff2de8f64d4aefa3db4f551.mp4",
|
||||||
|
MD5: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
response, err := client.AddTask(request)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("MaterialTaskNotify error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Log("response:", response)
|
||||||
|
fmt.Println("")
|
||||||
|
}
|
||||||
83
services/res-proc/task.go
Normal file
83
services/res-proc/task.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package mkt2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||||
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddTaskRequest struct {
|
||||||
|
*requests.JsonRequest
|
||||||
|
TaskType string `position:"Json" field:"task_type"`
|
||||||
|
MaxRetry int64 `position:"Json" field:"max_retry"`
|
||||||
|
TraceId string `position:"Json" field:"trace_id"`
|
||||||
|
Payload any `position:"Json" field:"payload"`
|
||||||
|
Extra any `position:"Json" field:"extra"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddTaskResponseData struct {
|
||||||
|
TaskId int64 `json:"task_id"`
|
||||||
|
}
|
||||||
|
type AddTaskResponse struct {
|
||||||
|
*responses.BaseResponse
|
||||||
|
Data AddTaskResponseData `json:"data"`
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
Err string `json:"err"`
|
||||||
|
TraceId string `json:"trace_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddTaskParam struct {
|
||||||
|
TaskType string `position:"Json" field:"task_type"`
|
||||||
|
MaxRetry int64 `position:"Json" field:"max_retry"`
|
||||||
|
TraceId string `position:"Json" field:"trace_id"`
|
||||||
|
Payload any `position:"Json" field:"payload"`
|
||||||
|
Extra any `position:"Json" field:"extra"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateAddTaskRequest(param AddTaskParam) (req *AddTaskRequest) {
|
||||||
|
req = &AddTaskRequest{
|
||||||
|
JsonRequest: &requests.JsonRequest{},
|
||||||
|
TaskType: param.TaskType,
|
||||||
|
MaxRetry: param.MaxRetry,
|
||||||
|
TraceId: param.TraceId,
|
||||||
|
Payload: param.Payload,
|
||||||
|
Extra: param.Extra,
|
||||||
|
}
|
||||||
|
req.InitWithApiInfo(HOST, VERSION, "/api/task/add")
|
||||||
|
req.Method = requests.POST
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateAddTaskResponse() (response *AddTaskResponse) {
|
||||||
|
response = &AddTaskResponse{
|
||||||
|
BaseResponse: &responses.BaseResponse{},
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResourceToVdbPayload
|
||||||
|
//素材上传向量库任务playLod
|
||||||
|
|
||||||
|
const TaskTypeResourceToVdb = "resource_to_vdb"
|
||||||
|
|
||||||
|
type ResourceToVdbPayload struct {
|
||||||
|
ResourceURL string `json:"resource_url"` // 资源 URL
|
||||||
|
MD5 string `json:"md5"` // 资源 MD5
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResourceToVdbTaskParam struct {
|
||||||
|
MaxRetry int64
|
||||||
|
TraceId string
|
||||||
|
Payload ResourceToVdbPayload
|
||||||
|
Extra map[string]any
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateResourceToVdbTaskRequest(param ResourceToVdbTaskParam) (req *AddTaskRequest) {
|
||||||
|
return CreateAddTaskRequest(AddTaskParam{
|
||||||
|
TaskType: TaskTypeResourceToVdb,
|
||||||
|
MaxRetry: param.MaxRetry,
|
||||||
|
TraceId: param.TraceId,
|
||||||
|
Payload: param.Payload,
|
||||||
|
Extra: param.Extra,
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user