mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] Normalize status content (don't parse status content as IRI) (#1665)
* start fannying about * finish up Normalize * tidy up * pin to tag * move errors about just a little bit
This commit is contained in:
@@ -19,14 +19,11 @@ package dereferencing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/superseriousbusiness/activity/streams"
|
||||
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
@@ -161,78 +158,10 @@ func (d *deref) dereferenceStatusable(ctx context.Context, tsport transport.Tran
|
||||
|
||||
b, err := tsport.Dereference(ctx, remoteStatusID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("DereferenceStatusable: error deferencing %s: %s", remoteStatusID.String(), err)
|
||||
return nil, fmt.Errorf("dereferenceStatusable: error deferencing %s: %w", remoteStatusID.String(), err)
|
||||
}
|
||||
|
||||
m := make(map[string]interface{})
|
||||
if err := json.Unmarshal(b, &m); err != nil {
|
||||
return nil, fmt.Errorf("DereferenceStatusable: error unmarshalling bytes into json: %s", err)
|
||||
}
|
||||
|
||||
t, err := streams.ToType(ctx, m)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("DereferenceStatusable: error resolving json into ap vocab type: %s", err)
|
||||
}
|
||||
|
||||
// Article, Document, Image, Video, Note, Page, Event, Place, Mention, Profile
|
||||
switch t.GetTypeName() {
|
||||
case ap.ObjectArticle:
|
||||
p, ok := t.(vocab.ActivityStreamsArticle)
|
||||
if !ok {
|
||||
return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsArticle")
|
||||
}
|
||||
return p, nil
|
||||
case ap.ObjectDocument:
|
||||
p, ok := t.(vocab.ActivityStreamsDocument)
|
||||
if !ok {
|
||||
return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsDocument")
|
||||
}
|
||||
return p, nil
|
||||
case ap.ObjectImage:
|
||||
p, ok := t.(vocab.ActivityStreamsImage)
|
||||
if !ok {
|
||||
return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsImage")
|
||||
}
|
||||
return p, nil
|
||||
case ap.ObjectVideo:
|
||||
p, ok := t.(vocab.ActivityStreamsVideo)
|
||||
if !ok {
|
||||
return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsVideo")
|
||||
}
|
||||
return p, nil
|
||||
case ap.ObjectNote:
|
||||
p, ok := t.(vocab.ActivityStreamsNote)
|
||||
if !ok {
|
||||
return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsNote")
|
||||
}
|
||||
return p, nil
|
||||
case ap.ObjectPage:
|
||||
p, ok := t.(vocab.ActivityStreamsPage)
|
||||
if !ok {
|
||||
return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsPage")
|
||||
}
|
||||
return p, nil
|
||||
case ap.ObjectEvent:
|
||||
p, ok := t.(vocab.ActivityStreamsEvent)
|
||||
if !ok {
|
||||
return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsEvent")
|
||||
}
|
||||
return p, nil
|
||||
case ap.ObjectPlace:
|
||||
p, ok := t.(vocab.ActivityStreamsPlace)
|
||||
if !ok {
|
||||
return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsPlace")
|
||||
}
|
||||
return p, nil
|
||||
case ap.ObjectProfile:
|
||||
p, ok := t.(vocab.ActivityStreamsProfile)
|
||||
if !ok {
|
||||
return nil, errors.New("DereferenceStatusable: error resolving type as ActivityStreamsProfile")
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
return nil, newErrWrongType(fmt.Errorf("DereferenceStatusable: type name %s not supported as Statusable", t.GetTypeName()))
|
||||
return ap.ResolveStatusable(ctx, b)
|
||||
}
|
||||
|
||||
// populateStatusFields fetches all the information we temporarily pinned to an incoming
|
||||
|
Reference in New Issue
Block a user