|
@@ -2,46 +2,22 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
-use Illuminate\Http\Request;
|
|
|
|
-use App\Http\Controllers\{
|
|
|
|
- Controller,
|
|
|
|
- AvatarController
|
|
|
|
-};
|
|
|
|
-use Auth, Cache, Storage, URL;
|
|
|
|
-use Carbon\Carbon;
|
|
|
|
-use App\{
|
|
|
|
- Avatar,
|
|
|
|
- Like,
|
|
|
|
- Media,
|
|
|
|
- Notification,
|
|
|
|
- Profile,
|
|
|
|
- Status,
|
|
|
|
- StatusArchived
|
|
|
|
-};
|
|
|
|
-use App\Transformer\Api\{
|
|
|
|
- AccountTransformer,
|
|
|
|
- NotificationTransformer,
|
|
|
|
- MediaTransformer,
|
|
|
|
- MediaDraftTransformer,
|
|
|
|
- StatusTransformer,
|
|
|
|
- StatusStatelessTransformer
|
|
|
|
-};
|
|
|
|
-use League\Fractal;
|
|
|
|
-use App\Util\Media\Filter;
|
|
|
|
-use League\Fractal\Serializer\ArraySerializer;
|
|
|
|
-use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
|
|
|
|
+use App\Avatar;
|
|
|
|
+use App\Http\Controllers\AvatarController;
|
|
|
|
+use App\Http\Controllers\Controller;
|
|
use App\Jobs\AvatarPipeline\AvatarOptimize;
|
|
use App\Jobs\AvatarPipeline\AvatarOptimize;
|
|
-use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
|
|
|
-use App\Jobs\VideoPipeline\{
|
|
|
|
- VideoOptimize,
|
|
|
|
- VideoPostProcess,
|
|
|
|
- VideoThumbnail
|
|
|
|
-};
|
|
|
|
|
|
+use App\Jobs\NotificationPipeline\NotificationWarmUserCache;
|
|
use App\Services\AccountService;
|
|
use App\Services\AccountService;
|
|
use App\Services\NotificationService;
|
|
use App\Services\NotificationService;
|
|
-use App\Services\MediaPathService;
|
|
|
|
-use App\Services\MediaBlocklistService;
|
|
|
|
use App\Services\StatusService;
|
|
use App\Services\StatusService;
|
|
|
|
+use App\Status;
|
|
|
|
+use App\StatusArchived;
|
|
|
|
+use App\Transformer\Api\StatusStatelessTransformer;
|
|
|
|
+use Auth;
|
|
|
|
+use Cache;
|
|
|
|
+use Illuminate\Http\Request;
|
|
|
|
+use League\Fractal;
|
|
|
|
+use League\Fractal\Serializer\ArraySerializer;
|
|
|
|
|
|
class BaseApiController extends Controller
|
|
class BaseApiController extends Controller
|
|
{
|
|
{
|
|
@@ -50,47 +26,47 @@ class BaseApiController extends Controller
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
// $this->middleware('auth');
|
|
// $this->middleware('auth');
|
|
- $this->fractal = new Fractal\Manager();
|
|
|
|
- $this->fractal->setSerializer(new ArraySerializer());
|
|
|
|
|
|
+ $this->fractal = new Fractal\Manager;
|
|
|
|
+ $this->fractal->setSerializer(new ArraySerializer);
|
|
}
|
|
}
|
|
|
|
|
|
public function notifications(Request $request)
|
|
public function notifications(Request $request)
|
|
{
|
|
{
|
|
- abort_if(!$request->user(), 403);
|
|
|
|
-
|
|
|
|
- $pid = $request->user()->profile_id;
|
|
|
|
- $limit = $request->input('limit', 20);
|
|
|
|
-
|
|
|
|
- $since = $request->input('since_id');
|
|
|
|
- $min = $request->input('min_id');
|
|
|
|
- $max = $request->input('max_id');
|
|
|
|
-
|
|
|
|
- if(!$since && !$min && !$max) {
|
|
|
|
- $min = 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $maxId = null;
|
|
|
|
- $minId = null;
|
|
|
|
-
|
|
|
|
- if($max) {
|
|
|
|
- $res = NotificationService::getMax($pid, $max, $limit);
|
|
|
|
- $ids = NotificationService::getRankedMaxId($pid, $max, $limit);
|
|
|
|
- if(!empty($ids)) {
|
|
|
|
- $maxId = max($ids);
|
|
|
|
- $minId = min($ids);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- $res = NotificationService::getMin($pid, $min ?? $since, $limit);
|
|
|
|
- $ids = NotificationService::getRankedMinId($pid, $min ?? $since, $limit);
|
|
|
|
- if(!empty($ids)) {
|
|
|
|
- $maxId = max($ids);
|
|
|
|
- $minId = min($ids);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(empty($res) && !Cache::has('pf:services:notifications:hasSynced:'.$pid)) {
|
|
|
|
- Cache::put('pf:services:notifications:hasSynced:'.$pid, 1, 1209600);
|
|
|
|
- NotificationService::warmCache($pid, 100, true);
|
|
|
|
|
|
+ abort_if(! $request->user(), 403);
|
|
|
|
+
|
|
|
|
+ $pid = $request->user()->profile_id;
|
|
|
|
+ $limit = $request->input('limit', 20);
|
|
|
|
+
|
|
|
|
+ $since = $request->input('since_id');
|
|
|
|
+ $min = $request->input('min_id');
|
|
|
|
+ $max = $request->input('max_id');
|
|
|
|
+
|
|
|
|
+ if (! $since && ! $min && ! $max) {
|
|
|
|
+ $min = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $maxId = null;
|
|
|
|
+ $minId = null;
|
|
|
|
+
|
|
|
|
+ if ($max) {
|
|
|
|
+ $res = NotificationService::getMax($pid, $max, $limit);
|
|
|
|
+ $ids = NotificationService::getRankedMaxId($pid, $max, $limit);
|
|
|
|
+ if (! empty($ids)) {
|
|
|
|
+ $maxId = max($ids);
|
|
|
|
+ $minId = min($ids);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $res = NotificationService::getMin($pid, $min ?? $since, $limit);
|
|
|
|
+ $ids = NotificationService::getRankedMinId($pid, $min ?? $since, $limit);
|
|
|
|
+ if (! empty($ids)) {
|
|
|
|
+ $maxId = max($ids);
|
|
|
|
+ $minId = min($ids);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (empty($res) && ! Cache::has('pf:services:notifications:hasSynced:'.$pid)) {
|
|
|
|
+ Cache::put('pf:services:notifications:hasSynced:'.$pid, 1, 1209600);
|
|
|
|
+ NotificationWarmUserCache::dispatch($pid);
|
|
}
|
|
}
|
|
|
|
|
|
return response()->json($res);
|
|
return response()->json($res);
|
|
@@ -98,17 +74,17 @@ class BaseApiController extends Controller
|
|
|
|
|
|
public function avatarUpdate(Request $request)
|
|
public function avatarUpdate(Request $request)
|
|
{
|
|
{
|
|
- abort_if(!$request->user(), 403);
|
|
|
|
|
|
+ abort_if(! $request->user(), 403);
|
|
|
|
|
|
$this->validate($request, [
|
|
$this->validate($request, [
|
|
- 'upload' => 'required|mimetypes:image/jpeg,image/jpg,image/png|max:'.config('pixelfed.max_avatar_size'),
|
|
|
|
|
|
+ 'upload' => 'required|mimetypes:image/jpeg,image/jpg,image/png|max:'.config('pixelfed.max_avatar_size'),
|
|
]);
|
|
]);
|
|
|
|
|
|
try {
|
|
try {
|
|
$user = Auth::user();
|
|
$user = Auth::user();
|
|
$profile = $user->profile;
|
|
$profile = $user->profile;
|
|
$file = $request->file('upload');
|
|
$file = $request->file('upload');
|
|
- $path = (new AvatarController())->getPath($user, $file);
|
|
|
|
|
|
+ $path = (new AvatarController)->getPath($user, $file);
|
|
$dir = $path['root'];
|
|
$dir = $path['root'];
|
|
$name = $path['name'];
|
|
$name = $path['name'];
|
|
$public = $path['storage'];
|
|
$public = $path['storage'];
|
|
@@ -129,13 +105,13 @@ class BaseApiController extends Controller
|
|
|
|
|
|
return response()->json([
|
|
return response()->json([
|
|
'code' => 200,
|
|
'code' => 200,
|
|
- 'msg' => 'Avatar successfully updated',
|
|
|
|
|
|
+ 'msg' => 'Avatar successfully updated',
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
public function verifyCredentials(Request $request)
|
|
public function verifyCredentials(Request $request)
|
|
{
|
|
{
|
|
- abort_if(!$request->user(), 403);
|
|
|
|
|
|
+ abort_if(! $request->user(), 403);
|
|
|
|
|
|
$user = $request->user();
|
|
$user = $request->user();
|
|
if ($user->status != null) {
|
|
if ($user->status != null) {
|
|
@@ -143,47 +119,51 @@ class BaseApiController extends Controller
|
|
abort(403);
|
|
abort(403);
|
|
}
|
|
}
|
|
$res = AccountService::get($user->profile_id);
|
|
$res = AccountService::get($user->profile_id);
|
|
|
|
+
|
|
return response()->json($res);
|
|
return response()->json($res);
|
|
}
|
|
}
|
|
|
|
|
|
public function accountLikes(Request $request)
|
|
public function accountLikes(Request $request)
|
|
{
|
|
{
|
|
- abort_if(!$request->user(), 403);
|
|
|
|
|
|
+ abort_if(! $request->user(), 403);
|
|
|
|
|
|
$this->validate($request, [
|
|
$this->validate($request, [
|
|
- 'page' => 'sometimes|int|min:1|max:20',
|
|
|
|
- 'limit' => 'sometimes|int|min:1|max:10'
|
|
|
|
|
|
+ 'page' => 'sometimes|int|min:1|max:20',
|
|
|
|
+ 'limit' => 'sometimes|int|min:1|max:10',
|
|
]);
|
|
]);
|
|
|
|
|
|
$user = $request->user();
|
|
$user = $request->user();
|
|
$limit = $request->input('limit', 10);
|
|
$limit = $request->input('limit', 10);
|
|
|
|
|
|
$res = \DB::table('likes')
|
|
$res = \DB::table('likes')
|
|
- ->whereProfileId($user->profile_id)
|
|
|
|
- ->latest()
|
|
|
|
- ->simplePaginate($limit)
|
|
|
|
- ->map(function($id) {
|
|
|
|
- $status = StatusService::get($id->status_id, false);
|
|
|
|
- $status['favourited'] = true;
|
|
|
|
- return $status;
|
|
|
|
- })
|
|
|
|
- ->filter(function($post) {
|
|
|
|
- return $post && isset($post['account']);
|
|
|
|
- })
|
|
|
|
- ->values();
|
|
|
|
|
|
+ ->whereProfileId($user->profile_id)
|
|
|
|
+ ->latest()
|
|
|
|
+ ->simplePaginate($limit)
|
|
|
|
+ ->map(function ($id) use ($user) {
|
|
|
|
+ $status = StatusService::get($id->status_id, false);
|
|
|
|
+ $status['favourited'] = true;
|
|
|
|
+ $status['reblogged'] = (bool) StatusService::isShared($id->status_id, $user->profile_id);
|
|
|
|
+
|
|
|
|
+ return $status;
|
|
|
|
+ })
|
|
|
|
+ ->filter(function ($post) {
|
|
|
|
+ return $post && isset($post['account']);
|
|
|
|
+ })
|
|
|
|
+ ->values();
|
|
|
|
+
|
|
return response()->json($res);
|
|
return response()->json($res);
|
|
}
|
|
}
|
|
|
|
|
|
public function archive(Request $request, $id)
|
|
public function archive(Request $request, $id)
|
|
{
|
|
{
|
|
- abort_if(!$request->user(), 403);
|
|
|
|
|
|
+ abort_if(! $request->user(), 403);
|
|
|
|
|
|
$status = Status::whereNull('in_reply_to_id')
|
|
$status = Status::whereNull('in_reply_to_id')
|
|
->whereNull('reblog_of_id')
|
|
->whereNull('reblog_of_id')
|
|
->whereProfileId($request->user()->profile_id)
|
|
->whereProfileId($request->user()->profile_id)
|
|
->findOrFail($id);
|
|
->findOrFail($id);
|
|
|
|
|
|
- if($status->scope === 'archived') {
|
|
|
|
|
|
+ if ($status->scope === 'archived') {
|
|
return [200];
|
|
return [200];
|
|
}
|
|
}
|
|
|
|
|
|
@@ -204,14 +184,14 @@ class BaseApiController extends Controller
|
|
|
|
|
|
public function unarchive(Request $request, $id)
|
|
public function unarchive(Request $request, $id)
|
|
{
|
|
{
|
|
- abort_if(!$request->user(), 403);
|
|
|
|
|
|
+ abort_if(! $request->user(), 403);
|
|
|
|
|
|
$status = Status::whereNull('in_reply_to_id')
|
|
$status = Status::whereNull('in_reply_to_id')
|
|
->whereNull('reblog_of_id')
|
|
->whereNull('reblog_of_id')
|
|
->whereProfileId($request->user()->profile_id)
|
|
->whereProfileId($request->user()->profile_id)
|
|
->findOrFail($id);
|
|
->findOrFail($id);
|
|
|
|
|
|
- if($status->scope !== 'archived') {
|
|
|
|
|
|
+ if ($status->scope !== 'archived') {
|
|
return [200];
|
|
return [200];
|
|
}
|
|
}
|
|
|
|
|
|
@@ -231,16 +211,17 @@ class BaseApiController extends Controller
|
|
|
|
|
|
public function archivedPosts(Request $request)
|
|
public function archivedPosts(Request $request)
|
|
{
|
|
{
|
|
- abort_if(!$request->user(), 403);
|
|
|
|
|
|
+ abort_if(! $request->user(), 403);
|
|
|
|
|
|
$statuses = Status::whereProfileId($request->user()->profile_id)
|
|
$statuses = Status::whereProfileId($request->user()->profile_id)
|
|
->whereScope('archived')
|
|
->whereScope('archived')
|
|
->orderByDesc('id')
|
|
->orderByDesc('id')
|
|
->simplePaginate(10);
|
|
->simplePaginate(10);
|
|
|
|
|
|
- $fractal = new Fractal\Manager();
|
|
|
|
- $fractal->setSerializer(new ArraySerializer());
|
|
|
|
- $resource = new Fractal\Resource\Collection($statuses, new StatusStatelessTransformer());
|
|
|
|
|
|
+ $fractal = new Fractal\Manager;
|
|
|
|
+ $fractal->setSerializer(new ArraySerializer);
|
|
|
|
+ $resource = new Fractal\Resource\Collection($statuses, new StatusStatelessTransformer);
|
|
|
|
+
|
|
return $fractal->createData($resource)->toArray();
|
|
return $fractal->createData($resource)->toArray();
|
|
}
|
|
}
|
|
}
|
|
}
|