Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 关闭代理同时更新 Docker 代理 #7028

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/app/service/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (u *DockerService) UpdateConf(req dto.SettingUpdate) error {
}
daemonMap["proxies"] = proxies
}
case "socks5-proxy":
case "socks5-proxy", "close-proxy":
delete(daemonMap, "proxies")
if len(req.Value) > 0 {
proxies := map[string]interface{}{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个代码是关于docker服务更新配置的部分,但是没有找到具体的修改和优化之处。代码只是简单的删除一个map的值,并且如果输入参数不为空,就生成一个新的proxy信息映射map。可以简化为以下方式:

func UpdateConf(req dto.SettingUpdate) error {

}

var proxyInfo []string

if !req.Empty() && req.StringMap != nil { // 如果非空并且有字符串key-value对...
	for k, v := range req.Value {
		switch key := strings.ToLower(k); key { // 检查字符串是否包含"socks5"或"island"

以上就是代码中的主要改进的地方以及可能的问题。

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/views/setting/panel/proxy/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ const submitChangePassword = async (formEl: FormInstance | undefined) => {
loading.value = false;
emit('search');
passwordVisible.value = false;
if (isClose) {
await updateDaemonJson(`${form.proxyType}-proxy`, '');
}
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
})
.catch(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个代码看起来应该没有明显的错误或不恰当之处,但是有一个优化建议:为了保持一致性的响应式设计(responsive design),可以将emit('search')替换为一个函数,并且在这个函数中传入一个表示请求状态的状态更新消息。这是一个很小的改进,因为这是个基础问题而并非是复杂的代码结构修改。

下面是经过修订后的代码示例:

const submitChangePassword = async (formEl?: FormInstance | undefined, dispatch?) => {
    // ...

}

// 假设需要在调用成功后发送的消息类型
function handleOperationSuccess(state?: string) {

}

现在我们传递了一个state参数到操作成功的回调函数handleOperationSuccess。请注意,在实际应用中,我们需要提供正确的数据源来设置相应的state值。

submitChangePassword(
    formEl,
    (dispatch: any) => (
        handleOperationSuccess(form.proxyType == 'serverProxy' ? 'proxyUpdateComplete': 'noData')
    )
)

这将使组件能正确地接收和处理其生命周期钩子中的信息流变化,并确保所有相关的状态通信都得到了应有的管理。

Expand Down
Loading