common

package module
v0.0.0-...-2706752 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 35 Imported by: 2

Documentation

Overview

MIT License: https://github.com/prplecake/go-thumbnail Package thumbnail provides a method to create thumbnails from images.

Index

Constants

View Source
const (
	QUIET   int = 60
	ANOMALY int = 50
	ERROR   int = 40
	WARNING int = 30
	INFO    int = 20
	DEBUG   int = 10
	VERBOSE int = 0
)
View Source
const (
	ColorReset  = "\033[0m"
	ColorBlack  = "\033[30m"
	ColorRed    = "\033[31m"
	ColorGreen  = "\033[32m"
	ColorYellow = "\033[33m"
	ColorBlue   = "\033[34m"
	ColorPurple = "\033[35m"
	ColorCyan   = "\033[36m"
	ColorWhite  = "\033[37m"
	ColorGrey   = "\033[0;90m"
)
View Source
const (
	ColorBoldBlack  = "\033[1;30m"
	ColorBoldRed    = "\033[1;31m"
	ColorBoldGreen  = "\033[1;32m"
	ColorBoldYellow = "\033[1;33m"
	ColorBoldBlue   = "\033[1;34m"
	ColorBoldPurple = "\033[1;35m"
	ColorBoldCyan   = "\033[1;36m"
	ColorBoldWhite  = "\033[1;37m"
)

Variables

View Source
var (
	// ErrInvalidMimeType is returned when a non-image content type is
	// detected.
	ErrInvalidMimeType = errors.New("invalid mimetype")

	// ErrInvalidScaler is returned when an unrecognized scaler is
	// passed to the Generator.
	ErrInvalidScaler = errors.New("invalid scaler")
)

Functions

func AESDecrypt

func AESDecrypt(key string, iv []byte, encryptedData []byte) (decrypted []byte, err error)

func CheckPassword

func CheckPassword(input string, bcryptString string) bool

func CheckPasswordHashed

func CheckPasswordHashed(inputHashed []byte, bcryptString string) bool

func CheckPasswordHashedHex

func CheckPasswordHashedHex(inputHex string, bcryptString string) bool

func ClearPasswordCache

func ClearPasswordCache()

func CreateBeatmap

func CreateBeatmap(beatmap *Beatmap, state *State) error

func CreateBeatmaps

func CreateBeatmaps(beatmaps []Beatmap, state *State) error

func CreateBeatmapset

func CreateBeatmapset(beatmapset *Beatmapset, state *State) error

func CreateDatabaseSession

func CreateDatabaseSession(config *DatabaseConfiguration) (*gorm.DB, error)

func CreateForum

func CreateForum(forum *Forum, state *State) error

func CreatePasswordHash

func CreatePasswordHash(password string) (string, error)

func CreatePost

func CreatePost(post *ForumPost, state *State) error

func CreateRedisSession

func CreateRedisSession(ctx context.Context, config *RedisConfiguration) (*redis.Client, error)

func CreateScore

func CreateScore(score *Score, state *State) error

func CreateStats

func CreateStats(stats *Stats, state *State) error

func CreateTopic

func CreateTopic(topic *ForumTopic, state *State) error

func CreateUser

func CreateUser(user *User, state *State) error

func CreateUserRelationship

func CreateUserRelationship(relationship *Relationship, state *State) error

func DecryptScoreData

func DecryptScoreData(iv []byte, encryptedData []byte) ([]byte, error)

func DeleteForum

func DeleteForum(forum *Forum, state *State) error

func DeletePost

func DeletePost(post *ForumPost, state *State) error

func DeleteScore

func DeleteScore(score *Score, state *State) error

func DeleteTopic

func DeleteTopic(topic *ForumTopic, state *State) error

func ExtractAudioSnippet

func ExtractAudioSnippet(audioData []byte, offset int, duration int, bitrate int, storage Storage) ([]byte, error)

ExtractAudioSnippet extracts a snippet from the audio byte slice, compresses it, and saves it into an MP3 file

func FetchBeatmapsetCountByCreatorId

func FetchBeatmapsetCountByCreatorId(userId int, state *State) (int, error)

func FetchBeatmapsetRankedCountByCreatorId

func FetchBeatmapsetRankedCountByCreatorId(userId int, state *State) (int, error)

func FetchBeatmapsetUnrankedCountByCreatorId

func FetchBeatmapsetUnrankedCountByCreatorId(userId int, state *State) (int, error)

func FormatBytes

func FormatBytes(data []byte) string

FormatBytes returns a string representation of a byte slice similar to how python handles byte strings

func FormatStruct

func FormatStruct(s interface{}) string

FormatStruct returns a string representation of a struct

