Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
859697f2
authored
Mar 14, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: fix image-seed error
parent
cee6f9c3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
20 deletions
+9
-20
relay/relay-mj.go
+0
-18
service/midjourney.go
+9
-2
No files found.
relay/relay-mj.go
View file @
859697f2
...
...
@@ -266,24 +266,6 @@ func RelayMidjourneyTaskImageSeed(c *gin.Context) *dto.MidjourneyResponse {
if
err
!=
nil
{
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
c
.
Writer
.
WriteHeader
(
midjResponseWithStatus
.
StatusCode
)
respBody
,
err
:=
json
.
Marshal
(
midjResponse
)
...
...
service/midjourney.go
View file @
859697f2
...
...
@@ -158,6 +158,8 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU
//requestBody = c.Request.Body
// read request body to json, delete accountFilter and notifyHook
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
)
if
err
!=
nil
{
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)
// make new request with mapResult
}
reqBody
,
err
:=
json
.
Marshal
(
mapResult
)
if
err
!=
nil
{
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
{
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
)
log
.
Printf
(
"responseBody: %s"
,
string
(
responseBody
))
if
err
!=
nil
{
return
MidjourneyErrorWithStatusCodeWrapper
(
constant
.
MjErrorUnknown
,
"unmarshal_response_body_failed"
,
statusCode
),
responseBody
,
err
}
}
//log.Printf("midjResponse: %v", midjResponse)
//for k, v := range resp.Header {
// c.Writer.Header().Set(k, v[0])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment