2021-05-27 14:06:24 +00:00
|
|
|
/*
|
|
|
|
GoToSocial
|
|
|
|
Copyright (C) 2021 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 federatingdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/go-fed/activity/streams/vocab"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Get returns the database entry for the specified id.
|
|
|
|
//
|
|
|
|
// The library makes this call only after acquiring a lock first.
|
2021-08-25 13:34:33 +00:00
|
|
|
func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type, err error) {
|
2021-10-11 12:37:33 +00:00
|
|
|
l := logrus.WithFields(
|
2021-05-27 14:06:24 +00:00
|
|
|
logrus.Fields{
|
|
|
|
"func": "Get",
|
2021-10-04 13:24:19 +00:00
|
|
|
"id": id,
|
2021-05-27 14:06:24 +00:00
|
|
|
},
|
|
|
|
)
|
2021-10-04 13:24:19 +00:00
|
|
|
l.Debug("entering Get")
|
2021-05-27 14:06:24 +00:00
|
|
|
|
|
|
|
if util.IsUserPath(id) {
|
2021-08-25 13:34:33 +00:00
|
|
|
acct, err := f.db.GetAccountByURI(ctx, id.String())
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2021-05-27 14:06:24 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
return f.typeConverter.AccountToAS(ctx, acct)
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
|
|
|
|
2021-10-04 13:24:19 +00:00
|
|
|
if util.IsStatusesPath(id) {
|
|
|
|
status, err := f.db.GetStatusByURI(ctx, id.String())
|
2021-05-27 14:06:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-10-04 13:24:19 +00:00
|
|
|
return f.typeConverter.StatusToAS(ctx, status)
|
|
|
|
}
|
2021-05-27 14:06:24 +00:00
|
|
|
|
2021-10-04 13:24:19 +00:00
|
|
|
if util.IsFollowersPath(id) {
|
|
|
|
return f.Followers(ctx, id)
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if util.IsFollowingPath(id) {
|
2021-10-04 13:24:19 +00:00
|
|
|
return f.Following(ctx, id)
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errors.New("could not get")
|
|
|
|
}
|