Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
2e59998c
Commit
2e59998c
authored
Dec 19, 2025
by
shaw
Browse files
fix: 代理表单字段保存时自动去除前后空格
前后端同时处理,防止因意外空格导致代理连接失败
parent
32e58115
Changes
2
Show whitespace changes
Inline
Side-by-side
backend/internal/handler/admin/proxy_handler.go
View file @
2e59998c
...
...
@@ -2,6 +2,7 @@ package admin
import
(
"strconv"
"strings"
"sub2api/internal/pkg/response"
"sub2api/internal/service"
...
...
@@ -112,12 +113,12 @@ func (h *ProxyHandler) Create(c *gin.Context) {
}
proxy
,
err
:=
h
.
adminService
.
CreateProxy
(
c
.
Request
.
Context
(),
&
service
.
CreateProxyInput
{
Name
:
req
.
Name
,
Protocol
:
req
.
Protocol
,
Host
:
req
.
Host
,
Name
:
strings
.
TrimSpace
(
req
.
Name
)
,
Protocol
:
strings
.
TrimSpace
(
req
.
Protocol
)
,
Host
:
strings
.
TrimSpace
(
req
.
Host
)
,
Port
:
req
.
Port
,
Username
:
req
.
Username
,
Password
:
req
.
Password
,
Username
:
strings
.
TrimSpace
(
req
.
Username
)
,
Password
:
strings
.
TrimSpace
(
req
.
Password
)
,
})
if
err
!=
nil
{
response
.
BadRequest
(
c
,
"Failed to create proxy: "
+
err
.
Error
())
...
...
@@ -143,13 +144,13 @@ func (h *ProxyHandler) Update(c *gin.Context) {
}
proxy
,
err
:=
h
.
adminService
.
UpdateProxy
(
c
.
Request
.
Context
(),
proxyID
,
&
service
.
UpdateProxyInput
{
Name
:
req
.
Name
,
Protocol
:
req
.
Protocol
,
Host
:
req
.
Host
,
Name
:
strings
.
TrimSpace
(
req
.
Name
)
,
Protocol
:
strings
.
TrimSpace
(
req
.
Protocol
)
,
Host
:
strings
.
TrimSpace
(
req
.
Host
)
,
Port
:
req
.
Port
,
Username
:
req
.
Username
,
Password
:
req
.
Password
,
Status
:
req
.
Status
,
Username
:
strings
.
TrimSpace
(
req
.
Username
)
,
Password
:
strings
.
TrimSpace
(
req
.
Password
)
,
Status
:
strings
.
TrimSpace
(
req
.
Status
)
,
})
if
err
!=
nil
{
response
.
InternalError
(
c
,
"Failed to update proxy: "
+
err
.
Error
())
...
...
@@ -263,8 +264,14 @@ func (h *ProxyHandler) BatchCreate(c *gin.Context) {
skipped
:=
0
for
_
,
item
:=
range
req
.
Proxies
{
// Trim all string fields
host
:=
strings
.
TrimSpace
(
item
.
Host
)
protocol
:=
strings
.
TrimSpace
(
item
.
Protocol
)
username
:=
strings
.
TrimSpace
(
item
.
Username
)
password
:=
strings
.
TrimSpace
(
item
.
Password
)
// Check for duplicates (same host, port, username, password)
exists
,
err
:=
h
.
adminService
.
CheckProxyExists
(
c
.
Request
.
Context
(),
item
.
H
ost
,
item
.
Port
,
item
.
U
sername
,
item
.
P
assword
)
exists
,
err
:=
h
.
adminService
.
CheckProxyExists
(
c
.
Request
.
Context
(),
h
ost
,
item
.
Port
,
u
sername
,
p
assword
)
if
err
!=
nil
{
response
.
InternalError
(
c
,
"Failed to check proxy existence: "
+
err
.
Error
())
return
...
...
@@ -278,11 +285,11 @@ func (h *ProxyHandler) BatchCreate(c *gin.Context) {
// Create proxy with default name
_
,
err
=
h
.
adminService
.
CreateProxy
(
c
.
Request
.
Context
(),
&
service
.
CreateProxyInput
{
Name
:
"default"
,
Protocol
:
item
.
P
rotocol
,
Host
:
item
.
H
ost
,
Protocol
:
p
rotocol
,
Host
:
h
ost
,
Port
:
item
.
Port
,
Username
:
item
.
U
sername
,
Password
:
item
.
P
assword
,
Username
:
u
sername
,
Password
:
p
assword
,
})
if
err
!=
nil
{
// If creation fails due to duplicate, count as skipped
...
...
frontend/src/views/admin/ProxiesView.vue
View file @
2e59998c
...
...
@@ -647,10 +647,10 @@ const parseProxyUrl = (line: string): {
return
{
protocol
:
protocol
.
toLowerCase
()
as
ProxyProtocol
,
host
,
host
:
host
.
trim
()
,
port
:
portNum
,
username
:
username
||
''
,
password
:
password
||
''
username
:
username
?.
trim
()
||
''
,
password
:
password
?.
trim
()
||
''
}
}
...
...
@@ -714,9 +714,12 @@ const handleCreateProxy = async () => {
submitting
.
value
=
true
try
{
await
adminAPI
.
proxies
.
create
({
...
createForm
,
username
:
createForm
.
username
||
null
,
password
:
createForm
.
password
||
null
name
:
createForm
.
name
.
trim
(),
protocol
:
createForm
.
protocol
,
host
:
createForm
.
host
.
trim
(),
port
:
createForm
.
port
,
username
:
createForm
.
username
.
trim
()
||
null
,
password
:
createForm
.
password
.
trim
()
||
null
})
appStore
.
showSuccess
(
t
(
'
admin.proxies.proxyCreated
'
))
closeCreateModal
()
...
...
@@ -752,17 +755,18 @@ const handleUpdateProxy = async () => {
submitting
.
value
=
true
try
{
const
updateData
:
any
=
{
name
:
editForm
.
name
,
name
:
editForm
.
name
.
trim
()
,
protocol
:
editForm
.
protocol
,
host
:
editForm
.
host
,
host
:
editForm
.
host
.
trim
()
,
port
:
editForm
.
port
,
username
:
editForm
.
username
||
null
,
username
:
editForm
.
username
.
trim
()
||
null
,
status
:
editForm
.
status
}
// Only include password if it was changed
if
(
editForm
.
password
)
{
updateData
.
password
=
editForm
.
password
const
trimmedPassword
=
editForm
.
password
.
trim
()
if
(
trimmedPassword
)
{
updateData
.
password
=
trimmedPassword
}
await
adminAPI
.
proxies
.
update
(
editingProxy
.
value
.
id
,
updateData
)
...
...
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