designs

package
v0.0.0-...-95891f2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package designs is the campaign library of saved designs and the ways an Owner shares them: a share code, a link, or named owners on this instance.

A design is data only, a list of choices from known parts. Each kind (room-theme, crafting-circle, ...) is validated by the feature that owns it through a KindRegistry that app wiring fills, so this package imports no other plugin and a design that names an unknown part is refused by the feature that knows the parts.

Hand-written SQL for the server gallery.

SECURITY: these are plain lookups. Which entries a reader may see is decided in the service; Browse is the one query that filters by status itself, because it is the only listing every Owner on the server can reach.

Hand-written SQL for the design library and its shares.

SECURITY: a row is only ever as visible as the service lets it be. Every method here is a plain lookup; the service decides who may see the result and returns NotFound for a design the reader may not reach.

Index

Constants

View Source
const (
	ReasonMaturity    = "maturity"
	ReasonLink        = "link"
	ReasonEmail       = "email"
	ReasonHandle      = "handle"
	ReasonCaps        = "caps"
	ReasonRepeat      = "repeat"
	ReasonNameRepeat  = "name_repeat"
	ReasonRate        = "rate"
	ReasonDuplicate   = "duplicate"
	ReasonReported    = "reported"
	ReasonResubmitted = "resubmitted"
	ReasonRemoved     = "removed"
)

Reason codes are stored with a gallery entry and sent to the client; they name the kind of problem, never the matched word, so a flagged publisher is not handed a way to probe the list.

View Source
const (
	StatusVisible  = "visible"
	StatusPending  = "pending"
	StatusRejected = "rejected"
	StatusRemoved  = "removed"
)

Gallery entry states. Only StatusVisible is shown to anyone but the publisher and the instance admins.

View Source
const (
	// GalleryPageSize is how many cards one browse page holds.
	GalleryPageSize = 12
	// ReportThreshold is how many distinct reports send a visible entry back
	// to review.
	ReportThreshold = 3
	// MaxReportNoteLen caps the optional note on a report.
	MaxReportNoteLen = 140
	// MaxPage bounds a page number from a client.
	MaxPage = 10000
)

Gallery limits.

View Source
const (
	ReportAdult = "adult"
	ReportSpam  = "spam"
	ReportOther = "other"
)

Report reasons an Owner may give.

View Source
const (
	KindFilterAll      = "all"
	KindFilterRooms    = "rooms"
	KindFilterCrafting = "crafting"
)

Kind filters of the browse sheet.

View Source
const (
	DecisionApprove = "approve"
	DecisionReject  = "reject"
	DecisionRemove  = "remove"
)

Admin decisions.

View Source
const (
	OriginMade   = "made"
	OriginCode   = "code"
	OriginShared = "shared"
)

Origins say how a library row came to be. They are labels only: a copy never links back to what it was copied from.

View Source
const (
	MaxNameLen      = 60
	MaxNoteLen      = 140
	MaxMakerNameLen = 100
	// MaxCodeBytes caps a share code's decoded JSON. A room theme is well under
	// 2 KB; 16 KB leaves room for richer kinds without admitting a blob.
	MaxCodeBytes = 16 * 1024
	// MaxDataBytes caps one design's data on save, matching the code cap so a
	// design that saves can always be shared as a code.
	MaxDataBytes = MaxCodeBytes
	// MaxLibrary stops one campaign from filling the table.
	MaxLibrary = 500
)

Limits on the free text a design carries, which is all a reader sees that a kind's validator does not check.

View Source
const CodePrefix = "chronicle-design:v1:"

CodePrefix starts every share code; the version lets a later format coexist.

View Source
const KindRoomTheme = "room-theme"

KindRoomTheme is the shop counter room's theme; the armory validates it.

View Source
const LinkPath = "/designs/link/"

LinkPath is where a design link lives; the token follows it.

View Source
const (

	// MaxGalleryPerDay is how many publishes or updates one user may make in
	// 24 hours before the next one waits for review.
	MaxGalleryPerDay = 5
)

Spam limits.

View Source
const MaxSuggestNoteLen = 240

MaxSuggestNoteLen caps the optional note to a package maintainer.

View Source
const OriginGallery = "gallery"

OriginGallery labels a library row copied from the server gallery. Like the other origins it is a label only; the copy never links back.