func FormatValue

func FormatValue(v reflect.Value) string

FormatValue handles different types and returns the formatted string

func GetClearsRank

func GetClearsRank(userId int, state *State) (int, error)

func GetCountryClearsRank

func GetCountryClearsRank(userId int, countryCode string, state *State) (int, error)

func GetCountryScoreRank

func GetCountryScoreRank(userId int, country string, state *State) (int, error)

func GetCountryTotalScoreRank

func GetCountryTotalScoreRank(userId int, country string, state *State) (int, error)

func GetPasswordCache

func GetPasswordCache() map[string]bool

func GetSHA512Hash

func GetSHA512Hash(input string) []byte

func GetScoreRank

func GetScoreRank(userId int, state *State) (int, error)

func GetTotalScoreRank

func GetTotalScoreRank(userId int, state *State) (int, error)

func HandlePanic

func HandlePanic(err *error)

func JulianToTime

func JulianToTime(julianDate float64) time.Time

JulianToTime converts a Julian date to time.Time

func ReadBigIntBE

func ReadBigIntBE(data []byte) *big.Int

func ReadU16

func ReadU16(data []byte) uint16

func ReadU16BE

func ReadU16BE(data []byte) uint16

func ReadU32

func ReadU32(data []byte) uint32

func ReadU32BE

func ReadU32BE(data []byte) uint32

func ReadU64

func ReadU64(data []byte) uint64

func ReadU64BE

func ReadU64BE(data []byte) uint64

func ReadU8

func ReadU8(data []byte) uint8

func RemoveBeatmap

func RemoveBeatmap(beatmap *Beatmap, state *State) error

func RemoveBeatmapsBySetId

func RemoveBeatmapsBySetId(setId int, state *State) error

func RemoveBeatmapset

func RemoveBeatmapset(beatmapset *Beatmapset, state *State) error

func RemoveRankingsEntry

func RemoveRankingsEntry(stats *Stats, country string, state *State) error

func RemoveUserRelationship

func RemoveUserRelationship(relationship *Relationship, state *State) error

func TimeToJulian

func TimeToJulian(t time.Time) float64

TimeToJulian converts a time.Time object to Julian date

func UnpadPKCS7

func UnpadPKCS7(data []byte) ([]byte, error)

func UpdateBeatmap

func UpdateBeatmap(beatmap *Beatmap, state *State) error

func UpdateBeatmapset

func UpdateBeatmapset(beatmapset *Beatmapset, state *State) error

func UpdateForum

func UpdateForum(forum *Forum, state *State) error

func UpdatePlaytime

func UpdatePlaytime(userId int, secondsToAdd int, state *State) error

func UpdatePost

func UpdatePost(post *ForumPost, state *State) error

func UpdateRankingsEntry

func UpdateRankingsEntry(stats *Stats, country string, state *State) error

func UpdateScore

func UpdateScore(score *Score, state *State) error

func UpdateStats

func UpdateStats(stats *Stats, state *State) error

func UpdateTopic

func UpdateTopic(topic *ForumTopic, state *State) error

func WriteBigIntBE

func WriteBigIntBE(value *big.Int, length int) []byte

func WriteU16

func WriteU16[T constraints.Integer](value T) []byte

func WriteU16BE

func WriteU16BE[T constraints.Integer](value T) []byte

func WriteU32

func WriteU32[T constraints.Integer](value T) []byte

func WriteU32BE

func WriteU32BE[T constraints.Integer](value T) []byte

func WriteU64

func WriteU64[T constraints.Integer](value T) []byte

func WriteU64BE

func WriteU64BE[T constraints.Integer](value T) []byte

func WriteU8

func WriteU8[T constraints.Integer](value T) []byte

Types

type Beatmap

type Beatmap struct {
	Id            int           `gorm:"primaryKey;autoIncrement;not null"`
	SetId         int           `gorm:"not null"`
	Checksum      string        `gorm:"size:32;not null"`
	Version       string        `gorm:"size:255;not null"`
	Filename      string        `gorm:"size:512;not null"`
	CreatorId     int           `gorm:"not null"`
	CreatedAt     time.Time     `gorm:"not null;default:now()"`
	LastUpdated   time.Time     `gorm:"not null;default:now()"`
	Status        BeatmapStatus `gorm:"not null"`
	TotalLength   int           `gorm:"not null;default:0"`
	DrainLength   int           `gorm:"not null;default:0"`
	TotalCircles  int           `gorm:"not null;default:0"`
	TotalSliders  int           `gorm:"not null;default:0"`
	TotalSpinners int           `gorm:"not null;default:0"`
	TotalHolds    int           `gorm:"not null;default:0"`
	MaxCombo      int           `gorm:"not null;default:0"`
	MedianBpm     float64       `gorm:"not null;default:0"`
	HighestBpm    float64       `gorm:"not null;default:0"`
	LowestBpm     float64       `gorm:"not null;default:0"`
	CS            float64       `gorm:"not null;default:0"`
	HP            float64       `gorm:"not null;default:0"`
	OD            float64       `gorm:"not null;default:0"`
	AR            float64       `gorm:"not null;default:0"`
	SR            float64       `gorm:"not null;default:0"`

	Set     Beatmapset `gorm:"foreignKey:SetId"`
	Creator User       `gorm:"foreignKey:CreatorId"`
}

