fix(inbounds): accept v2.x client fields on inbound import

Panels up to v2.x stored a client's tgId as a string, "" when unset. The
startup migration heals copies already in the database, but an exported
inbound imported into a current panel goes straight to AddInbound, whose
typed client parse failed with "cannot unmarshal string into Go struct
field .0.tgId of type int64", so every such import was refused.

AddInbound now runs the legacy normalizer the clients-table seeder already
used (moved from database to model so both share it) over the incoming
settings before parsing them. String numbers become integers and empty ones
are dropped, and the settings are stored in that shape. The same applies to
/inbounds/add callers still sending the old types.

The seeder change is a pure move; the PostgreSQL lane was not run (no
Docker on this host) and is left to CI.

Closes #6663
This commit is contained in:
MHSanaei
2026-09-27 18:28:07 +02:00
parent 092cbd55e4
commit 15d82a5e47
5 changed files with 98 additions and 27 deletions
@@ -0,0 +1,27 @@
package model
import (
"strconv"
"strings"
)
var legacyClientIntFields = []string{"tgId", "limitIp", "totalGB", "expiryTime", "reset", "created_at", "updated_at"}
// NormalizeLegacyClientFields turns the string numbers older panels stored on a
// client object into integers; an empty or unparseable value is dropped.
func NormalizeLegacyClientFields(obj map[string]any) (changed bool) {
for _, key := range legacyClientIntFields {
s, ok := obj[key].(string)
if !ok {
continue
}
changed = true
trimmed := strings.ReplaceAll(strings.TrimSpace(s), " ", "")
if n, err := strconv.ParseInt(trimmed, 10, 64); err == nil {
obj[key] = n
} else {
delete(obj, key)
}
}
return changed
}