View Source
const OriginPackage = "package"

OriginPackage labels a library row copied from a game system package. Like the other origins it is a label only: the copy never links back.

View Source
const PluginSlug = "designs"

PluginSlug names this plugin in the registry and the health bookkeeping.

View Source
const SuggestionFormat = "chronicle-design-suggestion:v1"

SuggestionFormat names the export file's shape; the version lets a later shape coexist with files maintainers already hold.

Variables

View Source
var ErrGalleryDuplicate = errors.New("gallery entry already exists")

ErrGalleryDuplicate is returned by Insert when the publisher already has an entry for that library design (the unique key), so a race reads as a conflict.

View Source
var MigrationsFS embed.FS

MigrationsFS holds the embedded SQL migrations, so the tables are created from the compiled binary regardless of the working directory.

Functions

func BuildCode

func BuildCode(d *Design) (string, error)

BuildCode writes a design as a share code. It is unsigned: whoever reads it validates it again, so a hand-edited code gains nothing.

func ReasonText

func ReasonText(code string) string

ReasonText turns a stored code into plain words; an unknown code reads as a generic review note rather than leaking the code.

func RegisterAdminRoutes

func RegisterAdminRoutes(adminGroup *echo.Group, gh *GalleryHandler)

RegisterAdminRoutes adds the gallery moderation queue to the admin group, which already requires a signed-in site admin; nothing here is reachable without that gate.

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, h *Handler, gh *GalleryHandler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService)

RegisterRoutes mounts the library. Every route is Owner-only: players never reach saving or sharing, and the service checks the same rule again. The link routes sit outside a campaign because a link is opened before the reader has chosen which of their campaigns takes the design; the service requires them to own a campaign, and the one they copy into.

Types

type ActivityRecorder

type ActivityRecorder interface {
	RecordAdminChange(c *echo.Context, action, targetType, targetID, label string)
}

ActivityRecorder is the slice of the admin change log the moderation routes write to. It is declared here so this plugin imports neither admin nor auth for it; app wiring supplies an adapter that stamps the signed-in admin. It is the site-wide log, because the campaign audit log needs a campaign and a gallery decision belongs to none.

type AdminEntry

type AdminEntry struct {
	ID        string `json:"id"`
	Kind      string `json:"kind"`
	SystemID  string `json:"systemId"`
	Name      string `json:"name"`
	Note      string `json:"note"`
	MakerName string `json:"makerName"`
	// PublisherName is the publisher's real display name, which can differ from
	// the shown-as name they chose; only admins see it.
	PublisherName string `json:"publisherName"`
	// DataName is the "name" inside the design's own data.
	DataName    string          `json:"dataName"`
	Summary     string          `json:"summary"`
	Status      string          `json:"status"`
	ReasonCodes []string        `json:"reasonCodes"`
	Reasons     []string        `json:"reasons"`
	Reports     []GalleryReport `json:"reports"`
	PublishedAt time.Time       `json:"publishedAt"`
}

AdminEntry is an entry as the admin queue shows it: who made it, why it is there and what has been reported.

type AdminPage

type AdminPage struct {
	Entries []AdminEntry `json:"entries"`
	Total   int          `json:"total"`
	Page    int          `json:"page"`
	PerPage int          `json:"perPage"`
	Status  string       `json:"status"`
}

AdminPage is one page of the admin queue.

type BrowseInput

type BrowseInput struct {
	AllSystems bool
	Kind       string
	Q          string
	Page       int
}

BrowseInput is the browse sheet's filters.

type BrowseQuery

type BrowseQuery struct {
	SystemID string // "" means every system
	AnySys   bool
	Kinds    []string
	Prefix   string // kind prefix, for "crafting-*"
	Text     string
	Limit    int
	Offset   int
}

BrowseQuery is a browse after the service has turned the filters into what the repository can run.

type CampaignDirectory

