Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐少华
midjourney-proxy
Commits
995e50d6
Commit
995e50d6
authored
Jul 28, 2023
by
xushaohua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:部署
parent
8d724f10
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
9 deletions
+19
-9
SubmitController.java
...thub/novicezk/midjourney/controller/SubmitController.java
+8
-8
TaskQueueHelper.java
...m/github/novicezk/midjourney/support/TaskQueueHelper.java
+3
-0
ImagineMessageHandler.java
...novicezk/midjourney/wss/handle/ImagineMessageHandler.java
+5
-1
UserMessageListener.java
...hub/novicezk/midjourney/wss/user/UserMessageListener.java
+2
-0
UserWebSocketStarter.java
...ub/novicezk/midjourney/wss/user/UserWebSocketStarter.java
+1
-0
No files found.
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/controller/SubmitController.java
View file @
995e50d6
...
...
@@ -66,15 +66,15 @@ public class SubmitController {
task
.
setAction
(
TaskAction
.
IMAGINE
);
task
.
setPrompt
(
prompt
);
String
promptEn
;
int
paramStart
=
prompt
.
indexOf
(
" --"
);
if
(
paramStart
>
0
)
{
promptEn
=
this
.
translateService
.
translateToEnglish
(
prompt
.
substring
(
0
,
paramStart
)).
trim
()
+
prompt
.
substring
(
paramStart
);
}
else
{
promptEn
=
this
.
translateService
.
translateToEnglish
(
prompt
).
trim
();
}
if
(
CharSequenceUtil
.
isBlank
(
promptEn
))
{
//
int paramStart = prompt.indexOf(" --");
//
if (paramStart > 0) {
//
promptEn = this.translateService.translateToEnglish(prompt.substring(0, paramStart)).trim() + prompt.substring(paramStart);
//
} else {
//
promptEn = this.translateService.translateToEnglish(prompt).trim();
//
}
//
if (CharSequenceUtil.isBlank(promptEn)) {
promptEn
=
prompt
;
}
//
}
if
(
BannedPromptUtils
.
isBanned
(
promptEn
))
{
return
SubmitResultVO
.
fail
(
ReturnCode
.
BANNED_PROMPT
,
"可能包含敏感词"
);
}
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/support/TaskQueueHelper.java
View file @
995e50d6
...
...
@@ -9,6 +9,7 @@ import com.github.novicezk.midjourney.result.SubmitResultVO;
import
com.github.novicezk.midjourney.service.NotifyService
;
import
com.github.novicezk.midjourney.service.TaskStoreService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.json.JSONObject
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.stereotype.Component
;
...
...
@@ -118,6 +119,7 @@ public class TaskQueueHelper {
// 更新任务状态为已提交
changeStatusAndNotify
(
task
,
TaskStatus
.
SUBMITTED
);
do
{
// 任务提交后让当前任务线程处于休眠状态,当mj有回调监听消息时,会在ImagineMessageHandler中唤醒线程,此时这里就会继续执行更新任务状态
task
.
sleep
();
changeStatusAndNotify
(
task
,
task
.
getStatus
());
}
while
(
task
.
getStatus
()
==
TaskStatus
.
IN_PROGRESS
);
...
...
@@ -140,6 +142,7 @@ public class TaskQueueHelper {
* @param status
*/
public
void
changeStatusAndNotify
(
Task
task
,
TaskStatus
status
)
{
log
.
info
(
"更新任务状态:{}"
,
status
);
// 更新任务状态
task
.
setStatus
(
status
);
// 更新map值
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/wss/handle/ImagineMessageHandler.java
View file @
995e50d6
...
...
@@ -11,6 +11,7 @@ import com.github.novicezk.midjourney.util.ContentParseData;
import
lombok.extern.slf4j.Slf4j
;
import
net.dv8tion.jda.api.entities.Message
;
import
net.dv8tion.jda.api.utils.data.DataObject
;
import
org.json.JSONObject
;
import
org.springframework.stereotype.Component
;
import
java.util.Set
;
...
...
@@ -31,12 +32,14 @@ public class ImagineMessageHandler extends MessageHandler {
@Override
public
void
handle
(
MessageType
messageType
,
DataObject
message
)
{
log
.
info
(
"监听处理绘图数据:{}"
,
messageType
);
String
content
=
getMessageContent
(
message
);
ContentParseData
parseData
=
parse
(
content
);
if
(
parseData
==
null
)
{
return
;
}
String
realPrompt
=
this
.
discordHelper
.
getRealPrompt
(
parseData
.
getPrompt
());
log
.
info
(
"realPrompt=======>{}"
,
realPrompt
);
if
(
MessageType
.
CREATE
==
messageType
)
{
if
(
"Waiting to start"
.
equals
(
parseData
.
getStatus
()))
{
// 开始
...
...
@@ -73,6 +76,7 @@ public class ImagineMessageHandler extends MessageHandler {
.
setStatusSet
(
Set
.
of
(
TaskStatus
.
SUBMITTED
,
TaskStatus
.
IN_PROGRESS
));
Task
task
=
this
.
taskQueueHelper
.
findRunningTask
(
taskPredicate
(
condition
,
realPrompt
))
.
findFirst
().
orElse
(
null
);
log
.
info
(
"进度更新:{}"
,
JSONObject
.
valueToString
(
task
));
if
(
task
==
null
)
{
return
;
}
...
...
@@ -142,7 +146,7 @@ public class ImagineMessageHandler extends MessageHandler {
}
private
Predicate
<
Task
>
taskPredicate
(
TaskCondition
condition
,
String
prompt
)
{
return
condition
.
and
(
t
->
prompt
.
startsWith
(
t
.
getPromptEn
(
)));
return
condition
.
and
(
t
->
prompt
.
replaceAll
(
"\\s"
,
""
).
equals
(
t
.
getPromptEn
().
replaceAll
(
"\\s"
,
""
)));
}
private
ContentParseData
parse
(
String
content
)
{
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/wss/user/UserMessageListener.java
View file @
995e50d6
package
com
.
github
.
novicezk
.
midjourney
.
wss
.
user
;
import
cn.hutool.json.JSON
;
import
com.github.novicezk.midjourney.ProxyProperties
;
import
com.github.novicezk.midjourney.enums.MessageType
;
import
com.github.novicezk.midjourney.wss.handle.MessageHandler
;
import
lombok.extern.slf4j.Slf4j
;
import
net.dv8tion.jda.api.utils.data.DataObject
;
import
org.json.JSONObject
;
import
org.springframework.boot.context.event.ApplicationStartedEvent
;
import
org.springframework.context.ApplicationListener
;
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/wss/user/UserWebSocketStarter.java
View file @
995e50d6
...
...
@@ -102,6 +102,7 @@ public class UserWebSocketStarter extends WebSocketAdapter implements WebSocketS
String
json
=
new
String
(
decompressBinary
,
StandardCharsets
.
UTF_8
);
DataObject
data
=
DataObject
.
fromJson
(
json
);
int
opCode
=
data
.
getInt
(
"op"
);
log
.
info
(
"监听二进制消息类型opCode:{}"
,
opCode
);
if
(
opCode
!=
WebSocketCode
.
HEARTBEAT_ACK
)
{
this
.
sequence
.
incrementAndGet
();
}
...
...
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