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
96bab57e
Commit
96bab57e
authored
Aug 01, 2023
by
xushaohua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:部署
parent
cdfa8086
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
149 additions
and
11 deletions
+149
-11
pom.xml
midjourney-proxy/pom.xml
+4
-8
TaskController.java
...github/novicezk/midjourney/controller/TaskController.java
+2
-2
InMemoryTaskStoreServiceImpl.java
...idjourney/service/store/InMemoryTaskStoreServiceImpl.java
+2
-1
FileUtil.java
...in/java/com/github/novicezk/midjourney/util/FileUtil.java
+18
-0
OBSUtil.java
...ain/java/com/github/novicezk/midjourney/util/OBSUtil.java
+118
-0
application-prod.yml
midjourney-proxy/src/main/resources/application-prod.yml
+5
-0
No files found.
midjourney-proxy/pom.xml
View file @
96bab57e
...
...
@@ -112,17 +112,13 @@
<optional>
true
</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/com.huaweicloud/esdk-obs-java -->
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.13
</version>
<groupId>
com.huaweicloud
</groupId>
<artifactId>
esdk-obs-java
</artifactId>
<version>
3.23.3.1
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpmime
</artifactId>
<version>
4.5.13
</version>
</dependency>
</dependencies>
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/controller/TaskController.java
View file @
96bab57e
...
...
@@ -39,9 +39,9 @@ public class TaskController {
@ApiOperation
(
value
=
"转换url"
)
@GetMapping
(
"convertUrl"
)
public
String
convertUrl
(
String
url
)
{
public
String
convertUrl
(
String
url
,
String
endPoint
)
{
FileUtil
fileUtil
=
SpringUtil
.
getBean
(
"fileUtil"
);
String
s
=
fileUtil
.
convertFile
(
url
);
String
s
=
fileUtil
.
convertFile
1
(
url
,
endPoint
);
return
s
;
}
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/service/store/InMemoryTaskStoreServiceImpl.java
View file @
96bab57e
...
...
@@ -48,7 +48,8 @@ public class InMemoryTaskStoreServiceImpl implements TaskStoreService {
if
(
TaskStatus
.
SUCCESS
.
equals
(
status
)
&&
StrUtil
.
isNotBlank
(
task
.
getImageUrl
())
&&
task
.
getImageUrl
().
contains
(
"cdn.discordapp.com"
))
{
// 将discord地址转换成华为云地址返回
String
imageUrl
=
task
.
getImageUrl
();
task
.
setImageUrl
(
fileUtil
.
convertFile
(
imageUrl
));
String
oosurl
=
fileUtil
.
convertFile
(
imageUrl
);
task
.
setImageUrl
(
StrUtil
.
isNotBlank
(
oosurl
)
?
oosurl
:
imageUrl
);
}
try
{
if
(
ObjectUtil
.
isNotNull
(
task
.
getFinishTime
()))
{
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/util/FileUtil.java
View file @
96bab57e
...
...
@@ -31,6 +31,7 @@ public class FileUtil {
public
String
convertFile
(
String
discordUrl
)
{
File
file
=
urlToFile
(
discordUrl
);
if
(
ObjectUtil
.
isNull
(
file
))
{
log
.
info
(
"在线图片地址转换成File返回为空"
);
return
""
;
}
log
.
info
(
"开始调用转换url接口:{}"
,
discordUrl
);
...
...
@@ -50,6 +51,23 @@ public class FileUtil {
}
/**
* 将外网地址url转换成华为云地址
*
* @param discordUrl
* @return
*/
public
String
convertFile1
(
String
discordUrl
,
String
end
)
{
File
file
=
urlToFile
(
discordUrl
);
if
(
ObjectUtil
.
isNull
(
file
))
{
log
.
info
(
"在线图片地址转换成File返回为空"
);
return
""
;
}
log
.
info
(
"调用华为云上传图片:{}"
,
discordUrl
);
String
uploadUrl
=
OBSUtil
.
upload
(
file
,
discordUrl
.
substring
(
discordUrl
.
lastIndexOf
(
"."
)
+
1
),
end
);
return
uploadUrl
;
}
/**
* 在线图片地址转换成File
*
* @param urlStr
...
...
midjourney-proxy/src/main/java/com/github/novicezk/midjourney/util/OBSUtil.java
0 → 100644
View file @
96bab57e
package
com
.
github
.
novicezk
.
midjourney
.
util
;
import
cn.hutool.core.util.StrUtil
;
import
com.obs.services.ObsClient
;
import
com.obs.services.model.*
;
import
io.netty.util.internal.StringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.json.JSONObject
;
import
java.io.File
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.UUID
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
@Slf4j
public
class
OBSUtil
{
private
static
final
String
endPoint
=
"obs.cn-east-2.myhuaweicloud.com"
;
private
static
final
String
ak
=
"CROQ0IJRW2FW5NSERZBR"
;
private
static
final
String
sk
=
"rAbki4thgWx9iKXendlIH3gvKi8JFHUcVOWwObyS"
;
private
static
final
DateTimeFormatter
SHORT_MILLISECOND
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMddHHmmssSSS"
);
public
static
void
listbucket
()
{
// 创建ObsClient实例
ObsClient
obsClient
=
new
ObsClient
(
ak
,
sk
,
endPoint
);
// 列举桶
ListBucketsRequest
request
=
new
ListBucketsRequest
();
request
.
setQueryLocation
(
true
);
List
<
ObsBucket
>
buckets
=
obsClient
.
listBuckets
(
request
);
for
(
ObsBucket
bucket
:
buckets
)
{
System
.
out
.
println
(
"BucketName:"
+
bucket
.
getBucketName
());
System
.
out
.
println
(
"CreationDate:"
+
bucket
.
getCreationDate
());
System
.
out
.
println
(
"Location:"
+
bucket
.
getLocation
());
}
}
/**
* 文件上传
* @param file
* @param fileType
* @return
*/
public
static
String
upload
(
File
file
,
String
fileType
,
String
end
)
{
// 创建ObsClient实例
ObsClient
obsClient
=
new
ObsClient
(
ak
,
sk
,
end
);
// localfile为待上传的本地文件路径,需要指定到具体的文件名
PutObjectResult
putObjectResult
=
obsClient
.
putObject
(
"wuhan-oss-test-002"
,
getObjectKey
(
file
.
getName
(),
fileType
),
file
);
log
.
info
(
"华为云返回结果:{}"
,
JSONObject
.
valueToString
(
putObjectResult
));
String
url
=
Optional
.
ofNullable
(
putObjectResult
)
.
map
(
x
->
x
.
getObjectUrl
())
.
orElse
(
""
);
return
url
;
}
/**
* 组装ObjectKey
*/
private
static
String
getObjectKey
(
String
fileName
,
String
fileType
)
{
fileName
=
StrUtil
.
isEmpty
(
fileName
)
?
taskName
()
:
(
formatName
(
fileName
)
+
"_"
+
getYmdhmss
());
return
new
StringBuilder
(
"oss/"
).
append
(
"upload"
).
append
(
"/"
).
append
(
"IMAGE"
).
append
(
"/"
)
.
append
(
fileType
).
append
(
"/"
).
append
(
fileName
).
append
(
"."
).
append
(
fileType
).
toString
();
}
/**
* 获取当前的日期字符串(yyyyMMddHHmmssSSS)
*
* @return
*/
public
static
String
getYmdhmss
()
{
return
LocalDateTime
.
now
().
format
(
SHORT_MILLISECOND
);
}
/**
* 格式化文件名称,过滤特殊字符(名称太长进行截断)
*
* @param fileName
*/
public
static
String
formatName
(
String
fileName
)
{
if
(
StrUtil
.
isEmpty
(
fileName
))
{
return
null
;
}
try
{
String
regEx
=
"[*/\\\\:?\"<|>\\s+%#&=.()]"
;
Pattern
p
=
Pattern
.
compile
(
regEx
);
Matcher
m
=
p
.
matcher
(
fileName
);
String
result
=
m
.
replaceAll
(
""
).
trim
();
// 文件名称过长的话,限制40个字
return
result
.
length
()
>
40
?
result
.
substring
(
0
,
40
)
:
result
;
}
catch
(
Exception
e
)
{
log
.
error
(
"【文件API】格式化文件名称.[formatName]:"
+
e
.
getMessage
(),
e
);
return
taskName
();
}
}
/**
* 生成随机任务名称
*
* @return
*/
public
static
String
taskName
()
{
return
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
}
public
static
void
main
(
String
[]
args
)
{
listbucket
();
}
}
midjourney-proxy/src/main/resources/application-prod.yml
View file @
96bab57e
server
:
port
:
9091
mj
:
proxy
:
host
:
127.0.0.1
port
:
7890
file
:
convert
:
...
...
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