type CampaignDirectory interface {
	// Campaign returns nil, nil for a campaign that is missing or in the Trash.
	Campaign(ctx context.Context, id string) (*CampaignInfo, error)
	// Member says whether userID is the campaign's Owner (campaigns.RoleOwner,
	// not a co-DM) and the display name to put on what they make. A user who is
	// not a member is (name "", owner false).
	Member(ctx context.Context, campaignID, userID string) (name string, owner bool, err error)
	// Live says whether the campaign exists and is neither in the Trash nor
	// archived. A design from a campaign that is not live is not offered to
	// anyone else, as if it had never been shared.
	Live(ctx context.Context, id string) (bool, error)
	// OwnedCampaigns lists the live, unarchived campaigns userID is Owner of.
	OwnedCampaigns(ctx context.Context, userID string) ([]CampaignInfo, error)
}

CampaignDirectory is what the sharing rules need from campaigns. App wiring implements it over the campaigns service, so this package never imports it.

type CampaignInfo

type CampaignInfo struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	SystemID string `json:"systemId"`
}

CampaignInfo is the little the sharing rules need to know of a campaign.

type Design

type Design struct {
	ID          string          `json:"id"`
	CampaignID  string          `json:"campaignId"`
	Kind        string          `json:"kind"`
	SystemID    string          `json:"systemId"`
	Name        string          `json:"name"`
	Note        string          `json:"note"`
	MakerUserID string          `json:"-"`
	MakerName   string          `json:"makerName"`
	Data        json.RawMessage `json:"data"`
	Origin      string          `json:"origin"`
	OriginRef   string          `json:"originRef,omitempty"`
	// Shared is true while the design has a working link or any named owner.
	Shared    bool      `json:"shared"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Design is one saved design as the Owner's library shows it.

type Gallery interface {
	Publish(ctx context.Context, campaignID, userID, designID string, in PublishInput) (*GalleryMine, error)
	Republish(ctx context.Context, campaignID, userID, designID string, in RepublishInput) (*GalleryMine, error)
	Unpublish(ctx context.Context, campaignID, userID, entryID string) error
	Mine(ctx context.Context, campaignID, userID string) ([]GalleryMine, error)
	Browse(ctx context.Context, campaignID, userID string, in BrowseInput) (*GalleryPage, error)
	Copy(ctx context.Context, campaignID, userID, entryID string) (*Design, error)
	Report(ctx context.Context, campaignID, userID, entryID string, in ReportInput) error

	AdminQueue(ctx context.Context, status string, page int) (*AdminPage, error)
	// AdminDecide applies approve, reject or remove and returns the entry as it
	// now stands. It records nothing itself; the handler logs the decision.
	AdminDecide(ctx context.Context, actorID, entryID, decision string) (*AdminEntry, error)
}

Gallery is the server gallery: publishing a snapshot of a library design, browsing and copying what other Owners published, reporting, and the admin queue. Like Service, every campaign-scoped call checks the Owner itself; the Admin* calls trust their route gate (/admin, site admins only) and never reach the Owner rules.

func NewGalleryService

func NewGalleryService(lib Repository, repo GalleryRepository, dir CampaignDirectory, kinds KindRegistry, names UserNames) Gallery

NewGalleryService builds the gallery over the same library, directory and kind registry the library service uses, so a published design is validated by the feature that owns its kind.

type GalleryCard

type GalleryCard struct {
	ID          string    `json:"id"`
	Kind        string    `json:"kind"`
	SystemID    string    `json:"systemId"`
	Name        string    `json:"name"`
	Note        string    `json:"note"`
	MakerName   string    `json:"makerName"`
	Summary     string    `json:"summary"`
	PublishedAt time.Time `json:"publishedAt"`
	Mine        bool      `json:"mine"`
	SameSystem  bool      `json:"sameSystem"`
	Lacks       []string  `json:"lacks"`
	Reported    bool      `json:"reported"`
}

GalleryCard is one visible entry as the browse sheet shows it.

type GalleryEntry

type GalleryEntry struct {
	ID              string
	PublisherUserID string
	SourceDesignID  string
	Kind            string
	SystemID        string
	Name            string
	Note            string
	MakerName       string
	Data            json.RawMessage
	DataHash        string
	Status          string
	Reasons         []string
	ReviewedBy      string
	PublishedAt     time.Time
	UpdatedAt       time.Time
}

GalleryEntry is a published snapshot. Data is only ever sent out through a copy, never in a listing.

type GalleryHandler

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

GalleryHandler is the JSON surface for the gallery, thin like Handler.

func NewGalleryHandler

func NewGalleryHandler(svc Gallery, activity ActivityRecorder) *GalleryHandler

NewGalleryHandler creates the handler; the recorder may be nil.

func (*GalleryHandler) AdminEntries

func (h *GalleryHandler) AdminEntries(c *echo.Context) error

AdminEntries handles GET /admin/design-gallery/entries?status=&page=.

func (*GalleryHandler) AdminPage

func (h *GalleryHandler) AdminPage(c *echo.Context) error

AdminPage handles GET /admin/design-gallery: the page shell, which loads its queue as JSON from AdminEntries.

func (*GalleryHandler) Approve

func (h *GalleryHandler) Approve(c *echo.Context) error

Approve, Reject and Remove handle POST /admin/design-gallery/:gid/<decision>.

func (*GalleryHandler) Browse

func (h *GalleryHandler) Browse(c *echo.Context) error

Browse handles GET /campaigns/:id/designs/gallery?system=all&kind=&q=&page=.

func (*GalleryHandler) Copy

func (h *GalleryHandler) Copy(c *echo.Context) error

Copy handles POST /campaigns/:id/designs/gallery/:gid/copy.

func (*GalleryHandler) Mine

func (h *GalleryHandler) Mine(c *echo.Context) error

Mine handles GET /campaigns/:id/designs/gallery/mine.

func (*GalleryHandler) Publish

func (h *GalleryHandler) Publish(c *echo.Context) error

Publish handles POST /campaigns/:id/designs/:did/gallery.

func (*GalleryHandler) Reject

func (h *GalleryHandler) Reject(c *echo.Context) error

func (*GalleryHandler) Remove

func (h *GalleryHandler) Remove(c *echo.Context) error

func (*GalleryHandler) Report

func (h *GalleryHandler) Report(c *echo.Context) error

Report handles POST /campaigns/:id/designs/gallery/:gid/report.

func (*GalleryHandler) Republish

func (h *GalleryHandler) Republish(c *echo.Context) error

Republish handles PUT /campaigns/:id/designs/:did/gallery, a partial update: only the keys sent change.

func (*GalleryHandler) Unpublish

func (h *GalleryHandler) Unpublish(c *echo.Context) error

Unpublish handles DELETE /campaigns/:id/designs/gallery/:gid.

type GalleryMine

type GalleryMine struct {
	ID             string    `json:"id"`
	SourceDesignID string    `json:"sourceDesignId,omitempty"`
	Kind           string    `json:"kind"`
	SystemID       string    `json:"systemId"`
	Name           string    `json:"name"`
	Note           string    `json:"note"`
	MakerName      string    `json:"makerName"`
	Status         string    `json:"status"`
	Reasons        []string  `json:"reasons"`
	PublishedAt    time.Time `json:"publishedAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
}

