files

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package files redirects to stored files by resource kind and ID, applying per-kind access rules (player photos respect the safeguarding rule).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheControl

func CacheControl(kind string) string

CacheControl returns the Cache-Control for a file redirect of the given kind (shared by the API handler and /download). Player photos must not be cached publicly: if a player moves to a youth team, or an under-18's photo must stop being shown, a year-long public cache would keep serving the old redirect to browsers and CDNs regardless.

func LegacyKind

func LegacyKind(code string) (string, bool)

LegacyKind maps the old /download?s=<code> codes to kinds.

func Resolvers

func Resolvers(src Sources) map[string]Resolver

Resolvers builds the kind → lookup table.

func ValidID

func ValidID(kind, raw string) bool

ValidID reports whether raw is a well-formed ID for kind.

Types

type Handlers

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

Handlers serves /files.

func NewHandlers

func NewHandlers(svc *Service) *Handlers

func (*Handlers) Register

func (h *Handlers) Register(g *echo.Group, _ web.Guards)

Register mounts the file route on the /api/v1 group.

func (*Handlers) RegisterDownload

func (h *Handlers) RegisterDownload(e *echo.Echo)

RegisterDownload keeps /download?s=<code>&id=<n> working for old links, including ones inside saved articles; it redirects like GET /api/v1/files.

type PhotoKeyer

type PhotoKeyer interface {
	PhotoKey(ctx context.Context, id string) (string, error)
}

PhotoKeyer resolves player photos by public UUID, enforcing the safeguarding rule (satisfied by *player.Service).

type Resolver

type Resolver func(ctx context.Context, id string) (string, error)

Resolver returns the storage key for a resource ID ("" when it has no file). The ID is a positive integer, or a UUID for the kinds in uuidKinds.

type Service

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

Service resolves files to public URLs.

func NewService

func NewService(files *upload.Files, resolvers map[string]Resolver) *Service

func (*Service) URL

func (s *Service) URL(ctx context.Context, kind, id string) (string, error)

URL returns the CDN URL for the file behind (kind, id), or NotFound.

type Sources

type Sources struct {
	Affiliation interface {
		GetAffiliation(ctx context.Context, a affiliation.Affiliation) (affiliation.Affiliation, error)
	}
	Document interface {
		GetDocument(ctx context.Context, d document.Document) (document.Document, error)
	}
	Image interface {
		GetImage(ctx context.Context, i image.Image) (image.Image, error)
	}
	News interface {
		GetNewsArticle(ctx context.Context, n news.News) (news.News, error)
	}
	Programme interface {
		GetProgramme(ctx context.Context, p programme.Programme) (programme.Programme, error)
	}
	Sponsor interface {
		GetSponsor(ctx context.Context, s sponsor.Sponsor) (sponsor.Sponsor, error)
	}
	Team interface {
		GetTeam(ctx context.Context, t team.Team) (team.Team, error)
	}
	User interface {
		GetUserByUUID(ctx context.Context, id string) (user.User, error)
	}
	WhatsOn interface {
		GetWhatsOnArticle(ctx context.Context, w whatson.WhatsOn) (whatson.WhatsOn, error)
	}
	Players PhotoKeyer
}

Sources are the lookups behind each kind (satisfied by the domain stores).

Jump to

Keyboard shortcuts

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