{"modulePath":"github.com/GoCodeAlone/workflow-plugin-cms","version":"v0.1.10","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package media\n\nPackage media implements tenant-scoped media upload + retrieval.\n\nPer gocodealone-multisite SPEC.md T25.\n\nTwo backends are supported via the Backend interface:\n\n  - LocalFS — files written under \\\u003croot\u003e/\\\u003ctenant\\_id\u003e/\\\u003csha256\u003e.\\\u003cext\u003e.\n  - Spaces — DigitalOcean Spaces (S3-compatible) via presigned URL.\n\nThe LocalFS backend ships in this file; Spaces lives in media/spaces.go (added when the host needs it).\n\n## Constants\n\n```go\nconst MaxUploadBytes = 10 * 1024 * 1024\n```\nMaxUploadBytes is the default per-request cap (10 MiB).\n\n## Variables\n\n```go\nvar ErrNotFound = errors.New(\"media: not found\")\n```\nErrNotFound is returned by Backend.Get on a miss.\n\n```go\nvar ErrTooLarge = errors.New(\"media: payload too large\")\n```\nErrTooLarge is returned by the handler when the upload exceeds the configured cap.\n\n## Types\n\n```go\ntype Backend interface {\n\t// Put stores body for tenantID, returning a stable public URL.\n\tPut(tenantID int64, body io.Reader, contentType string) (string, error)\n\t// Get returns the file contents + content-type for a stored URL.\n\t// Implementations may return ErrNotFound.\n\tGet(url string) (io.ReadCloser, string, error)\n}\n```\nBackend persists + retrieves tenant-scoped media.\n\n```go\ntype LocalFS struct {\n\tRoot      string\n\tPublicURL string // e.g. \"https://gocodealone.tech/media\"; appended with /\u003ctenant\u003e/\u003csha\u003e.\u003cext\u003e\n}\n```\nLocalFS is a development backend that writes under root.\n\nPath layout: \\\u003croot\u003e/\\\u003ctenant\\_id\u003e/\\\u003csha256\u003e.\\\u003cext\u003e. The sha256 is content-addressed — uploading the same file twice yields the same URL (idempotent).\n\n```go\nfunc (l *LocalFS) Get(url string) (io.ReadCloser, string, error)\n```\n\n```go\nfunc (l *LocalFS) Put(tenantID int64, body io.Reader, contentType string) (string, error)\n```\n\n```go\ntype UploadHandler struct {\n\tBackend Backend\n}\n```\nUploadHandler is an http.Handler that consumes multipart/form-data uploads under POST /api/v1/admin/tenants/:id/upload. Tenant ID is extracted from the URL by the caller.\n\nThe handler:\n\n 1. Caps the read at MaxUploadBytes + 1 byte to detect overflow.\n 2. Hands the body to the configured Backend.\n 3. Returns 201 + {url, content\\_type, bytes} on success.\n\n```go\nfunc (h *UploadHandler) ServeForTenant(w http.ResponseWriter, r *http.Request, tenantID int64)\n```\nServeForTenant performs an upload scoped to tenantID. Returns the stored URL.\n\n","path":"github.com/GoCodeAlone/workflow-plugin-cms/media","name":"media","synopsis":"Package media implements tenant-scoped media upload + retrieval.","isRedistributable":true}