GalleryMine is one of the publisher's own entries, with its state and, when it waits or was refused, the reasons in plain words (never the matched term).

type GalleryPage

type GalleryPage struct {
	Entries  []GalleryCard `json:"entries"`
	Total    int           `json:"total"`
	Page     int           `json:"page"`
	PerPage  int           `json:"perPage"`
	SystemID string        `json:"systemId"`
}

GalleryPage is one page of browse results.

type GalleryReport

type GalleryReport struct {
	ReporterUserID string    `json:"-"`
	Reason         string    `json:"reason"`
	Note           string    `json:"note,omitempty"`
	CreatedAt      time.Time `json:"createdAt"`
}

GalleryReport is one Owner's report of an entry.

type GalleryRepository

type GalleryRepository interface {
	Insert(ctx context.Context, e *GalleryEntry) error
	// Get returns nil when the entry does not exist.
	Get(ctx context.Context, id string) (*GalleryEntry, error)
	BySource(ctx context.Context, publisher, sourceDesignID string) (*GalleryEntry, error)
	// Save writes the mutable fields of an entry, including its state.
	Save(ctx context.Context, e *GalleryEntry) error
	Delete(ctx context.Context, id string) error
	// Browse lists visible entries only, newest first, with the total.
	Browse(ctx context.Context, q BrowseQuery) ([]GalleryEntry, int, error)
	ByPublisher(ctx context.Context, publisher string) ([]GalleryEntry, error)
	ByStatus(ctx context.Context, statuses []string, limit, offset int) ([]GalleryEntry, int, error)
	// DuplicateExists is true when the publisher has another live entry with
	// the same data hash.
	DuplicateExists(ctx context.Context, publisher, hash, exceptID string) (bool, error)
	// RefusedExists is true when the publisher has another entry with this data
	// hash that an admin refused or took down.
	RefusedExists(ctx context.Context, publisher, hash, exceptID string) (bool, error)
	// FlagReported sends a still-visible entry back to review with these
	// reasons, touching only status and reasons. It reports whether it did.
	FlagReported(ctx context.Context, id string, reasons []string) (bool, error)
	CountEvents(ctx context.Context, user string, since time.Time) (int, error)
	AddEvent(ctx context.Context, user string) error
	// AddReport returns false when this reporter already reported the entry.
	AddReport(ctx context.Context, entryID, reporter, reason, note string) (bool, error)
	Reports(ctx context.Context, entryID string) ([]GalleryReport, error)
	ReportedBy(ctx context.Context, reporter string, ids []string) (map[string]bool, error)
	ClearReports(ctx context.Context, entryID string) error
}

GalleryRepository is the persistence boundary for the gallery.

func NewGalleryRepository

func NewGalleryRepository(db *sql.DB) GalleryRepository

NewGalleryRepository creates a MariaDB-backed gallery repository.

type Handler

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

Handler is the JSON surface for the library. It is thin on purpose: it binds, calls the service and shapes the answer; every rule lives in the service.

func NewHandler

func NewHandler(svc Service) *Handler

NewHandler creates the handler.

func (*Handler) AddOwner

func (h *Handler) AddOwner(c *echo.Context) error

AddOwner handles POST /campaigns/:id/designs/:did/share/owners.

func (*Handler) CopyPackage

func (h *Handler) CopyPackage(c *echo.Context) error

CopyPackage handles POST /campaigns/:id/designs/package/:pid/copy ("Save as my design").

func (*Handler) Delete

func (h *Handler) Delete(c *echo.Context) error

Delete handles DELETE /campaigns/:id/designs/:did.

func (*Handler) Get

func (h *Handler) Get(c *echo.Context) error

Get handles GET /campaigns/:id/designs/:did.

func (h *Handler) Link(c *echo.Context) error

Link handles GET /designs/link/:token. A browser gets the page, which loads the preview from this same route as JSON; the page itself reveals nothing.

func (*Handler) List

func (h *Handler) List(c *echo.Context) error

List handles GET /campaigns/:id/designs?kind=.

func (*Handler) Package

func (h *Handler) Package(c *echo.Context) error

Package handles GET /campaigns/:id/designs/package?kind=: the read-only group the campaign's game system package ships.

func (*Handler) PreviewCode

func (h *Handler) PreviewCode(c *echo.Context) error

PreviewCode handles POST /campaigns/:id/designs/code/preview.

func (*Handler) PreviewShared

func (h *Handler) PreviewShared(c *echo.Context) error

PreviewShared handles GET /campaigns/:id/designs/shared/:did/preview.

func (*Handler) RemoveOwner

func (h *Handler) RemoveOwner(c *echo.Context) error

RemoveOwner handles DELETE /campaigns/:id/designs/:did/share/owners/:uid.

func (*Handler) Save

func (h *Handler) Save(c *echo.Context) error

Save handles POST /campaigns/:id/designs.

func (*Handler) SearchOwners

func (h *Handler) SearchOwners(c *echo.Context) error

SearchOwners handles GET /campaigns/:id/designs/owners?q=.

func (h *Handler) SetLink(c *echo.Context) error

SetLink handles PUT /campaigns/:id/designs/:did/share/link with {"on": bool}.

func (*Handler) ShareState

func (h *Handler) ShareState(c *echo.Context) error

ShareState handles GET /campaigns/:id/designs/:did/share.

func (*Handler) SharedWithMe

func (h *Handler) SharedWithMe(c *echo.Context) error

SharedWithMe handles GET /campaigns/:id/designs/shared-with-me?kind=.

func (*Handler) StopSharing

func (h *Handler) StopSharing(c *echo.Context) error

StopSharing handles DELETE /campaigns/:id/designs/:did/share.

func (*Handler) Suggest

