Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
power-node
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Odysseus
power-node
Commits
19d610ea
Commit
19d610ea
authored
Mar 14, 2024
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parse container resp
parent
680c5621
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
30 deletions
+38
-30
nm_operate.go
nm/nm_operate.go
+1
-1
task_msg.go
nm/task_msg.go
+18
-23
util.go
utils/util.go
+19
-6
No files found.
nm/nm_operate.go
View file @
19d610ea
...
...
@@ -73,6 +73,7 @@ func inputNodeManagerChan(manager *NodeManager, nodeManagerClient *models.NodeMa
IsSelected
:
isSelect
,
LastHeartTime
:
time
.
Now
(),
}
usedNodeManagerClient
=
append
(
usedNodeManagerClient
,
nodeManagerClient
)
}
serviceClient
:=
operate
.
ConnNmGrpc
(
manager
.
Info
.
Endpoint
)
if
serviceClient
==
nil
{
...
...
@@ -82,7 +83,6 @@ func inputNodeManagerChan(manager *NodeManager, nodeManagerClient *models.NodeMa
nodeManagerClient
.
Status
=
true
nodeManagerClient
.
Client
=
serviceClient
nodeManagerClientChan
<-
nodeManagerClient
usedNodeManagerClient
=
append
(
usedNodeManagerClient
,
nodeManagerClient
)
manager
.
IsUsed
=
true
return
true
}
nm/task_msg.go
View file @
19d610ea
...
...
@@ -2,7 +2,6 @@ package nm
import
(
"bytes"
"encoding/base64"
"encoding/json"
"example.com/m/conf"
"example.com/m/log"
...
...
@@ -272,20 +271,22 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage)
default
:
log
.
Error
(
"data is unknown type"
,
v
)
}
if
base64ImageStr
!=
""
&&
utils
.
IsBase64ImageStr
(
base64ImageStr
)
{
containerRespOutput
:=
strings
.
SplitN
(
base64ImageStr
,
","
,
2
)
imageStr
:=
containerRespOutput
[
1
]
queryString
:=
utils
.
MatchFileCacheQueryString
(
taskParam
.
Headers
,
taskCmd
.
ImageName
,
t
.
DockerOp
.
ModelsInfo
,
containerRespOutput
[
0
])
prefix
:=
strings
.
Split
(
strings
.
Split
(
containerRespOutput
[
0
],
";"
)[
0
],
":"
)[
1
]
ossUri
,
err
:=
t
.
uploadOSS
(
taskMsg
.
TaskId
,
queryString
,
imageStr
,
prefix
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"upload image into file cache failed"
)
return
}
log
.
WithField
(
"uri"
,
ossUri
)
.
Info
(
"upload image OSS successful"
)
if
ossUri
!=
""
{
taskExecResult
.
TaskHttpStatusCode
=
models
.
RedirectCode
post
.
Header
.
Set
(
"Location"
,
ossUri
)
if
base64ImageStr
!=
""
{
isBase64
,
decodeByte
,
respFormat
,
suffix
:=
utils
.
IsBase64ImageStr
(
base64ImageStr
)
if
isBase64
{
queryString
:=
utils
.
MatchFileCacheQueryString
(
taskParam
.
Headers
,
taskCmd
.
ImageName
,
t
.
DockerOp
.
ModelsInfo
,
respFormat
)
ossUri
,
err
:=
t
.
uploadOSS
(
taskMsg
.
TaskId
,
queryString
,
decodeByte
,
suffix
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"upload image into file cache failed"
)
return
}
log
.
WithField
(
"uri"
,
ossUri
)
.
Info
(
"upload image OSS successful"
)
if
ossUri
!=
""
{
taskExecResult
.
TaskHttpStatusCode
=
models
.
RedirectCode
post
.
Header
.
Set
(
"Location"
,
ossUri
)
}
}
else
{
taskExecResult
.
TaskRespBody
=
respBody
}
}
else
{
taskExecResult
.
TaskRespBody
=
respBody
...
...
@@ -371,21 +372,15 @@ func (t *TaskHandler) foundImageIsRunning(imageId string) (bool, string, uint16)
return
false
,
""
,
0
}
func
(
t
*
TaskHandler
)
uploadOSS
(
taskId
string
,
queries
string
,
base64Image
,
pre
fix
string
)
(
string
,
error
)
{
func
(
t
*
TaskHandler
)
uploadOSS
(
taskId
string
,
queries
string
,
decodedImage
[]
byte
,
suf
fix
string
)
(
string
,
error
)
{
var
requestBody
bytes
.
Buffer
writer
:=
multipart
.
NewWriter
(
&
requestBody
)
// 创建文件表单字段
fileField
,
err
:=
writer
.
CreateFormFile
(
"file"
,
fmt
.
Sprintf
(
"%s.%s"
,
taskId
,
pre
fix
))
fileField
,
err
:=
writer
.
CreateFormFile
(
"file"
,
fmt
.
Sprintf
(
"%s.%s"
,
taskId
,
suf
fix
))
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"Error creating form file"
)
return
""
,
err
}
// 将 base64 解码后的内容复制到表单字段
decodedImage
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
base64Image
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"Error decoding base64 image"
)
return
""
,
err
}
_
,
err
=
io
.
Copy
(
fileField
,
bytes
.
NewReader
(
decodedImage
))
//_, err = io.Copy(fileField, strings.NewReader(base64Image))
if
err
!=
nil
{
...
...
utils/util.go
View file @
19d610ea
...
...
@@ -96,14 +96,28 @@ func readPrivateKey() (*ecdsa.PrivateKey, error) {
}
// IsBase64ImageStr 检查字符串是否是 Base64 编码的图像数据
func
IsBase64ImageStr
(
imageStr
string
)
bool
{
func
IsBase64ImageStr
(
imageStr
string
)
(
bool
,
[]
byte
,
string
,
string
)
{
// 移除可能的前缀(如 "data:image/png;base64,")
imageStr
=
strings
.
SplitN
(
imageStr
,
","
,
2
)[
1
]
_
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
imageStr
)
return
err
==
nil
imageStrArr
:=
strings
.
SplitN
(
imageStr
,
","
,
2
)
base64CodePrefix
:=
""
base64Code
:=
""
if
len
(
imageStrArr
)
==
1
{
base64Code
=
imageStrArr
[
0
]
base64CodePrefix
=
"data:image/png;base64"
}
else
{
base64CodePrefix
=
imageStrArr
[
0
]
base64Code
=
imageStrArr
[
1
]
}
decodeBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
base64Code
)
if
err
!=
nil
{
return
false
,
nil
,
""
,
""
}
formatStr
:=
strings
.
Split
(
strings
.
Split
(
base64CodePrefix
,
";"
)[
0
],
":"
)[
1
]
suffix
:=
strings
.
Split
(
formatStr
,
"/"
)[
1
]
return
true
,
decodeBytes
,
formatStr
,
suffix
}
func
MatchFileCacheQueryString
(
params
map
[
string
][]
string
,
taskImageName
string
,
modelsInfo
[]
*
models
.
ModelInfo
,
forma
tType
string
)
string
{
func
MatchFileCacheQueryString
(
params
map
[
string
][]
string
,
taskImageName
string
,
modelsInfo
[]
*
models
.
ModelInfo
,
conten
tType
string
)
string
{
values
:=
url
.
Values
{}
isExistFileExpires
:=
false
for
key
,
value
:=
range
params
{
...
...
@@ -126,7 +140,6 @@ func MatchFileCacheQueryString(params map[string][]string, taskImageName string,
if
!
isModelExistFileExpires
{
values
.
Add
(
models
.
ResultFileExpiresDB
,
"600"
)
}
contentType
:=
strings
.
Split
(
strings
.
Split
(
formatType
,
";"
)[
0
],
":"
)[
1
]
values
.
Add
(
models
.
ContentType
,
contentType
)
return
values
.
Encode
()
}
...
...
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