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
0465b186
authored
Mar 29, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/main'
parents
54c18dc8
78a88010
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
15 deletions
+35
-15
middleware/distributor.go
+1
-1
relay/constant/relay_mode.go
+10
-10
relay/relay-mj.go
+15
-3
router/relay-router.go
+9
-1
No files found.
middleware/distributor.go
View file @
0465b186
...
...
@@ -44,7 +44,7 @@ func Distribute() func(c *gin.Context) {
// Select a channel for the user
var
modelRequest
ModelRequest
var
err
error
if
strings
.
HasPrefix
(
c
.
Request
.
URL
.
Path
,
"/mj
"
)
{
if
strings
.
Contains
(
c
.
Request
.
URL
.
Path
,
"/mj/
"
)
{
relayMode
:=
relayconstant
.
Path2RelayModeMidjourney
(
c
.
Request
.
URL
.
Path
)
if
relayMode
==
relayconstant
.
RelayModeMidjourneyTaskFetch
||
relayMode
==
relayconstant
.
RelayModeMidjourneyTaskFetchByCondition
||
...
...
relay/constant/relay_mode.go
View file @
0465b186
...
...
@@ -56,29 +56,29 @@ func Path2RelayMode(path string) int {
func
Path2RelayModeMidjourney
(
path
string
)
int
{
relayMode
:=
RelayModeUnknown
if
strings
.
Has
Pre
fix
(
path
,
"/mj/submit/action"
)
{
if
strings
.
Has
Suf
fix
(
path
,
"/mj/submit/action"
)
{
// midjourney plus
relayMode
=
RelayModeMidjourneyAction
}
else
if
strings
.
Has
Pre
fix
(
path
,
"/mj/submit/modal"
)
{
}
else
if
strings
.
Has
Suf
fix
(
path
,
"/mj/submit/modal"
)
{
// midjourney plus
relayMode
=
RelayModeMidjourneyModal
}
else
if
strings
.
Has
Pre
fix
(
path
,
"/mj/submit/shorten"
)
{
}
else
if
strings
.
Has
Suf
fix
(
path
,
"/mj/submit/shorten"
)
{
// midjourney plus
relayMode
=
RelayModeMidjourneyShorten
}
else
if
strings
.
Has
Pre
fix
(
path
,
"/mj/insight-face/swap"
)
{
}
else
if
strings
.
Has
Suf
fix
(
path
,
"/mj/insight-face/swap"
)
{
// midjourney plus
relayMode
=
RelayModeSwapFace
}
else
if
strings
.
Has
Pre
fix
(
path
,
"/mj/submit/imagine"
)
{
}
else
if
strings
.
Has
Suf
fix
(
path
,
"/mj/submit/imagine"
)
{
relayMode
=
RelayModeMidjourneyImagine
}
else
if
strings
.
Has
Pre
fix
(
path
,
"/mj/submit/blend"
)
{
}
else
if
strings
.
Has
Suf
fix
(
path
,
"/mj/submit/blend"
)
{
relayMode
=
RelayModeMidjourneyBlend
}
else
if
strings
.
Has
Pre
fix
(
path
,
"/mj/submit/describe"
)
{
}
else
if
strings
.
Has
Suf
fix
(
path
,
"/mj/submit/describe"
)
{
relayMode
=
RelayModeMidjourneyDescribe
}
else
if
strings
.
Has
Pre
fix
(
path
,
"/mj/notify"
)
{
}
else
if
strings
.
Has
Suf
fix
(
path
,
"/mj/notify"
)
{
relayMode
=
RelayModeMidjourneyNotify
}
else
if
strings
.
Has
Pre
fix
(
path
,
"/mj/submit/change"
)
{
}
else
if
strings
.
Has
Suf
fix
(
path
,
"/mj/submit/change"
)
{
relayMode
=
RelayModeMidjourneyChange
}
else
if
strings
.
Has
Pre
fix
(
path
,
"/mj/submit/simple-change"
)
{
}
else
if
strings
.
Has
Suf
fix
(
path
,
"/mj/submit/simple-change"
)
{
relayMode
=
RelayModeMidjourneyChange
}
else
if
strings
.
HasSuffix
(
path
,
"/fetch"
)
{
relayMode
=
RelayModeMidjourneyTaskFetch
...
...
relay/relay-mj.go
View file @
0465b186
...
...
@@ -180,7 +180,7 @@ func RelaySwapFace(c *gin.Context) *dto.MidjourneyResponse {
Description
:
"quota_not_enough"
,
}
}
requestURL
:=
c
.
Request
.
URL
.
String
(
)
requestURL
:=
getMjRequestPath
(
c
.
Request
.
URL
.
String
()
)
baseURL
:=
c
.
GetString
(
"base_url"
)
fullRequestURL
:=
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
requestURL
)
mjResp
,
_
,
err
:=
service
.
DoMidjourneyHttpRequest
(
c
,
time
.
Second
*
60
,
fullRequestURL
)
...
...
@@ -260,7 +260,7 @@ func RelayMidjourneyTaskImageSeed(c *gin.Context) *dto.MidjourneyResponse {
c
.
Set
(
"channel_id"
,
originTask
.
ChannelId
)
c
.
Request
.
Header
.
Set
(
"Authorization"
,
fmt
.
Sprintf
(
"Bearer %s"
,
channel
.
Key
))
requestURL
:=
c
.
Request
.
URL
.
String
(
)
requestURL
:=
getMjRequestPath
(
c
.
Request
.
URL
.
String
()
)
fullRequestURL
:=
fmt
.
Sprintf
(
"%s%s"
,
channel
.
GetBaseURL
(),
requestURL
)
midjResponseWithStatus
,
_
,
err
:=
service
.
DoMidjourneyHttpRequest
(
c
,
time
.
Second
*
30
,
fullRequestURL
)
if
err
!=
nil
{
...
...
@@ -440,7 +440,7 @@ func RelayMidjourneySubmit(c *gin.Context, relayMode int) *dto.MidjourneyRespons
}
//baseURL := common.ChannelBaseURLs[channelType]
requestURL
:=
c
.
Request
.
URL
.
String
(
)
requestURL
:=
getMjRequestPath
(
c
.
Request
.
URL
.
String
()
)
baseURL
:=
c
.
GetString
(
"base_url"
)
...
...
@@ -605,3 +605,15 @@ type taskChangeParams struct {
Action
string
Index
int
}
func
getMjRequestPath
(
path
string
)
string
{
requestURL
:=
path
if
strings
.
Contains
(
requestURL
,
"/mj-"
)
{
urls
:=
strings
.
Split
(
requestURL
,
"/mj/"
)
if
len
(
urls
)
<
2
{
return
requestURL
}
requestURL
=
"/mj/"
+
urls
[
1
]
}
return
requestURL
}
router/relay-router.go
View file @
0465b186
...
...
@@ -43,7 +43,16 @@ func SetRelayRouter(router *gin.Engine) {
relayV1Router
.
DELETE
(
"/models/:model"
,
controller
.
RelayNotImplemented
)
relayV1Router
.
POST
(
"/moderations"
,
controller
.
Relay
)
}
relayMjRouter
:=
router
.
Group
(
"/mj"
)
registerMjRouterGroup
(
relayMjRouter
)
relayMjModeRouter
:=
router
.
Group
(
"/:mode/mj"
)
registerMjRouterGroup
(
relayMjModeRouter
)
//relayMjRouter.Use()
}
func
registerMjRouterGroup
(
relayMjRouter
*
gin
.
RouterGroup
)
{
relayMjRouter
.
GET
(
"/image/:id"
,
relay
.
RelayMidjourneyImage
)
relayMjRouter
.
Use
(
middleware
.
TokenAuth
(),
middleware
.
Distribute
())
{
...
...
@@ -61,5 +70,4 @@ func SetRelayRouter(router *gin.Engine) {
relayMjRouter
.
POST
(
"/task/list-by-condition"
,
controller
.
RelayMidjourney
)
relayMjRouter
.
POST
(
"/insight-face/swap"
,
controller
.
RelayMidjourney
)
}
//relayMjRouter.Use()
}
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