summaryrefslogtreecommitdiff
path: root/internal/processing/federation
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-09-06 12:42:55 +0200
committerLibravatar GitHub <noreply@github.com>2022-09-06 12:42:55 +0200
commita872ddebe67c7b76cbb78667224b393a847834ac (patch)
tree28b7d0081ee12ab9928eff0aecd6b55d32d8228d /internal/processing/federation
parent[bugfix] Catch json syntax errors in the frontend + display a more helpful me... (diff)
downloadgotosocial-a872ddebe67c7b76cbb78667224b393a847834ac.tar.xz
[feature] Custom emoji updates (serve emoji via s2s api, tune db models) (#805)
* migrate emojis * add get emoji to s2s (federation) API * add new emoji db + cache functions * add shortcodeDomain lookup for emojis * check existing emojis w/cache, not w/constraints * go fmt * add putEmoji func * use new db emoji funcs instead of where * remove emojistringstotags func * add unique constraint back in * fix up broken migration * update index
Diffstat (limited to 'internal/processing/federation')
-rw-r--r--internal/processing/federation/federation.go3
-rw-r--r--internal/processing/federation/getemoji.go59
2 files changed, 62 insertions, 0 deletions
diff --git a/internal/processing/federation/federation.go b/internal/processing/federation/federation.go
index adf7b0437..c79baec3c 100644
--- a/internal/processing/federation/federation.go
+++ b/internal/processing/federation/federation.go
@@ -56,6 +56,9 @@ type Processor interface {
// GetWebfingerAccount handles the GET for a webfinger resource. Most commonly, it will be used for returning account lookups.
GetWebfingerAccount(ctx context.Context, requestedUsername string) (*apimodel.WellKnownResponse, gtserror.WithCode)
+ // GetFediEmoji handles the GET for a federated emoji originating from this instance.
+ GetEmoji(ctx context.Context, requestedEmojiID string, requestURL *url.URL) (interface{}, gtserror.WithCode)
+
// GetNodeInfoRel returns a well known response giving the path to node info.
GetNodeInfoRel(ctx context.Context, request *http.Request) (*apimodel.WellKnownResponse, gtserror.WithCode)
diff --git a/internal/processing/federation/getemoji.go b/internal/processing/federation/getemoji.go
new file mode 100644
index 000000000..a6d76deee
--- /dev/null
+++ b/internal/processing/federation/getemoji.go
@@ -0,0 +1,59 @@
+/*
+ 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 federation
+
+import (
+ "context"
+ "fmt"
+ "net/url"
+
+ "github.com/superseriousbusiness/activity/streams"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
+)
+
+func (p *processor) GetEmoji(ctx context.Context, requestedEmojiID string, requestURL *url.URL) (interface{}, gtserror.WithCode) {
+ if _, errWithCode := p.federator.AuthenticateFederatedRequest(ctx, ""); errWithCode != nil {
+ return nil, errWithCode
+ }
+
+ requestedEmoji, err := p.db.GetEmojiByID(ctx, requestedEmojiID)
+ if err != nil {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("database error getting emoji with id %s: %s", requestedEmojiID, err))
+ }
+
+ if requestedEmoji.Domain != "" {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("emoji with id %s doesn't belong to this instance (domain %s)", requestedEmojiID, requestedEmoji.Domain))
+ }
+
+ if *requestedEmoji.Disabled {
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("emoji with id %s has been disabled", requestedEmojiID))
+ }
+
+ apEmoji, err := p.tc.EmojiToAS(ctx, requestedEmoji)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting gtsmodel emoji with id %s to ap emoji: %s", requestedEmojiID, err))
+ }
+
+ data, err := streams.Serialize(apEmoji)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ return data, nil
+}