store

package
v0.0.0-...-7544f7c Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: BSD-3-Clause Imports: 21 Imported by: 3

Documentation

Overview

Package store stores and retrieves fiddles and associated assets in Google Storage.

Index

Constants

View Source
const (
	FIDDLE_STORAGE_BUCKET = "skia-fiddle"

	LRU_CACHE_SIZE = 10000

	// *_METADATA are the keys used to store the metadata values in Google Storage.
	USER_METADATA                   = "user"
	HASH_METADATA                   = "hash"
	STATUS_METADATA                 = "status"
	WIDTH_METADATA                  = "width"
	HEIGHT_METADATA                 = "height"
	SOURCE_METADATA                 = "source"
	SOURCE_MIPMAP_METADATA          = "source_mipmap"
	TEXTONLY_METADATA               = "textOnly"
	SRGB_METADATA                   = "srgb"
	F16_METADATA                    = "f16"
	ANIMATED_METADATA               = "animated"
	DURATION_METADATA               = "duration"
	OFFSCREEN_METADATA              = "offscreen"
	OFFSCREEN_WIDTH_METADATA        = "offscreen_width"
	OFFSCREEN_HEIGHT_METADATA       = "offscreen_height"
	OFFSCREEN_SAMPLE_COUNT_METADATA = "offscreen_sample_count"
	OFFSCREEN_TEXTURABLE_METADATA   = "offscreen_texturable"
	OFFSCREEN_MIPMAP_METADATA       = "offscreen_mipmap"
)

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, local bool) (*store, error)

New creates a new *store, which implements Store.

local - True if running locally.

Types

type Media

type Media string

Media is the type of outputs we can get from running a fiddle.

const (
	CPU      Media = "CPU"
	GPU      Media = "GPU"
	PDF      Media = "PDF"
	SKP      Media = "SKP"
	TXT      Media = "TXT"
	ANIM_CPU Media = "ANIM_CPU"
	ANIM_GPU Media = "ANIM_GPU"
	GLINFO   Media = "GLINFO"
	UNKNOWN  Media = ""
)

Media constants.

type Named

type Named struct {
	Name   string
	User   string
	Hash   string
	Status string // If a non-empty string then this named fiddle is broken and the string contains some information about the breakage.
}

Named is the information about a named fiddle.

type Store

type Store interface {
	// Put writes the code and media to Google Storage.
	//
	//    code - The user's code.
	//    options - The options the user chose to run the code under.
	//    results - The results from running fiddle_run.
	//
	// Code is written to:
	//
	//   gs://skia-fiddle/fiddle/<fiddleHash>/draw.cpp
	//
	// And media files are written to:
	//
	//   gs://skia-fiddle/fiddle/<fiddleHash>/cpu.png
	//   gs://skia-fiddle/fiddle/<fiddleHash>/gpu.png
	//   gs://skia-fiddle/fiddle/<fiddleHash>/skp.skp
	//   gs://skia-fiddle/fiddle/<fiddleHash>/pdf.pdf
	//
	// If results is nil then only the code is written.
	//
	// Returns the fiddleHash.
	Put(code string, options types.Options, results *types.Result) (string, error)

	// PutMedia writes the media for the given fiddleHash to Google Storage.
	//
	//    fiddleHash - The fiddle hash.
	//    results - The results from running fiddle_run.
	//
	// Media files are written to:
	//
	//   gs://skia-fiddle/fiddle/<fiddleHash>/cpu.png
	//   gs://skia-fiddle/fiddle/<fiddleHash>/gpu.png
	//   gs://skia-fiddle/fiddle/<fiddleHash>/skp.skp
	//   gs://skia-fiddle/fiddle/<fiddleHash>/pdf.pdf
	//
	// If results is nil then only the code is written.
	//
	// Returns the fiddleHash.
	PutMedia(options types.Options, fiddleHash string, results *types.Result) error

	// GetCode returns the code and options for the given fiddle hash.
	//
	//    fiddleHash - The fiddle hash.
	//
	// Returns the code and the options the code was run under.
	GetCode(fiddleHash string) (string, *types.Options, error)

	// GetMedia returns the file, content-type, filename, and error for a given fiddle hash and type of media.
	//
	//    fiddleHash - The hash of the fiddle.
	//    media - The type of the file to read.
	//
	// Returns the media file contents as a byte slice, the content-type, and the filename of the media.
	GetMedia(fiddleHash string, media Media) ([]byte, string, string, error)

	// ListAllNames returns the list of all named fiddles.
	ListAllNames() ([]Named, error)

	// GetHashFromName loads the fiddle hash for the given name.
	GetHashFromName(name string) (string, error)

	// ValidName returns true if the name conforms to the restrictions on names.
	//
	//   name - The name of the fidde.
	ValidName(name string) bool

	// WriteName writes the name file for a named fiddle.
	//
	//   name - The name of the fidde.
	//   hash - The fiddle hash.
	//   user - The email of the user that created the name.
	//   status - The current status of the named fiddle. An empty string means it
	//       is working. Non-empty string implies the fiddle is broken.
	WriteName(name, hash, user, status string) error

	// SetStatus updates just the status of a named fiddle.
	//
	//   name - The name of the fidde.
	//   status - The current status of the named fiddle. An empty string means it
	//       is working. Non-empty string implies the fiddle is broken.
	SetStatus(name, status string) error

	// DeleteName deletes a named fiddle.
	//
	//   name - The name of the fidde.
	DeleteName(name string) error

	// Exists returns true if the hash exists.
	//
	//   hash - A fiddle hash, maybe.
	Exists(hash string) error
}

Store is used to read and write user code and media to and from Google Storage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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