mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-06 22:33:41 +08:00
fix: fix image-seed error
This commit is contained in:
@@ -266,24 +266,6 @@ func RelayMidjourneyTaskImageSeed(c *gin.Context) *dto.MidjourneyResponse {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return &midjResponseWithStatus.Response
|
return &midjResponseWithStatus.Response
|
||||||
}
|
}
|
||||||
//defer func(ctx context.Context) {
|
|
||||||
// err := model.PostConsumeTokenQuota(tokenId, userQuota, quota, 0, true)
|
|
||||||
// if err != nil {
|
|
||||||
// common.SysError("error consuming token remain quota: " + err.Error())
|
|
||||||
// }
|
|
||||||
// err = model.CacheUpdateUserQuota(userId)
|
|
||||||
// if err != nil {
|
|
||||||
// common.SysError("error update user quota cache: " + err.Error())
|
|
||||||
// }
|
|
||||||
// if quota != 0 {
|
|
||||||
// tokenName := c.GetString("token_name")
|
|
||||||
// logContent := fmt.Sprintf("模型固定价格 %.2f,分组倍率 %.2f,操作 %s", modelPrice, groupRatio, midjRequest.Action)
|
|
||||||
// model.RecordConsumeLog(ctx, userId, channelId, 0, 0, modelName, tokenName, quota, logContent, tokenId, userQuota, 0, false)
|
|
||||||
// model.UpdateUserUsedQuotaAndRequestCount(userId, quota)
|
|
||||||
// channelId := c.GetInt("channel_id")
|
|
||||||
// model.UpdateChannelUsedQuota(channelId, quota)
|
|
||||||
// }
|
|
||||||
//}(c.Request.Context())
|
|
||||||
midjResponse := &midjResponseWithStatus.Response
|
midjResponse := &midjResponseWithStatus.Response
|
||||||
c.Writer.WriteHeader(midjResponseWithStatus.StatusCode)
|
c.Writer.WriteHeader(midjResponseWithStatus.StatusCode)
|
||||||
respBody, err := json.Marshal(midjResponse)
|
respBody, err := json.Marshal(midjResponse)
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU
|
|||||||
//requestBody = c.Request.Body
|
//requestBody = c.Request.Body
|
||||||
// read request body to json, delete accountFilter and notifyHook
|
// read request body to json, delete accountFilter and notifyHook
|
||||||
var mapResult map[string]interface{}
|
var mapResult map[string]interface{}
|
||||||
|
// if get request, no need to read request body
|
||||||
|
if c.Request.Method != "GET" {
|
||||||
err := json.NewDecoder(c.Request.Body).Decode(&mapResult)
|
err := json.NewDecoder(c.Request.Body).Decode(&mapResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "read_request_body_failed", http.StatusInternalServerError), nullBytes, err
|
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "read_request_body_failed", http.StatusInternalServerError), nullBytes, err
|
||||||
@@ -168,6 +170,7 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU
|
|||||||
}
|
}
|
||||||
//req, err := http.NewRequest(c.Request.Method, fullRequestURL, requestBody)
|
//req, err := http.NewRequest(c.Request.Method, fullRequestURL, requestBody)
|
||||||
// make new request with mapResult
|
// make new request with mapResult
|
||||||
|
}
|
||||||
reqBody, err := json.Marshal(mapResult)
|
reqBody, err := json.Marshal(mapResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "marshal_request_body_failed", http.StatusInternalServerError), nullBytes, err
|
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "marshal_request_body_failed", http.StatusInternalServerError), nullBytes, err
|
||||||
@@ -209,12 +212,16 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "close_response_body_failed", statusCode), responseBody, err
|
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "close_response_body_failed", statusCode), responseBody, err
|
||||||
}
|
}
|
||||||
|
respStr := string(responseBody)
|
||||||
|
log.Printf("responseBody: %s", respStr)
|
||||||
|
if respStr == "" {
|
||||||
|
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "empty_response_body", statusCode), responseBody, nil
|
||||||
|
} else {
|
||||||
err = json.Unmarshal(responseBody, &midjResponse)
|
err = json.Unmarshal(responseBody, &midjResponse)
|
||||||
log.Printf("responseBody: %s", string(responseBody))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "unmarshal_response_body_failed", statusCode), responseBody, err
|
return MidjourneyErrorWithStatusCodeWrapper(constant.MjErrorUnknown, "unmarshal_response_body_failed", statusCode), responseBody, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//log.Printf("midjResponse: %v", midjResponse)
|
//log.Printf("midjResponse: %v", midjResponse)
|
||||||
//for k, v := range resp.Header {
|
//for k, v := range resp.Header {
|
||||||
// c.Writer.Header().Set(k, v[0])
|
// c.Writer.Header().Set(k, v[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user