files

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package files serves an object bucket over a route prefix.

It exists so that every module that accepts user uploads gets the same three guarantees without rewriting them: the stored type is the one deduced from the bytes, the key is minted by the server, and the size is checked before a single byte of the body is buffered.

Index

Constants

View Source
const (
	// DefaultMaxSize is the largest upload accepted unless the caller says otherwise.
	DefaultMaxSize = 10 << 20 // 10 MiB

)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket interface {
	Put(key string, data []byte, contentType string) error
	Get(key string) (data []byte, contentType string, err error)
}

Bucket is the storage this package needs. r2.Bucket satisfies it.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store registers the upload and serve handlers for one bucket under one prefix.

func New

func New(b Bucket, prefix string) (*Store, error)

New builds a Store on the safe defaults: raster images only, 10 MiB. prefix must end in "/" — it is matched by prefix, and the key is what hangs off it.

func (*Store) Allow

func (s *Store) Allow(a filetype.Allowlist) *Store

Allow narrows or widens the accepted types. Never add SVG or HTML: both carry JavaScript and, served from your own domain, execute in your origin.

func (*Store) MaxSize

func (s *Store) MaxSize(n int) *Store

MaxSize caps the upload size in bytes.

func (*Store) Mount

func (s *Store) Mount(r router.Router)

Mount registers both routes: uploading requires the "files"/"write" permission, serving is public because an <img src> cannot send headers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL