Trim comments to the non-obvious why
Drop narration, history and restated-code comments across the repo, keep short ones for security boundaries, upstream quirks and ordering constraints, and record the convention in CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -10,19 +10,8 @@ import (
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
)
|
||||
|
||||
// Upload backs POST /uploads (login required): the one endpoint the frontend
|
||||
// stores a file through (vue/src/uploads.js). Multipart form:
|
||||
//
|
||||
// file the file (required)
|
||||
// private "true" to store it as an admin-only chat attachment
|
||||
//
|
||||
// It answers {"url": "/uploads/<name>"}, or {"error": "..."} with 400 when
|
||||
// the file was refused (wrong type, too large) and 500 when storing failed.
|
||||
// Validation, naming and storage are all services.Uploads.Save; this handler
|
||||
// only reads the form and decides who may use `private`.
|
||||
//
|
||||
// `private` is admin-only because private messages themselves are: an
|
||||
// attachment URL leaking out is the same disclosure as the message leaking.
|
||||
// Upload stores a multipart `file` via services.Uploads.Save and returns its
|
||||
// URL. `private` is admin-only, as private messages are.
|
||||
func (store *Store) Upload(ctx *gin.Context) {
|
||||
private := ctx.PostForm("private") == "true"
|
||||
if private && !requestIsAdmin(ctx) {
|
||||
@@ -49,12 +38,7 @@ func (store *Store) Upload(ctx *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// ListUploads backs GET /uploads (admin): every public upload, newest first,
|
||||
// for the upload picker on the canvas pages (vue/src/components/util/
|
||||
// UploadPicker.vue). It answers {"files": [{name, url, size, modified}]}.
|
||||
//
|
||||
// Admin-only because the listing is the one thing that turns unguessable
|
||||
// upload URLs into known ones; see services.Uploads.List.
|
||||
// ListUploads is admin-only: listing is what turns unguessable URLs into known ones.
|
||||
func (store *Store) ListUploads(ctx *gin.Context) {
|
||||
files, err := store.Uploads.List(ctx.Request.Context())
|
||||
if err != nil {
|
||||
@@ -68,12 +52,8 @@ func (store *Store) ListUploads(ctx *gin.Context) {
|
||||
ctx.JSON(http.StatusOK, gin.H{"files": files})
|
||||
}
|
||||
|
||||
// requestIsAdmin reports whether the caller's access token carries admin=true.
|
||||
//
|
||||
// This route sits in the `protected` group, which runs AuthMiddlewear but not
|
||||
// AdminMiddleware — the endpoint has to stay usable by any signed-in user for
|
||||
// public attachments — so the admin check is made here from the same
|
||||
// "userClaims" value AdminMiddleware would have read.
|
||||
// requestIsAdmin: this route is in `protected`, not `admin`, since any
|
||||
// signed-in user may upload public files.
|
||||
func requestIsAdmin(ctx *gin.Context) bool {
|
||||
claims, exists := ctx.Get("userClaims")
|
||||
if !exists {
|
||||
|
||||
Reference in New Issue
Block a user