func (h *Handler) Suggest(c *echo.Context) error

Suggest handles POST /campaigns/:id/designs/:did/suggestion. The body is {note, credit}; the answer carries the file's name and content for the page to download. POST keeps the maintainer note out of URLs and access logs.

func (*Handler) TakeCode

func (h *Handler) TakeCode(c *echo.Context) error

TakeCode handles POST /campaigns/:id/designs/code/take.

func (h *Handler) TakeLink(c *echo.Context) error

TakeLink handles POST /designs/link/:token/take with {"campaignId": "..."}.

func (*Handler) TakeShared

func (h *Handler) TakeShared(c *echo.Context) error

TakeShared handles POST /campaigns/:id/designs/shared/:did/take.

func (*Handler) Update

func (h *Handler) Update(c *echo.Context) error

Update handles PATCH /campaigns/:id/designs/:did. A partial update: only the keys sent change.

type Kind

type Kind interface {
	// Validate returns the canonical form of raw, or an error that names the
	// part it refuses. It runs on save, on import and on every take, so a
	// design made before a part was retired is refused rather than stored.
	Validate(raw json.RawMessage) (json.RawMessage, error)
	// Lacks says in plain sentences what the receiving campaign does not have
	// that this design uses (a material, a shape). It may return none.
	Lacks(ctx context.Context, campaignID string, raw json.RawMessage) ([]string, error)
}

Kind is the owning feature's say over one kind of design. The feature is the authority: this package never looks inside Data.

type KindRegistry

type KindRegistry interface {
	Kind(name string) (Kind, bool)
	Names() []string
}

KindRegistry is what the service reads kinds from. App wiring registers a kind per feature, so features never import each other and a feature that starts later (crafting) can still add its kinds.

type Kinds

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

Kinds is the usual KindRegistry; Register may be called at any time.

func NewKinds

func NewKinds() *Kinds

NewKinds returns an empty registry.

func (*Kinds) Kind

func (k *Kinds) Kind(name string) (Kind, bool)

Kind returns the registered kind, if any.

func (*Kinds) Names

func (k *Kinds) Names() []string

Names lists the registered kinds in order.

func (*Kinds) Register

func (k *Kinds) Register(name string, kind Kind)

Register adds or replaces a kind.

type LinkPreview

type LinkPreview struct {
	Preview
	Targets []LinkTarget `json:"targets"`
}

LinkPreview is a link's preview plus the campaigns the reader may copy the design into: their own, on the design's game system.

type LinkTarget

type LinkTarget struct {
	CampaignInfo
	Lacks []string `json:"lacks"`
}

LinkTarget is one campaign a link's design can be copied into, with what that campaign lacks for it.

type Owner

type Owner struct {
	UserID string `json:"userId"`
	Name   string `json:"name"`
}

Owner names a person a design is shared with.

type OwnerMatch

type OwnerMatch struct {
	UserID      string   `json:"userId"`
	DisplayName string   `json:"displayName"`
	Systems     []string `json:"systems"`
}

OwnerMatch is a search hit: an owner on this instance and the game systems they run a campaign on. Campaign names and ids stay private, because a name can give away a table the searcher was never invited to.

type PackageDesign

type PackageDesign struct {
	ID        string          `json:"id"`
	Kind      string          `json:"kind"`
	Name      string          `json:"name"`
	Note      string          `json:"note,omitempty"`
	MakerName string          `json:"makerName,omitempty"`
	Data      json.RawMessage `json:"data"`
}

PackageDesign is a package design as the library shows it. The id is derived from the kind and file, so it stays the same across restarts and never collides with a library row's id.

type PackageGroup

type PackageGroup struct {
	SystemID   string `json:"systemId"`
	SystemName string `json:"systemName"`
	// You is the name a "Credit me" suggestion would carry, so the page can
	// show it before anything is exported.
	You     string          `json:"you"`
	Designs []PackageDesign `json:"designs"`
}

PackageGroup is the read-only "From <system>" group: the designs of the campaign's own game system package, and nothing from any other.

type PackageItem

type PackageItem struct {
	Kind, Name, Note, Maker, File string
	Data                          json.RawMessage
}

PackageItem is one design a game system package ships, already validated by the package loader. App wiring supplies it, so this package never imports the systems package.

type PackageSource

