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
dc60c751
authored
Aug 02, 2024
by
Calcium-Ion
Committed by
GitHub
Aug 02, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #399 from kakingone/main
add-mjp-discord-upload
parents
35b6d7b2
442a2f0f
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
6 deletions
+35
-6
common/model-ratio.go
+1
-0
constant/midjourney.go
+2
-0
dto/midjourney.go
+6
-0
relay/constant/relay_mode.go
+4
-0
relay/relay-mj.go
+6
-2
router/relay-router.go
+1
-0
service/midjourney.go
+8
-3
web/src/components/MjLogsTable.js
+7
-1
No files found.
common/model-ratio.go
View file @
dc60c751
...
...
@@ -181,6 +181,7 @@ var defaultModelPrice = map[string]float64{
"mj_describe"
:
0.05
,
"mj_upscale"
:
0.05
,
"swap_face"
:
0.05
,
"mj_upload"
:
0.05
,
}
var
(
...
...
constant/midjourney.go
View file @
dc60c751
...
...
@@ -27,6 +27,7 @@ const (
MjActionLowVariation
=
"LOW_VARIATION"
MjActionPan
=
"PAN"
MjActionSwapFace
=
"SWAP_FACE"
MjActionUpload
=
"UPLOAD"
)
var
MidjourneyModel2Action
=
map
[
string
]
string
{
...
...
@@ -45,4 +46,5 @@ var MidjourneyModel2Action = map[string]string{
"mj_low_variation"
:
MjActionLowVariation
,
"mj_pan"
:
MjActionPan
,
"swap_face"
:
MjActionSwapFace
,
"mj_upload"
:
MjActionUpload
,
}
dto/midjourney.go
View file @
dc60c751
...
...
@@ -33,6 +33,12 @@ type MidjourneyResponse struct {
Result
string
`json:"result"`
}
type
MidjourneyUploadResponse
struct
{
Code
int
`json:"code"`
Description
string
`json:"description"`
Result
[]
string
`json:"result"`
}
type
MidjourneyResponseWithStatusCode
struct
{
StatusCode
int
`json:"statusCode"`
Response
MidjourneyResponse
...
...
relay/constant/relay_mode.go
View file @
dc60c751
...
...
@@ -27,6 +27,7 @@ const (
RelayModeMidjourneyModal
RelayModeMidjourneyShorten
RelayModeSwapFace
RelayModeMidjourneyUpload
RelayModeAudioSpeech
// tts
RelayModeAudioTranscription
// whisper
...
...
@@ -81,6 +82,9 @@ func Path2RelayModeMidjourney(path string) int {
}
else
if
strings
.
HasSuffix
(
path
,
"/mj/insight-face/swap"
)
{
// midjourney plus
relayMode
=
RelayModeSwapFace
}
else
if
strings
.
HasSuffix
(
path
,
"/submit/upload-discord-images"
)
{
// midjourney plus
relayMode
=
RelayModeMidjourneyUpload
}
else
if
strings
.
HasSuffix
(
path
,
"/mj/submit/imagine"
)
{
relayMode
=
RelayModeMidjourneyImagine
}
else
if
strings
.
HasSuffix
(
path
,
"/mj/submit/blend"
)
{
...
...
relay/relay-mj.go
View file @
dc60c751
...
...
@@ -382,6 +382,8 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
midjRequest
.
Action
=
constant
.
MjActionShorten
}
else
if
relayMode
==
relayconstant
.
RelayModeMidjourneyBlend
{
//绘画任务,此类任务可重复
midjRequest
.
Action
=
constant
.
MjActionBlend
}
else
if
relayMode
==
relayconstant
.
RelayModeMidjourneyUpload
{
//绘画任务,此类任务可重复
midjRequest
.
Action
=
constant
.
MjActionUpload
}
else
if
midjRequest
.
TaskId
!=
""
{
//放大、变换任务,此类任务,如果重复且已有结果,远端api会直接返回最终结果
mjId
:=
""
if
relayMode
==
relayconstant
.
RelayModeMidjourneyChange
{
...
...
@@ -580,7 +582,10 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
responseBody
=
[]
byte
(
newBody
)
}
}
if
midjResponse
.
Code
==
1
&&
midjRequest
.
Action
==
"UPLOAD"
{
midjourneyTask
.
Progress
=
"100%"
midjourneyTask
.
Status
=
"SUCCESS"
}
err
=
midjourneyTask
.
Insert
()
if
err
!=
nil
{
return
&
dto
.
MidjourneyResponse
{
...
...
@@ -594,7 +599,6 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
newBody
:=
strings
.
Replace
(
string
(
responseBody
),
`"code":22`
,
`"code":1`
,
-
1
)
responseBody
=
[]
byte
(
newBody
)
}
//resp.Body = io.NopCloser(bytes.NewBuffer(responseBody))
bodyReader
:=
io
.
NopCloser
(
bytes
.
NewBuffer
(
responseBody
))
...
...
router/relay-router.go
View file @
dc60c751
...
...
@@ -79,5 +79,6 @@ func registerMjRouterGroup(relayMjRouter *gin.RouterGroup) {
relayMjRouter
.
GET
(
"/task/:id/image-seed"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/task/list-by-condition"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/insight-face/swap"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/submit/upload-discord-images"
,
controller
.
RelayMidjourney
)
}
}
service/midjourney.go
View file @
dc60c751
...
...
@@ -49,6 +49,8 @@ func GetMjRequestModel(relayMode int, midjRequest *dto.MidjourneyRequest) (strin
action
=
constant
.
MjActionModal
case
relayconstant
.
RelayModeSwapFace
:
action
=
constant
.
MjActionSwapFace
case
relayconstant
.
RelayModeMidjourneyUpload
:
action
=
constant
.
MjActionUpload
case
relayconstant
.
RelayModeMidjourneySimpleChange
:
params
:=
ConvertSimpleChangeParams
(
midjRequest
.
Content
)
if
params
==
nil
{
...
...
@@ -220,7 +222,7 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU
return
MidjourneyErrorWithStatusCodeWrapper
(
constant
.
MjErrorUnknown
,
"close_request_body_failed"
,
statusCode
),
nullBytes
,
err
}
var
midjResponse
dto
.
MidjourneyResponse
var
midjourneyUploadsResponse
dto
.
MidjourneyUploadResponse
responseBody
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
MidjourneyErrorWithStatusCodeWrapper
(
constant
.
MjErrorUnknown
,
"read_response_body_failed"
,
statusCode
),
nullBytes
,
err
...
...
@@ -230,13 +232,16 @@ func DoMidjourneyHttpRequest(c *gin.Context, timeout time.Duration, fullRequestU
return
MidjourneyErrorWithStatusCodeWrapper
(
constant
.
MjErrorUnknown
,
"close_response_body_failed"
,
statusCode
),
responseBody
,
err
}
respStr
:=
string
(
responseBody
)
log
.
Printf
(
"resp
onseBody
: %s"
,
respStr
)
log
.
Printf
(
"resp
Str
: %s"
,
respStr
)
if
respStr
==
""
{
return
MidjourneyErrorWithStatusCodeWrapper
(
constant
.
MjErrorUnknown
,
"empty_response_body"
,
statusCode
),
responseBody
,
nil
}
else
{
err
=
json
.
Unmarshal
(
responseBody
,
&
midjResponse
)
if
err
!=
nil
{
return
MidjourneyErrorWithStatusCodeWrapper
(
constant
.
MjErrorUnknown
,
"unmarshal_response_body_failed"
,
statusCode
),
responseBody
,
err
err2
:=
json
.
Unmarshal
(
responseBody
,
&
midjourneyUploadsResponse
)
if
err2
!=
nil
{
return
MidjourneyErrorWithStatusCodeWrapper
(
constant
.
MjErrorUnknown
,
"unmarshal_response_body_failed"
,
statusCode
),
responseBody
,
err
}
}
}
//log.Printf("midjResponse: %v", midjResponse)
...
...
web/src/components/MjLogsTable.js
View file @
dc60c751
...
...
@@ -90,6 +90,12 @@ function renderType(type) {
图混合
<
/Tag
>
);
case
'UPLOAD'
:
return
(
<
Tag
color
=
'blue'
size
=
'large'
>
上传文件
<
/Tag
>
);
case
'SHORTEN'
:
return
(
<
Tag
color
=
'pink'
size
=
'large'
>
...
...
@@ -239,7 +245,7 @@ const renderTimestamp = (timestampInSeconds) => {
// 修改renderDuration函数以包含颜色逻辑
function
renderDuration
(
submit_time
,
finishTime
)
{
// 确保startTime和finishTime都是有效的时间戳
if
(
!
submit_time
||
!
finishTime
)
return
'N/A'
;
if
(
!
submit_time
||
!
finishTime
)
return
'N/A'
;
// 将时间戳转换为Date对象
const
start
=
new
Date
(
submit_time
);
...
...
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