Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
ShenghuoquanBusiness
Project
Project
Details
Activity
Releases
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
bp
ShenghuoquanBusiness
Commits
bfd5e754
Commit
bfd5e754
authored
May 23, 2021
by
yinjiacheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update Ks3Core逻辑
parent
1eb0eeab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
56 deletions
+55
-56
NewsContentApplication.kt
...an/shenghuoquan/newscontent/app/NewsContentApplication.kt
+0
-5
Ks3Core.kt
...java/com/yidian/shenghuoquan/newscontent/utils/Ks3Core.kt
+55
-51
No files found.
Components/newscontent/src/main/java/com/yidian/shenghuoquan/newscontent/app/NewsContentApplication.kt
View file @
bfd5e754
...
...
@@ -66,7 +66,6 @@ class NewsContentApplication : YdBaseApplication() {
initVideo
()
initChameleon
()
initChameleonService
()
initKs3Core
()
}
}
...
...
@@ -328,10 +327,6 @@ class NewsContentApplication : YdBaseApplication() {
PlayerFactory
.
setPlayManager
(
CustomPlayerManager
::
class
.
java
)
}
private
fun
initKs3Core
()
{
Ks3Core
.
instance
.
init
(
this
)
}
override
fun
onTerminate
()
{
super
.
onTerminate
()
ChameleonServiceManager
.
unregisterAllChameleonService
()
...
...
Components/newscontent/src/main/java/com/yidian/shenghuoquan/newscontent/utils/Ks3Core.kt
View file @
bfd5e754
...
...
@@ -11,10 +11,11 @@ import com.ksyun.ks3.services.Ks3ClientConfiguration
import
com.ksyun.ks3.services.handler.PutObjectACLResponseHandler
import
com.ksyun.ks3.services.handler.PutObjectResponseHandler
import
com.ksyun.ks3.services.request.PutObjectRequest
import
com.yidian.common.YdBaseApplication
import
com.yidian.framework.mobile.xdiamond.SecretUtil
import
com.yidian.shenghuoquan.newscontent.bean.KSYunTokenBean
import
com.yidian.shenghuoquan.newscontent.http.ApiService
import
com.yidian.shenghuoquan.newscontent.http.httpbean.
GetKSYunTokenBean
import
com.yidian.shenghuoquan.newscontent.http.httpbean.
*
import
com.yidian.utils.MD5Util
import
com.yidian.yac.ftdevicefinger.core.FtDeviceFingerManager
import
cz.msebera.android.httpclient.Header
...
...
@@ -25,45 +26,13 @@ import java.io.File
* date: 5/20/21 11:08 AM
* description: 金山云存储
*/
class
Ks3Core
private
constructor
()
:
AuthListener
{
class
Ks3Core
private
constructor
(
val
context
:
Context
)
:
AuthListener
{
private
lateinit
var
client
:
Ks3Client
private
lateinit
var
putObjectResponseHandler
:
PutObjectResponseHandler
private
lateinit
var
putObjectACLResponseHandler
:
PutObjectACLResponseHandler
private
lateinit
var
json
:
Gson
private
val
client
by
lazy
{
Ks3Client
(
this
,
context
)
}
private
val
gson
by
lazy
{
Gson
()
}
private
val
onKs3UploadListenerList
:
ArrayList
<
OnKs3UploadListener
>
by
lazy
{
ArrayList
<
OnKs3UploadListener
>()
}
companion
object
{
const
val
TAG
=
"Ks3Core"
const
val
BUCKET_NAME
=
"bp-yidian"
const
val
END_POINT
=
"ks3-cn-beijing.ksyun.com"
const
val
VIDEO_SUFFIX
=
".mp4"
const
val
IMAGE_SUFFIX
=
".png"
val
instance
:
Ks3Core
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
Ks3Core
()
}
}
/**
* 初始化
*/
fun
init
(
context
:
Context
)
{
initClient
(
context
)
initListener
()
initOther
()
}
/**
* 初始化金山云存储client
*/
private
fun
initClient
(
context
:
Context
)
{
client
=
Ks3Client
(
this
,
context
)
client
.
setConfiguration
(
Ks3ClientConfiguration
.
getDefaultConfiguration
())
client
.
setEndpoint
(
END_POINT
)
}
private
fun
initListener
()
{
putObjectResponseHandler
=
object
:
PutObjectResponseHandler
()
{
private
val
putObjectResponseHandler
by
lazy
{
object
:
PutObjectResponseHandler
()
{
override
fun
onTaskProgress
(
progress
:
Double
)
{
// work thread
if
(
onKs3UploadListenerList
.
size
>
0
)
{
...
...
@@ -82,7 +51,7 @@ class Ks3Core private constructor() : AuthListener {
)
{
Log
.
e
(
TAG
,
"put object fail:,
stateCode: $statesCode, errorMsg: ${error?.errorMessage}, response: $response
"
"put object fail:,
errorMsg: ${error?.errorMessage}
"
)
if
(
onKs3UploadListenerList
.
size
>
0
)
{
for
(
listener
in
onKs3UploadListenerList
)
{
...
...
@@ -123,10 +92,11 @@ class Ks3Core private constructor() : AuthListener {
}
}
}
}
}
putObjectACLResponseHandler
=
object
:
PutObjectACLResponseHandler
()
{
private
val
putObjectACLResponseHandler
by
lazy
{
object
:
PutObjectACLResponseHandler
()
{
override
fun
onSuccess
(
statesCode
:
Int
,
responceHeaders
:
Array
<
out
Header
>?)
{
Log
.
d
(
TAG
,
"put object acl success."
)
}
...
...
@@ -140,34 +110,68 @@ class Ks3Core private constructor() : AuthListener {
)
{
Log
.
e
(
TAG
,
"put object acl fail:, errorMsg: ${error?.errorMessage}"
)
}
}
}
companion
object
{
const
val
TAG
=
"Ks3Core"
const
val
DEFAULT_BUCKET_NAME
=
"bp-yidian"
const
val
DEFAULT_END_POINT
=
"ks3-cn-beijing.ksyun.com"
const
val
VIDEO_SUFFIX
=
".mp4"
const
val
IMAGE_SUFFIX
=
".png"
val
instance
:
Ks3Core
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
Ks3Core
(
context
=
YdBaseApplication
.
context
)
}
}
private
fun
initOther
()
{
json
=
Gson
()
init
{
setupClient
()
}
/**
* 配置金山云client
*/
private
fun
setupClient
()
{
client
.
setConfiguration
(
Ks3ClientConfiguration
.
getDefaultConfiguration
())
client
.
setEndpoint
(
DEFAULT_END_POINT
)
}
/**
* 文件上传
* @param path 本地文件全路径
*/
fun
uploadObject
(
path
:
String
,
type
:
ObjectType
)
{
val
file
=
File
(
path
)
val
request
=
PutObjectRequest
(
BUCKET_NAME
,
getObjectKey
(
file
.
name
,
type
),
file
)
request
.
cannedAcl
=
CannedAccessControlList
.
PublicRead
client
.
putObject
(
request
,
putObjectResponseHandler
)
fun
uploadObject
(
path
:
String
)
{
ApiService
.
getKSYunObjectId
(
object
:
IGetKSYunObjectIdCallback
{
override
fun
getKSYunObjectIdSuccess
(
result
:
GetKSYunObjectIdBean
.
Response
?)
{
Log
.
d
(
TAG
,
"request getKSYun objectId success, objectId: ${result?.objectid}, bucket: ${result?.bucket}"
)
// 执行金山云上传
// val request = PutObjectRequest(result?.bucket, result?.objectid, File(path))
val
request
=
PutObjectRequest
(
DEFAULT_BUCKET_NAME
,
result
?.
objectid
,
File
(
path
))
request
.
cannedAcl
=
CannedAccessControlList
.
PublicRead
client
.
putObject
(
request
,
putObjectResponseHandler
)
}
override
fun
getKSYunObjectIdFailure
(
message
:
String
?)
{
Log
.
e
(
TAG
,
"request get KSYun objectId fail, message: $message"
)
}
})
}
/**
*
获取
ObjectKey
*
本地生成
ObjectKey
* 作为Object在云空间的唯一标识
*/
private
fun
getObjectKey
(
name
:
String
,
type
:
ObjectType
):
String
{
private
fun
get
Local
ObjectKey
(
name
:
String
,
type
:
ObjectType
):
String
{
return
MD5Util
.
md5Encrypt32Upper
(
name
+
FtDeviceFingerManager
.
getDeviceFinger
())
+
if
(
type
==
ObjectType
.
VIDEO
)
VIDEO_SUFFIX
else
IMAGE_SUFFIX
}
/**
* 调用金山云API后 SDK会回调此函数用于获取必要参数向AppServer请求token
*/
override
fun
onCalculateAuth
(
httpMethod
:
String
,
contentType
:
String
,
...
...
@@ -183,7 +187,7 @@ class Ks3Core private constructor() : AuthListener {
"KSYun calculate auth, httpMethod: $httpMethod, contentType: $contentType, date: $date, contentMD5: $contentMD5, resource: $resource, headers: $headers"
)
val
tok
=
SecretUtil
.
rsaEncrypt
(
j
son
.
toJson
(
g
son
.
toJson
(
KSYunTokenBean
(
SecretUtil
.
sign
(
httpMethod
+
date
+
resource
),
httpMethod
,
...
...
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