type PackageSource interface {
	// Package returns the system's display name and its designs. A system with
	// none, or an unknown one, returns no items.
	Package(ctx context.Context, systemID string) (name string, items []PackageItem)
}

PackageSource reads the designs a game system package ships.

type Preview

type Preview struct {
	Name       string   `json:"name"`
	Note       string   `json:"note,omitempty"`
	Kind       string   `json:"kind"`
	MakerName  string   `json:"makerName"`
	SystemID   string   `json:"systemId"`
	SameSystem bool     `json:"sameSystem"`
	Lacks      []string `json:"lacks"`
}

Preview is what a reader sees before taking a design: who made it, what it is, whether it was made for the same game system, and what the receiving campaign lacks.

type PublishInput

type PublishInput struct {
	Name      string
	Note      string
	MakerName string
}

PublishInput is what the Share sheet sends. An empty name or shown-as name falls back to the library design's name and the Owner's display name.

type ReportInput

type ReportInput struct {
	Reason string `json:"reason"`
	Note   string `json:"note"`
}

ReportInput is an Owner's report of a visible entry.

type Repository

type Repository interface {
	// List is a campaign's library, newest first; kind "" lists every kind.
	List(ctx context.Context, campaignID, kind string) ([]Design, error)
	// Get returns nil when the design does not exist, whatever campaign it is in.
	Get(ctx context.Context, id string) (*Design, error)
	Count(ctx context.Context, campaignID string) (int, error)
	Insert(ctx context.Context, d *Design) error
	Update(ctx context.Context, id, name, note string) error
	// Delete removes the design and, by cascade, its share state.
	Delete(ctx context.Context, id string) error

	// Share state. SetLink upserts the share row; token is kept when on is false
	// only if the caller passes it, so an off link can be cleared.
	Share(ctx context.Context, id string) (token string, on bool, owners []Owner, err error)
	SetLink(ctx context.Context, id, token string, on bool) error
	// FindByToken returns the design behind a link token, or nil, and whether
	// that link is on.
	FindByToken(ctx context.Context, token string) (*Design, bool, error)
	AddOwner(ctx context.Context, designID, userID string) error
	RemoveOwner(ctx context.Context, designID, userID string) error
	IsNamedOwner(ctx context.Context, designID, userID string) (bool, error)
	// StopSharing turns the link off, forgets its token and removes every
	// named owner, in one transaction.
	StopSharing(ctx context.Context, id string) error
	// SharedWith lists designs named to the user on a game system, leaving out
	// the campaign they are being listed for.
	SharedWith(ctx context.Context, userID, systemID, kind, exceptCampaignID string) ([]SharedDesign, error)
	// SearchOwners finds users who own at least one live campaign, by display
	// name. It reads the users and campaign_members tables read-only, because
	// no service offers a cross-campaign owner search.
	SearchOwners(ctx context.Context, query, exceptUserID string, limit int) ([]OwnerMatch, error)
}

Repository is the persistence boundary for designs.

func NewRepository

func NewRepository(db *sql.DB) Repository

NewRepository creates a MariaDB-backed repository.

type RepublishInput

type RepublishInput struct {
	Name      patch.Field[string] `json:"name"`
	Note      patch.Field[string] `json:"note"`
	MakerName patch.Field[string] `json:"makerName"`
}

RepublishInput is "Update in gallery": a partial update, so a key left out keeps what the entry already says. The design data is always re-read from the library.

type SaveInput

type SaveInput struct {
	Kind string
	Name string
	Note string
	Data json.RawMessage
}

SaveInput is what the Owner sends to put a design in the library.

type Service