func FetchBeatmapByChecksum

func FetchBeatmapByChecksum(checksum string, state *State, preload ...string) (*Beatmap, error)

func FetchBeatmapById

func FetchBeatmapById(id int, state *State, preload ...string) (*Beatmap, error)

func FetchBeatmapsBySetId

func FetchBeatmapsBySetId(setId int, state *State, preload ...string) ([]Beatmap, error)

func (*Beatmap) TotalObjects

func (beatmap *Beatmap) TotalObjects() int

type BeatmapAvailability

type BeatmapAvailability int
const (
	BeatmapHasDownload             BeatmapAvailability = iota
	BeatmapHasDMCA                 BeatmapAvailability = iota
	BeatmapHasInappropriateContent BeatmapAvailability = iota
)

type BeatmapStatus

type BeatmapStatus int
const (
	BeatmapStatusUnknown      BeatmapStatus = iota
	BeatmapStatusNotSubmitted BeatmapStatus = iota
	BeatmapStatusPending      BeatmapStatus = iota
	BeatmapStatusRanked       BeatmapStatus = iota
	BeatmapStatusApproved     BeatmapStatus = iota
)

type Beatmapset

type Beatmapset struct {
	Id                 int                 `gorm:"primaryKey;autoIncrement;not null"`
	Title              string              `gorm:"size:255;not null"`
	Artist             string              `gorm:"size:255;not null"`
	Source             string              `gorm:"size:255;not null"`
	Tags               pq.StringArray      `gorm:"type:text[];not null;default:'{}'"`
	CreatorId          int                 `gorm:"not null"`
	CreatedAt          time.Time           `gorm:"not null;default:now()"`
	LastUpdated        time.Time           `gorm:"not null;default:now()"`
	ApprovedAt         *time.Time          `gorm:"default:null"`
	ApprovedBy         *int                `gorm:"default:null"`
	Status             BeatmapStatus       `gorm:"not null;default:1"`
	Description        string              `gorm:"type:text;not null"`
	HasVideo           bool                `gorm:"not null;default:false"`
	AvailabilityStatus BeatmapAvailability `gorm:"not null;default:0"`
	AvailabilityInfo   string              `gorm:"type:text;not null;default:''"`
	TopicId            *int                `gorm:"default:null"`

	Beatmaps []Beatmap  `gorm:"foreignKey:SetId"`
	Topic    ForumTopic `gorm:"foreignKey:TopicId"`
	Creator  User       `gorm:"foreignKey:CreatorId"`
}

func FetchBeatmapsetById

func FetchBeatmapsetById(id int, state *State, preload ...string) (*Beatmapset, error)

func FetchBeatmapsetsByCreatorId

func FetchBeatmapsetsByCreatorId(userId int, state *State, preload ...string) ([]Beatmapset, error)

func FetchBeatmapsetsByStatus

func FetchBeatmapsetsByStatus(userId int, status BeatmapStatus, state *State, preload ...string) ([]Beatmapset, error)

type DatabaseConfiguration

type DatabaseConfiguration struct {
	Host        string
	Port        int
	Username    string
	Password    string
	Database    string
	MaxIdle     int
	MaxOpen     int
	MaxLifetime time.Duration
}

func (*DatabaseConfiguration) GetDSN

func (config *DatabaseConfiguration) GetDSN() string

type ErrorCollection

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

func NewErrorCollection

func NewErrorCollection() *ErrorCollection

func (*ErrorCollection) Add

func (ec *ErrorCollection) Add(err error)

func (*ErrorCollection) Errors

func (ec *ErrorCollection) Errors() []error

func (*ErrorCollection) HasErrors

func (ec *ErrorCollection) HasErrors() bool

func (*ErrorCollection) Length

func (ec *ErrorCollection) Length() int

func (*ErrorCollection) Next

func (ec *ErrorCollection) Next() error

func (*ErrorCollection) Pop

func (ec *ErrorCollection) Pop(index int) error

func (*ErrorCollection) String

