Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
548581a0
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
9 个月 前同步成功
通知
11
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zentaoatf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
548581a0
编写于
7月 25, 2022
作者:
Z
zhaoke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* Add auto select proxy
上级
e21d0222
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
69 addition
and
10 deletion
+69
-10
internal/server/modules/v1/controller/proxy.go
internal/server/modules/v1/controller/proxy.go
+15
-0
internal/server/modules/v1/index/proxy.go
internal/server/modules/v1/index/proxy.go
+1
-0
internal/server/modules/v1/service/proxy.go
internal/server/modules/v1/service/proxy.go
+9
-0
pkg/lib/http/http.go
pkg/lib/http/http.go
+5
-4
ui/src/views/exec/LogList.vue
ui/src/views/exec/LogList.vue
+5
-6
ui/src/views/proxy/service.ts
ui/src/views/proxy/service.ts
+6
-0
ui/src/views/workspace/FormWorkspace.vue
ui/src/views/workspace/FormWorkspace.vue
+4
-0
ui/src/views/workspace/service.ts
ui/src/views/workspace/service.ts
+24
-0
未找到文件。
internal/server/modules/v1/controller/proxy.go
浏览文件 @
548581a0
...
...
@@ -93,3 +93,18 @@ func (c *ProxyCtrl) Delete(ctx iris.Context) {
ctx
.
JSON
(
c
.
SuccessResp
(
nil
))
}
func
(
c
*
ProxyCtrl
)
CheckConnect
(
ctx
iris
.
Context
)
{
id
,
err
:=
ctx
.
Params
()
.
GetInt
(
"id"
)
if
err
!=
nil
{
ctx
.
JSON
(
c
.
ErrResp
(
commConsts
.
CommErr
,
err
.
Error
()))
return
}
path
,
err
:=
c
.
ProxyService
.
CheckConnect
(
uint
(
id
))
if
err
!=
nil
{
ctx
.
JSON
(
c
.
SuccessResp
(
iris
.
Map
{
"status"
:
"fail"
,
"path"
:
path
}))
return
}
ctx
.
JSON
(
c
.
SuccessResp
(
iris
.
Map
{
"status"
:
"ok"
,
"path"
:
path
}))
}
internal/server/modules/v1/index/proxy.go
浏览文件 @
548581a0
...
...
@@ -22,6 +22,7 @@ func (m *ProxyModule) Party() module.WebModule {
index
.
Get
(
"/"
,
m
.
ProxyCtrl
.
List
)
.
Name
=
"列表"
index
.
Get
(
"/{id:int}"
,
m
.
ProxyCtrl
.
Get
)
.
Name
=
"详情"
index
.
Get
(
"/{id:int}/check"
,
m
.
ProxyCtrl
.
CheckConnect
)
.
Name
=
"测试连接可用"
index
.
Post
(
"/"
,
m
.
ProxyCtrl
.
Create
)
.
Name
=
"新建"
index
.
Put
(
"/{id:int}"
,
m
.
ProxyCtrl
.
Update
)
.
Name
=
"更新"
index
.
Delete
(
"/{id:int}"
,
m
.
ProxyCtrl
.
Delete
)
.
Name
=
"删除"
...
...
internal/server/modules/v1/service/proxy.go
浏览文件 @
548581a0
...
...
@@ -64,3 +64,12 @@ func (s *ProxyService) CheckServer(url string) (err error) {
_
,
err
=
httpUtils
.
Get
(
url
+
"api/v1/heartbeat"
)
return
}
func
(
s
*
ProxyService
)
CheckConnect
(
id
uint
)
(
path
string
,
err
error
)
{
proxy
,
err
:=
s
.
Get
(
id
)
if
err
!=
nil
{
return
path
,
errors
.
New
(
"proxy not found"
)
}
_
,
err
=
httpUtils
.
Get
(
proxy
.
Path
+
"api/v1/heartbeat"
)
return
proxy
.
Path
,
err
}
pkg/lib/http/http.go
浏览文件 @
548581a0
...
...
@@ -3,13 +3,14 @@ package httpUtils
import
(
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"strings"
"github.com/bitly/go-simplejson"
commConsts
"github.com/easysoft/zentaoatf/internal/pkg/consts"
logUtils
"github.com/easysoft/zentaoatf/pkg/lib/log"
"github.com/fatih/color"
"io/ioutil"
"net/http"
"strings"
)
func
Get
(
url
string
)
(
ret
[]
byte
,
err
error
)
{
...
...
@@ -32,13 +33,13 @@ func Get(url string) (ret []byte, err error) {
}
resp
,
err
:=
client
.
Do
(
req
)
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
if
commConsts
.
Verbose
{
logUtils
.
Infof
(
color
.
RedString
(
"get request failed, error: %s."
,
err
.
Error
()))
}
return
}
defer
resp
.
Body
.
Close
()
if
!
IsSuccessCode
(
resp
.
StatusCode
)
{
if
commConsts
.
Verbose
{
...
...
ui/src/views/exec/LogList.vue
浏览文件 @
548581a0
...
...
@@ -66,20 +66,18 @@ import Icon from '@/components/Icon.vue';
import
{
momentTime
}
from
"
@/utils/datetime
"
;
import
{
isInArray
}
from
"
@/utils/array
"
;
import
{
StateType
as
GlobalStateType
}
from
"
@/store/global
"
;
import
{
get
as
getWorkspace
,
uploadToProxy
}
from
"
@/views/workspace/service
"
;
import
{
get
as
getWorkspace
,
uploadToProxy
,
autoSelectProxy
}
from
"
@/views/workspace/service
"
;
import
{
mvLog
}
from
"
@/views/result/service
"
;
import
{
key
}
from
"
localforage
"
;
const
{
t
}
=
useI18n
();
const
store
=
useStore
<
{
global
:
GlobalStateType
,
Zentao
:
ZentaoData
,
WebSocket
:
WebSocketData
,
Exec
:
ExecStatus
,
proxy
:
ProxyData
,
workspace
:
WorkspaceData
}
>
();
const
store
=
useStore
<
{
global
:
GlobalStateType
,
Zentao
:
ZentaoData
,
WebSocket
:
WebSocketData
,
Exec
:
ExecStatus
,
workspace
:
WorkspaceData
}
>
();
const
logContentExpand
=
computed
<
boolean
>
(()
=>
store
.
state
.
global
.
logContentExpand
);
store
.
dispatch
(
"
proxy/fetchProxies
"
);
const
currSite
=
computed
<
any
>
(()
=>
store
.
state
.
Zentao
.
currSite
);
const
currProduct
=
computed
<
any
>
(()
=>
store
.
state
.
Zentao
.
currProduct
);
const
wsStatus
=
computed
<
any
>
(()
=>
store
.
state
.
WebSocket
.
connStatus
);
const
isRunning
=
computed
<
any
>
(()
=>
store
.
state
.
Exec
.
isRunning
);
const
proxyMap
=
computed
<
any
>
(()
=>
store
.
state
.
proxy
.
proxyMap
);
const
currentWorkspace
=
ref
({}
as
any
);
const
cachedExecData
=
ref
({})
...
...
@@ -252,7 +250,7 @@ const exec = async (data: any) => {
console
.
log
(
'
exec testing
'
,
msg
)
currentWorkspace
.
value
=
{};
let
workspaceInfo
=
{};
let
workspaceInfo
=
{}
as
any
;
if
(
workspaceId
>
0
){
workspaceInfo
=
await
getWorkspace
(
workspaceId
)
}
...
...
@@ -275,7 +273,8 @@ const exec = async (data: any) => {
}
})
}
WebSocket
.
sentMsg
(
settings
.
webSocketRoom
,
JSON
.
stringify
(
msg
),
proxyMap
.
value
[
workspaceInfo
?.
data
?.
proxy_id
])
const
proxyPath
=
await
autoSelectProxy
(
workspaceInfo
.
data
);
WebSocket
.
sentMsg
(
settings
.
webSocketRoom
,
JSON
.
stringify
(
msg
),
proxyPath
)
}
const
logLevel
=
ref
(
'
result
'
)
...
...
ui/src/views/proxy/service.ts
浏览文件 @
548581a0
...
...
@@ -30,4 +30,10 @@ export async function removeProxy(id: number): Promise<any> {
url
:
`/
${
apiPath
}
/
${
id
}
`
,
method
:
'
delete
'
,
});
}
export
async
function
checkProxy
(
seq
:
number
):
Promise
<
any
>
{
return
request
({
url
:
`/
${
apiPath
}
/
${
seq
}
/check`
});
}
\ No newline at end of file
ui/src/views/workspace/FormWorkspace.vue
浏览文件 @
548581a0
...
...
@@ -155,6 +155,9 @@ const loadInfo = async () => {
proxy_id
:
info
.
value
.
proxy_id
,
};
proxyList
.
value
=
info
.
value
.
proxies
.
split
(
'
,
'
);
proxyList
.
value
.
forEach
((
item
,
index
)
=>
{
proxyList
.
value
[
index
]
=
parseInt
(
item
);
});
selectType
()
}
});
...
...
@@ -204,6 +207,7 @@ const emit = defineEmits<{
}
>
();
const
submit
=
()
=>
{
proxyList
.
value
=
[...
new
Set
(
proxyList
.
value
)]
modelRef
.
value
.
proxies
=
proxyList
.
value
.
join
(
'
,
'
);
if
(
validate
())
{
emit
(
"
submit
"
,
modelRef
.
value
);
...
...
ui/src/views/workspace/service.ts
浏览文件 @
548581a0
import
request
from
'
@/utils/request
'
;
import
{
QueryParams
}
from
'
@/types/data.d
'
;
import
{
checkProxy
}
from
"
@/views/proxy/service
"
;
const
apiPath
=
'
workspaces
'
;
...
...
@@ -48,4 +49,27 @@ export async function uploadToProxy(params: any): Promise<any> {
method
:
'
POST
'
,
data
:
params
,
});
}
export
async
function
autoSelectProxy
(
workspace
)
{
const
proxies
=
workspace
.
proxies
.
split
(
'
,
'
);
const
handleList
=
[]
as
any
;
let
localIndex
=
proxies
.
length
;
proxies
.
forEach
((
proxy
,
index
)
=>
{
if
(
proxy
>
0
)
{
handleList
.
push
(
checkProxy
(
proxy
)
);
}
else
{
localIndex
=
index
;
}
})
const
resp
=
await
Promise
.
all
(
handleList
);
let
proxyPath
=
''
;
resp
.
forEach
((
item
:
any
,
index
)
=>
{
if
(
proxyPath
==
''
&&
item
.
data
.
status
==
'
ok
'
&&
index
<
localIndex
){
proxyPath
=
item
.
data
.
path
;
}
})
return
proxyPath
?
proxyPath
:
'
local
'
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录