imageframe

package
v0.0.0-...-740805f Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BackgroundNotificationsAccepted = "notifications-accepted.png"
	BackgroundNotificationsDenied   = "notifications-denied.png"
	BackgroundNotifications         = "notifications.png"
	BackgroundNotificationsError    = "notifications-error.png"
	BackgroundNotificationsManage   = "notifications-manage.png"

	BackgroundsDir    = "images/"
	ImageGeneratorURL = "https://img.frame.vote"

	TimeoutImageGeneration = 15 * time.Second
)

Variables

This section is empty.

Functions

func AddImageToCache

func AddImageToCache(data []byte) string

AddImageToCache adds an image to the LRU cache. Returns the cache key. The key is the hash of the image data.

func AddImageToCacheWithID

func AddImageToCacheWithID(id string, data []byte)

AddImageToCacheWithID adds an image to the LRU cache with a specific ID.

func AfterVoteImage

func AfterVoteImage() string

AfterVoteImage creates a static image to be displayed after a vote has been cast.

func AlreadyDelegated

func AlreadyDelegated() string

AlreadyDelegated creates a static image to be displayed when a user has already delegated their vote.

func AlreadyVotedImage

func AlreadyVotedImage() string

AlreadyVotedImage creates a static image to be displayed when a user has already voted.

func ErrorImage

func ErrorImage(errorMessage string) (string, error)

ErrorImage creates an image representing an error message.

func FromCache

func FromCache(id string) []byte

FromCache tries to retrieve data from cache with a specified id. Returns nil if the image is not in the cache. If the data is not available, it retries until the timeout is reached.

func InfoImage

func InfoImage(infoLines []string) (string, error)

InfoImage creates an image displaying an informational message. Returns the image id that can be fetch using FromCache(id).

func IsInCache

func IsInCache(id string) bool

IsInCache checks if an image is in the LRU cache.

func NotElegibleImage

func NotElegibleImage() string

NotElegibleImage creates a static image to be displayed when a user is not elegible to vote.

func NotFoundImage

func NotFoundImage() string

NotFoundImage creates a static image to be displayed when an election is not found.

func NotificationsAcceptedImage

func NotificationsAcceptedImage() string

NotificationsAcceptedImage creates a static image to be displayed when notifications are accepted.

func NotificationsDeniedImage

func NotificationsDeniedImage() string

NotificationsDeniedImage creates a static image to be displayed when notifications are denied.

func NotificationsErrorImage

func NotificationsErrorImage() string

NotificationsErrorImage creates a static image to be displayed when there is an error with notifications.

func NotificationsImage

func NotificationsImage() string

NotificationsImage creates a static image to be displayed when notifications are requested.

func NotificationsManageImage

func NotificationsManageImage() string

NotificationsManageImage creates a static image to be displayed when the user tries to manage muted users.

func Preview

func Preview(election *api.Election) (string, error)

Preview creates an image representing a question preview.

func QuestionImage

func QuestionImage(election *api.Election) (string, error)

QuestionImage creates an image representing a question with choices.

func ResultsImage

func ResultsImage(election *api.Election, electiondb *mongo.Election, totalWeightStr string) (string, error)

ResultsImage creates an image showing the results of a poll. It returns the image id that can be fetch using FromCache(id). The totalWeightStr is the total weight of the census, if empty Turnout is not calculated. The electiondb is the election data from the database, if nil the participation is not calculated.

Types

type ImageRequest

type ImageRequest struct {
	Title         string   `json:"title,omitempty"`
	Type          string   `json:"type"`
	Error         string   `json:"error,omitempty"`
	Info          []string `json:"info,omitempty"`
	Question      string   `json:"question,omitempty"`
	Choices       []string `json:"choices,omitempty"`
	Results       []string `json:"results,omitempty"`
	VoteCount     uint64   `json:"voteCount"`
	Participation float32  `json:"participation"`
	Turnout       float32  `json:"turnout"`
	Ends          string   `json:"ends,omitempty"`
	Ended         bool     `json:"ended,omitempty"`
}

ImageRequest is a general struct for making requests to the API. It includes all possible fields that can be sent to the API.

Jump to

Keyboard shortcuts

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