Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeoFlyApi
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GeoFly
GeoFlyApi
Commits
79aea4cd
Commit
79aea4cd
authored
Aug 19, 2025
by
gdj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改oss配置
parent
04c142d5
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
225 additions
and
6 deletions
+225
-6
sample/src/main/java/com/dji/sample/common/util/IPUtils.java
+33
-0
sample/src/main/java/com/dji/sample/component/oss/model/OssConfiguration.java
+6
-0
sample/src/main/java/com/dji/sample/component/oss/service/IOssService.java
+14
-0
sample/src/main/java/com/dji/sample/component/oss/service/impl/AliyunOssServiceImpl.java
+24
-0
sample/src/main/java/com/dji/sample/component/oss/service/impl/AmazonS3ServiceImpl.java
+24
-0
sample/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java
+75
-3
sample/src/main/java/com/dji/sample/component/oss/service/impl/OssServiceContext.java
+12
-0
sample/src/main/java/com/dji/sample/map/service/impl/FlightAreaServiceImpl.java
+1
-1
sample/src/main/java/com/dji/sample/wayline/service/IWaylineFileService.java
+15
-0
sample/src/main/java/com/dji/sample/wayline/service/impl/FlightTaskServiceImpl.java
+1
-1
sample/src/main/java/com/dji/sample/wayline/service/impl/SDKWaylineService.java
+1
-1
sample/src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java
+18
-0
sample/src/main/resources/application.yml
+1
-0
No files found.
sample/src/main/java/com/dji/sample/common/util/IPUtils.java
View file @
79aea4cd
...
...
@@ -26,6 +26,39 @@ public class IPUtils {
private
static
final
String
LOCALHOST_IP
=
"0:0:0:0:0:0:0:1"
;
private
static
final
String
LOCALHOST_IP1
=
"127.0.0.1"
;
public
static
boolean
isLanIp
()
{
String
ipAddr
=
getIpAddr
();
logger
.
info
(
"isLanIp getIpAddr(): {} "
,
ipAddr
);
return
isLanIp
(
ipAddr
);
}
public
static
boolean
isLanIp
(
String
ip
)
{
InetAddress
inet
=
null
;
try
{
inet
=
InetAddress
.
getByName
(
ip
);
}
catch
(
UnknownHostException
e
)
{
// e.printStackTrace();
return
false
;
}
byte
[]
addr
=
inet
.
getAddress
();
int
first
=
addr
[
0
]
&
0xFF
;
int
second
=
addr
[
1
]
&
0xFF
;
if
(
first
==
10
)
{
return
true
;
// 10.0.0.0/8
}
if
(
first
==
172
&&
(
second
>=
16
&&
second
<=
31
))
{
return
true
;
// 172.16.0.0 - 172.31.255.255
}
if
(
first
==
192
&&
second
==
168
)
{
return
true
;
// 192.168.0.0/16
}
if
(
first
==
127
)
{
return
true
;
// 本地环回
}
return
false
;
}
public
static
String
getIpAddr
()
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
...
...
sample/src/main/java/com/dji/sample/component/oss/model/OssConfiguration.java
View file @
79aea4cd
...
...
@@ -28,6 +28,8 @@ public class OssConfiguration {
*/
public
static
String
endpoint
;
public
static
String
localEndpoint
;
public
static
String
accessKey
;
public
static
String
secretKey
;
...
...
@@ -56,6 +58,10 @@ public class OssConfiguration {
OssConfiguration
.
endpoint
=
endpoint
;
}
public
void
setLocalEndpoint
(
String
localEndpoint
)
{
OssConfiguration
.
localEndpoint
=
localEndpoint
;
}
public
void
setAccessKey
(
String
accessKey
)
{
OssConfiguration
.
accessKey
=
accessKey
;
}
...
...
sample/src/main/java/com/dji/sample/component/oss/service/IOssService.java
View file @
79aea4cd
...
...
@@ -30,6 +30,20 @@ public interface IOssService {
URL
getObjectUrl
(
String
bucket
,
String
objectKey
);
/**
* Get the local address of the object based on the bucket name and the object name.
* @param bucket bucket name
* @param objectKey object name
* @return download link
*/
URL
getObjectLocalUrl
(
String
bucket
,
String
objectKey
);
/**
* Get the net address of the object based on the bucket name and the object name.
* @param bucket bucket name
* @param objectKey object name
* @return download link
*/
URL
getObjectNetUrl
(
String
bucket
,
String
objectKey
);
/**
* Deletes the object in the storage bucket.
* @param bucket
* @param objectKey
...
...
sample/src/main/java/com/dji/sample/component/oss/service/impl/AliyunOssServiceImpl.java
View file @
79aea4cd
...
...
@@ -75,6 +75,30 @@ public class AliyunOssServiceImpl implements IOssService {
new
Date
(
System
.
currentTimeMillis
()
+
OssConfiguration
.
expire
*
1000
));
}
/**
* Get the local address of the object based on the bucket name and the object name.
*
* @param bucket bucket name
* @param objectKey object name
* @return download link
*/
@Override
public
URL
getObjectLocalUrl
(
String
bucket
,
String
objectKey
)
{
return
null
;
}
/**
* Get the net address of the object based on the bucket name and the object name.
*
* @param bucket bucket name
* @param objectKey object name
* @return download link
*/
@Override
public
URL
getObjectNetUrl
(
String
bucket
,
String
objectKey
)
{
return
null
;
}
@Override
public
Boolean
deleteObject
(
String
bucket
,
String
objectKey
)
{
if
(!
ossClient
.
doesObjectExist
(
bucket
,
objectKey
))
{
...
...
sample/src/main/java/com/dji/sample/component/oss/service/impl/AmazonS3ServiceImpl.java
View file @
79aea4cd
...
...
@@ -66,6 +66,30 @@ public class AmazonS3ServiceImpl implements IOssService {
new
Date
(
System
.
currentTimeMillis
()
+
OssConfiguration
.
expire
*
1000
),
HttpMethod
.
GET
);
}
/**
* Get the local address of the object based on the bucket name and the object name.
*
* @param bucket bucket name
* @param objectKey object name
* @return download link
*/
@Override
public
URL
getObjectLocalUrl
(
String
bucket
,
String
objectKey
)
{
return
null
;
}
/**
* Get the net address of the object based on the bucket name and the object name.
*
* @param bucket bucket name
* @param objectKey object name
* @return download link
*/
@Override
public
URL
getObjectNetUrl
(
String
bucket
,
String
objectKey
)
{
return
null
;
}
@Override
public
Boolean
deleteObject
(
String
bucket
,
String
objectKey
)
{
if
(!
client
.
doesObjectExist
(
bucket
,
objectKey
))
{
...
...
sample/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java
View file @
79aea4cd
...
...
@@ -20,6 +20,8 @@ import java.security.InvalidKeyException;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Objects
;
import
static
com
.
dji
.
sample
.
common
.
util
.
IPUtils
.
isLanIp
;
/**
* @author sean
* @version 0.3
...
...
@@ -31,6 +33,8 @@ public class MinIOServiceImpl implements IOssService {
private
MinioClient
client
;
private
MinioClient
localClient
;
@Override
public
OssTypeEnum
getOssType
()
{
return
OssTypeEnum
.
MINIO
;
...
...
@@ -38,8 +42,16 @@ public class MinIOServiceImpl implements IOssService {
@Override
public
CredentialsToken
getCredentials
()
{
// 根据ip 是否局域网
boolean
isLanIp
=
isLanIp
();
String
endpoint
;
if
(
isLanIp
)
{
endpoint
=
OssConfiguration
.
endpoint
;
}
else
{
endpoint
=
OssConfiguration
.
localEndpoint
;
}
try
{
AssumeRoleProvider
provider
=
new
AssumeRoleProvider
(
OssConfiguration
.
endpoint
,
OssConfiguration
.
accessKey
,
AssumeRoleProvider
provider
=
new
AssumeRoleProvider
(
endpoint
,
OssConfiguration
.
accessKey
,
OssConfiguration
.
secretKey
,
Math
.
toIntExact
(
OssConfiguration
.
expire
),
null
,
OssConfiguration
.
region
,
null
,
null
,
null
,
null
);
Credentials
credential
=
provider
.
fetch
();
...
...
@@ -53,6 +65,28 @@ public class MinIOServiceImpl implements IOssService {
@Override
public
URL
getObjectUrl
(
String
bucket
,
String
objectKey
)
{
// 根据ip 是否局域网
boolean
isLanIp
=
isLanIp
();
MinioClient
client
;
if
(
isLanIp
)
{
client
=
this
.
localClient
;
}
else
{
client
=
this
.
client
;
}
return
getObjectUrl
(
client
,
bucket
,
objectKey
);
}
@Override
public
URL
getObjectLocalUrl
(
String
bucket
,
String
objectKey
)
{
return
getObjectUrl
(
this
.
localClient
,
bucket
,
objectKey
);
}
@Override
public
URL
getObjectNetUrl
(
String
bucket
,
String
objectKey
)
{
return
getObjectUrl
(
this
.
client
,
bucket
,
objectKey
);
}
public
URL
getObjectUrl
(
MinioClient
client
,
String
bucket
,
String
objectKey
)
{
try
{
return
new
URL
(
client
.
getPresignedObjectUrl
(
...
...
@@ -71,6 +105,14 @@ public class MinIOServiceImpl implements IOssService {
@Override
public
Boolean
deleteObject
(
String
bucket
,
String
objectKey
)
{
// 根据ip 是否局域网
boolean
isLanIp
=
isLanIp
();
MinioClient
client
;
if
(
isLanIp
)
{
client
=
this
.
localClient
;
}
else
{
client
=
this
.
client
;
}
try
{
client
.
removeObject
(
RemoveObjectArgs
.
builder
().
bucket
(
bucket
).
object
(
objectKey
).
build
());
}
catch
(
MinioException
|
NoSuchAlgorithmException
|
IOException
|
InvalidKeyException
e
)
{
...
...
@@ -83,6 +125,14 @@ public class MinIOServiceImpl implements IOssService {
@Override
public
InputStream
getObject
(
String
bucket
,
String
objectKey
)
{
// 根据ip 是否局域网
boolean
isLanIp
=
isLanIp
();
MinioClient
client
;
if
(
isLanIp
)
{
client
=
this
.
localClient
;
}
else
{
client
=
this
.
client
;
}
try
{
GetObjectResponse
object
=
client
.
getObject
(
GetObjectArgs
.
builder
().
bucket
(
bucket
).
object
(
objectKey
).
build
());
return
new
ByteArrayInputStream
(
object
.
readAllBytes
());
...
...
@@ -94,6 +144,14 @@ public class MinIOServiceImpl implements IOssService {
@Override
public
void
putObject
(
String
bucket
,
String
objectKey
,
InputStream
input
)
{
// 根据ip 是否局域网
boolean
isLanIp
=
isLanIp
();
MinioClient
client
;
if
(
isLanIp
)
{
client
=
this
.
localClient
;
}
else
{
client
=
this
.
client
;
}
try
{
client
.
statObject
(
StatObjectArgs
.
builder
().
bucket
(
bucket
).
object
(
objectKey
).
build
());
throw
new
RuntimeException
(
"The filename already exists."
);
...
...
@@ -112,12 +170,26 @@ public class MinIOServiceImpl implements IOssService {
public
void
createClient
()
{
if
(
Objects
.
nonNull
(
this
.
client
))
{
return
;
}
}
else
{
this
.
client
=
MinioClient
.
builder
()
.
endpoint
(
OssConfiguration
.
endpoint
)
.
credentials
(
OssConfiguration
.
accessKey
,
OssConfiguration
.
secretKey
)
.
region
(
OssConfiguration
.
region
)
.
build
();
}
// 增加 本地连接
try
{
if
(
Objects
.
nonNull
(
this
.
localClient
))
{
}
else
{
this
.
localClient
=
MinioClient
.
builder
()
.
endpoint
(
OssConfiguration
.
localEndpoint
)
.
credentials
(
OssConfiguration
.
accessKey
,
OssConfiguration
.
secretKey
)
.
region
(
OssConfiguration
.
region
)
.
build
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"createClient Exception: "
,
e
);
}
}
}
sample/src/main/java/com/dji/sample/component/oss/service/impl/OssServiceContext.java
View file @
79aea4cd
...
...
@@ -49,6 +49,18 @@ public class OssServiceContext {
}
return
this
.
ossService
.
getObjectUrl
(
bucket
,
objectKey
);
}
public
URL
getObjectLocalUrl
(
String
bucket
,
String
objectKey
)
{
if
(!
StringUtils
.
hasText
(
bucket
)
||
!
StringUtils
.
hasText
(
objectKey
))
{
throw
new
IllegalArgumentException
();
}
return
this
.
ossService
.
getObjectLocalUrl
(
bucket
,
objectKey
);
}
public
URL
getObjectNetUrl
(
String
bucket
,
String
objectKey
)
{
if
(!
StringUtils
.
hasText
(
bucket
)
||
!
StringUtils
.
hasText
(
objectKey
))
{
throw
new
IllegalArgumentException
();
}
return
this
.
ossService
.
getObjectNetUrl
(
bucket
,
objectKey
);
}
public
Boolean
deleteObject
(
String
bucket
,
String
objectKey
)
{
return
this
.
ossService
.
deleteObject
(
bucket
,
objectKey
);
...
...
sample/src/main/java/com/dji/sample/map/service/impl/FlightAreaServiceImpl.java
View file @
79aea4cd
...
...
@@ -305,7 +305,7 @@ public class FlightAreaServiceImpl extends AbstractFlightAreaService implements
.
setName
(
file
.
getName
())
.
setSize
(
file
.
getSize
())
.
setChecksum
(
file
.
getSign
())
.
setUrl
(
ossServiceContext
.
getObjectUrl
(
OssConfiguration
.
bucket
,
file
.
getObjectKey
()).
toString
())
.
setUrl
(
ossServiceContext
.
getObject
Net
Url
(
OssConfiguration
.
bucket
,
file
.
getObjectKey
()).
toString
())
))));
}
...
...
sample/src/main/java/com/dji/sample/wayline/service/IWaylineFileService.java
View file @
79aea4cd
...
...
@@ -47,6 +47,21 @@ public interface IWaylineFileService extends IService<WaylineFileEntity> {
URL
getObjectUrl
(
String
workspaceId
,
String
waylineId
)
throws
SQLException
;
/**
* Get the download address of the file object.
* @param workspaceId
* @param waylineId
* @return
*/
URL
getObjectLocalUrl
(
String
workspaceId
,
String
waylineId
)
throws
SQLException
;
/**
* Get the download address of the file object.
* @param workspaceId
* @param waylineId
* @return
*/
URL
getObjectNetUrl
(
String
workspaceId
,
String
waylineId
)
throws
SQLException
;
/**
* Save the basic information of the wayline file.
* @param workspaceId
* @param metadata
...
...
sample/src/main/java/com/dji/sample/wayline/service/impl/FlightTaskServiceImpl.java
View file @
79aea4cd
...
...
@@ -325,7 +325,7 @@ public class FlightTaskServiceImpl extends AbstractWaylineService implements IFl
}
// get file url
URL
url
=
waylineFileService
.
getObjectUrl
(
waylineJob
.
getWorkspaceId
(),
waylineFile
.
get
().
getId
());
URL
url
=
waylineFileService
.
getObject
Net
Url
(
waylineJob
.
getWorkspaceId
(),
waylineFile
.
get
().
getId
());
FlighttaskPrepareRequest
flightTask
=
new
FlighttaskPrepareRequest
()
.
setFlightId
(
waylineJob
.
getJobId
())
...
...
sample/src/main/java/com/dji/sample/wayline/service/impl/SDKWaylineService.java
View file @
79aea4cd
...
...
@@ -145,7 +145,7 @@ public class SDKWaylineService extends AbstractWaylineService {
}
// get file url
try
{
URL
url
=
waylineFileService
.
getObjectUrl
(
waylineJob
.
getWorkspaceId
(),
waylineFile
.
get
().
getId
());
URL
url
=
waylineFileService
.
getObject
Net
Url
(
waylineJob
.
getWorkspaceId
(),
waylineFile
.
get
().
getId
());
return
new
TopicRequestsResponse
<
MqttReply
<
FlighttaskResourceGetResponse
>>().
setData
(
MqttReply
.
success
(
new
FlighttaskResourceGetResponse
()
.
setFile
(
new
FlighttaskFile
()
...
...
sample/src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java
View file @
79aea4cd
...
...
@@ -144,6 +144,24 @@ public class WaylineFileServiceImpl extends ServiceImpl<IWaylineFileMapper, Wayl
}
@Override
public
URL
getObjectLocalUrl
(
String
workspaceId
,
String
waylineId
)
throws
SQLException
{
Optional
<
GetWaylineListResponse
>
waylineOpt
=
this
.
getWaylineByWaylineId
(
workspaceId
,
waylineId
);
if
(
waylineOpt
.
isEmpty
())
{
throw
new
SQLException
(
waylineId
+
" does not exist."
);
}
return
ossService
.
getObjectLocalUrl
(
OssConfiguration
.
bucket
,
waylineOpt
.
get
().
getObjectKey
());
}
@Override
public
URL
getObjectNetUrl
(
String
workspaceId
,
String
waylineId
)
throws
SQLException
{
Optional
<
GetWaylineListResponse
>
waylineOpt
=
this
.
getWaylineByWaylineId
(
workspaceId
,
waylineId
);
if
(
waylineOpt
.
isEmpty
())
{
throw
new
SQLException
(
waylineId
+
" does not exist."
);
}
return
ossService
.
getObjectNetUrl
(
OssConfiguration
.
bucket
,
waylineOpt
.
get
().
getObjectKey
());
}
@Override
public
Integer
saveWaylineFile
(
String
workspaceId
,
WaylineFileDTO
metadata
)
{
// 航线文件 一定是文件
metadata
.
setIsDir
(
WaylineFileTypeEnum
.
FILE
.
getVal
());
...
...
sample/src/main/resources/application.yml
View file @
79aea4cd
...
...
@@ -168,6 +168,7 @@ oss:
# endpoint: https://gt7-oss.geotwin.cc
# 深圳
endpoint
:
https://gt-oss-dev.geotwin.cn
local-endpoint
:
http://10.0.8.72:9000
access-key
:
minioadmin
secret-key
:
minioadmin
bucket
:
gtfly
...
...
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