Started working on emoji

This commit is contained in:
tsmethurst 2021-04-13 11:56:12 +02:00
parent 2e7ac10d00
commit 9826f3f6d9
16 changed files with 75 additions and 14 deletions

View File

@ -36,6 +36,10 @@ const (
mediaTypeKey = "media_type"
mediaSizeKey = "media_size"
fileNameKey = "file_name"
shortcodeKey = "shortcode"
emojisPath = "emojis"
filesPath = "files"
)
// fileServer implements the RESTAPIModule interface.
@ -62,6 +66,7 @@ func New(config *config.Config, db db.DB, storage storage.Storage, log *logrus.L
// Route satisfies the RESTAPIModule interface
func (m *fileServer) Route(s router.Router) error {
s.AttachHandler(http.MethodGet, fmt.Sprintf("%s/:%s/:%s/:%s/:%s", m.storageBase, accountIDKey, mediaTypeKey, mediaSizeKey, fileNameKey), m.ServeFile)
s.AttachHandler(http.MethodGet, fmt.Sprintf("%s/:%s/:%s/:%s/:%s", m.storageBase, accountIDKey, mediaTypeKey, mediaSizeKey, fileNameKey), m.serveEmoji)
return nil
}

View File

@ -0,0 +1,7 @@
package fileserver
import "github.com/gin-gonic/gin"
func (m *fileServer) serveEmoji(c *gin.Context) {
}

View File

@ -111,6 +111,10 @@ type DB interface {
HANDY SHORTCUTS
*/
// CreateInstanceAccount creates an account in the database with the same username as the instance host value.
// Ie., if the instance is hosted at 'example.org' the instance user will have a username of 'example.org'.
CreateInstanceAccount() error
// GetAccountByUserID is a shortcut for the common action of fetching an account corresponding to a user ID.
// The given account pointer will be set to the result of the query, whatever it is.
// In case of no entries, a 'no entries' error will be returned

View File

@ -21,17 +21,41 @@ package gtsmodel
import "time"
type Emoji struct {
ID string `pg:"type:uuid,default:gen_random_uuid(),pk,notnull"`
Shortcode string `pg:"notnull"`
CreatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
UpdatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
ImageFileName string
ImageContentType string
ImageFileSize string
ImageUpdatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
Disabled bool
URI string
ImageRemoteURL string
VisibleInPicker bool
CategoryID string
// database ID of this emoji
ID string `pg:"type:uuid,default:gen_random_uuid(),pk,notnull"`
// String shortcode for this emoji -- the part that's between colons. This should be lowercase a-z_
// eg., 'blob_hug' 'purple_heart' Must be unique with domain.
Shortcode string `pg:"notnull,unique:shortcodedomain"`
// Origin domain of this emoji, eg 'example.org', 'queer.party'. Null for local emojis.
Domain string `pg:",unique:shortcodedomain"`
// When was this emoji created. Must be unique with shortcode.
CreatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
// When was this emoji updated
UpdatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
// Where can this emoji be retrieved remotely? Null for local emojis.
// For remote emojis, it'll be something like:
// https://hackers.town/system/custom_emojis/images/000/049/842/original/1b74481204feabfd.png
ImageRemoteURL string
// Where can this emoji be retrieved from the local server? Null for remote emojis.
// Assuming our server is hosted at 'example.org', this will be something like:
// 'https://example.org/fileserver/emojis/bfa6c9c5-6c25-4ea4-98b4-d78b8126fb52.png'
ImageURL string
// Path of the emoji image in the server storage system.
// Will be something like '/gotosocial/storage/emojis/bfa6c9c5-6c25-4ea4-98b4-d78b8126fb52.png'
ImagePath string `pg:",notnull"`
// MIME content type of the emoji image
// Probably "image/png"
ImageContentType string `pg:",notnull"`
// Size of the emoji image file in bytes, for serving purposes.
ImageFileSize int `pg:",notnull"`
// When was the emoji image last updated?
ImageUpdatedAt time.Time `pg:"type:timestamp,notnull,default:now()"`
// Has a moderation action disabled this emoji from being shown?
Disabled bool `pg:",notnull,default:false"`
// ActivityStreams uri of this emoji. Something like 'https://example.org/emojis/1234'
URI string `pg:",notnull,unique"`
// Is this emoji visible in the admin emoji picker?
VisibleInPicker bool `pg:",notnull,default:true"`
// In which emoji category is this emoji visible?
CategoryID string
}

View File

@ -312,6 +312,23 @@ func (ps *postgresService) DeleteWhere(key string, value interface{}, i interfac
HANDY SHORTCUTS
*/
func (ps *postgresService) CreateInstanceAccount() error {
username := ps.config.Host
instanceAccount := &gtsmodel.Account{
Username: username,
}
inserted, err := ps.conn.Model(instanceAccount).Where("username = ?", username).SelectOrInsert();
if err != nil {
return err
}
if inserted {
ps.log.Infof("created instance account %s with id %s",username, instanceAccount.ID)
} else {
ps.log.Infof("instance account %s already exists with id %s", username, instanceAccount.ID)
}
return nil
}
func (ps *postgresService) GetAccountByUserID(userID string, account *gtsmodel.Account) error {
user := &gtsmodel.User{
ID: userID,

View File

@ -38,6 +38,7 @@ const (
MediaAttachment = "attachment"
MediaHeader = "header"
MediaAvatar = "avatar"
MediaEmoji = "emoji"
)
// MediaHandler provides an interface for parsing, storing, and retrieving media objects like photos, videos, and gifs.

View File

@ -58,6 +58,10 @@ func NewTestDB() db.DB {
// StandardDBSetup populates a given db with all the necessary tables/models for perfoming tests.
func StandardDBSetup(db db.DB) {
if err := db.CreateInstanceAccount(); err != nil {
panic(err)
}
for _, m := range testModels {
if err := db.CreateTable(m); err != nil {
panic(err)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB