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
bb93c4fb
Commit
bb93c4fb
authored
Jul 28, 2023
by
xushaohua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:部署
parent
995e50d6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
9 deletions
+108
-9
SubmitController.java
...thub/novicezk/midjourney/controller/SubmitController.java
+4
-0
InMemoryTaskStoreServiceImpl.java
...idjourney/service/store/InMemoryTaskStoreServiceImpl.java
+21
-5
FileUtil.java
...in/java/com/github/novicezk/midjourney/util/FileUtil.java
+71
-0
ImagineMessageHandler.java
...novicezk/midjourney/wss/handle/ImagineMessageHandler.java
+0
-2
application-dev.yml
midjourney-proxy/src/main/resources/application-dev.yml
+6
-2
application-prod.yml
midjourney-proxy/src/main/resources/application-prod.yml
+6
-0
No files found.
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/controller/SubmitController.java
View file @
bb93c4fb
...
@@ -26,6 +26,8 @@ import eu.maxschuster.dataurl.IDataUrlSerializer;
...
@@ -26,6 +26,8 @@ import eu.maxschuster.dataurl.IDataUrlSerializer;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -47,6 +49,7 @@ import java.util.Set;
...
@@ -47,6 +49,7 @@ import java.util.Set;
@RestController
@RestController
@RequestMapping
(
"/submit"
)
@RequestMapping
(
"/submit"
)
@RequiredArgsConstructor
@RequiredArgsConstructor
@Slf4j
public
class
SubmitController
{
public
class
SubmitController
{
private
final
TranslateService
translateService
;
private
final
TranslateService
translateService
;
...
@@ -57,6 +60,7 @@ public class SubmitController {
...
@@ -57,6 +60,7 @@ public class SubmitController {
@ApiOperation
(
value
=
"提交Imagine任务"
)
@ApiOperation
(
value
=
"提交Imagine任务"
)
@PostMapping
(
"/imagine"
)
@PostMapping
(
"/imagine"
)
public
SubmitResultVO
imagine
(
@RequestBody
SubmitImagineDTO
imagineDTO
)
{
public
SubmitResultVO
imagine
(
@RequestBody
SubmitImagineDTO
imagineDTO
)
{
log
.
info
(
"提交Imagine任务入参:{}"
,
JSONObject
.
valueToString
(
imagineDTO
));
String
prompt
=
imagineDTO
.
getPrompt
();
String
prompt
=
imagineDTO
.
getPrompt
();
if
(
CharSequenceUtil
.
isBlank
(
prompt
))
{
if
(
CharSequenceUtil
.
isBlank
(
prompt
))
{
return
SubmitResultVO
.
fail
(
ReturnCode
.
VALIDATION_ERROR
,
"prompt不能为空"
);
return
SubmitResultVO
.
fail
(
ReturnCode
.
VALIDATION_ERROR
,
"prompt不能为空"
);
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/service/store/InMemoryTaskStoreServiceImpl.java
View file @
bb93c4fb
...
@@ -3,26 +3,31 @@ package com.github.novicezk.midjourney.service.store;
...
@@ -3,26 +3,31 @@ package com.github.novicezk.midjourney.service.store;
import
cn.hutool.cache.CacheUtil
;
import
cn.hutool.cache.CacheUtil
;
import
cn.hutool.cache.impl.TimedCache
;
import
cn.hutool.cache.impl.TimedCache
;
import
cn.hutool.core.collection.ListUtil
;
import
cn.hutool.core.collection.ListUtil
;
import
cn.hutool.core.date.DatePattern
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.stream.StreamUtil
;
import
cn.hutool.core.stream.StreamUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.extra.spring.SpringUtil
;
import
com.github.novicezk.midjourney.enums.TaskStatus
;
import
com.github.novicezk.midjourney.service.TaskStoreService
;
import
com.github.novicezk.midjourney.service.TaskStoreService
;
import
com.github.novicezk.midjourney.support.Task
;
import
com.github.novicezk.midjourney.support.Task
;
import
com.github.novicezk.midjourney.support.TaskCondition
;
import
com.github.novicezk.midjourney.support.TaskCondition
;
import
org.springframework.stereotype.Component
;
import
com.github.novicezk.midjourney.util.FileUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.StringUtils
;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
@Slf4j
public
class
InMemoryTaskStoreServiceImpl
implements
TaskStoreService
{
public
class
InMemoryTaskStoreServiceImpl
implements
TaskStoreService
{
private
final
TimedCache
<
String
,
Task
>
taskMap
;
private
final
TimedCache
<
String
,
Task
>
taskMap
;
public
InMemoryTaskStoreServiceImpl
(
Duration
timeout
)
{
public
InMemoryTaskStoreServiceImpl
(
Duration
timeout
)
{
this
.
taskMap
=
CacheUtil
.
newTimedCache
(
timeout
.
toMillis
());
this
.
taskMap
=
CacheUtil
.
newTimedCache
(
timeout
.
toMillis
());
}
}
@Override
@Override
public
void
save
(
Task
task
)
{
public
void
save
(
Task
task
)
{
...
@@ -36,8 +41,18 @@ public class InMemoryTaskStoreServiceImpl implements TaskStoreService {
...
@@ -36,8 +41,18 @@ public class InMemoryTaskStoreServiceImpl implements TaskStoreService {
@Override
@Override
public
Task
get
(
String
key
)
{
public
Task
get
(
String
key
)
{
FileUtil
fileUtil
=
SpringUtil
.
getBean
(
"fileUtil"
);
Task
task
=
this
.
taskMap
.
get
(
key
);
Task
task
=
this
.
taskMap
.
get
(
key
);
if
(
ObjectUtil
.
isNotNull
(
task
))
{
if
(
ObjectUtil
.
isNotNull
(
task
))
{
TaskStatus
status
=
task
.
getStatus
();
if
(
TaskStatus
.
SUCCESS
.
equals
(
status
))
{
// 将discord地址转换成华为云地址返回
if
(
task
.
getImageUrl
().
contains
(
"cdn.discordapp.com"
))
{
if
(
StrUtil
.
isNotBlank
(
task
.
getImageUrl
()))
{
task
.
setImageUrl
(
fileUtil
.
convertFile
(
task
.
getImageUrl
()));
}
}
}
try
{
try
{
task
.
setFinishDate
(
DateUtil
.
formatDateTime
(
new
Date
(
task
.
getFinishTime
())));
task
.
setFinishDate
(
DateUtil
.
formatDateTime
(
new
Date
(
task
.
getFinishTime
())));
task
.
setSubmitDate
(
DateUtil
.
formatDateTime
(
new
Date
(
task
.
getSubmitTime
())));
task
.
setSubmitDate
(
DateUtil
.
formatDateTime
(
new
Date
(
task
.
getSubmitTime
())));
...
@@ -45,9 +60,10 @@ public class InMemoryTaskStoreServiceImpl implements TaskStoreService {
...
@@ -45,9 +60,10 @@ public class InMemoryTaskStoreServiceImpl implements TaskStoreService {
Long
costTime
=
(
task
.
getFinishTime
()
-
task
.
getStartTime
())
/
1000
;
Long
costTime
=
(
task
.
getFinishTime
()
-
task
.
getStartTime
())
/
1000
;
task
.
setCostTime
(
costTime
);
task
.
setCostTime
(
costTime
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"获取任务详情,转换图片异常:{}"
,
key
,
e
);
}
}
}
}
return
t
his
.
taskMap
.
get
(
key
)
;
return
t
ask
;
}
}
@Override
@Override
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/util/FileUtil.java
0 → 100644
View file @
bb93c4fb
package
com
.
github
.
novicezk
.
midjourney
.
util
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.http.HttpUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
springfox.documentation.schema.Maps
;
import
javax.crypto.spec.OAEPParameterSpec
;
import
java.io.ByteArrayOutputStream
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.util.Base64
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Optional
;
@Slf4j
@Component
(
"fileUtil"
)
public
class
FileUtil
{
@Value
(
"${file.convert.domain}"
)
private
String
domain
;
/**
* 将外网地址url转换成华为云地址
* @param discordUrl
* @return
*/
public
String
convertFile
(
String
discordUrl
)
{
try
{
// 在线图片地址转换成base64
URL
url
=
new
URL
(
discordUrl
);
InputStream
inputStream
=
url
.
openStream
();
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
// 将图片数据读取到字节数组输出流
byte
[]
buffer
=
new
byte
[
4096
];
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
// 将字节数组输出流中的图片数据进行 Base64 编码
byte
[]
imageBytes
=
outputStream
.
toByteArray
();
String
base64Data
=
Base64
.
getEncoder
().
encodeToString
(
imageBytes
);
String
last
=
discordUrl
.
substring
(
discordUrl
.
lastIndexOf
(
"."
)
+
1
);
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"base64Image"
,
base64Data
);
jsonObject
.
put
(
"extension"
,
last
);
HttpRequest
request
=
HttpRequest
.
post
(
domain
+
"/raysserve/v1.0/readArticle/obsUploadbase64"
)
.
setConnectionTimeout
(
1000
*
60
*
10
)
.
header
(
"accept"
,
"application/json"
)
.
header
(
"content-type"
,
"application/json"
)
.
body
(
jsonObject
.
toString
(),
"application/json;charset=utf-8"
);
HttpResponse
httpResponse
=
request
.
execute
();
String
uploadUrl
=
Optional
.
ofNullable
(
httpResponse
.
body
())
.
map
(
JSONObject:
:
new
)
.
map
(
x
->
x
.
getJSONObject
(
"data"
))
.
map
(
x
->
x
.
getString
(
"url"
))
.
orElse
(
""
);
return
uploadUrl
;
}
catch
(
Exception
e
)
{
log
.
error
(
"将在线图片url转换成base64异常:{}"
,
e
);
}
return
""
;
}
}
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/wss/handle/ImagineMessageHandler.java
View file @
bb93c4fb
...
@@ -39,7 +39,6 @@ public class ImagineMessageHandler extends MessageHandler {
...
@@ -39,7 +39,6 @@ public class ImagineMessageHandler extends MessageHandler {
return
;
return
;
}
}
String
realPrompt
=
this
.
discordHelper
.
getRealPrompt
(
parseData
.
getPrompt
());
String
realPrompt
=
this
.
discordHelper
.
getRealPrompt
(
parseData
.
getPrompt
());
log
.
info
(
"realPrompt=======>{}"
,
realPrompt
);
if
(
MessageType
.
CREATE
==
messageType
)
{
if
(
MessageType
.
CREATE
==
messageType
)
{
if
(
"Waiting to start"
.
equals
(
parseData
.
getStatus
()))
{
if
(
"Waiting to start"
.
equals
(
parseData
.
getStatus
()))
{
// 开始
// 开始
...
@@ -76,7 +75,6 @@ public class ImagineMessageHandler extends MessageHandler {
...
@@ -76,7 +75,6 @@ public class ImagineMessageHandler extends MessageHandler {
.
setStatusSet
(
Set
.
of
(
TaskStatus
.
SUBMITTED
,
TaskStatus
.
IN_PROGRESS
));
.
setStatusSet
(
Set
.
of
(
TaskStatus
.
SUBMITTED
,
TaskStatus
.
IN_PROGRESS
));
Task
task
=
this
.
taskQueueHelper
.
findRunningTask
(
taskPredicate
(
condition
,
realPrompt
))
Task
task
=
this
.
taskQueueHelper
.
findRunningTask
(
taskPredicate
(
condition
,
realPrompt
))
.
findFirst
().
orElse
(
null
);
.
findFirst
().
orElse
(
null
);
log
.
info
(
"进度更新:{}"
,
JSONObject
.
valueToString
(
task
));
if
(
task
==
null
)
{
if
(
task
==
null
)
{
return
;
return
;
}
}
...
...
midjourney-proxy/src/main/resources/application-dev.yml
View file @
bb93c4fb
mj
:
mj
:
proxy
:
proxy
:
host
:
127.0.0.1
host
:
127.0.0.1
port
:
33210
port
:
33210
\ No newline at end of file
file
:
convert
:
domain
:
raysgo.com
\ No newline at end of file
midjourney-proxy/src/main/resources/application-prod.yml
View file @
bb93c4fb
server
:
server
:
port
:
9091
port
:
9091
file
:
convert
:
domain
:
raysgo.com
\ No newline at end of file
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