store

package
v0.0.0-...-03d6fc4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

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

This section is empty.

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 struct {
	// contains filtered or unexported fields
}

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

func New

func New(local bool) (*Store, error)

New creates a new Store.

local - True if running locally.

func (*Store) DeleteName

func (s *Store) DeleteName(name string) error

DeleteName deletes a named fiddle.

name - The name of the fidde.

func (*Store) Exists

func (s *Store) Exists(hash string) error

Exists returns true if the hash exists.

hash - A fiddle hash, maybe.

func (*Store) GetCode

func (s *Store) GetCode(fiddleHash string) (string, *types.Options, 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.

func (*Store) GetHashFromName

func (s *Store) GetHashFromName(name string) (string, error)

GetHashFromName loads the fiddle hash for the given name.

func (*Store) GetMedia

func (s *Store) GetMedia(fiddleHash string, media Media) ([]byte, string, string, 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.

func (*Store) ListAllNames

func (s *Store) ListAllNames() ([]Named, error)

ListAllNames returns the list of all named fiddles.

func (*Store) Put

func (s *Store) Put(code string, options types.Options, results *types.Result) (string, error)

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.

func (*Store) PutMedia

func (s *Store) PutMedia(options types.Options, fiddleHash string, results *types.Result) 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.

func (*Store) SetStatus

func (s *Store) SetStatus(name, 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.

func (*Store) ValidName

func (s *Store) ValidName(name string) bool

ValidName returns true if the name conforms to the restrictions on names.

name - The name of the fidde.

func (*Store) WriteName

func (s *Store) WriteName(name, hash, user, status string) error

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.

Jump to

Keyboard shortcuts

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