func (ec *ErrorCollection) String() string

type FileStorage

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

func (*FileStorage) CreateTempFile

func (storage *FileStorage) CreateTempFile() (*os.File, error)

func (*FileStorage) DefaultAvatar

func (storage *FileStorage) DefaultAvatar() ([]byte, error)

func (*FileStorage) Download

func (storage *FileStorage) Download(url string, key string, folder string) error

func (*FileStorage) EnsureDefaultAvatar

func (storage *FileStorage) EnsureDefaultAvatar() error

func (*FileStorage) GetAvatar

func (storage *FileStorage) GetAvatar(userId int) ([]byte, error)

func (*FileStorage) GetBeatmapFile

func (storage *FileStorage) GetBeatmapFile(beatmapId int) ([]byte, error)

func (*FileStorage) GetBeatmapPackage

func (storage *FileStorage) GetBeatmapPackage(beatmapsetId int) ([]byte, error)

func (*FileStorage) GetBeatmapPreview

func (storage *FileStorage) GetBeatmapPreview(beatmapId int) ([]byte, error)

func (*FileStorage) GetBeatmapThumbnail

func (storage *FileStorage) GetBeatmapThumbnail(beatmapId int, large bool) ([]byte, error)

func (*FileStorage) GetReplayFile

func (storage *FileStorage) GetReplayFile(scoreId int) ([]byte, error)

func (*FileStorage) Read

func (storage *FileStorage) Read(key string, folder string) ([]byte, error)

func (*FileStorage) Remove

func (storage *FileStorage) Remove(key string, folder string) error

func (*FileStorage) RemoveBeatmapFile

func (storage *FileStorage) RemoveBeatmapFile(beatmapId int) error

func (*FileStorage) RemoveBeatmapPackage

func (storage *FileStorage) RemoveBeatmapPackage(beatmapsetId int) error

func (*FileStorage) RemoveBeatmapPreview

func (storage *FileStorage) RemoveBeatmapPreview(beatmapId int) error

func (*FileStorage) RemoveBeatmapThumbnail

func (storage *FileStorage) RemoveBeatmapThumbnail(beatmapId int) error

func (*FileStorage) RemoveReplayFile

func (storage *FileStorage) RemoveReplayFile(scoreId int) error

func (*FileStorage) Save

func (storage *FileStorage) Save(key string, folder string, data []byte) error

func (*FileStorage) SaveAvatar

func (storage *FileStorage) SaveAvatar(userId int, data []byte) error

func (*FileStorage) SaveBeatmapFile

func (storage *FileStorage) SaveBeatmapFile(beatmapId int, data []byte) error

func (*FileStorage) SaveBeatmapPackage

func (storage *FileStorage) SaveBeatmapPackage(beatmapsetId int, data []byte) error

func (*FileStorage) SaveBeatmapPreview

func (storage *FileStorage) SaveBeatmapPreview(beatmapId int, data []byte) error

func (*FileStorage) SaveBeatmapThumbnail

func (storage *FileStorage) SaveBeatmapThumbnail(beatmapId int, data []byte, large bool) error

func (*FileStorage) SaveReplayFile

func (storage *FileStorage) SaveReplayFile(scoreId int, data []byte) error

type Forum

type Forum struct {
	Id          int       `gorm:"primaryKey;autoIncrement;not null"`
	ParentId    *int      `gorm:"default:null"`
	CreatedAt   time.Time `gorm:"not null;default:now()"`
	Name        string    `gorm:"size:32;not null"`
	Description string    `gorm:"size:255;not null;default:''"`
	Hidden      bool      `gorm:"not null;default:false"`

	Parent *Forum `gorm:"foreignKey:ParentId"`
}

func FetchForumById

func FetchForumById(id int, state *State, preload ...string) (*Forum, error)

func FetchForumByName

func FetchForumByName(name string, state *State, preload ...string) (*Forum, error)

type ForumPost

type ForumPost struct {
	Id         int       `gorm:"primaryKey;autoIncrement;not null"`
	TopicId    int       `gorm:"not null"`
	ForumId    int       `gorm:"not null"`
	UserId     int       `gorm:"not null"`
	Content    string    `gorm:"type:text;not null"`
	CreatedAt  time.Time `gorm:"not null;default:now()"`
	EditTime   time.Time `gorm:"not null;default:now()"`
	EditCount  int       `gorm:"not null;default:0"`
	EditLocked bool      `gorm:"not null;default:false"`
	Hidden     bool      `gorm:"not null;default:false"`
	Deleted    bool      `gorm:"not null;default:false"`

	Topic ForumTopic `gorm:"foreignKey:TopicId"`
	Forum Forum      `gorm:"foreignKey:ForumId"`
	User  User       `gorm:"foreignKey:UserId"`
}

