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
391cbb85
Commit
391cbb85
authored
Jun 10, 2019
by
songxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
胡老板的需求改的方法
parent
1cbb0669
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
55 deletions
+82
-55
OssUtils.java
...rc/main/java/com/pcloud/common/utils/aliyun/OssUtils.java
+46
-41
UrlUtils.java
...ain/java/com/pcloud/common/utils/httpclient/UrlUtils.java
+36
-14
No files found.
pcloud-common/src/main/java/com/pcloud/common/utils/aliyun/OssUtils.java
View file @
391cbb85
package
com
.
pcloud
.
common
.
utils
.
aliyun
;
package
com
.
pcloud
.
common
.
utils
.
aliyun
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.net.URLEncoder
;
import
java.util.List
;
import
org.apache.commons.codec.binary.Base64
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
...
@@ -50,19 +63,6 @@ import com.pcloud.common.utils.rsa.MD5;
...
@@ -50,19 +63,6 @@ import com.pcloud.common.utils.rsa.MD5;
import
com.pcloud.common.utils.string.StringTools
;
import
com.pcloud.common.utils.string.StringTools
;
import
com.pcloud.common.utils.string.StringUtil
;
import
com.pcloud.common.utils.string.StringUtil
;
import
org.apache.commons.codec.binary.Base64
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.net.URLEncoder
;
import
java.util.List
;
/**
/**
* @描述:
* @描述:
* @作者:songx
* @作者:songx
...
@@ -934,11 +934,12 @@ public class OssUtils {
...
@@ -934,11 +934,12 @@ public class OssUtils {
*/
*/
public
static
UploadResultInfo
getOSSResultByRegion
(
String
transcodeJobId
,
String
buckectName
)
public
static
UploadResultInfo
getOSSResultByRegion
(
String
transcodeJobId
,
String
buckectName
)
throws
FileException
{
throws
FileException
{
if
(
AliyunConstant
.
LIVE_BUCKET
.
equals
(
buckectName
))
if
(
AliyunConstant
.
LIVE_BUCKET
.
equals
(
buckectName
))
{
return
getOSSResult
(
transcodeJobId
,
AliyunConstant
.
LIVE_BUCKET
);
return
getOSSResult
(
transcodeJobId
,
AliyunConstant
.
LIVE_BUCKET
);
else
}
else
{
return
getOSSResult
(
transcodeJobId
,
AliyunConstant
.
FILE_BUCKET
);
return
getOSSResult
(
transcodeJobId
,
AliyunConstant
.
FILE_BUCKET
);
}
}
}
/**
/**
* 组装转换后的地址
* 组装转换后的地址
...
@@ -1102,12 +1103,15 @@ public class OssUtils {
...
@@ -1102,12 +1103,15 @@ public class OssUtils {
throw
new
FileException
(
FileException
.
FILE_DOWNLOAD_FAILURE
,
"下载文件失败"
);
throw
new
FileException
(
FileException
.
FILE_DOWNLOAD_FAILURE
,
"下载文件失败"
);
}
finally
{
}
finally
{
try
{
try
{
if
(
is
!=
null
)
if
(
is
!=
null
)
{
is
.
close
();
is
.
close
();
if
(
os
!=
null
)
}
if
(
os
!=
null
)
{
os
.
close
();
os
.
close
();
if
(
ossClient
!=
null
)
}
if
(
ossClient
!=
null
)
{
ossClient
.
shutdown
();
ossClient
.
shutdown
();
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【aliOSS】下载文件,关闭文件流失败:"
+
e
.
getMessage
(),
e
);
LOGGER
.
error
(
"【aliOSS】下载文件,关闭文件流失败:"
+
e
.
getMessage
(),
e
);
}
}
...
@@ -1134,10 +1138,11 @@ public class OssUtils {
...
@@ -1134,10 +1138,11 @@ public class OssUtils {
LOGGER
.
error
(
"【aliOSS】下载文件失败:"
+
e
.
getMessage
(),
e
);
LOGGER
.
error
(
"【aliOSS】下载文件失败:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_DOWNLOAD_FAILURE
,
"下载文件失败"
);
throw
new
FileException
(
FileException
.
FILE_DOWNLOAD_FAILURE
,
"下载文件失败"
);
}
finally
{
}
finally
{
if
(
ossClient
!=
null
)
if
(
ossClient
!=
null
)
{
ossClient
.
shutdown
();
ossClient
.
shutdown
();
}
}
}
}
}
/**
/**
* 组装返回的文件信息 <br> isPrivateKey=true,表示地址可下载,但需要加上密钥,密钥生产使用方法getHashValue或者addUrlKey <br>
* 组装返回的文件信息 <br> isPrivateKey=true,表示地址可下载,但需要加上密钥,密钥生产使用方法getHashValue或者addUrlKey <br>
...
@@ -1224,12 +1229,7 @@ public class OssUtils {
...
@@ -1224,12 +1229,7 @@ public class OssUtils {
* @return
* @return
*/
*/
private
static
String
getInObjectKey
(
AliyunEnum
aliyunEnum
,
String
fileName
,
String
fileType
)
{
private
static
String
getInObjectKey
(
AliyunEnum
aliyunEnum
,
String
fileName
,
String
fileType
)
{
fileName
=
StringUtil
.
isEmpty
(
fileName
)
?
UUIDUitl
.
taskName
()
return
getObjectKey
(
aliyunEnum
,
fileName
,
fileType
);
:
(
FileUtils
.
formatName
(
fileName
)
+
"_"
+
LocalDateUtils
.
getYmdhmss
());
String
gatherName
=
FileUtils
.
getGatherName
(
fileType
);
gatherName
=
StringUtil
.
isEmpty
(
gatherName
)
?
"other"
:
gatherName
.
toLowerCase
();
return
new
StringBuilder
(
"oss/"
).
append
(
aliyunEnum
.
value
).
append
(
"/"
).
append
(
gatherName
).
append
(
"/"
).
append
(
fileType
)
.
append
(
"/"
).
append
(
fileName
).
append
(
"."
).
append
(
fileType
).
toString
();
}
}
/**
/**
...
@@ -1241,12 +1241,24 @@ public class OssUtils {
...
@@ -1241,12 +1241,24 @@ public class OssUtils {
* @return
* @return
*/
*/
private
static
String
getOutObjectKey
(
AliyunEnum
aliyunEnum
,
String
fileName
,
String
fileType
)
{
private
static
String
getOutObjectKey
(
AliyunEnum
aliyunEnum
,
String
fileName
,
String
fileType
)
{
return
getObjectKey
(
aliyunEnum
,
fileName
,
fileType
);
}
/**
* 组装ObjectKey
*
* @param aliyunEnum
* @param fileName
* @param fileType
* @return
*/
private
static
String
getObjectKey
(
AliyunEnum
aliyunEnum
,
String
fileName
,
String
fileType
)
{
fileName
=
StringUtil
.
isEmpty
(
fileName
)
?
UUIDUitl
.
taskName
()
fileName
=
StringUtil
.
isEmpty
(
fileName
)
?
UUIDUitl
.
taskName
()
:
(
FileUtils
.
formatName
(
fileName
)
+
"_"
+
LocalDateUtils
.
getYmdhmss
());
:
(
FileUtils
.
formatName
(
fileName
)
+
"_"
+
LocalDateUtils
.
getYmdhmss
());
String
gatherName
=
FileUtils
.
getGatherName
(
fileType
);
String
gatherName
=
FileUtils
.
getGatherName
(
fileType
);
gatherName
=
StringUtil
.
isEmpty
(
gatherName
)
?
"other"
:
gatherName
.
toLowerCase
();
gatherName
=
StringUtil
.
isEmpty
(
gatherName
)
?
"other"
:
gatherName
.
toLowerCase
();
return
new
StringBuilder
(
"oss/"
).
append
(
aliyunEnum
.
value
).
append
(
"/"
).
append
(
gatherName
).
append
(
"/"
)
.
append
(
fileType
)
return
new
StringBuilder
(
"oss/"
).
append
(
aliyunEnum
.
value
).
append
(
"/"
).
append
(
gatherName
).
append
(
"/"
)
.
append
(
"/"
).
append
(
fileName
).
append
(
"."
).
append
(
fileType
).
toString
();
.
append
(
fileType
)
.
append
(
"/"
).
append
(
fileName
).
append
(
"."
).
append
(
fileType
).
toString
();
}
}
/**
/**
...
@@ -1537,13 +1549,13 @@ public class OssUtils {
...
@@ -1537,13 +1549,13 @@ public class OssUtils {
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
public
static
OssImageCropDTO
imageCropSaveas
(
String
fileUrl
,
int
width
,
int
height
,
int
x
,
int
y
)
throws
FileException
{
public
static
OssImageCropDTO
imageCropSaveas
(
String
fileUrl
,
int
width
,
int
height
,
int
x
,
int
y
)
throws
FileException
{
LOGGER
.
info
(
"【aliOSS】图片裁剪持久化,<START>.[fileUrl]="
+
fileUrl
);
LOGGER
.
info
(
"【aliOSS】图片裁剪持久化,<START>.[fileUrl]="
+
fileUrl
);
ImageUtils
.
checkIsImage
(
fileUrl
);
ImageUtils
.
checkIsImage
(
fileUrl
);
if
(!(
width
>=
0
&&
width
<=
4096
&&
height
>=
0
&&
height
<=
4096
&&
x
>=
0
&&
y
>=
0
))
{
if
(!(
width
>=
0
&&
width
<=
4096
&&
height
>=
0
&&
height
<=
4096
&&
x
>=
0
&&
y
>=
0
))
{
throw
new
FileException
(
FileException
.
PARAM_ERROR
,
"裁剪的长宽或者坐标数值必须大于0且长宽必须小于4096"
);
throw
new
FileException
(
FileException
.
PARAM_ERROR
,
"裁剪的长宽或者坐标数值必须大于0且长宽必须小于4096"
);
}
}
String
fileName
=
FileUtils
.
getFileName
(
fileUrl
);
String
fileType
=
FileUtils
.
getFileType
(
fileUrl
);
String
fileType
=
FileUtils
.
getFileType
(
fileUrl
);
String
bucketName
=
AliyunConstant
.
getBucketName
(
fileUrl
);
String
bucketName
=
AliyunConstant
.
getBucketName
(
fileUrl
);
String
sourceKey
=
splitObjectKey
(
fileUrl
);
String
sourceKey
=
splitObjectKey
(
fileUrl
);
...
@@ -1553,7 +1565,8 @@ public class OssUtils {
...
@@ -1553,7 +1565,8 @@ public class OssUtils {
style
.
append
(
",x_"
).
append
(
x
);
style
.
append
(
",x_"
).
append
(
x
);
style
.
append
(
",y_"
).
append
(
y
);
style
.
append
(
",y_"
).
append
(
y
);
style
.
append
(
"|sys/saveas"
);
style
.
append
(
"|sys/saveas"
);
style
.
append
(
",o_"
).
append
(
BinaryUtil
.
toBase64String
(
getOutObjectKey
(
AliyunEnum
.
CUT
,
fileName
,
fileType
).
getBytes
()));
String
outObjectKey
=
getOutObjectKey
(
AliyunEnum
.
CUT
,
null
,
fileType
);
style
.
append
(
",o_"
).
append
(
BinaryUtil
.
toBase64String
(
outObjectKey
.
getBytes
()));
style
.
append
(
",b_"
).
append
(
BinaryUtil
.
toBase64String
(
bucketName
.
getBytes
()));
style
.
append
(
",b_"
).
append
(
BinaryUtil
.
toBase64String
(
bucketName
.
getBytes
()));
ProcessObjectRequest
request
=
new
ProcessObjectRequest
(
bucketName
,
sourceKey
,
style
.
toString
());
ProcessObjectRequest
request
=
new
ProcessObjectRequest
(
bucketName
,
sourceKey
,
style
.
toString
());
// 创建OSSClient实例
// 创建OSSClient实例
...
@@ -1774,7 +1787,7 @@ public class OssUtils {
...
@@ -1774,7 +1787,7 @@ public class OssUtils {
* @param objectKey
* @param objectKey
* @return
* @return
*/
*/
private
static
boolean
doesO
bjectExist
(
String
bucketName
,
String
objectKey
)
{
private
static
boolean
o
bjectExist
(
String
bucketName
,
String
objectKey
)
{
OSSClient
ossClient
=
getOSSClient
(
bucketName
);
OSSClient
ossClient
=
getOSSClient
(
bucketName
);
boolean
found
=
ossClient
.
doesObjectExist
(
bucketName
,
objectKey
);
boolean
found
=
ossClient
.
doesObjectExist
(
bucketName
,
objectKey
);
// 关闭client
// 关闭client
...
@@ -1789,12 +1802,8 @@ public class OssUtils {
...
@@ -1789,12 +1802,8 @@ public class OssUtils {
* @return true:001,false:002
* @return true:001,false:002
*/
*/
public
static
boolean
fileUrlExist001
(
String
fileUrl
)
{
public
static
boolean
fileUrlExist001
(
String
fileUrl
)
{
boolean
isUploadfe
=
false
;
String
objectKey
=
splitObjectKey
(
fileUrl
);
String
objectKey
=
splitObjectKey
(
fileUrl
);
if
(
doesObjectExist
(
AliyunConstant
.
INPUT_BUCKET
,
objectKey
))
{
return
objectExist
(
AliyunConstant
.
INPUT_BUCKET
,
objectKey
);
isUploadfe
=
true
;
}
return
isUploadfe
;
}
}
/**
/**
...
@@ -1804,12 +1813,8 @@ public class OssUtils {
...
@@ -1804,12 +1813,8 @@ public class OssUtils {
* @return true:001,false:002
* @return true:001,false:002
*/
*/
public
static
boolean
fileUrlExist002
(
String
fileUrl
)
{
public
static
boolean
fileUrlExist002
(
String
fileUrl
)
{
boolean
isUploadfe
=
false
;
String
objectKey
=
splitObjectKey
(
fileUrl
);
String
objectKey
=
splitObjectKey
(
fileUrl
);
if
(
doesObjectExist
(
AliyunConstant
.
FILE_BUCKET
,
objectKey
))
{
return
objectExist
(
AliyunConstant
.
FILE_BUCKET
,
objectKey
);
isUploadfe
=
true
;
}
return
isUploadfe
;
}
}
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/httpclient/UrlUtils.java
View file @
391cbb85
package
com
.
pcloud
.
common
.
utils
.
httpclient
;
package
com
.
pcloud
.
common
.
utils
.
httpclient
;
import
com.alibaba.fastjson.JSONArray
;
import
java.io.IOException
;
import
com.alibaba.fastjson.JSONObject
;
import
java.nio.charset.Charset
;
import
com.pcloud.common.utils.rsa.MD5
;
import
com.pcloud.common.utils.string.StringUtil
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpGet
;
...
@@ -15,8 +14,10 @@ import org.apache.http.util.EntityUtils;
...
@@ -15,8 +14,10 @@ import org.apache.http.util.EntityUtils;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
com.alibaba.fastjson.JSONArray
;
import
java.nio.charset.Charset
;
import
com.alibaba.fastjson.JSONObject
;
import
com.pcloud.common.utils.rsa.MD5
;
import
com.pcloud.common.utils.string.StringUtil
;
/**
/**
* @author:songx
* @author:songx
...
@@ -40,6 +41,11 @@ public class UrlUtils {
...
@@ -40,6 +41,11 @@ public class UrlUtils {
private
static
final
String
REQUEST_URL2
=
"https://rays.5rs.me/convert/v1.0/url/shorten"
;
private
static
final
String
REQUEST_URL2
=
"https://rays.5rs.me/convert/v1.0/url/shorten"
;
/**
/**
* 请求地址(OWN)
*/
private
static
final
String
REQUEST_URL3
=
"https://rays.5rs.me/convert/v1.0/url/expand?hex="
;
/**
* 自定义生成 MD5 加密字符传前的混合 KEY
* 自定义生成 MD5 加密字符传前的混合 KEY
*/
*/
public
static
final
String
PRIVATE_KEY
=
"lgsc1205"
;
public
static
final
String
PRIVATE_KEY
=
"lgsc1205"
;
...
@@ -51,7 +57,7 @@ public class UrlUtils {
...
@@ -51,7 +57,7 @@ public class UrlUtils {
* @return
* @return
*/
*/
public
static
String
getShortUrl
(
String
long_url
)
{
public
static
String
getShortUrl
(
String
long_url
)
{
String
result
=
callHttp
(
long_url
);
String
result
=
callHttp
(
REQUEST_URL
+
long_url
);
if
(
StringUtil
.
isEmpty
(
result
))
{
if
(
StringUtil
.
isEmpty
(
result
))
{
return
null
;
return
null
;
}
}
...
@@ -64,13 +70,13 @@ public class UrlUtils {
...
@@ -64,13 +70,13 @@ public class UrlUtils {
/**
/**
* 发送请求(新浪)
* 发送请求(新浪)
*
*
* @param long_url
* @param request
* @return
* @return
*/
*/
private
static
String
callHttp
(
String
long_url
)
{
private
static
String
callHttp
(
String
request
)
{
LOGGER
.
info
(
"【URL】短链接转换(新浪),<START>.[long_url]="
+
long_url
);
LOGGER
.
info
(
"【URL】短链接转换(新浪),<START>.[request]="
+
request
);
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
HttpGet
httpGet
=
new
HttpGet
(
REQUEST_URL
+
long_url
);
HttpGet
httpGet
=
new
HttpGet
(
request
);
String
resContent
=
null
;
String
resContent
=
null
;
try
{
try
{
CloseableHttpResponse
response
=
httpclient
.
execute
(
httpGet
);
CloseableHttpResponse
response
=
httpclient
.
execute
(
httpGet
);
...
@@ -87,6 +93,22 @@ public class UrlUtils {
...
@@ -87,6 +93,22 @@ public class UrlUtils {
}
}
/**
/**
* 获取长链接(OWN)
*
* @param hex
* @return
*/
public
static
String
getUrl4Own
(
String
hex
)
{
String
result
=
callHttp
(
REQUEST_URL3
+
hex
);
if
(
StringUtil
.
isEmpty
(
result
))
{
return
null
;
}
JSONObject
resultObject
=
JSONObject
.
parseObject
(
result
);
JSONObject
dataObject
=
resultObject
.
getJSONObject
(
"data"
);
return
dataObject
.
getString
(
"originUrl"
);
}
/**
* 获取短链接(OWN)
* 获取短链接(OWN)
*
*
* @param long_url
* @param long_url
...
@@ -153,15 +175,15 @@ public class UrlUtils {
...
@@ -153,15 +175,15 @@ public class UrlUtils {
/**
/**
* 缩短链接
* 缩短链接
*
*
* @param url
* @param hex
* @return
* @return
*/
*/
public
static
String
[]
shortenUrlMd5
(
String
hex
)
{
public
static
String
[]
shortenUrlMd5
(
String
hex
)
{
// 要使用生成 URL 的字符
// 要使用生成 URL 的字符
String
[]
chars
=
new
String
[]
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
,
"g"
,
"h"
,
"i"
,
"j"
,
"k"
,
"l"
,
"m"
,
"n"
,
"o"
,
"p"
,
String
[]
chars
=
new
String
[]{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
,
"g"
,
"h"
,
"i"
,
"j"
,
"k"
,
"l"
,
"m"
,
"n"
,
"o"
,
"p"
,
"q"
,
"r"
,
"s"
,
"t"
,
"u"
,
"v"
,
"w"
,
"x"
,
"y"
,
"z"
,
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"A"
,
"q"
,
"r"
,
"s"
,
"t"
,
"u"
,
"v"
,
"w"
,
"x"
,
"y"
,
"z"
,
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
,
"K"
,
"L"
,
"M"
,
"N"
,
"O"
,
"P"
,
"Q"
,
"R"
,
"S"
,
"T"
,
"U"
,
"V"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
,
"K"
,
"L"
,
"M"
,
"N"
,
"O"
,
"P"
,
"Q"
,
"R"
,
"S"
,
"T"
,
"U"
,
"V"
,
"W"
,
"X"
,
"Y"
,
"Z"
};
"W"
,
"X"
,
"Y"
,
"Z"
};
String
[]
resUrl
=
new
String
[
4
];
String
[]
resUrl
=
new
String
[
4
];
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
...
...
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