mirror of
https://github.com/YunoHost-Apps/pixelfed_ynh.git
synced 2024-09-03 20:06:04 +02:00
Merge pull request #372 from pixelfed/frontend-ui-refactor
Frontend ui refactor
This commit is contained in:
commit
aa62dd5895
5 changed files with 97 additions and 10 deletions
|
@ -3,33 +3,40 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Auth, Cache;
|
use Auth, Cache;
|
||||||
use App\Jobs\StatusPipeline\{NewStatusPipeline, StatusDelete};
|
use League\Fractal;
|
||||||
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\{Media, Profile, Status, User};
|
|
||||||
use Vinkla\Hashids\Facades\Hashids;
|
use Vinkla\Hashids\Facades\Hashids;
|
||||||
|
use App\{Media, Profile, Status, User};
|
||||||
|
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
||||||
|
use App\Transformer\ActivityPub\StatusTransformer;
|
||||||
|
use App\Jobs\StatusPipeline\{NewStatusPipeline, StatusDelete};
|
||||||
|
|
||||||
class StatusController extends Controller
|
class StatusController extends Controller
|
||||||
{
|
{
|
||||||
public function show(Request $request, $username, int $id)
|
public function show(Request $request, $username, int $id)
|
||||||
{
|
{
|
||||||
$user = Profile::whereUsername($username)->firstOrFail();
|
$user = Profile::whereUsername($username)->firstOrFail();
|
||||||
|
|
||||||
$status = Status::whereProfileId($user->id)
|
$status = Status::whereProfileId($user->id)
|
||||||
->withCount(['likes', 'comments', 'media'])
|
->withCount(['likes', 'comments', 'media'])
|
||||||
->findOrFail($id);
|
->findOrFail($id);
|
||||||
|
|
||||||
if(!$status->media_path && $status->in_reply_to_id) {
|
if(!$status->media_path && $status->in_reply_to_id) {
|
||||||
return redirect($status->url());
|
return redirect($status->url());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($request->wantsJson() && config('pixelfed.activitypub_enabled')) {
|
||||||
|
return $this->showActivityPub($request, $status);
|
||||||
|
}
|
||||||
|
|
||||||
$replies = Status::whereInReplyToId($status->id)->simplePaginate(30);
|
$replies = Status::whereInReplyToId($status->id)->simplePaginate(30);
|
||||||
|
|
||||||
return view('status.show', compact('user', 'status', 'replies'));
|
return view('status.show', compact('user', 'status', 'replies'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compose()
|
public function compose()
|
||||||
{
|
{
|
||||||
if(Auth::check() == false)
|
$this->authCheck();
|
||||||
{
|
|
||||||
abort(403);
|
|
||||||
}
|
|
||||||
return view('status.compose');
|
return view('status.compose');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,4 +163,20 @@ class StatusController extends Controller
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function showActivityPub(Request $request, $status)
|
||||||
|
{
|
||||||
|
$fractal = new Fractal\Manager();
|
||||||
|
$resource = new Fractal\Resource\Item($status, new StatusTransformer);
|
||||||
|
$res = $fractal->createData($resource)->toArray();
|
||||||
|
return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function authCheck()
|
||||||
|
{
|
||||||
|
if(Auth::check() == false)
|
||||||
|
{
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,9 @@ class ProfileTransformer extends Fractal\TransformerAbstract
|
||||||
'https://w3id.org/security/v1',
|
'https://w3id.org/security/v1',
|
||||||
[
|
[
|
||||||
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
|
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
|
||||||
"featured" => 'https://pixelfed.org/ns/featured',
|
"featured" => [
|
||||||
|
"https://pixelfed.org/ns#featured" => ["@type" => "@id"],
|
||||||
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'id' => $profile->permalink(),
|
'id' => $profile->permalink(),
|
||||||
|
|
62
app/Transformer/ActivityPub/StatusTransformer.php
Normal file
62
app/Transformer/ActivityPub/StatusTransformer.php
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Transformer\ActivityPub;
|
||||||
|
|
||||||
|
use App\{Profile, Status};
|
||||||
|
use League\Fractal;
|
||||||
|
|
||||||
|
class StatusTransformer extends Fractal\TransformerAbstract
|
||||||
|
{
|
||||||
|
|
||||||
|
public function transform(Status $status)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'@context' => [
|
||||||
|
'https://www.w3.org/ns/activitystreams',
|
||||||
|
'https://w3id.org/security/v1',
|
||||||
|
[
|
||||||
|
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
|
||||||
|
"featured" => [
|
||||||
|
"https://pixelfed.org/ns#featured" => ["@type" => "@id"],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'id' => $status->url(),
|
||||||
|
|
||||||
|
// TODO: handle other types
|
||||||
|
'type' => 'Note',
|
||||||
|
|
||||||
|
// XXX: CW Title
|
||||||
|
'summary' => null,
|
||||||
|
'content' => $status->rendered ?? $status->caption,
|
||||||
|
'inReplyTo' => null,
|
||||||
|
|
||||||
|
// TODO: fix date format
|
||||||
|
'published' => $status->created_at->toAtomString(),
|
||||||
|
'url' => $status->url(),
|
||||||
|
'attributedTo' => $status->profile->permalink(),
|
||||||
|
'to' => [
|
||||||
|
// TODO: handle proper scope
|
||||||
|
'https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
],
|
||||||
|
'cc' => [
|
||||||
|
// TODO: add cc's
|
||||||
|
$status->profile->permalink('/followers'),
|
||||||
|
],
|
||||||
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
|
'atomUri' => $status->url(),
|
||||||
|
'inReplyToAtomUri' => null,
|
||||||
|
'conversation' => $status->url(),
|
||||||
|
'attachment' => $status->media->map(function($media) {
|
||||||
|
return [
|
||||||
|
'type' => 'Document',
|
||||||
|
'mediaType' => $media->mime,
|
||||||
|
'url' => $media->url(),
|
||||||
|
'name' => null
|
||||||
|
];
|
||||||
|
}),
|
||||||
|
'tag' => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.1.5',
|
'version' => '0.1.6',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
@ -169,4 +169,4 @@
|
||||||
@push('meta')
|
@push('meta')
|
||||||
<meta property="og:description" content="{{ $status->caption }}">
|
<meta property="og:description" content="{{ $status->caption }}">
|
||||||
<meta property="og:image" content="{{$status->mediaUrl()}}">
|
<meta property="og:image" content="{{$status->mediaUrl()}}">
|
||||||
@endpush
|
<link href='{{$status->url()}}' rel='alternate' type='application/activity+json'>@endpush
|
||||||
|
|
Loading…
Add table
Reference in a new issue