Merge pull request #609 from pixelfed/frontend-ui-refactor

Frontend ui refactor
This commit is contained in:
daniel 2018-11-29 01:35:21 -07:00 committed by GitHub
commit 3da65132c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 142 additions and 2 deletions

View file

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\{ use App\{
Hashtag, Hashtag,
Follower,
Like, Like,
Media, Media,
Notification, Notification,
@ -30,7 +31,7 @@ class PublicApiController extends Controller
public function __construct() public function __construct()
{ {
$this->middleware('throttle:200, 15'); $this->middleware('throttle:200, 30');
$this->fractal = new Fractal\Manager(); $this->fractal = new Fractal\Manager();
$this->fractal->setSerializer(new ArraySerializer()); $this->fractal->setSerializer(new ArraySerializer());
} }
@ -50,6 +51,7 @@ class PublicApiController extends Controller
{ {
$profile = Profile::whereUsername($username)->first(); $profile = Profile::whereUsername($username)->first();
$status = Status::whereProfileId($profile->id)->find($postid); $status = Status::whereProfileId($profile->id)->find($postid);
$this->scopeCheck($profile, $status);
$item = new Fractal\Resource\Item($status, new StatusTransformer()); $item = new Fractal\Resource\Item($status, new StatusTransformer());
$res = [ $res = [
'status' => $this->fractal->createData($item)->toArray(), 'status' => $this->fractal->createData($item)->toArray(),
@ -73,6 +75,7 @@ class PublicApiController extends Controller
$limit = $request->limit ?? 10; $limit = $request->limit ?? 10;
$profile = Profile::whereUsername($username)->first(); $profile = Profile::whereUsername($username)->first();
$status = Status::whereProfileId($profile->id)->find($postId); $status = Status::whereProfileId($profile->id)->find($postId);
$this->scopeCheck($profile, $status);
if($request->filled('min_id') || $request->filled('max_id')) { if($request->filled('min_id') || $request->filled('max_id')) {
if($request->filled('min_id')) { if($request->filled('min_id')) {
$replies = $status->comments() $replies = $status->comments()
@ -100,4 +103,47 @@ class PublicApiController extends Controller
$res = $this->fractal->createData($resource)->toArray(); $res = $this->fractal->createData($resource)->toArray();
return response()->json($res, 200, [], JSON_PRETTY_PRINT); return response()->json($res, 200, [], JSON_PRETTY_PRINT);
} }
protected function scopeCheck(Profile $profile, Status $status)
{
if($profile->is_private == true && Auth::check() == false) {
abort(404);
}
switch ($status->scope) {
case 'public':
case 'unlisted':
$user = Auth::check() ? Auth::user() : false;
if($user && $profile->is_private) {
$follows = Follower::whereProfileId($user->profile->id)
->whereFollowingId($profile->id)
->exists();
if($follows == false && $profile->id !== $user->profile->id) {
abort(404);
}
}
break;
case 'private':
$follows = Follower::whereProfileId($user->profile->id)
->whereFollowingId($profile->id)
->exists();
if($follows == false && $profile->id !== $user->profile->id) {
abort(404);
}
break;
case 'direct':
abort(404);
break;
case 'draft':
abort(404);
break;
default:
abort(404);
break;
}
}
} }

View file

@ -0,0 +1,18 @@
<?php
namespace App\Transformer\Api;
use League\Fractal;
class EmojiTransformer extends Fractal\TransformerAbstract
{
public function transform($emoji)
{
return [
'shortcode' => '',
'static_url' => '',
'url' => '',
'visible_in_picker' => false
];
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace App\Transformer\Api;
use App\Instance;
use League\Fractal;
class InstanceTransformer extends Fractal\TransformerAbstract
{
public function transform(Instance $instance)
{
return [
'uri' => $instance->url,
'title' => null,
'description' => null,
'email' => null,
'version' => null,
'thumbnail' => null,
'urls' => [],
'stats' => [],
'languages' => null,
'contact_account' => null
];
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace App\Transformer\Api;
use App\Notification;
use League\Fractal;
class NotificationTransformer extends Fractal\TransformerAbstract
{
protected $defaultIncludes = [
'account',
'status',
];
public function transform(Notification $notification)
{
return [
'id' => $notification->id,
'type' => $this->replaceTypeVerb($notification->action),
'created_at' => (string) $notification->created_at,
'account' => null,
'status' => null
];
}
public function includeAccount(Notification $notification)
{
return $this->item($notification->actor, new AccountTransformer());
}
public function includeStatus(Notification $notification)
{
$item = $notification->item;
if(get_class($item) === 'App\Status') {
return $this->item($item, new StatusTransformer());
} else {
return null;
}
}
public function replaceTypeVerb($verb)
{
$verbs = [
'follow' => 'follow',
'mention' => 'mention',
'reblog' => 'share',
'like' => 'favourite',
];
return $verbs[$verb];
}
}

View file

@ -23,7 +23,7 @@ return [
| This value is the version of your PixelFed instance. | This value is the version of your PixelFed instance.
| |
*/ */
'version' => '0.2.1', 'version' => '0.3.0',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------