mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-04 00:15:09 +03:00
0afa11ddff
Replace full inbound/client-list downloads on cold remote ID lookups with an owner-scoped six-field catalog projected directly from the database. Coalesce concurrent catalog refreshes per remote while preserving independent caller cancellation and rejecting stale ID mappings after topology mutations. Seed reconciliation from the catalog, create missing inbounds directly, preserve prefixed/adopted aliases and invalidate pushed state when remote IDs change. Avoid invalidating catalog generations on unchanged-ID settings pushes. Retain client-membership-aware reconciliation state and legacy full-list fallback only on HTTP 404/405. Cover permissions, query projection, concurrent refresh/cancellation, deletion/recreation, reconciliation request counts and mixed-version node compatibility. Integrated CI and Docs CI passed, including race, node E2E and PostgreSQL catalog projection. Synthetic response-size comparison is not a production latency benchmark. Fixes #7303.
235 lines
5.8 KiB
Go
235 lines
5.8 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
root := flag.String("root", ".", "repository root containing internal/database/model and internal/web/entity")
|
|
outDir := flag.String("out", "frontend/src/generated", "output directory relative to root")
|
|
flag.Parse()
|
|
|
|
if err := run(*root, *outDir); err != nil {
|
|
fmt.Fprintln(os.Stderr, "openapigen:", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run(root, outDir string) error {
|
|
requests := []packageRequest{
|
|
{
|
|
Path: resolveRel(root, "internal/database/model"),
|
|
StructAllow: setOf(
|
|
"User",
|
|
"Inbound",
|
|
"FallbackParentInfo",
|
|
"OutboundTraffics",
|
|
"InboundClientIps",
|
|
"ApiToken",
|
|
"HistoryOfSeeders",
|
|
"Setting",
|
|
"Node",
|
|
"ClientReverse",
|
|
"WireguardDevice",
|
|
"Client",
|
|
"ClientRecord",
|
|
"ClientInbound",
|
|
"InboundFallback",
|
|
"Host",
|
|
"SubBalancer",
|
|
"ClientTrafficWindow",
|
|
"ClientChangeLog",
|
|
),
|
|
AliasAllow: setOf("Protocol"),
|
|
Overrides: map[string][]walkOverride{
|
|
"Inbound": {
|
|
{Field: "Settings", Kind: KindAny},
|
|
{Field: "StreamSettings", Kind: KindAny},
|
|
{Field: "Sniffing", Kind: KindAny},
|
|
},
|
|
"Client": {
|
|
{Field: "KeepAlive", Type: TypeRef{Kind: KindUnion, Variants: []TypeRef{{Kind: KindInt}, {Kind: KindString}}}},
|
|
},
|
|
"ClientRecord": {
|
|
{Field: "KeepAlive", Type: TypeRef{Kind: KindUnion, Variants: []TypeRef{{Kind: KindInt}, {Kind: KindString}}}},
|
|
{Field: "Reverse", Kind: KindAny},
|
|
},
|
|
"InboundClientIps": {
|
|
{Field: "Ips", Kind: KindAny},
|
|
},
|
|
"Host": {
|
|
{Field: "MuxParams", Kind: KindAny},
|
|
{Field: "SockoptParams", Kind: KindAny},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/web/entity"),
|
|
StructAllow: setOf(
|
|
"Msg",
|
|
"AllSetting",
|
|
"AllSettingView",
|
|
"HostGroup",
|
|
"PanelRestart",
|
|
),
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/xray"),
|
|
StructAllow: setOf(
|
|
"ClientTraffic",
|
|
"Traffic",
|
|
),
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/xray/geodata"),
|
|
StructAllow: setOf(
|
|
"GeoFile",
|
|
"GeoCategory",
|
|
"GeoEntry",
|
|
"GeoCategoryPage",
|
|
"GeoEntryPage",
|
|
),
|
|
AliasAllow: setOf("GeoKind"),
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/web/runtime"),
|
|
StructAllow: setOf("NodeSnapshotAttachment", "NodeSnapshotStructure", "NodeInboundTraffic", "NodeClientTraffic", "NodeTrafficSnapshotV1", "RemoteInboundOption"),
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/web/service"),
|
|
StructAllow: setOf(
|
|
"InboundOption",
|
|
"NetworkInterfaceOption",
|
|
"NetworkInterfacesResponse",
|
|
"NetworkTrafficSelection",
|
|
"Status",
|
|
"HappLinkResult",
|
|
"ClientSlim",
|
|
"ClientNodeApplyResponse",
|
|
"ClientNodeApplyOutcome",
|
|
"ClientRenewalPreviewRequest",
|
|
"ClientRenewalPreview",
|
|
"ClientPageResponse",
|
|
"AttachCandidate",
|
|
"AttachCandidatePage",
|
|
"AttachSelectionResult",
|
|
"BulkAdjustResult",
|
|
"BulkAdjustReport",
|
|
"BulkAttachResult",
|
|
"BulkDetachResult",
|
|
"BulkCreateResult",
|
|
"BulkCreateReport",
|
|
"BulkDeleteResult",
|
|
"BulkDeleteReport",
|
|
"BulkSetEnableResult",
|
|
"BulkSetEnableReport",
|
|
"BulkExternalLinksResult",
|
|
"ExternalLinkInput",
|
|
"ClientsSummary",
|
|
"InboundTrafficSummary",
|
|
"LogEntry",
|
|
"NewUUIDResponse",
|
|
"MLDSA65Response",
|
|
"MLKEM768Response",
|
|
"NodeMutationRequest",
|
|
"NodeView",
|
|
"ProbeResultUI",
|
|
"RealityScanResult",
|
|
"RealityWatchEntry",
|
|
"RealityWatchEvent",
|
|
"RealityWatchStatus",
|
|
"GeodataTokenIssue",
|
|
"AmneziaWGLogs",
|
|
"PeerActivity",
|
|
"HwidSlotStatus",
|
|
"ClientUsageHistory",
|
|
"ClientNodeUsage",
|
|
"SubBalancerWithProblems",
|
|
"SubBalancerProblem",
|
|
),
|
|
AliasAllow: setOf("ProcessState"),
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/web/service/panel"),
|
|
StructAllow: setOf("ApiTokenView", "PanelUpdateStatus", "Sponsor", "SponsorList"),
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/web/controller"),
|
|
StructAllow: setOf("TgBotCapabilities", "AttachJobStatus"),
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/amneziawg"),
|
|
StructAllow: setOf("ServerSettings"),
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/amneziawgkern"),
|
|
StructAllow: setOf("Readiness", "Blocker"),
|
|
AliasAllow: setOf("BlockerCode"),
|
|
},
|
|
{
|
|
Path: resolveRel(root, "internal/tuic"),
|
|
StructAllow: setOf("TuicServerSettings", "TuicClientSettings"),
|
|
},
|
|
}
|
|
|
|
schemas, aliases, err := walkPackages(requests)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
schemas = flattenEmbedded(schemas)
|
|
|
|
if len(schemas) == 0 {
|
|
return fmt.Errorf("no schemas produced; nothing to write")
|
|
}
|
|
|
|
target := filepath.Join(root, outDir)
|
|
if err := os.MkdirAll(target, 0o755); err != nil {
|
|
return err
|
|
}
|
|
|
|
zodBuf := &bytes.Buffer{}
|
|
if err := emitZod(zodBuf, schemas, aliases); err != nil {
|
|
return err
|
|
}
|
|
typesBuf := &bytes.Buffer{}
|
|
if err := emitTypes(typesBuf, schemas, aliases); err != nil {
|
|
return err
|
|
}
|
|
examplesBuf := &bytes.Buffer{}
|
|
if err := emitExamples(examplesBuf, schemas, aliases); err != nil {
|
|
return err
|
|
}
|
|
schemasBuf := &bytes.Buffer{}
|
|
if err := emitJSONSchema(schemasBuf, schemas, aliases); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := os.WriteFile(filepath.Join(target, "zod.ts"), zodBuf.Bytes(), 0o644); err != nil {
|
|
return err
|
|
}
|
|
if err := os.WriteFile(filepath.Join(target, "types.ts"), typesBuf.Bytes(), 0o644); err != nil {
|
|
return err
|
|
}
|
|
if err := os.WriteFile(filepath.Join(target, "examples.ts"), examplesBuf.Bytes(), 0o644); err != nil {
|
|
return err
|
|
}
|
|
if err := os.WriteFile(filepath.Join(target, "schemas.ts"), schemasBuf.Bytes(), 0o644); err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("openapigen: wrote %d schemas to %s\n", len(schemas), target)
|
|
return nil
|
|
}
|
|
|
|
func setOf(names ...string) map[string]bool {
|
|
m := make(map[string]bool, len(names))
|
|
for _, n := range names {
|
|
m[n] = true
|
|
}
|
|
return m
|
|
}
|