feat: add list/upload flag UI
This commit is contained in:
parent
a4698e179a
commit
8b03521382
10 changed files with 223 additions and 12 deletions
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
const ErrInvalidDataURI = errors.Sentinel("invalid data URI")
|
||||
const ErrInvalidContentType = errors.Sentinel("invalid avatar content type")
|
||||
const ErrFileTooLarge = errors.Sentinel("file to be converted exceeds maximum size")
|
||||
|
||||
// ConvertAvatar parses an avatar from a data URI, converts it to WebP and JPEG, and returns the results.
|
||||
func (db *DB) ConvertAvatar(data string) (
|
||||
|
|
|
@ -59,7 +59,7 @@ const (
|
|||
)
|
||||
|
||||
func (db *DB) AccountFlags(ctx context.Context, userID xid.ID) (fs []PrideFlag, err error) {
|
||||
sql, args, err := sq.Select("*").From("pride_flags").Where("user_id = ?", userID).OrderBy("id").ToSql()
|
||||
sql, args, err := sq.Select("*").From("pride_flags").Where("user_id = ?", userID).OrderBy("lower(name)").ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "building query")
|
||||
}
|
||||
|
@ -285,6 +285,8 @@ func (db *DB) FlagObject(ctx context.Context, flagID xid.ID, hash string) (io.Re
|
|||
return obj, nil
|
||||
}
|
||||
|
||||
const MaxFlagInputSize = 512_000
|
||||
|
||||
// ConvertFlag parses a flag from a data URI, converts it to WebP, and returns the result.
|
||||
func (db *DB) ConvertFlag(data string) (webpOut *bytes.Buffer, err error) {
|
||||
defer vips.ShutdownThread()
|
||||
|
@ -300,6 +302,10 @@ func (db *DB) ConvertFlag(data string) (webpOut *bytes.Buffer, err error) {
|
|||
return nil, errors.Wrap(err, "invalid base64 data")
|
||||
}
|
||||
|
||||
if len(rawData) > MaxFlagInputSize {
|
||||
return nil, ErrFileTooLarge
|
||||
}
|
||||
|
||||
image, err := vips.LoadImageFromBuffer(rawData, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "decoding image")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue