MCPcopy
hub / github.com/mudler/LocalAI / resolveUsageUser

Function resolveUsageUser

core/http/routes/usage.go:126–131  ·  view source on GitHub ↗

resolveUsageUser returns the authenticated user when present, otherwise the synthetic local user when auth is off. Centralizes the "if not auth, fall back to local" pattern that both routes need.

(c echo.Context, app *application.Application)

Source from the content-addressed store, hash-verified

124// otherwise the synthetic local user when auth is off. Centralizes the
125// "if not auth, fall back to local" pattern that both routes need.
126func resolveUsageUser(c echo.Context, app *application.Application) *auth.User {
127 if u := auth.GetUser(c); u != nil {
128 return u
129 }
130 return app.FallbackUser()
131}
132
133// usageResponse builds the JSON shape the UI consumes. The "viewer"
134// field surfaces who the data belongs to so a single-user dashboard

Callers 3

RegisterUsageRoutesFunction · 0.85
RegisterMiddlewareRoutesFunction · 0.85
RegisterPIIRoutesFunction · 0.85

Calls 2

GetUserFunction · 0.92
FallbackUserMethod · 0.80

Tested by

no test coverage detected