func FetchInitialPost

func FetchInitialPost(topicId int, state *State, preload ...string) (*ForumPost, error)

func FetchPostById

func FetchPostById(id int, state *State, preload ...string) (*ForumPost, error)

type ForumTopic

type ForumTopic struct {
	Id           int        `gorm:"primaryKey;autoIncrement;not null"`
	ForumId      int        `gorm:"not null"`
	CreatorId    int        `gorm:"not null"`
	Title        string     `gorm:"size:255;not null"`
	StatusText   *string    `gorm:"size:255;default:null"`
	CreatedAt    time.Time  `gorm:"not null;default:now()"`
	LastPostAt   time.Time  `gorm:"not null;default:now()"`
	LockedAt     *time.Time `gorm:"default:null"`
	Views        int        `gorm:"not null;default:0"`
	Announcement bool       `gorm:"not null;default:false"`
	Hidden       bool       `gorm:"not null;default:false"`
	Pinned       bool       `gorm:"not null;default:false"`

	Forum   Forum `gorm:"foreignKey:ForumId"`
	Creator User  `gorm:"foreignKey:CreatorId"`
}

func FetchTopicById

func FetchTopicById(id int, state *State, preload ...string) (*ForumTopic, error)

type Grade

type Grade int
const (
	GradeF Grade = iota + 1
	GradeD
	GradeC
	GradeB
	GradeA
	GradeS
	GradeSH
	GradeX
	GradeXH
)

func (*Grade) Scan

func (g *Grade) Scan(value interface{}) error

func (Grade) String

func (g Grade) String() string

func (Grade) Value

func (g Grade) Value() (driver.Value, error)

type IOStream

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

func NewIOStream

func NewIOStream(data []byte, endian binary.ByteOrder) *IOStream

func (*IOStream) Available

func (stream *IOStream) Available() int

func (*IOStream) Eof

func (stream *IOStream) Eof() bool

func (*IOStream) Get

func (stream *IOStream) Get() []byte

func (*IOStream) Len

func (stream *IOStream) Len() int

func (*IOStream) Push

func (stream *IOStream) Push(data []byte)

func (*IOStream) Read

func (stream *IOStream) Read(size int) []byte

func (*IOStream) ReadAll

func (stream *IOStream) ReadAll() []byte

func (*IOStream) ReadBool

func (stream *IOStream) ReadBool() bool

func (*IOStream) ReadDateTime

func (stream *IOStream) ReadDateTime() time.Time

func (*IOStream) ReadF32

func (stream *IOStream) ReadF32() float32

func (*IOStream) ReadF64

func (stream *IOStream) ReadF64() float64

func (*IOStream) ReadI16

func (stream *IOStream) ReadI16() int16

func (*IOStream) ReadI32

func (stream *IOStream) ReadI32() int32

func (*IOStream) ReadI64

func (stream *IOStream) ReadI64() int64

func (*IOStream) ReadI8

func (stream *IOStream) ReadI8() int8

func (*IOStream) ReadIntList

func (stream *IOStream) ReadIntList() []uint32

func (*IOStream) ReadString

func (stream *IOStream) ReadString() string

func (*IOStream) ReadU16

func (stream *IOStream) ReadU16() uint16

func (*IOStream) ReadU32

func (stream *IOStream) ReadU32() uint32

func (*IOStream) ReadU32Bool

func (stream *IOStream) ReadU32Bool() bool

func (*IOStream) ReadU64

func (stream *IOStream) ReadU64() uint64

func (*IOStream) ReadU8

func (stream *IOStream) ReadU8() uint8

func (*IOStream) Seek

func (stream *IOStream) Seek(position int)

func (*IOStream) Skip

func (stream *IOStream) Skip(offset int)

func (*IOStream) Tell

func (stream *IOStream) Tell() int

func (*IOStream) Write

func (stream *IOStream) Write(data []byte)

func (*IOStream) WriteBool

func (stream *IOStream) WriteBool(value bool)

func (*IOStream) WriteDateTime

func (stream *IOStream) WriteDateTime(value time.Time)

func (*IOStream) WriteF32

func (stream *IOStream) WriteF32(value float32)

func (*IOStream) WriteF64

func (stream *IOStream) WriteF64(value float64)

func (*IOStream) WriteI16

func (stream *IOStream) WriteI16(value int16)

func (*IOStream) WriteI32

func (stream *IOStream) WriteI32(value int32)

func (*IOStream) WriteI64

func (stream *IOStream) WriteI64(value int64)

func (*IOStream) WriteI8

func (stream *IOStream) WriteI8(value int8)

