Files
llmgw/internal/web/nav.go
T
Ilker ManapandClaude Opus 5.5 2f54780802 G4: a page that makes 3D models, and ctl 3d
/3d beside /images, while some model makes meshes: a picture chosen, the
job asked for through the same path an API client's takes, its progress
shown (waiting for the card, n ahead; making it, the node and percent),
and the mesh in a viewer — model-viewer 4.4.0 (Apache 2.0, with three.js
and lit), served from the gateway since the page's policy loads scripts
from nowhere else — with a download and the model's licence. The mesh is
served to its owner from /3d/jobs/{id}/file; another project's person is
told there is no such job.

A job made from the portal acted for a key that does not exist: the
worker now rebuilds a session's principal from the account that made it,
while it is active and still in the project the job is charged to.

ctl 3d list|get|cancel, over /api/v1/client-jobs (/api/v1/jobs is the
control plane's own work, which ctl jobs shows).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 19:16:20 +02:00

88 lines
2.7 KiB
Go

package web
import (
"context"
"net/http"
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
)
// Nav is the menu at the top of every signed-in page.
//
// One menu, drawn by one template, because each page used to write its own:
// the same links in a different order, some missing, and the page you were on
// sometimes listed and sometimes not. Moving between pages then read as moving
// between different programs.
type Nav struct {
// Current is the page being shown, so its link is marked rather than
// offered: "cluster", "people", "quotas", "usage", "mirror", "chat", "images",
// "keys".
Current string
// Admin shows the administration links, and Role which of them: a
// billing role sees usage and quotas only.
Admin bool
Role string
// Mirror and Quotas are whether those pages were mounted at all; usage is
// mounted with quotas.
Mirror, Quotas bool
// Guard is whether the guardrails page was mounted.
Guard bool
// Settings offers the cluster's settings: mounted, and to an
// administrator only.
Settings bool
// CSRF signs the sign-out form.
CSRF string
// Org offers the organization page: to an administrator, and to anyone
// who manages an organization.
Org bool
// Images offers the pictures page, while some model makes them; Meshes
// the 3D page.
Images, Meshes bool
}
type navKey struct{}
// navFor builds the menu for a signed-in person.
func (p *AccountPages) navFor(r *http.Request, user store.User, current string) Nav {
n := Nav{
Current: current,
Admin: user.Staff(),
Role: user.StaffRole(),
Mirror: p.hasMirror,
Quotas: p.hasQuotas,
Guard: p.hasGuard,
Settings: p.hasSettings && user.IsAdmin,
CSRF: csrfFor(r),
Images: p.images != nil && p.images(),
Meshes: p.meshes != nil && p.meshes(),
}
// Only when there is an organization to show: a link that leads to "there
// are none" on every page is noise.
if p.orgs != nil {
var orgs []store.Org
var err error
if user.IsAdmin {
orgs, err = p.orgs.AllOrgs(r.Context())
} else {
orgs, err = p.orgs.ManagedOrgs(r.Context(), user.ID)
}
n.Org = err == nil && len(orgs) > 0
}
return n
}
// withNav carries the menu to a page rendered by a handler that has no
// session of its own — the dashboard and the node logs are built without the
// account pages and wrapped by them.
func (p *AccountPages) withNav(r *http.Request, user store.User) *http.Request {
return r.WithContext(context.WithValue(r.Context(), navKey{}, p.navFor(r, user, "")))
}
// navFrom reads the menu withNav stored, marked for the page being drawn.
// Zero when there is none, which draws no admin links.
func navFrom(r *http.Request, current string) Nav {
n, _ := r.Context().Value(navKey{}).(Nav)
n.Current = current
return n
}