Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoPTYWriter = errors.New("upload: no PTY writer configured")
ErrNoPTYWriter is returned when the handler was constructed without a writePTY callback. Auto-paste is unavailable.
Functions ¶
This section is empty.
Types ¶
type AuditFn ¶
AuditFn is the upload handler's decoupled audit callback. The daemon's server.go wires it to security.AuditLog.Log via a tiny adapter so upload stays free of the security package import. Status is the HTTP status we ended on (200/400/500/etc.) so the audit trail can distinguish successful uploads from rejected ones.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler owns the uploads directory + the session-PTY writer. Both endpoints (POST /api/upload + POST /api/paste-images) live on it so the route registration in server.go is a single wiring point.
func New ¶
func New(dir string, maxSizeBytes int64, writePTY func(sessionID string, p []byte) error, kindFor func(sessionID string) string) (*Handler, error)
New constructs a Handler. dir is created if missing. writePTY is the callback that writes bytes into a named session's PTY (typically sessions.Manager.Input); nil disables auto-paste (uploads return the path but don't inject anything). kindFor resolves a session to its agent kind so HandlePasteImages can pick the right PTY trigger (Codex binds image attach to Ctrl+V, not bracketed paste); nil falls back to bracketed paste for all agents.
func (*Handler) HandlePasteImages ¶
func (h *Handler) HandlePasteImages(w http.ResponseWriter, r *http.Request)
HandlePasteImages handles POST /api/paste-images. Body JSON: {paths, session?}. For each image path: load onto the daemon host's clipboard (macOS via osascript, Linux via xclip/wl-copy), then write the agent-specific PTY trigger so Claude/Grok's TUI reads the clipboard + attaches the image (rendering `[imageN]` exactly like the legacy Mac server did).
Without host clipboard access, falls back to writing `@<path>` text — Claude still reads the image from disk via the @ reference, but the visual differs from the legacy `[imageN]` placeholder.
The 600ms inter-image spacing matches the Mac server's `imagePasteSpacing` — without it, rapid clipboard writes clobber each other before Claude reads them, collapsing a multi-image batch to one attachment.
func (*Handler) HandleUpload ¶
func (h *Handler) HandleUpload(w http.ResponseWriter, r *http.Request)
HandleUpload handles POST /api/upload. Multipart form-data with field "file". Query params (both ignored for paste — kept for iOS wire-compat only):
?session=<id> historically routed an auto-paste into the session ?nopaste=1 historically skipped the auto-paste
Writes the file to <dir>/<unique-prefix>-<original-name>, returns {name, path}. NEVER auto-pastes — iOS's CombinedFooterView does its own paste via bridge.sendText (path+\n for files), and the legacy Mac clipboard-based image auto-paste can't be reproduced without NSPasteboard. The daemon's /api/paste-images route handles the batched-image case via @<path> references that Claude reads from disk.
type UploadResult ¶
type UploadResult struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
Error string `json:"error,omitempty"`
}
UploadResult matches iOS's APIClient.UploadResult decodable struct. Both `name` and `path` are returned on success; `error` is set on failure.