func (*IOStream) WriteIntList

func (stream *IOStream) WriteIntList(list []uint32)

func (*IOStream) WriteString

func (stream *IOStream) WriteString(value string)

func (*IOStream) WriteU16

func (stream *IOStream) WriteU16(value uint16)

func (*IOStream) WriteU32

func (stream *IOStream) WriteU32(value uint32)

func (*IOStream) WriteU32Bool

func (stream *IOStream) WriteU32Bool(value bool)

func (*IOStream) WriteU64

func (stream *IOStream) WriteU64(value uint64)

func (*IOStream) WriteU8

func (stream *IOStream) WriteU8(value uint8)

type Image

type Image struct {
	// Path is a path to an image.
	Path string

	// ContentType is the content type of the image.
	ContentType string

	// Data is the image data in a byte-array
	Data []byte

	// Size is the length of Data
	Size int

	// Current stores the existing image's dimensions
	Current ImageDimensions

	// Future store the new thumbnail dimensions.
	Future ImageDimensions
}

An Image is an image and information about it.

type ImageDimensions

type ImageDimensions struct {
	// Width is the width of an image in pixels.
	Width int

	// Height is the height on an image in pixels.
	Height int

	// X is the right-most X-coordinate.
	X int

	// Y is the top-most Y-coordinate.
	Y int
}

ImageDimensions stores dimensional information for an Image.

type ImageGenerator

type ImageGenerator struct {
	// Width is the destination thumbnail width.
	Width int

	// Height is the destination thumbnail height.
	Height int

	// DestinationPath is the destination thumbnail path.
	DestinationPath string

	// DestinationPrefix is the prefix for the destination thumbnail
	// filename.
	DestinationPrefix string

	// Scaler is the scaler to be used when generating thumbnails.
	Scaler string
}

ImageGenerator registers a generator configuration to be used when creating thumbnails.

func NewImageGenerator

func NewImageGenerator(c ImageGenerator) *ImageGenerator

NewImageGenerator returns an instance of a thumbnail generator with a given configuration.

func (*ImageGenerator) CreateThumbnail

func (gen *ImageGenerator) CreateThumbnail(i *Image) ([]byte, error)

CreateThumbnail generates a thumbnail.

func (*ImageGenerator) NewImageFromByteArray

func (gen *ImageGenerator) NewImageFromByteArray(imageBytes []byte) (*Image, error)

NewImageFromByteArray reads in an image from a byte array and populates an Image object. That new Image object is returned along with any errors that occur during the operation.

func (*ImageGenerator) NewImageFromFile

func (gen *ImageGenerator) NewImageFromFile(path string) (*Image, error)

NewImageFromFile reads in an image file from the file system and populates an Image object. That new Image object is returned along with any errors that occur during the operation.

type Logger

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

func CreateLogger

func CreateLogger(name string, level int) *Logger

func (*Logger) Anomaly

func (c *Logger) Anomaly(msg ...any)

func (*Logger) Anomalyf

func (c *Logger) Anomalyf(format string, msg ...any)

func (*Logger) Debug

func (c *Logger) Debug(msg ...any)

func (*Logger) Debugf

func (c *Logger) Debugf(format string, msg ...any)

func (*Logger) Error

func (c *Logger) Error(msg ...any)

func (*Logger) Errorf

func (c *Logger) Errorf(format string, msg ...any)

func (*Logger) GetLevel

func (c *Logger) GetLevel() int

func (*Logger) GetName

func (c *Logger) GetName() string

func (*Logger) Info

func (c *Logger) Info(msg ...any)

func (*Logger) Infof

func (c *Logger) Infof(format string, msg ...any)

func (*Logger) SetLevel

func (c *Logger) SetLevel(level int)

func (*Logger) SetName

func (c *Logger) SetName(name string)

func (*Logger) Verbose

func (c *Logger) Verbose(msg ...any)

func (*Logger) Verbosef

func (c *Logger) Verbosef(format string, msg ...any)

func (*Logger) Warning

func (c *Logger) Warning(msg ...any)

func (*Logger) Warningf

func (c *Logger) Warningf(format string, msg ...any)

type RedisConfiguration

type RedisConfiguration struct {
	Host     string
	Port     int
	Password string
	Database int
}

type Relationship

type Relationship struct {
	UserId   int                `gorm:"primaryKey;not null"`
	TargetId int                `gorm:"primaryKey;not null"`
	Status   RelationshipStatus `gorm:"type:relationship_status;not null"`

	User   User `gorm:"foreignKey:UserId"`
	Target User `gorm:"foreignKey:TargetId"`
}

func FetchUserRelationship

