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