Skip to content

Commit 7fd80ef

Browse files
committed
fix: logging middleware context
1 parent 1626c61 commit 7fd80ef

File tree

12 files changed

+779
-499
lines changed

12 files changed

+779
-499
lines changed

api/audit/middleware.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package audit
2+
3+
import (
4+
"github.com/0xJacky/Nginx-UI/model"
5+
"github.com/gin-gonic/gin"
6+
"github.com/spf13/cast"
7+
"github.com/uozi-tech/cosy/logger"
8+
)
9+
10+
func LoggingMiddleware() gin.HandlerFunc {
11+
return logger.AuditMiddleware(func(c *gin.Context, logMap map[string]string) {
12+
var userId uint64
13+
if user, ok := c.Get("user"); ok {
14+
userId = user.(*model.User).ID
15+
}
16+
logMap["user_id"] = cast.ToString(userId)
17+
})
18+
}

api/certificate/certificate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/go-acme/lego/v4/certcrypto"
1515
"github.com/spf13/cast"
1616
"github.com/uozi-tech/cosy"
17+
"github.com/uozi-tech/cosy/logger"
1718
)
1819

1920
type APICertificate struct {
@@ -57,6 +58,8 @@ func Transformer(certModel *model.Cert) (certificate *APICertificate) {
5758
}
5859

5960
func GetCertList(c *gin.Context) {
61+
s := logger.NewSessionLogger(c)
62+
s.Info("GetCertList")
6063
cosy.Core[model.Cert](c).SetFussy("name", "domain").
6164
SetTransformer(func(m *model.Cert) any {
6265
info, _ := cert.GetCertInfo(m.SSLCertificatePath)

app/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@fingerprintjs/fingerprintjs": "^4.6.2",
1919
"@formkit/auto-animate": "^0.8.4",
2020
"@simplewebauthn/browser": "^13.1.2",
21-
"@uozi-admin/curd": "^4.15.5",
21+
"@uozi-admin/curd": "^4.15.8",
2222
"@uozi-admin/request": "^2.8.4",
2323
"@vue/reactivity": "^3.5.21",
2424
"@vue/shared": "^3.5.21",
@@ -30,7 +30,7 @@
3030
"@xterm/addon-fit": "^0.10.0",
3131
"@xterm/xterm": "^5.5.0",
3232
"ant-design-vue": "^4.2.6",
33-
"apexcharts": "^5.3.4",
33+
"apexcharts": "^5.3.5",
3434
"axios": "^1.11.0",
3535
"dayjs": "^1.11.18",
3636
"echarts": "^6.0.0",
@@ -48,7 +48,7 @@
4848
"splitpanes": "^4.0.4",
4949
"sse.js": "^2.7.0",
5050
"universal-cookie": "^8.0.1",
51-
"unocss": "^66.5.0",
51+
"unocss": "^66.5.1",
5252
"uuid": "^11.1.0",
5353
"vite-plugin-build-id": "0.5.0",
5454
"vue": "^3.5.21",
@@ -62,7 +62,7 @@
6262
"vuedraggable": "^4.1.0"
6363
},
6464
"devDependencies": {
65-
"@antfu/eslint-config": "^5.2.2",
65+
"@antfu/eslint-config": "^5.3.0",
6666
"@iconify-json/fa": "1.2.2",
6767
"@iconify-json/tabler": "^1.2.22",
6868
"@iconify/tools": "^4.1.2",
@@ -87,7 +87,7 @@
8787
"unplugin-auto-import": "^20.1.0",
8888
"unplugin-vue-components": "^29.0.0",
8989
"unplugin-vue-define-options": "^1.5.5",
90-
"vite": "^7.1.4",
90+
"vite": "^7.1.5",
9191
"vite-plugin-inspect": "^11.3.3",
9292
"vite-svg-loader": "^5.1.0",
9393
"vue-tsc": "^3.0.6"

app/pnpm-lock.yaml

Lines changed: 326 additions & 320 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
onlyBuiltDependencies:
2+
- core-js
3+
- vue-demi

cmd/generate_licenses/main.go

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,53 +108,96 @@ func generateBackendLicenses() ([]License, error) {
108108

109109
log.Println("INFO: Collecting backend Go modules...")
110110

111-
// Get only direct and indirect dependencies, exclude workspace modules
112-
cmd := exec.Command("go", "mod", "graph")
113-
output, err := cmd.Output()
111+
// Read go.mod file directly
112+
goModPath := "go.mod"
113+
data, err := os.ReadFile(goModPath)
114114
if err != nil {
115-
return nil, fmt.Errorf("failed to run go mod graph: %v", err)
115+
return nil, fmt.Errorf("failed to read go.mod: %v", err)
116116
}
117117

118-
// Parse module graph to get unique dependencies
118+
// Parse go.mod content to extract dependencies
119119
depMap := make(map[string]string) // path -> version
120-
lines := strings.Split(string(output), "\n")
120+
lines := strings.Split(string(data), "\n")
121+
inRequireBlock := false
122+
inReplaceBlock := false
123+
124+
replaceMap := make(map[string]string) // original -> replacement
121125

122126
for _, line := range lines {
123127
line = strings.TrimSpace(line)
124-
if line == "" {
128+
129+
// Handle require block
130+
if strings.HasPrefix(line, "require (") {
131+
inRequireBlock = true
125132
continue
126133
}
127-
128-
parts := strings.Fields(line)
129-
if len(parts) != 2 {
134+
if strings.HasPrefix(line, "replace (") {
135+
inReplaceBlock = true
130136
continue
131137
}
132-
133-
// Extract dependency info from "module@version dependency@version"
134-
dep := parts[1]
135-
if dep == "" || !strings.Contains(dep, "@") {
138+
if line == ")" {
139+
inRequireBlock = false
140+
inReplaceBlock = false
136141
continue
137142
}
138143

139-
atIndex := strings.LastIndex(dep, "@")
140-
if atIndex == -1 {
144+
// Parse replace directives
145+
if inReplaceBlock || strings.HasPrefix(line, "replace ") {
146+
if strings.Contains(line, "=>") {
147+
parts := strings.Split(line, "=>")
148+
if len(parts) == 2 {
149+
original := strings.TrimSpace(parts[0])
150+
replacement := strings.TrimSpace(parts[1])
151+
152+
// Remove "replace " prefix if present
153+
original = strings.TrimPrefix(original, "replace ")
154+
155+
// Extract module path (before version if present)
156+
if strings.Contains(original, " ") {
157+
original = strings.Fields(original)[0]
158+
}
159+
if strings.Contains(replacement, " ") {
160+
replacement = strings.Fields(replacement)[0]
161+
}
162+
163+
replaceMap[original] = replacement
164+
}
165+
}
141166
continue
142167
}
143168

144-
path := dep[:atIndex]
145-
version := dep[atIndex+1:]
146-
147-
// Skip our own module and workspace modules
148-
if path == "" ||
149-
strings.HasPrefix(path, "github.com/0xJacky/Nginx-UI") ||
150-
strings.Contains(path, "git.uozi.org") ||
151-
strings.Contains(path, "apple-store-helper") {
152-
continue
153-
}
169+
// Parse dependencies in require block or single require line
170+
if inRequireBlock || strings.HasPrefix(line, "require ") {
171+
// Remove "require " prefix if present
172+
line = strings.TrimPrefix(line, "require ")
173+
174+
// Remove comments
175+
if idx := strings.Index(line, "//"); idx != -1 {
176+
line = line[:idx]
177+
}
178+
line = strings.TrimSpace(line)
179+
180+
if line == "" {
181+
continue
182+
}
154183

155-
// Only keep the first version we see (go mod graph shows all versions)
156-
if _, exists := depMap[path]; !exists {
157-
depMap[path] = version
184+
// Parse "module version" format
185+
parts := strings.Fields(line)
186+
if len(parts) >= 2 {
187+
path := parts[0]
188+
version := parts[1]
189+
190+
if path == "" {
191+
continue
192+
}
193+
194+
// Apply replacements if they exist
195+
if replacement, exists := replaceMap[path]; exists {
196+
path = replacement
197+
}
198+
199+
depMap[path] = version
200+
}
158201
}
159202
}
160203

0 commit comments

Comments
 (0)