func FetchUserRelationship(userId int, targetId int, state *State, preload ...string) (*Relationship, error)

func FetchUserRelationships

func FetchUserRelationships(userId int, status RelationshipStatus, state *State, preload ...string) ([]*Relationship, error)

type RelationshipStatus

type RelationshipStatus string
const (
	StatusFriend  RelationshipStatus = "friend"
	StatusBlocked RelationshipStatus = "blocked"
)

type ReplayData

type ReplayData struct {
	Header *ReplayHeader
	Frames []*ReplayFrame
}

func ReadCompressedReplay

func ReadCompressedReplay(stream *IOStream) (data *ReplayData, err error)

func ReadFullReplay

func ReadFullReplay(stream *IOStream) (*ReplayData, error)

func (*ReplayData) Serialize

func (replayData *ReplayData) Serialize(stream *IOStream)

func (*ReplayData) SerializeFrames

func (replayData *ReplayData) SerializeFrames(stream *IOStream)

func (*ReplayData) String

func (replayData *ReplayData) String() string

type ReplayFrame

type ReplayFrame struct {
	Time        uint32
	MouseX      float64
	MouseY      float64
	ButtonState uint32
}

func ReadReplayFrame

func ReadReplayFrame(stream *IOStream) *ReplayFrame

func (*ReplayFrame) Serialize

func (frame *ReplayFrame) Serialize(stream *IOStream)

func (*ReplayFrame) String

func (frame *ReplayFrame) String() string

type ReplayHeader

type ReplayHeader struct {
	Mode            uint32
	ReplayVersion   uint8
	BeatmapChecksum string
	PlayerName      string
	ScoreChecksum   string
	Count300        uint32
	Count100        uint32
	Count50         uint32
	CountGeki       uint32
	CountGood       uint32
	CountMiss       uint32
	TotalScore      float64
	MaxCombo        uint32
	FullCombo       bool
	Time            time.Time
	ModsData        []byte
}

func ReadReplayHeader

func ReadReplayHeader(stream *IOStream) *ReplayHeader

func (*ReplayHeader) Accuracy

func (header *ReplayHeader) Accuracy() float64

func (*ReplayHeader) Grade

func (header *ReplayHeader) Grade() Grade

func (*ReplayHeader) Serialize

func (header *ReplayHeader) Serialize(stream *IOStream)

func (*ReplayHeader) String

func (header *ReplayHeader) String() string

type Score

type Score struct {
	Id            int         `gorm:"primaryKey;autoIncrement;not null"`
	BeatmapId     int         `gorm:"not null"`
	UserId        int         `gorm:"not null"`
	Checksum      string      `gorm:"size:32;not null"`
	Status        ScoreStatus `gorm:"not null"`
	CreatedAt     time.Time   `gorm:"not null;default:now()"`
	ClientVersion int         `gorm:"not null"`
	TotalScore    int64       `gorm:"not null"`
	MaxCombo      int         `gorm:"not null"`
	Accuracy      float64     `gorm:"not null"`
	FullCombo     bool        `gorm:"not null"`
	Passed        bool        `gorm:"not null"`
	Grade         Grade       `gorm:"type:score_grade;not null"`
	Count300      int         `gorm:"not null;column:count_300"`
	Count100      int         `gorm:"not null;column:count_100"`
	Count50       int         `gorm:"not null;column:count_50"`
	CountGeki     int         `gorm:"not null;column:count_geki"`
	CountKatu     int         `gorm:"not null;column:count_katu"`
	CountGood     int         `gorm:"not null;column:count_good"`
	CountMiss     int         `gorm:"not null;column:count_miss"`
	AROffset      int         `gorm:"not null"`
	ODOffset      int         `gorm:"not null"`
	CSOffset      int         `gorm:"not null"`
	HPOffset      int         `gorm:"not null"`
	PSOffset      int         `gorm:"not null"`
	ModHidden     bool        `gorm:"not null"`
	ModNoFail     bool        `gorm:"not null;column:mod_nofail"`
	Visible       bool        `gorm:"not null;default:true"`
	Pinned        bool        `gorm:"not null;default:false"`

	Beatmap Beatmap `gorm:"foreignKey:BeatmapId"`
	User    User    `gorm:"foreignKey:UserId"`
}

func FetchBestScores

func FetchBestScores(userId int, beatmapStatus int, state *State) ([]*Score, error)

func FetchPersonalBest

func FetchPersonalBest(userId int, beatmapId int, state *State, preload ...string) (*Score, error)

func FetchRangeScores

func FetchRangeScores(beatmapId int, state *State, preload ...string) ([]*Score, error)

func FetchScoreById

