wasm

package
v0.0.0-...-d58ffde Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrParametersInvalid      = bridge.NewJSTypeError("ParameterError", "Invalid parameters")
	ErrParametersInvalidField = bridge.NewJSTypeError("ParameterError", "Invalid parameters field")

	ErrInvalidCloudflareEnv = bridge.NewJSTypeError("EnvError", "Invalid cloudflare env")
	ErrBucketNotFound       = bridge.NewJSTypeError("EnvError", "Bucket not found")
)
View Source
var JsDraw = js.FuncOf(func(this js.Value, args []js.Value) any {
	rawParameters := args[0]
	bucket := args[1]
	quality := args[2]

	return js.Global().Get("Promise").New(js.FuncOf(func(this js.Value, args []js.Value) any {
		resolve := args[0]
		reject := args[1]

		q, err := parseQuality(quality)
		if err != nil {
			reject.Invoke(bridge.ToJsError(err))
			return nil
		}

		go func() {
			parameters, err := LoadParameters(rawParameters, bucket)
			if err != nil {
				reject.Invoke(bridge.ToJsError(err))
				return
			}

			result, err := draw.Draw(parameters)
			if err != nil {
				reject.Invoke(bridge.ToJsError(err))
				return
			}

			pr, pw := io.Pipe()
			go func() {
				err = jpeg.Encode(pw, result, &jpeg.Options{
					Quality: q,
				})
				defer pw.Close()
				if err != nil {
					reject.Invoke(bridge.ToJsError(err))
					return
				}
			}()

			resolve.Invoke(reader.NewReadableStreamFrom(pr, 2048))
		}()

		return nil
	}))
})

signature: function draw(parameters: payload, bucketName: string, env: any): Promise<ReadableStream>

Functions

This section is empty.

Types

type Parameters

type Parameters struct {
	R2PathIcon       string
	R2PathBackground string

	FontTitle    string
	FontSubtitle string
	// contains filtered or unexported fields
}

func LoadParameters

func LoadParameters(parameters js.Value, bucket js.Value) (*Parameters, error)

func (*Parameters) Background

func (p *Parameters) Background() image.Image

func (*Parameters) FontFaceSubtitle

func (p *Parameters) FontFaceSubtitle() *truetype.Font

func (*Parameters) FontFaceTitle

func (p *Parameters) FontFaceTitle() *truetype.Font

func (*Parameters) Icon

func (p *Parameters) Icon() image.Image

func (*Parameters) SetBackground

func (p *Parameters) SetBackground(background image.Image) *Parameters

func (*Parameters) SetFontFaceSubtitle

func (p *Parameters) SetFontFaceSubtitle(fontFaceSubtitle *truetype.Font) *Parameters

func (*Parameters) SetFontFaceTitle

func (p *Parameters) SetFontFaceTitle(fontFaceTitle *truetype.Font) *Parameters

func (*Parameters) SetIcon

func (p *Parameters) SetIcon(icon image.Image) *Parameters

func (*Parameters) SetSubtitle

func (p *Parameters) SetSubtitle(subtitle string) *Parameters

func (*Parameters) SetTitle

func (p *Parameters) SetTitle(title string) *Parameters

func (*Parameters) Subtitle

func (p *Parameters) Subtitle() string

func (*Parameters) Title

func (p *Parameters) Title() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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