You've already forked VptPassiveAdapter
720p
This commit is contained in:
@@ -75,3 +75,17 @@ func OssUpload(ctx context.Context, url, filePath string) error {
|
||||
span.SetStatus(codes.Ok, "上传成功")
|
||||
return nil
|
||||
}
|
||||
|
||||
func UploadPreviewFile(ctx context.Context, taskId string, previewFilePath string) error {
|
||||
subCtx, span := tracer.Start(ctx, "UploadPreviewFile")
|
||||
defer span.End()
|
||||
url, err := QueryPreviewUploadUrl(subCtx, taskId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Info("开始上传预览文件", zap.String("url", url))
|
||||
if err := OssUpload(subCtx, url, previewFilePath); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -126,3 +126,71 @@ func ReportTaskSuccess(ctx context.Context, taskId string, file *dto.FileObject)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func QueryPreviewUploadUrl(ctx context.Context, taskId string) (string, error) {
|
||||
_, span := tracer.Start(ctx, "QueryPreviewUploadUrl")
|
||||
defer span.End()
|
||||
url := config.Config.Api.BaseUrl + "/" + taskId + "/previewUploadUrl"
|
||||
span.SetAttributes(attribute.String("http.url", url))
|
||||
span.SetAttributes(attribute.String("http.method", "GET"))
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
span.SetAttributes(attribute.String("error", err.Error()))
|
||||
span.SetStatus(codes.Error, "创建请求失败")
|
||||
logger.Error("创建请求失败", zap.Error(err))
|
||||
return "", err
|
||||
}
|
||||
resp, err := GetAPIClient().Do(req)
|
||||
if err != nil {
|
||||
span.SetAttributes(attribute.String("error", err.Error()))
|
||||
span.SetStatus(codes.Error, "发送请求失败")
|
||||
logger.Error("发送请求失败", zap.Error(err))
|
||||
return "", err
|
||||
}
|
||||
span.SetAttributes(attribute.String("http.status", resp.Status))
|
||||
span.SetAttributes(attribute.Int("http.status_code", resp.StatusCode))
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
span.SetAttributes(attribute.String("error", err.Error()))
|
||||
span.SetStatus(codes.Error, "读取响应体失败")
|
||||
logger.Error("读取响应体失败", zap.Error(err))
|
||||
return "", err
|
||||
}
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
func ReportPreviewSuccess(ctx context.Context, taskId string) bool {
|
||||
_, span := tracer.Start(ctx, "ReportPreviewSuccess")
|
||||
defer span.End()
|
||||
url := config.Config.Api.BaseUrl + "/" + taskId + "/previewSuccess"
|
||||
span.SetAttributes(attribute.String("http.url", url))
|
||||
span.SetAttributes(attribute.String("http.method", "POST"))
|
||||
|
||||
req, err := http.NewRequest("POST", url, nil)
|
||||
if err != nil {
|
||||
span.SetAttributes(attribute.String("error", err.Error()))
|
||||
span.SetStatus(codes.Error, "创建请求失败")
|
||||
logger.Error("创建请求失败", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
resp, err := GetAPIClient().Do(req)
|
||||
if err != nil {
|
||||
span.SetAttributes(attribute.String("error", err.Error()))
|
||||
span.SetStatus(codes.Error, "发送请求失败")
|
||||
logger.Error("发送请求失败", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
span.SetAttributes(attribute.String("http.status", resp.Status))
|
||||
span.SetAttributes(attribute.Int("http.status_code", resp.StatusCode))
|
||||
if resp.StatusCode == 200 {
|
||||
span.SetStatus(codes.Ok, "成功")
|
||||
return true
|
||||
} else {
|
||||
span.SetStatus(codes.Error, "失败")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user