mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] Allow newly uploaded emojis to be placed in categories (#939)
* [feature] Add emoji categories GET Serialize emojis in appropriate categories; make it possible to get categories via the admin API * [feature] Create (or use existing) category for new emoji uploads * fix lint issue * update misleading line in swagger docs
This commit is contained in:
@@ -46,6 +46,10 @@ func (p *processor) AdminEmojiDelete(ctx context.Context, authed *oauth.Auth, id
|
||||
return p.adminProcessor.EmojiDelete(ctx, id)
|
||||
}
|
||||
|
||||
func (p *processor) AdminEmojiCategoriesGet(ctx context.Context) ([]*apimodel.EmojiCategory, gtserror.WithCode) {
|
||||
return p.adminProcessor.EmojiCategoriesGet(ctx)
|
||||
}
|
||||
|
||||
func (p *processor) AdminDomainBlockCreate(ctx context.Context, authed *oauth.Auth, form *apimodel.DomainBlockCreateRequest) (*apimodel.DomainBlock, gtserror.WithCode) {
|
||||
return p.adminProcessor.DomainBlockCreate(ctx, authed.Account, form.Domain, form.Obfuscate, form.PublicComment, form.PrivateComment, "")
|
||||
}
|
||||
|
@@ -44,6 +44,7 @@ type Processor interface {
|
||||
EmojisGet(ctx context.Context, account *gtsmodel.Account, user *gtsmodel.User, domain string, includeDisabled bool, includeEnabled bool, shortcode string, maxShortcodeDomain string, minShortcodeDomain string, limit int) (*apimodel.PageableResponse, gtserror.WithCode)
|
||||
EmojiGet(ctx context.Context, account *gtsmodel.Account, user *gtsmodel.User, id string) (*apimodel.AdminEmoji, gtserror.WithCode)
|
||||
EmojiDelete(ctx context.Context, id string) (*apimodel.AdminEmoji, gtserror.WithCode)
|
||||
EmojiCategoriesGet(ctx context.Context) ([]*apimodel.EmojiCategory, gtserror.WithCode)
|
||||
MediaPrune(ctx context.Context, mediaRemoteCacheDays int) gtserror.WithCode
|
||||
}
|
||||
|
||||
|
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/media"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/uris"
|
||||
)
|
||||
|
||||
@@ -57,7 +58,19 @@ func (p *processor) EmojiCreate(ctx context.Context, account *gtsmodel.Account,
|
||||
return f, form.Image.Size, err
|
||||
}
|
||||
|
||||
processingEmoji, err := p.mediaManager.ProcessEmoji(ctx, data, nil, form.Shortcode, emojiID, emojiURI, nil, false)
|
||||
var ai *media.AdditionalEmojiInfo
|
||||
if form.CategoryName != "" {
|
||||
category, err := p.GetOrCreateEmojiCategory(ctx, form.CategoryName)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error putting id in category: %s", err), "error putting id in category")
|
||||
}
|
||||
|
||||
ai = &media.AdditionalEmojiInfo{
|
||||
CategoryID: &category.ID,
|
||||
}
|
||||
}
|
||||
|
||||
processingEmoji, err := p.mediaManager.ProcessEmoji(ctx, data, nil, form.Shortcode, emojiID, emojiURI, ai, false)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error processing emoji: %s", err), "error processing emoji")
|
||||
}
|
||||
|
60
internal/processing/admin/emojicategory.go
Normal file
60
internal/processing/admin/emojicategory.go
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
GoToSocial
|
||||
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||
)
|
||||
|
||||
func (p *processor) GetOrCreateEmojiCategory(ctx context.Context, name string) (*gtsmodel.EmojiCategory, error) {
|
||||
category, err := p.db.GetEmojiCategoryByName(ctx, name)
|
||||
if err == nil {
|
||||
return category, nil
|
||||
}
|
||||
|
||||
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
err = fmt.Errorf("GetOrCreateEmojiCategory: database error trying get emoji category by name: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// we don't have the category yet, just create it with the given name
|
||||
categoryID, err := id.NewRandomULID()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("GetOrCreateEmojiCategory: error generating id for new emoji category: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
category = >smodel.EmojiCategory{
|
||||
ID: categoryID,
|
||||
Name: name,
|
||||
}
|
||||
|
||||
if err := p.db.PutEmojiCategory(ctx, category); err != nil {
|
||||
err = fmt.Errorf("GetOrCreateEmojiCategory: error putting new emoji category in the database: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return category, nil
|
||||
}
|
47
internal/processing/admin/getcategories.go
Normal file
47
internal/processing/admin/getcategories.go
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
GoToSocial
|
||||
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
)
|
||||
|
||||
func (p *processor) EmojiCategoriesGet(ctx context.Context) ([]*apimodel.EmojiCategory, gtserror.WithCode) {
|
||||
categories, err := p.db.GetEmojiCategories(ctx)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("EmojiCategoriesGet: db error: %s", err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
apiCategories := make([]*apimodel.EmojiCategory, 0, len(categories))
|
||||
for _, category := range categories {
|
||||
apiCategory, err := p.tc.EmojiCategoryToAPIEmojiCategory(ctx, category)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("EmojiCategoriesGet: error converting emoji category to api emoji category: %s", err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
apiCategories = append(apiCategories, apiCategory)
|
||||
}
|
||||
|
||||
return apiCategories, nil
|
||||
}
|
@@ -119,6 +119,8 @@ type Processor interface {
|
||||
// AdminEmojiDelete deletes one *local* emoji with the given key. Remote emojis will not be deleted this way.
|
||||
// Only admin users in good standing should be allowed to access this function -- check this before calling it.
|
||||
AdminEmojiDelete(ctx context.Context, authed *oauth.Auth, id string) (*apimodel.AdminEmoji, gtserror.WithCode)
|
||||
// AdminEmojiCategoriesGet gets a list of all existing emoji categories.
|
||||
AdminEmojiCategoriesGet(ctx context.Context) ([]*apimodel.EmojiCategory, gtserror.WithCode)
|
||||
// AdminDomainBlockCreate handles the creation of a new domain block by an admin, using the given form.
|
||||
AdminDomainBlockCreate(ctx context.Context, authed *oauth.Auth, form *apimodel.DomainBlockCreateRequest) (*apimodel.DomainBlock, gtserror.WithCode)
|
||||
// AdminDomainBlocksImport handles the import of multiple domain blocks by an admin, using the given form.
|
||||
|
Reference in New Issue
Block a user