mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-25 06:23:18 +00:00
Update FederationController
This commit is contained in:
parent
5cfa7f877c
commit
154a6444e2
1 changed files with 27 additions and 16 deletions
|
@ -48,8 +48,8 @@ class FederationController extends Controller
|
||||||
{
|
{
|
||||||
$this->authCheck();
|
$this->authCheck();
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'url' => 'required|string',
|
'url' => 'required|string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (config('pixelfed.remote_follow_enabled') !== true) {
|
if (config('pixelfed.remote_follow_enabled') !== true) {
|
||||||
abort(403);
|
abort(403);
|
||||||
|
@ -123,16 +123,15 @@ class FederationController extends Controller
|
||||||
{
|
{
|
||||||
$this->validate($request, ['resource'=>'required|string|min:3|max:255']);
|
$this->validate($request, ['resource'=>'required|string|min:3|max:255']);
|
||||||
|
|
||||||
$hash = hash('sha256', $request->input('resource'));
|
$resource = $request->input('resource');
|
||||||
|
$hash = hash('sha256', $resource);
|
||||||
$webfinger = Cache::remember('api:webfinger:'.$hash, 1440, function () use ($request) {
|
$parsed = Nickname::normalizeProfileUrl($resource);
|
||||||
$resource = $request->input('resource');
|
$username = $parsed['username'];
|
||||||
$parsed = Nickname::normalizeProfileUrl($resource);
|
$profile = Profile::whereUsername($username)->firstOrFail();
|
||||||
$username = $parsed['username'];
|
if($profile->status != null) {
|
||||||
$user = Profile::whereUsername($username)->firstOrFail();
|
return ProfileController::accountCheck($profile);
|
||||||
|
}
|
||||||
return (new Webfinger($user))->generate();
|
$webfinger = (new Webfinger($profile))->generate();
|
||||||
});
|
|
||||||
|
|
||||||
return response()->json($webfinger, 200, [], JSON_PRETTY_PRINT);
|
return response()->json($webfinger, 200, [], JSON_PRETTY_PRINT);
|
||||||
}
|
}
|
||||||
|
@ -156,13 +155,16 @@ XML;
|
||||||
abort(403);
|
abort(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = Profile::whereNull('remote_url')->whereUsername($username)->firstOrFail();
|
$profile = Profile::whereNull('remote_url')->whereUsername($username)->firstOrFail();
|
||||||
if($user->is_private) {
|
if($profile->status != null) {
|
||||||
|
return ProfileController::accountCheck($profile);
|
||||||
|
}
|
||||||
|
if($profile->is_private) {
|
||||||
return response()->json(['error'=>'403', 'msg' => 'private profile'], 403);
|
return response()->json(['error'=>'403', 'msg' => 'private profile'], 403);
|
||||||
}
|
}
|
||||||
$timeline = $user->statuses()->whereVisibility('public')->orderBy('created_at', 'desc')->paginate(10);
|
$timeline = $profile->statuses()->whereVisibility('public')->orderBy('created_at', 'desc')->paginate(10);
|
||||||
$fractal = new Fractal\Manager();
|
$fractal = new Fractal\Manager();
|
||||||
$resource = new Fractal\Resource\Item($user, new ProfileOutbox());
|
$resource = new Fractal\Resource\Item($profile, new ProfileOutbox());
|
||||||
$res = $fractal->createData($resource)->toArray();
|
$res = $fractal->createData($resource)->toArray();
|
||||||
|
|
||||||
return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json');
|
return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json');
|
||||||
|
@ -175,6 +177,9 @@ XML;
|
||||||
}
|
}
|
||||||
|
|
||||||
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||||
|
if($profile->status != null) {
|
||||||
|
return ProfileController::accountCheck($profile);
|
||||||
|
}
|
||||||
$body = $request->getContent();
|
$body = $request->getContent();
|
||||||
$bodyDecoded = json_decode($body, true);
|
$bodyDecoded = json_decode($body, true);
|
||||||
$signature = $request->header('signature');
|
$signature = $request->header('signature');
|
||||||
|
@ -205,6 +210,9 @@ XML;
|
||||||
->whereUsername($username)
|
->whereUsername($username)
|
||||||
->whereIsPrivate(false)
|
->whereIsPrivate(false)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
if($profile->status != null) {
|
||||||
|
return ProfileController::accountCheck($profile);
|
||||||
|
}
|
||||||
$obj = [
|
$obj = [
|
||||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
'id' => $request->getUri(),
|
'id' => $request->getUri(),
|
||||||
|
@ -226,6 +234,9 @@ XML;
|
||||||
->whereUsername($username)
|
->whereUsername($username)
|
||||||
->whereIsPrivate(false)
|
->whereIsPrivate(false)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
if($profile->status != null) {
|
||||||
|
return ProfileController::accountCheck($profile);
|
||||||
|
}
|
||||||
$obj = [
|
$obj = [
|
||||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
'id' => $request->getUri(),
|
'id' => $request->getUri(),
|
||||||
|
|
Loading…
Reference in a new issue