feat: get hailuo video url
This commit is contained in:
@@ -52,6 +52,7 @@ func updateVideoTaskAll(ctx context.Context, platform constant.TaskPlatform, cha
|
|||||||
info.ChannelMeta = &relaycommon.ChannelMeta{
|
info.ChannelMeta = &relaycommon.ChannelMeta{
|
||||||
ChannelBaseUrl: cacheGetChannel.GetBaseURL(),
|
ChannelBaseUrl: cacheGetChannel.GetBaseURL(),
|
||||||
}
|
}
|
||||||
|
info.ApiKey = cacheGetChannel.Key
|
||||||
adaptor.Init(info)
|
adaptor.Init(info)
|
||||||
for _, taskId := range taskIds {
|
for _, taskId := range taskIds {
|
||||||
if err := updateVideoSingleTask(ctx, adaptor, cacheGetChannel, taskId, taskM); err != nil {
|
if err := updateVideoSingleTask(ctx, adaptor, cacheGetChannel, taskId, taskM); err != nil {
|
||||||
|
|||||||
@@ -429,3 +429,14 @@ func TaskCountAllUserTask(userId int, queryParams SyncTaskQueryParams) int64 {
|
|||||||
_ = query.Count(&total).Error
|
_ = query.Count(&total).Error
|
||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
func (t *Task) ToOpenAIVideo() *dto.OpenAIVideo {
|
||||||
|
openAIVideo := dto.NewOpenAIVideo()
|
||||||
|
openAIVideo.ID = t.TaskID
|
||||||
|
openAIVideo.Status = t.Status.ToVideoStatus()
|
||||||
|
openAIVideo.Model = t.Properties.OriginModelName
|
||||||
|
openAIVideo.SetProgressStr(t.Progress)
|
||||||
|
openAIVideo.CreatedAt = t.CreatedAt
|
||||||
|
openAIVideo.CompletedAt = t.UpdatedAt
|
||||||
|
openAIVideo.SetMetadata("url", t.FailReason)
|
||||||
|
return openAIVideo
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
|
|
||||||
"github.com/QuantumNous/new-api/common"
|
"github.com/QuantumNous/new-api/common"
|
||||||
"github.com/QuantumNous/new-api/model"
|
"github.com/QuantumNous/new-api/model"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
@@ -259,11 +258,7 @@ func (a *TaskAdaptor) ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, e
|
|||||||
case TaskStatusSuccess:
|
case TaskStatusSuccess:
|
||||||
taskResult.Status = model.TaskStatusSuccess
|
taskResult.Status = model.TaskStatusSuccess
|
||||||
taskResult.Progress = "100%"
|
taskResult.Progress = "100%"
|
||||||
if resTask.VideoURL != "" {
|
taskResult.Url = a.buildVideoURL(resTask.TaskID, resTask.FileID)
|
||||||
taskResult.Url = resTask.VideoURL
|
|
||||||
} else if resTask.FileID != "" {
|
|
||||||
taskResult.Url = fmt.Sprintf("https://api.minimaxi.com/v1/files/download?file_id=%s", resTask.FileID)
|
|
||||||
}
|
|
||||||
case TaskStatusFailed:
|
case TaskStatusFailed:
|
||||||
taskResult.Status = model.TaskStatusFailure
|
taskResult.Status = model.TaskStatusFailure
|
||||||
taskResult.Progress = "100%"
|
taskResult.Progress = "100%"
|
||||||
@@ -284,20 +279,7 @@ func (a *TaskAdaptor) ConvertToOpenAIVideo(originTask *model.Task) ([]byte, erro
|
|||||||
return nil, errors.Wrap(err, "unmarshal hailuo task data failed")
|
return nil, errors.Wrap(err, "unmarshal hailuo task data failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
openAIVideo := dto.NewOpenAIVideo()
|
openAIVideo := originTask.ToOpenAIVideo()
|
||||||
openAIVideo.ID = originTask.TaskID
|
|
||||||
openAIVideo.Status = originTask.Status.ToVideoStatus()
|
|
||||||
openAIVideo.SetProgressStr(originTask.Progress)
|
|
||||||
openAIVideo.CreatedAt = originTask.CreatedAt
|
|
||||||
openAIVideo.CompletedAt = originTask.UpdatedAt
|
|
||||||
|
|
||||||
if hailuoResp.VideoURL != "" {
|
|
||||||
openAIVideo.SetMetadata("url", hailuoResp.VideoURL)
|
|
||||||
} else if hailuoResp.FileID != "" {
|
|
||||||
openAIVideo.SetMetadata("file_id", hailuoResp.FileID)
|
|
||||||
openAIVideo.SetMetadata("url", fmt.Sprintf("https://api.minimaxi.com/v1/files/download?file_id=%s", hailuoResp.FileID))
|
|
||||||
}
|
|
||||||
|
|
||||||
if hailuoResp.BaseResp.StatusCode != StatusSuccess {
|
if hailuoResp.BaseResp.StatusCode != StatusSuccess {
|
||||||
openAIVideo.Error = &dto.OpenAIVideoError{
|
openAIVideo.Error = &dto.OpenAIVideoError{
|
||||||
Message: hailuoResp.BaseResp.StatusMsg,
|
Message: hailuoResp.BaseResp.StatusMsg,
|
||||||
@@ -313,6 +295,44 @@ func (a *TaskAdaptor) ConvertToOpenAIVideo(originTask *model.Task) ([]byte, erro
|
|||||||
return jsonData, nil
|
return jsonData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *TaskAdaptor) buildVideoURL(_, fileID string) string {
|
||||||
|
if a.apiKey == "" || a.baseURL == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/v1/files/retrieve?file_id=%s", a.baseURL, fileID)
|
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
req.Header.Set("Authorization", "Bearer "+a.apiKey)
|
||||||
|
|
||||||
|
resp, err := service.GetHttpClient().Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
responseBody, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var retrieveResp RetrieveFileResponse
|
||||||
|
if err := json.Unmarshal(responseBody, &retrieveResp); err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if retrieveResp.BaseResp.StatusCode != StatusSuccess {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return retrieveResp.File.DownloadURL
|
||||||
|
}
|
||||||
|
|
||||||
func contains(slice []string, item string) bool {
|
func contains(slice []string, item string) bool {
|
||||||
for _, s := range slice {
|
for _, s := range slice {
|
||||||
if s == item {
|
if s == item {
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ type QueryTaskResponse struct {
|
|||||||
TaskID string `json:"task_id"`
|
TaskID string `json:"task_id"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
FileID string `json:"file_id,omitempty"`
|
FileID string `json:"file_id,omitempty"`
|
||||||
VideoURL string `json:"video_url,omitempty"`
|
VideoWidth int `json:"video_width,omitempty"`
|
||||||
|
VideoHeight int `json:"video_height,omitempty"`
|
||||||
BaseResp BaseResp `json:"base_resp"`
|
BaseResp BaseResp `json:"base_resp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +57,20 @@ type ModelConfig struct {
|
|||||||
HasFastPretreatment bool
|
HasFastPretreatment bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RetrieveFileResponse struct {
|
||||||
|
File FileObject `json:"file"`
|
||||||
|
BaseResp BaseResp `json:"base_resp"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileObject struct {
|
||||||
|
FileID int64 `json:"file_id"`
|
||||||
|
Bytes int64 `json:"bytes"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
Filename string `json:"filename"`
|
||||||
|
Purpose string `json:"purpose"`
|
||||||
|
DownloadURL string `json:"download_url"`
|
||||||
|
}
|
||||||
|
|
||||||
func GetModelConfig(model string) ModelConfig {
|
func GetModelConfig(model string) ModelConfig {
|
||||||
configs := map[string]ModelConfig{
|
configs := map[string]ModelConfig{
|
||||||
"MiniMax-Hailuo-2.3": {
|
"MiniMax-Hailuo-2.3": {
|
||||||
|
|||||||
Reference in New Issue
Block a user