func FetchScoreById(id int, state *State, preload ...string) (*Score, error)

type ScoreStatus

type ScoreStatus int
const (
	ScoreStatusUnranked  ScoreStatus = iota
	ScoreStatusFailed    ScoreStatus = iota
	ScoreStatusSubmitted ScoreStatus = iota
	ScoreStatusPB        ScoreStatus = iota
)

type State

type State struct {
	Database     *gorm.DB
	Redis        *redis.Client
	RedisContext *context.Context
	Storage      Storage
}

func NewState

func NewState(config *StateConfiguration) (*State, error)

type StateConfiguration

type StateConfiguration struct {
	Database *DatabaseConfiguration
	Redis    *RedisConfiguration
	DataPath string
}

func NewStateConfiguration

func NewStateConfiguration() *StateConfiguration

type Stats

type Stats struct {
	UserId      int     `gorm:"primaryKey;not null"`
	Rank        int     `gorm:"not null;default:0"`
	TotalScore  int64   `gorm:"not null;default:0"`
	RankedScore int64   `gorm:"not null;default:0"`
	Playcount   int     `gorm:"not null;default:0"`
	Playtime    int     `gorm:"not null;default:0"`
	Accuracy    float64 `gorm:"not null;default:0.0000"`
	MaxCombo    int     `gorm:"not null;default:0"`
	TotalHits   int64   `gorm:"not null;default:0"`
	XHCount     int     `gorm:"not null;default:0"`
	XCount      int     `gorm:"not null;default:0"`
	SHCount     int     `gorm:"not null;default:0"`
	SCount      int     `gorm:"not null;default:0"`
	ACount      int     `gorm:"not null;default:0"`
	BCount      int     `gorm:"not null;default:0"`
	CCount      int     `gorm:"not null;default:0"`
	DCount      int     `gorm:"not null;default:0"`
}

func FetchStatsByUserId

func FetchStatsByUserId(userId int, state *State) (*Stats, error)

func (*Stats) Clears

func (stats *Stats) Clears() int

type Storage

type Storage interface {
	// Base
	Save(key string, bucket string, data []byte) error
	Read(key string, bucket string) ([]byte, error)
	Remove(key string, bucket string) error
	Download(url string, key string, bucket string) error
	CreateTempFile() (*os.File, error)

	// Replays
	GetReplayFile(replayId int) ([]byte, error)
	SaveReplayFile(replayId int, data []byte) error
	RemoveReplayFile(replayId int) error

	// Avatars
	GetAvatar(userId int) ([]byte, error)
	SaveAvatar(userId int, data []byte) error
	DefaultAvatar() ([]byte, error)
	EnsureDefaultAvatar() error

	// Beatmaps
	GetBeatmapFile(beatmapId int) ([]byte, error)
	GetBeatmapPackage(beatmapsetId int) ([]byte, error)
	GetBeatmapThumbnail(beatmapId int, large bool) ([]byte, error)
	GetBeatmapPreview(beatmapId int) ([]byte, error)
	SaveBeatmapFile(beatmapId int, data []byte) error
	SaveBeatmapPackage(beatmapsetId int, data []byte) error
	SaveBeatmapThumbnail(beatmapId int, data []byte, large bool) error
	SaveBeatmapPreview(beatmapId int, data []byte) error
	RemoveBeatmapFile(beatmapId int) error
	RemoveBeatmapPackage(beatmapsetId int) error
	RemoveBeatmapThumbnail(beatmapId int) error
	RemoveBeatmapPreview(beatmapId int) error
}

func NewFileStorage

func NewFileStorage(dataPath string) Storage

type User

type User struct {
	Id             int       `gorm:"primaryKey;autoIncrement;not null"`
	Name           string    `gorm:"size:32;not null"`
	Email          string    `gorm:"size:255;not null"`
	Password       string    `gorm:"size:60;not null"`
	Country        string    `gorm:"size:2;default:'XX';not null"`
	CreatedAt      time.Time `gorm:"not null;default:now()"`
	LatestActivity time.Time `gorm:"not null;default:now()"`
	Restricted     bool      `gorm:"not null;default:false"`
	Activated      bool      `gorm:"not null;default:false"`

	Stats Stats `gorm:"foreignKey:UserId"`
}

func FetchUserById

func FetchUserById(id int, state *State, preload ...string) (*User, error)

func FetchUserByName

func FetchUserByName(name string, state *State, preload ...string) (*User, error)

func FetchUserByNameCaseInsensitive

func FetchUserByNameCaseInsensitive(name string, state *State, preload ...string) (*User, error)

func (*User) EnsureStats

func (user *User) EnsureStats(state *State) error

Jump to

Keyboard shortcuts

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