type Service interface {
	List(ctx context.Context, campaignID, userID, kind string) ([]Design, error)
	Get(ctx context.Context, campaignID, userID, id string) (*Design, error)
	Save(ctx context.Context, campaignID, userID string, in SaveInput) (*Design, error)
	// Check runs Save's checks without saving.
	Check(ctx context.Context, campaignID, userID string, in SaveInput) error
	Update(ctx context.Context, campaignID, userID, id string, in UpdateDesignInput) (*Design, error)
	Delete(ctx context.Context, campaignID, userID, id string) error

	// Package is the read-only group of designs the campaign's game system
	// package ships; CopyPackage makes an independent library row from one;
	// Suggest builds the file an Owner sends a package maintainer.
	Package(ctx context.Context, campaignID, userID, kind string) (*PackageGroup, error)
	CopyPackage(ctx context.Context, campaignID, userID, id string) (*Design, error)
	Suggest(ctx context.Context, campaignID, userID, id string, in SuggestInput) (*Suggestion, error)

	ShareState(ctx context.Context, campaignID, userID, id string) (*ShareState, error)
	SetLink(ctx context.Context, campaignID, userID, id string, on bool) (*ShareState, error)
	SearchOwners(ctx context.Context, campaignID, userID, query string) ([]OwnerMatch, error)
	AddOwner(ctx context.Context, campaignID, userID, id, ownerUserID string) (*ShareState, error)
	RemoveOwner(ctx context.Context, campaignID, userID, id, ownerUserID string) (*ShareState, error)
	StopSharing(ctx context.Context, campaignID, userID, id string) (*ShareState, error)

	PreviewCode(ctx context.Context, campaignID, userID, code string) (*Preview, error)
	TakeCode(ctx context.Context, campaignID, userID, code string) (*Design, error)
	PreviewLink(ctx context.Context, userID, token string) (*LinkPreview, error)
	TakeLink(ctx context.Context, userID, token, targetCampaignID string) (*Design, error)
	SharedWithMe(ctx context.Context, campaignID, userID, kind string) ([]SharedDesign, error)
	PreviewShared(ctx context.Context, campaignID, userID, designID string) (*Preview, error)
	TakeShared(ctx context.Context, campaignID, userID, designID string) (*Design, error)
}

Service is the library and its sharing. Every method takes the acting user and checks they are the Owner of the campaign it acts for (or, for links, of the campaign they copy into); handlers pass the route's campaign and do no checking of their own beyond the route gate.

func NewService

func NewService(repo Repository, dir CampaignDirectory, kinds KindRegistry, pkgs PackageSource) Service

NewService creates the service. pkgs may be nil: the campaign then simply has no package group.

type ShareState

type ShareState struct {
	Code    string  `json:"code"`
	LinkOn  bool    `json:"linkOn"`
	LinkURL string  `json:"linkUrl,omitempty"`
	Owners  []Owner `json:"owners"`
}

ShareState is everything the Share sheet shows for one design.

type SharedDesign

type SharedDesign struct {
	ID        string `json:"id"`
	Kind      string `json:"kind"`
	Name      string `json:"name"`
	MakerName string `json:"makerName"`
	// contains filtered or unexported fields
}

SharedDesign is a design shared to the current user by name.

type SuggestInput

type SuggestInput struct {
	// Note is for the maintainer, up to MaxSuggestNoteLen.
	Note string `json:"note"`
	// Credit puts the Owner's display name on the design as its maker.
	Credit bool `json:"credit"`
}

SuggestInput is what the Owner chooses in the Suggest fold.

type Suggestion

type Suggestion struct {
	Format   string                     `json:"format"`
	System   string                     `json:"system"`
	Designs  []SuggestionEntry          `json:"designs"`
	Data     map[string]json.RawMessage `json:"data"`
	Message  string                     `json:"messageForMaintainer,omitempty"`
	Filename string                     `json:"-"`
}

Suggestion is the export: a file a maintainer can paste into a package. The Designs entries are exactly manifest `designs` entries, and Data holds the content of each entry's File, keyed by that path.

type SuggestionEntry

type SuggestionEntry struct {
	Kind  string `json:"kind"`
	Name  string `json:"name"`
	Note  string `json:"note,omitempty"`
	Maker string `json:"maker,omitempty"`
	File  string `json:"file"`
}

SuggestionEntry is one manifest `designs` entry.

type UpdateDesignInput

type UpdateDesignInput struct {
	Name patch.Field[string] `json:"name"`
	Note patch.Field[string] `json:"note"`
}

UpdateDesignInput renames or re-notes a design. It is a partial update: an absent key keeps what is stored, so a rename never touches the note.

type UserNames

type UserNames interface {
	DisplayName(ctx context.Context, userID string) (string, error)
}

UserNames resolves an account's display name for the admin queue; app wiring implements it over the auth service. It may be nil.

Jump to

Keyboard shortcuts

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