ApiV1Controller.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Str;
  6. use App\Util\ActivityPub\Helpers;
  7. use Laravel\Passport\Passport;
  8. use Auth, Cache, DB, URL;
  9. use App\{
  10. Follower,
  11. FollowRequest,
  12. Like,
  13. Media,
  14. Notification,
  15. Profile,
  16. Status,
  17. UserFilter,
  18. };
  19. use League\Fractal;
  20. use App\Transformer\Api\Mastodon\v1\{
  21. AccountTransformer,
  22. MediaTransformer,
  23. NotificationTransformer,
  24. StatusTransformer,
  25. };
  26. use App\Transformer\Api\{
  27. RelationshipTransformer,
  28. };
  29. use App\Http\Controllers\FollowerController;
  30. use League\Fractal\Serializer\ArraySerializer;
  31. use League\Fractal\Pagination\IlluminatePaginatorAdapter;
  32. use App\Jobs\LikePipeline\LikePipeline;
  33. use App\Jobs\StatusPipeline\StatusDelete;
  34. use App\Jobs\FollowPipeline\FollowPipeline;
  35. use App\Jobs\ImageOptimizePipeline\ImageOptimize;
  36. use App\Jobs\VideoPipeline\{
  37. VideoOptimize,
  38. VideoPostProcess,
  39. VideoThumbnail
  40. };
  41. use App\Services\NotificationService;
  42. class ApiV1Controller extends Controller
  43. {
  44. protected $fractal;
  45. public function __construct()
  46. {
  47. $this->fractal = new Fractal\Manager();
  48. $this->fractal->setSerializer(new ArraySerializer());
  49. }
  50. public function apps(Request $request)
  51. {
  52. abort_if(!config('pixelfed.oauth_enabled'), 404);
  53. $this->validate($request, [
  54. 'client_name' => 'required',
  55. 'redirect_uris' => 'required',
  56. 'scopes' => 'nullable',
  57. 'website' => 'nullable'
  58. ]);
  59. $client = Passport::client()->forceFill([
  60. 'user_id' => null,
  61. 'name' => e($request->client_name),
  62. 'secret' => Str::random(40),
  63. 'redirect' => $request->redirect_uris,
  64. 'personal_access_client' => false,
  65. 'password_client' => false,
  66. 'revoked' => false,
  67. ]);
  68. $client->save();
  69. $res = [
  70. 'id' => $client->id,
  71. 'name' => $client->name,
  72. 'website' => null,
  73. 'redirect_uri' => $client->redirect,
  74. 'client_id' => $client->id,
  75. 'client_secret' => $client->secret,
  76. 'vapid_key' => null
  77. ];
  78. return response()->json($res, 200, [
  79. 'Access-Control-Allow-Origin' => '*'
  80. ]);
  81. }
  82. /**
  83. * GET /api/v1/accounts/verify_credentials
  84. *
  85. *
  86. * @return \App\Transformer\Api\AccountTransformer
  87. */
  88. public function verifyCredentials(Request $request)
  89. {
  90. abort_if(!$request->user(), 403);
  91. $id = $request->user()->id;
  92. //$res = Cache::remember('mastoapi:user:account:id:'.$id, now()->addHours(6), function() use($id) {
  93. $profile = Profile::whereNull('status')->whereUserId($id)->firstOrFail();
  94. $resource = new Fractal\Resource\Item($profile, new AccountTransformer());
  95. $res = $this->fractal->createData($resource)->toArray();
  96. $res['source'] = [
  97. 'privacy' => $profile->is_private ? 'private' : 'public',
  98. 'sensitive' => $profile->cw ? true : false,
  99. 'language' => null,
  100. 'note' => '',
  101. 'fields' => []
  102. ];
  103. // return $res;
  104. // });
  105. return response()->json($res);
  106. }
  107. /**
  108. * GET /api/v1/accounts/{id}
  109. *
  110. * @param integer $id
  111. *
  112. * @return \App\Transformer\Api\AccountTransformer
  113. */
  114. public function accountById(Request $request, $id)
  115. {
  116. $profile = Profile::whereNull('status')->findOrFail($id);
  117. $resource = new Fractal\Resource\Item($profile, new AccountTransformer());
  118. $res = $this->fractal->createData($resource)->toArray();
  119. return response()->json($res);
  120. }
  121. /**
  122. * PATCH /api/v1/accounts/update_credentials
  123. *
  124. * @return \App\Transformer\Api\AccountTransformer
  125. */
  126. public function accountUpdateCredentials(Request $request)
  127. {
  128. abort_if(!$request->user(), 403);
  129. $this->validate($request, [
  130. 'display_name' => 'nullable|string',
  131. 'note' => 'nullable|string',
  132. 'locked' => 'nullable|boolean',
  133. // 'source.privacy' => 'nullable|in:unlisted,public,private',
  134. // 'source.sensitive' => 'nullable|boolean'
  135. ]);
  136. $user = $request->user();
  137. $profile = $user->profile;
  138. $displayName = $request->input('display_name');
  139. $note = $request->input('note');
  140. $locked = $request->input('locked');
  141. // $privacy = $request->input('source.privacy');
  142. // $sensitive = $request->input('source.sensitive');
  143. $changes = false;
  144. if($displayName !== $user->name) {
  145. $user->name = $displayName;
  146. $profile->name = $displayName;
  147. $changes = true;
  148. }
  149. if($note !== $profile->bio) {
  150. $profile->bio = e($note);
  151. $changes = true;
  152. }
  153. if(!is_null($locked)) {
  154. $profile->is_private = $locked;
  155. $changes = true;
  156. }
  157. if($changes) {
  158. $user->save();
  159. $profile->save();
  160. }
  161. $resource = new Fractal\Resource\Item($profile, new AccountTransformer());
  162. $res = $this->fractal->createData($resource)->toArray();
  163. return response()->json($res);
  164. }
  165. /**
  166. * GET /api/v1/accounts/{id}/followers
  167. *
  168. * @param integer $id
  169. *
  170. * @return \App\Transformer\Api\AccountTransformer
  171. */
  172. public function accountFollowersById(Request $request, $id)
  173. {
  174. abort_if(!$request->user(), 403);
  175. $profile = Profile::whereNull('status')->findOrFail($id);
  176. if($profile->domain) {
  177. $res = [];
  178. } else {
  179. $settings = $profile->user->settings;
  180. if($settings->show_profile_followers == true) {
  181. $limit = $request->input('limit') ?? 40;
  182. $followers = $profile->followers()->paginate($limit);
  183. $resource = new Fractal\Resource\Collection($followers, new AccountTransformer());
  184. $res = $this->fractal->createData($resource)->toArray();
  185. } else {
  186. $res = [];
  187. }
  188. }
  189. return response()->json($res);
  190. }
  191. /**
  192. * GET /api/v1/accounts/{id}/following
  193. *
  194. * @param integer $id
  195. *
  196. * @return \App\Transformer\Api\AccountTransformer
  197. */
  198. public function accountFollowingById(Request $request, $id)
  199. {
  200. abort_if(!$request->user(), 403);
  201. $profile = Profile::whereNull('status')->findOrFail($id);
  202. if($profile->domain) {
  203. $res = [];
  204. } else {
  205. $settings = $profile->user->settings;
  206. if($settings->show_profile_following == true) {
  207. $limit = $request->input('limit') ?? 40;
  208. $following = $profile->following()->paginate($limit);
  209. $resource = new Fractal\Resource\Collection($following, new AccountTransformer());
  210. $res = $this->fractal->createData($resource)->toArray();
  211. } else {
  212. $res = [];
  213. }
  214. }
  215. return response()->json($res);
  216. }
  217. /**
  218. * GET /api/v1/accounts/{id}/statuses
  219. *
  220. * @param integer $id
  221. *
  222. * @return \App\Transformer\Api\StatusTransformer
  223. */
  224. public function accountStatusesById(Request $request, $id)
  225. {
  226. abort_if(!$request->user(), 403);
  227. $this->validate($request, [
  228. 'only_media' => 'nullable',
  229. 'pinned' => 'nullable',
  230. 'exclude_replies' => 'nullable',
  231. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  232. 'since_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  233. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  234. 'limit' => 'nullable|integer|min:1|max:40'
  235. ]);
  236. $profile = Profile::whereNull('status')->findOrFail($id);
  237. $limit = $request->limit ?? 20;
  238. $max_id = $request->max_id;
  239. $min_id = $request->min_id;
  240. $pid = $request->user()->profile_id;
  241. $scope = $request->only_media == true ?
  242. ['photo', 'photo:album', 'video', 'video:album'] :
  243. ['photo', 'photo:album', 'video', 'video:album', 'share', 'reply'];
  244. if($pid == $profile->id) {
  245. $visibility = ['public', 'unlisted', 'private'];
  246. } else if($profile->is_private) {
  247. $following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
  248. $following = Follower::whereProfileId($pid)->pluck('following_id');
  249. return $following->push($pid)->toArray();
  250. });
  251. $visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : [];
  252. } else {
  253. $following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
  254. $following = Follower::whereProfileId($pid)->pluck('following_id');
  255. return $following->push($pid)->toArray();
  256. });
  257. $visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
  258. }
  259. if($min_id || $max_id) {
  260. $dir = $min_id ? '>' : '<';
  261. $id = $min_id ?? $max_id;
  262. $timeline = Status::select(
  263. 'id',
  264. 'uri',
  265. 'caption',
  266. 'rendered',
  267. 'profile_id',
  268. 'type',
  269. 'in_reply_to_id',
  270. 'reblog_of_id',
  271. 'is_nsfw',
  272. 'scope',
  273. 'local',
  274. 'place_id',
  275. 'created_at',
  276. 'updated_at'
  277. )->whereProfileId($profile->id)
  278. ->whereIn('type', $scope)
  279. ->where('id', $dir, $id)
  280. ->whereIn('visibility', $visibility)
  281. ->latest()
  282. ->limit($limit)
  283. ->get();
  284. } else {
  285. $timeline = Status::select(
  286. 'id',
  287. 'uri',
  288. 'caption',
  289. 'rendered',
  290. 'profile_id',
  291. 'type',
  292. 'in_reply_to_id',
  293. 'reblog_of_id',
  294. 'is_nsfw',
  295. 'scope',
  296. 'local',
  297. 'place_id',
  298. 'created_at',
  299. 'updated_at'
  300. )->whereProfileId($profile->id)
  301. ->whereIn('type', $scope)
  302. ->whereIn('visibility', $visibility)
  303. ->latest()
  304. ->limit($limit)
  305. ->get();
  306. }
  307. $resource = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  308. $res = $this->fractal->createData($resource)->toArray();
  309. return response()->json($res);
  310. }
  311. /**
  312. * POST /api/v1/accounts/{id}/follow
  313. *
  314. * @param integer $id
  315. *
  316. * @return \App\Transformer\Api\RelationshipTransformer
  317. */
  318. public function accountFollowById(Request $request, $id)
  319. {
  320. abort_if(!$request->user(), 403);
  321. $user = $request->user();
  322. $target = Profile::where('id', '!=', $user->id)
  323. ->whereNull('status')
  324. ->findOrFail($item);
  325. $private = (bool) $target->is_private;
  326. $remote = (bool) $target->domain;
  327. $blocked = UserFilter::whereUserId($target->id)
  328. ->whereFilterType('block')
  329. ->whereFilterableId($user->id)
  330. ->whereFilterableType('App\Profile')
  331. ->exists();
  332. if($blocked == true) {
  333. abort(400, 'You cannot follow this user.');
  334. }
  335. $isFollowing = Follower::whereProfileId($user->id)
  336. ->whereFollowingId($target->id)
  337. ->exists();
  338. // Following already, return empty relationship
  339. if($isFollowing == true) {
  340. $resource = new Fractal\Resource\Item($target, new RelationshipTransformer());
  341. $res = $this->fractal->createData($resource)->toArray();
  342. return response()->json($res);
  343. }
  344. // Rate limits, max 7500 followers per account
  345. if($user->following()->count() >= Follower::MAX_FOLLOWING) {
  346. abort(400, 'You cannot follow more than ' . Follower::MAX_FOLLOWING . ' accounts');
  347. }
  348. // Rate limits, follow 30 accounts per hour max
  349. if($user->following()->where('followers.created_at', '>', now()->subHour())->count() >= Follower::FOLLOW_PER_HOUR) {
  350. abort(400, 'You can only follow ' . Follower::FOLLOW_PER_HOUR . ' users per hour');
  351. }
  352. if($private == true) {
  353. $follow = FollowRequest::firstOrCreate([
  354. 'follower_id' => $user->id,
  355. 'following_id' => $target->id
  356. ]);
  357. if($remote == true && config('federation.activitypub.remoteFollow') == true) {
  358. (new FollowerController())->sendFollow($user, $target);
  359. }
  360. } else {
  361. $follower = new Follower();
  362. $follower->profile_id = $user->id;
  363. $follower->following_id = $target->id;
  364. $follower->save();
  365. if($remote == true && config('federation.activitypub.remoteFollow') == true) {
  366. (new FollowerController())->sendFollow($user, $target);
  367. }
  368. FollowPipeline::dispatch($follower);
  369. }
  370. Cache::forget('profile:following:'.$target->id);
  371. Cache::forget('profile:followers:'.$target->id);
  372. Cache::forget('profile:following:'.$user->id);
  373. Cache::forget('profile:followers:'.$user->id);
  374. Cache::forget('api:local:exp:rec:'.$user->id);
  375. Cache::forget('user:account:id:'.$target->user_id);
  376. Cache::forget('user:account:id:'.$user->user_id);
  377. $resource = new Fractal\Resource\Item($target, new RelationshipTransformer());
  378. $res = $this->fractal->createData($resource)->toArray();
  379. return response()->json($res);
  380. }
  381. /**
  382. * POST /api/v1/accounts/{id}/unfollow
  383. *
  384. * @param integer $id
  385. *
  386. * @return \App\Transformer\Api\RelationshipTransformer
  387. */
  388. public function accountUnfollowById(Request $request, $id)
  389. {
  390. abort_if(!$request->user(), 403);
  391. $user = $request->user();
  392. $target = Profile::where('id', '!=', $user->id)
  393. ->whereNull('status')
  394. ->findOrFail($item);
  395. $private = (bool) $target->is_private;
  396. $remote = (bool) $target->domain;
  397. $isFollowing = Follower::whereProfileId($user->id)
  398. ->whereFollowingId($target->id)
  399. ->exists();
  400. if($isFollowing == false) {
  401. $resource = new Fractal\Resource\Item($target, new RelationshipTransformer());
  402. $res = $this->fractal->createData($resource)->toArray();
  403. return response()->json($res);
  404. }
  405. // Rate limits, follow 30 accounts per hour max
  406. if($user->following()->where('followers.updated_at', '>', now()->subHour())->count() >= Follower::FOLLOW_PER_HOUR) {
  407. abort(400, 'You can only follow or unfollow ' . Follower::FOLLOW_PER_HOUR . ' users per hour');
  408. }
  409. FollowRequest::whereFollowerId($user->id)
  410. ->whereFollowingId($target->id)
  411. ->delete();
  412. Follower::whereProfileId($user->id)
  413. ->whereFollowingId($target->id)
  414. ->delete();
  415. if($remote == true && config('federation.activitypub.remoteFollow') == true) {
  416. (new FollowerController())->sendUndoFollow($user, $target);
  417. }
  418. Cache::forget('profile:following:'.$target->id);
  419. Cache::forget('profile:followers:'.$target->id);
  420. Cache::forget('profile:following:'.$user->id);
  421. Cache::forget('profile:followers:'.$user->id);
  422. Cache::forget('api:local:exp:rec:'.$user->id);
  423. Cache::forget('user:account:id:'.$target->user_id);
  424. Cache::forget('user:account:id:'.$user->user_id);
  425. $resource = new Fractal\Resource\Item($target, new RelationshipTransformer());
  426. $res = $this->fractal->createData($resource)->toArray();
  427. return response()->json($res);
  428. }
  429. /**
  430. * GET /api/v1/accounts/relationships
  431. *
  432. * @param array|integer $id
  433. *
  434. * @return \App\Transformer\Api\RelationshipTransformer
  435. */
  436. public function accountRelationshipsById(Request $request)
  437. {
  438. abort_if(!$request->user(), 403);
  439. $this->validate($request, [
  440. 'id' => 'required|array|min:1|max:20',
  441. 'id.*' => 'required|integer|min:1|max:' . PHP_INT_MAX
  442. ]);
  443. $pid = $request->user()->profile_id ?? $request->user()->profile->id;
  444. $ids = collect($request->input('id'));
  445. $filtered = $ids->filter(function($v) use($pid) {
  446. return $v != $pid;
  447. });
  448. $relations = Profile::whereNull('status')->findOrFail($filtered->values());
  449. $fractal = new Fractal\Resource\Collection($relations, new RelationshipTransformer());
  450. $res = $this->fractal->createData($fractal)->toArray();
  451. return response()->json($res);
  452. }
  453. /**
  454. * GET /api/v1/accounts/search
  455. *
  456. *
  457. *
  458. * @return \App\Transformer\Api\AccountTransformer
  459. */
  460. public function accountSearch(Request $request)
  461. {
  462. abort_if(!$request->user(), 403);
  463. $this->validate($request, [
  464. 'q' => 'required|string|min:1|max:255',
  465. 'limit' => 'nullable|integer|min:1|max:40',
  466. 'resolve' => 'nullable'
  467. ]);
  468. $user = $request->user();
  469. $query = $request->input('q');
  470. $limit = $request->input('limit') ?? 20;
  471. $resolve = (bool) $request->input('resolve', false);
  472. $q = '%' . $query . '%';
  473. $profiles = Profile::whereNull('status')
  474. ->where('username', 'like', $q)
  475. ->orWhere('name', 'like', $q)
  476. ->limit($limit)
  477. ->get();
  478. $resource = new Fractal\Resource\Collection($profiles, new AccountTransformer());
  479. $res = $this->fractal->createData($resource)->toArray();
  480. return response()->json($res);
  481. }
  482. /**
  483. * GET /api/v1/blocks
  484. *
  485. *
  486. *
  487. * @return \App\Transformer\Api\AccountTransformer
  488. */
  489. public function accountBlocks(Request $request)
  490. {
  491. abort_if(!$request->user(), 403);
  492. $this->validate($request, [
  493. 'limit' => 'nullable|integer|min:1|max:40',
  494. 'page' => 'nullable|integer|min:1|max:10'
  495. ]);
  496. $user = $request->user();
  497. $limit = $request->input('limit') ?? 40;
  498. $blocked = UserFilter::select('filterable_id','filterable_type','filter_type','user_id')
  499. ->whereUserId($user->profile_id)
  500. ->whereFilterableType('App\Profile')
  501. ->whereFilterType('block')
  502. ->simplePaginate($limit)
  503. ->pluck('filterable_id');
  504. $profiles = Profile::findOrFail($blocked);
  505. $resource = new Fractal\Resource\Collection($profiles, new AccountTransformer());
  506. $res = $this->fractal->createData($resource)->toArray();
  507. return response()->json($res);
  508. }
  509. /**
  510. * POST /api/v1/accounts/{id}/block
  511. *
  512. * @param integer $id
  513. *
  514. * @return \App\Transformer\Api\RelationshipTransformer
  515. */
  516. public function accountBlockById(Request $request, $id)
  517. {
  518. abort_if(!$request->user(), 403);
  519. $user = $request->user();
  520. $pid = $user->profile_id ?? $user->profile->id;
  521. if($id == $pid) {
  522. abort(400, 'You cannot block yourself');
  523. }
  524. $profile = Profile::findOrFail($id);
  525. Follower::whereProfileId($profile->id)->whereFollowingId($pid)->delete();
  526. Follower::whereProfileId($pid)->whereFollowingId($profile->id)->delete();
  527. Notification::whereProfileId($pid)->whereActorId($profile->id)->delete();
  528. $filter = UserFilter::firstOrCreate([
  529. 'user_id' => $pid,
  530. 'filterable_id' => $profile->id,
  531. 'filterable_type' => 'App\Profile',
  532. 'filter_type' => 'block',
  533. ]);
  534. Cache::forget("user:filter:list:$pid");
  535. Cache::forget("api:local:exp:rec:$pid");
  536. $resource = new Fractal\Resource\Item($profile, new RelationshipTransformer());
  537. $res = $this->fractal->createData($resource)->toArray();
  538. return response()->json($res);
  539. }
  540. /**
  541. * POST /api/v1/accounts/{id}/unblock
  542. *
  543. * @param integer $id
  544. *
  545. * @return \App\Transformer\Api\RelationshipTransformer
  546. */
  547. public function accountUnblockById(Request $request, $id)
  548. {
  549. abort_if(!$request->user(), 403);
  550. $user = $request->user();
  551. $pid = $user->profile_id ?? $user->profile->id;
  552. if($id == $pid) {
  553. abort(400, 'You cannot unblock yourself');
  554. }
  555. $profile = Profile::findOrFail($id);
  556. UserFilter::whereUserId($pid)
  557. ->whereFilterableId($profile->id)
  558. ->whereFilterableType('App\Profile')
  559. ->whereFilterType('block')
  560. ->delete();
  561. Cache::forget("user:filter:list:$pid");
  562. Cache::forget("api:local:exp:rec:$pid");
  563. $resource = new Fractal\Resource\Item($profile, new RelationshipTransformer());
  564. $res = $this->fractal->createData($resource)->toArray();
  565. return response()->json($res);
  566. }
  567. /**
  568. * GET /api/v1/custom_emojis
  569. *
  570. * Return empty array, we don't support custom emoji
  571. *
  572. * @return array
  573. */
  574. public function customEmojis()
  575. {
  576. return response()->json([]);
  577. }
  578. /**
  579. * GET /api/v1/domain_blocks
  580. *
  581. * Return empty array
  582. *
  583. * @return array
  584. */
  585. public function accountDomainBlocks(Request $request)
  586. {
  587. abort_if(!$request->user(), 403);
  588. return response()->json([]);
  589. }
  590. /**
  591. * GET /api/v1/endorsements
  592. *
  593. * Return empty array
  594. *
  595. * @return array
  596. */
  597. public function accountEndorsements(Request $request)
  598. {
  599. abort_if(!$request->user(), 403);
  600. return response()->json([]);
  601. }
  602. /**
  603. * GET /api/v1/favourites
  604. *
  605. * Returns collection of liked statuses
  606. *
  607. * @return \App\Transformer\Api\StatusTransformer
  608. */
  609. public function accountFavourites(Request $request)
  610. {
  611. abort_if(!$request->user(), 403);
  612. $user = $request->user();
  613. $limit = $request->input('limit') ?? 20;
  614. $favourites = Like::whereProfileId($user->profile_id)
  615. ->latest()
  616. ->simplePaginate($limit)
  617. ->pluck('status_id');
  618. $statuses = Status::findOrFail($favourites);
  619. $resource = new Fractal\Resource\Collection($statuses, new StatusTransformer());
  620. $res = $this->fractal->createData($resource)->toArray();
  621. return response()->json($res);
  622. }
  623. /**
  624. * POST /api/v1/statuses/{id}/favourite
  625. *
  626. * @param integer $id
  627. *
  628. * @return \App\Transformer\Api\StatusTransformer
  629. */
  630. public function statusFavouriteById(Request $request, $id)
  631. {
  632. abort_if(!$request->user(), 403);
  633. $user = $request->user();
  634. $status = Status::findOrFail($id);
  635. $like = Like::firstOrCreate([
  636. 'profile_id' => $user->profile_id,
  637. 'status_id' => $status->id
  638. ]);
  639. if($like->wasRecentlyCreated == true) {
  640. LikePipeline::dispatch($like);
  641. }
  642. $resource = new Fractal\Resource\Item($status, new StatusTransformer());
  643. $res = $this->fractal->createData($resource)->toArray();
  644. return response()->json($res);
  645. }
  646. /**
  647. * POST /api/v1/statuses/{id}/unfavourite
  648. *
  649. * @param integer $id
  650. *
  651. * @return \App\Transformer\Api\StatusTransformer
  652. */
  653. public function statusUnfavouriteById(Request $request, $id)
  654. {
  655. abort_if(!$request->user(), 403);
  656. $user = $request->user();
  657. $status = Status::findOrFail($id);
  658. $like = Like::whereProfileId($user->profile_id)
  659. ->whereStatusId($status->id)
  660. ->first();
  661. if($like) {
  662. $like->delete();
  663. }
  664. $resource = new Fractal\Resource\Item($status, new StatusTransformer());
  665. $res = $this->fractal->createData($resource)->toArray();
  666. return response()->json($res);
  667. }
  668. /**
  669. * GET /api/v1/filters
  670. *
  671. * Return empty response since we filter server side
  672. *
  673. * @return array
  674. */
  675. public function accountFilters(Request $request)
  676. {
  677. abort_if(!$request->user(), 403);
  678. return response()->json([]);
  679. }
  680. /**
  681. * GET /api/v1/follow_requests
  682. *
  683. * Return array of Accounts that have sent follow requests
  684. *
  685. * @return \App\Transformer\Api\AccountTransformer
  686. */
  687. public function accountFollowRequests(Request $request)
  688. {
  689. abort_if(!$request->user(), 403);
  690. $user = $request->user();
  691. $followRequests = FollowRequest::whereFollowingId($user->profile->id)->pluck('follower_id');
  692. $profiles = Profile::find($followRequests);
  693. $resource = new Fractal\Resource\Collection($profiles, new AccountTransformer());
  694. $res = $this->fractal->createData($resource)->toArray();
  695. return response()->json($res);
  696. }
  697. /**
  698. * POST /api/v1/follow_requests/{id}/authorize
  699. *
  700. * @param integer $id
  701. *
  702. * @return null
  703. */
  704. public function accountFollowRequestAccept(Request $request, $id)
  705. {
  706. abort_if(!$request->user(), 403);
  707. // todo
  708. return response()->json([]);
  709. }
  710. /**
  711. * POST /api/v1/follow_requests/{id}/reject
  712. *
  713. * @param integer $id
  714. *
  715. * @return null
  716. */
  717. public function accountFollowRequestReject(Request $request, $id)
  718. {
  719. abort_if(!$request->user(), 403);
  720. // todo
  721. return response()->json([]);
  722. }
  723. /**
  724. * GET /api/v1/suggestions
  725. *
  726. * Return empty array as we don't support suggestions
  727. *
  728. * @return null
  729. */
  730. public function accountSuggestions(Request $request)
  731. {
  732. abort_if(!$request->user(), 403);
  733. // todo
  734. return response()->json([]);
  735. }
  736. /**
  737. * GET /api/v1/instance
  738. *
  739. * Information about the server.
  740. *
  741. * @return Instance
  742. */
  743. public function instance(Request $request)
  744. {
  745. $res = [
  746. 'description' => 'Pixelfed - Photo sharing for everyone',
  747. 'email' => config('instance.email'),
  748. 'languages' => ['en'],
  749. 'max_toot_chars' => config('pixelfed.max_caption_length'),
  750. 'registrations' => config('pixelfed.open_registration'),
  751. 'stats' => [
  752. 'user_count' => 0,
  753. 'status_count' => 0,
  754. 'domain_count' => 0
  755. ],
  756. 'thumbnail' => config('app.url') . '/img/pixelfed-icon-color.png',
  757. 'title' => 'Pixelfed (' . config('pixelfed.domain.app') . ')',
  758. 'uri' => config('app.url'),
  759. 'urls' => [],
  760. 'version' => '2.7.2 (compatible; Pixelfed ' . config('pixelfed.version') . ')'
  761. ];
  762. return response()->json($res, 200, [], JSON_PRETTY_PRINT);
  763. }
  764. /**
  765. * GET /api/v1/lists
  766. *
  767. * Return empty array as we don't support lists
  768. *
  769. * @return null
  770. */
  771. public function accountLists(Request $request)
  772. {
  773. abort_if(!$request->user(), 403);
  774. return response()->json([]);
  775. }
  776. /**
  777. * GET /api/v1/accounts/{id}/lists
  778. *
  779. * @param integer $id
  780. *
  781. * @return null
  782. */
  783. public function accountListsById(Request $request, $id)
  784. {
  785. abort_if(!$request->user(), 403);
  786. return response()->json([]);
  787. }
  788. /**
  789. * POST /api/v1/media
  790. *
  791. *
  792. * @return MediaTransformer
  793. */
  794. public function mediaUpload(Request $request)
  795. {
  796. abort_if(!$request->user(), 403);
  797. $this->validate($request, [
  798. 'file.*' => function() {
  799. return [
  800. 'required',
  801. 'mimes:' . config('pixelfed.media_types'),
  802. 'max:' . config('pixelfed.max_photo_size'),
  803. ];
  804. },
  805. 'filter_name' => 'nullable|string|max:24',
  806. 'filter_class' => 'nullable|alpha_dash|max:24',
  807. 'description' => 'nullable|string|max:420'
  808. ]);
  809. $user = $request->user();
  810. $profile = $user->profile;
  811. if(config('pixelfed.enforce_account_limit') == true) {
  812. $size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) {
  813. return Media::whereUserId($user->id)->sum('size') / 1000;
  814. });
  815. $limit = (int) config('pixelfed.max_account_size');
  816. if ($size >= $limit) {
  817. abort(403, 'Account size limit reached.');
  818. }
  819. }
  820. $monthHash = hash('sha1', date('Y').date('m'));
  821. $userHash = hash('sha1', $user->id . (string) $user->created_at);
  822. $photo = $request->file('file');
  823. $mimes = explode(',', config('pixelfed.media_types'));
  824. if(in_array($photo->getMimeType(), $mimes) == false) {
  825. abort(403, 'Invalid or unsupported mime type.');
  826. }
  827. $storagePath = "public/m/{$monthHash}/{$userHash}";
  828. $path = $photo->store($storagePath);
  829. $hash = \hash_file('sha256', $photo);
  830. $media = new Media();
  831. $media->status_id = null;
  832. $media->profile_id = $profile->id;
  833. $media->user_id = $user->id;
  834. $media->media_path = $path;
  835. $media->original_sha256 = $hash;
  836. $media->size = $photo->getSize();
  837. $media->mime = $photo->getMimeType();
  838. $media->caption = $request->input('description');
  839. $media->filter_class = $request->input('filter_class');
  840. $media->filter_name = $request->input('filter_name');
  841. $media->save();
  842. switch ($media->mime) {
  843. case 'image/jpeg':
  844. case 'image/png':
  845. ImageOptimize::dispatch($media);
  846. break;
  847. case 'video/mp4':
  848. VideoThumbnail::dispatch($media);
  849. $preview_url = '/storage/no-preview.png';
  850. $url = '/storage/no-preview.png';
  851. break;
  852. }
  853. $resource = new Fractal\Resource\Item($media, new MediaTransformer());
  854. $res = $this->fractal->createData($resource)->toArray();
  855. $res['preview_url'] = url('/storage/no-preview.png');
  856. $res['url'] = url('/storage/no-preview.png');
  857. return response()->json($res);
  858. }
  859. /**
  860. * PUT /api/v1/media/{id}
  861. *
  862. * @param integer $id
  863. *
  864. * @return MediaTransformer
  865. */
  866. public function mediaUpdate(Request $request, $id)
  867. {
  868. abort_if(!$request->user(), 403);
  869. $this->validate($request, [
  870. 'description' => 'nullable|string|max:420'
  871. ]);
  872. $user = $request->user();
  873. $media = Media::whereUserId($user->id)
  874. ->whereNull('status_id')
  875. ->findOrFail($id);
  876. $media->caption = $request->input('description');
  877. $media->save();
  878. $resource = new Fractal\Resource\Item($media, new MediaTransformer());
  879. $res = $this->fractal->createData($resource)->toArray();
  880. $res['preview_url'] = url('/storage/no-preview.png');
  881. $res['url'] = url('/storage/no-preview.png');
  882. return response()->json($res);
  883. }
  884. /**
  885. * GET /api/v1/mutes
  886. *
  887. *
  888. * @return AccountTransformer
  889. */
  890. public function accountMutes(Request $request)
  891. {
  892. abort_if(!$request->user(), 403);
  893. $this->validate($request, [
  894. 'limit' => 'nullable|integer|min:1|max:40'
  895. ]);
  896. $user = $request->user();
  897. $limit = $request->input('limit') ?? 40;
  898. $mutes = UserFilter::whereUserId($user->profile_id)
  899. ->whereFilterableType('App\Profile')
  900. ->whereFilterType('mute')
  901. ->simplePaginate($limit)
  902. ->pluck('filterable_id');
  903. $accounts = Profile::find($mutes);
  904. $resource = new Fractal\Resource\Collection($accounts, new AccountTransformer());
  905. $res = $this->fractal->createData($resource)->toArray();
  906. return response()->json($res);
  907. }
  908. /**
  909. * POST /api/v1/accounts/{id}/mute
  910. *
  911. * @param integer $id
  912. *
  913. * @return RelationshipTransformer
  914. */
  915. public function accountMuteById(Request $request, $id)
  916. {
  917. abort_if(!$request->user(), 403);
  918. $user = $request->user();
  919. $pid = $user->profile_id;
  920. $account = Profile::findOrFail($id);
  921. $filter = UserFilter::firstOrCreate([
  922. 'user_id' => $pid,
  923. 'filterable_id' => $account->id,
  924. 'filterable_type' => 'App\Profile',
  925. 'filter_type' => 'mute',
  926. ]);
  927. Cache::forget("user:filter:list:$pid");
  928. Cache::forget("feature:discover:posts:$pid");
  929. Cache::forget("api:local:exp:rec:$pid");
  930. $resource = new Fractal\Resource\Item($account, new RelationshipTransformer());
  931. $res = $this->fractal->createData($resource)->toArray();
  932. return response()->json($res);
  933. }
  934. /**
  935. * POST /api/v1/accounts/{id}/unmute
  936. *
  937. * @param integer $id
  938. *
  939. * @return RelationshipTransformer
  940. */
  941. public function accountUnmuteById(Request $request, $id)
  942. {
  943. abort_if(!$request->user(), 403);
  944. $user = $request->user();
  945. $pid = $user->profile_id;
  946. $account = Profile::findOrFail($id);
  947. $filter = UserFilter::whereUserId($pid)
  948. ->whereFilterableId($account->id)
  949. ->whereFilterableType('App\Profile')
  950. ->whereFilterType('mute')
  951. ->first();
  952. if($filter) {
  953. $filter->delete();
  954. Cache::forget("user:filter:list:$pid");
  955. Cache::forget("feature:discover:posts:$pid");
  956. Cache::forget("api:local:exp:rec:$pid");
  957. }
  958. $resource = new Fractal\Resource\Item($account, new RelationshipTransformer());
  959. $res = $this->fractal->createData($resource)->toArray();
  960. return response()->json($res);
  961. }
  962. /**
  963. * GET /api/v1/notifications
  964. *
  965. *
  966. * @return NotificationTransformer
  967. */
  968. public function accountNotifications(Request $request)
  969. {
  970. abort_if(!$request->user(), 403);
  971. $this->validate($request, [
  972. 'page' => 'nullable|integer|min:1|max:10',
  973. 'limit' => 'nullable|integer|min:1|max:80',
  974. 'max_id' => 'nullable|integer|min:1',
  975. 'min_id' => 'nullable|integer|min:0',
  976. ]);
  977. $pid = $request->user()->profile_id;
  978. $limit = $request->input('limit') ?? 20;
  979. $timeago = now()->subMonths(6);
  980. $min = $request->input('min_id');
  981. $max = $request->input('max_id');
  982. if($min || $max) {
  983. $dir = $min ? '>' : '<';
  984. $id = $min ?? $max;
  985. $notifications = Notification::whereProfileId($pid)
  986. ->whereDate('created_at', '>', $timeago)
  987. ->latest()
  988. ->where('id', $dir, $id)
  989. ->limit($limit)
  990. ->get();
  991. } else {
  992. $notifications = Notification::whereProfileId($pid)
  993. ->whereDate('created_at', '>', $timeago)
  994. ->latest()
  995. ->simplePaginate($limit);
  996. }
  997. $resource = new Fractal\Resource\Collection($notifications, new NotificationTransformer());
  998. $res = $this->fractal->createData($resource)->toArray();
  999. return response()->json($res);
  1000. }
  1001. /**
  1002. * GET /api/v1/timelines/home
  1003. *
  1004. *
  1005. * @return StatusTransformer
  1006. */
  1007. public function timelineHome(Request $request)
  1008. {
  1009. abort_if(!$request->user(), 403);
  1010. $this->validate($request,[
  1011. 'page' => 'nullable|integer|max:40',
  1012. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  1013. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  1014. 'limit' => 'nullable|integer|max:80'
  1015. ]);
  1016. $page = $request->input('page');
  1017. $min = $request->input('min_id');
  1018. $max = $request->input('max_id');
  1019. $limit = $request->input('limit') ?? 3;
  1020. $pid = $request->user()->profile_id;
  1021. $following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
  1022. $following = Follower::whereProfileId($pid)->pluck('following_id');
  1023. return $following->push($pid)->toArray();
  1024. });
  1025. if($min || $max) {
  1026. $dir = $min ? '>' : '<';
  1027. $id = $min ?? $max;
  1028. $timeline = Status::select(
  1029. 'id',
  1030. 'uri',
  1031. 'caption',
  1032. 'rendered',
  1033. 'profile_id',
  1034. 'type',
  1035. 'in_reply_to_id',
  1036. 'reblog_of_id',
  1037. 'is_nsfw',
  1038. 'scope',
  1039. 'local',
  1040. 'reply_count',
  1041. 'comments_disabled',
  1042. 'place_id',
  1043. 'created_at',
  1044. 'updated_at'
  1045. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  1046. ->with('profile', 'hashtags', 'mentions')
  1047. ->where('id', $dir, $id)
  1048. ->whereIn('profile_id', $following)
  1049. ->whereIn('visibility',['public', 'unlisted', 'private'])
  1050. ->latest()
  1051. ->limit($limit)
  1052. ->get();
  1053. } else {
  1054. $timeline = Status::select(
  1055. 'id',
  1056. 'uri',
  1057. 'caption',
  1058. 'rendered',
  1059. 'profile_id',
  1060. 'type',
  1061. 'in_reply_to_id',
  1062. 'reblog_of_id',
  1063. 'is_nsfw',
  1064. 'scope',
  1065. 'local',
  1066. 'reply_count',
  1067. 'comments_disabled',
  1068. 'place_id',
  1069. 'created_at',
  1070. 'updated_at'
  1071. )->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  1072. ->with('profile', 'hashtags', 'mentions')
  1073. ->whereIn('profile_id', $following)
  1074. ->whereIn('visibility',['public', 'unlisted', 'private'])
  1075. ->latest()
  1076. ->simplePaginate($limit);
  1077. }
  1078. $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  1079. $res = $this->fractal->createData($fractal)->toArray();
  1080. return response()->json($res);
  1081. }
  1082. /**
  1083. * GET /api/v1/conversations
  1084. *
  1085. * Not implemented
  1086. *
  1087. * @return array
  1088. */
  1089. public function conversations(Request $request)
  1090. {
  1091. abort_if(!$request->user(), 403);
  1092. return response()->json([]);
  1093. }
  1094. /**
  1095. * GET /api/v1/timelines/public
  1096. *
  1097. *
  1098. * @return StatusTransformer
  1099. */
  1100. public function timelinePublic(Request $request)
  1101. {
  1102. $this->validate($request,[
  1103. 'page' => 'nullable|integer|max:40',
  1104. 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  1105. 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
  1106. 'limit' => 'nullable|integer|max:80'
  1107. ]);
  1108. $page = $request->input('page');
  1109. $min = $request->input('min_id');
  1110. $max = $request->input('max_id');
  1111. $limit = $request->input('limit') ?? 3;
  1112. if($min || $max) {
  1113. $dir = $min ? '>' : '<';
  1114. $id = $min ?? $max;
  1115. $timeline = Status::select(
  1116. 'id',
  1117. 'uri',
  1118. 'caption',
  1119. 'rendered',
  1120. 'profile_id',
  1121. 'type',
  1122. 'in_reply_to_id',
  1123. 'reblog_of_id',
  1124. 'is_nsfw',
  1125. 'scope',
  1126. 'local',
  1127. 'reply_count',
  1128. 'comments_disabled',
  1129. 'place_id',
  1130. 'created_at',
  1131. 'updated_at'
  1132. )->whereNull('uri')
  1133. ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  1134. ->with('profile', 'hashtags', 'mentions')
  1135. ->where('id', $dir, $id)
  1136. ->whereVisibility('public')
  1137. ->latest()
  1138. ->limit($limit)
  1139. ->get();
  1140. } else {
  1141. $timeline = Status::select(
  1142. 'id',
  1143. 'uri',
  1144. 'caption',
  1145. 'rendered',
  1146. 'profile_id',
  1147. 'type',
  1148. 'in_reply_to_id',
  1149. 'reblog_of_id',
  1150. 'is_nsfw',
  1151. 'scope',
  1152. 'local',
  1153. 'reply_count',
  1154. 'comments_disabled',
  1155. 'place_id',
  1156. 'created_at',
  1157. 'updated_at'
  1158. )->whereNull('uri')
  1159. ->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
  1160. ->with('profile', 'hashtags', 'mentions')
  1161. ->whereVisibility('public')
  1162. ->latest()
  1163. ->simplePaginate($limit);
  1164. }
  1165. $fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
  1166. $res = $this->fractal->createData($fractal)->toArray();
  1167. return response()->json($res);
  1168. }
  1169. /**
  1170. * GET /api/v1/statuses/{id}
  1171. *
  1172. * @param integer $id
  1173. *
  1174. * @return StatusTransformer
  1175. */
  1176. public function statusById(Request $request, $id)
  1177. {
  1178. abort_if(!$request->user(), 403);
  1179. $status = Status::whereVisibility('public')->findOrFail($id);
  1180. $resource = new Fractal\Resource\Item($status, new StatusTransformer());
  1181. $res = $this->fractal->createData($resource)->toArray();
  1182. return response()->json($res);
  1183. }
  1184. /**
  1185. * GET /api/v1/statuses/{id}/context
  1186. *
  1187. * @param integer $id
  1188. *
  1189. * @return StatusTransformer
  1190. */
  1191. public function statusContext(Request $request, $id)
  1192. {
  1193. abort_if(!$request->user(), 403);
  1194. $status = Status::whereVisibility('public')->findOrFail($id);
  1195. // Return empty response since we don't handle threading like this
  1196. $res = [
  1197. 'ancestors' => [],
  1198. 'descendants' => []
  1199. ];
  1200. return response()->json($res);
  1201. }
  1202. /**
  1203. * GET /api/v1/statuses/{id}/card
  1204. *
  1205. * @param integer $id
  1206. *
  1207. * @return StatusTransformer
  1208. */
  1209. public function statusCard(Request $request, $id)
  1210. {
  1211. abort_if(!$request->user(), 403);
  1212. $status = Status::whereVisibility('public')->findOrFail($id);
  1213. // Return empty response since we don't handle support cards
  1214. $res = [];
  1215. return response()->json($res);
  1216. }
  1217. /**
  1218. * GET /api/v1/statuses/{id}/reblogged_by
  1219. *
  1220. * @param integer $id
  1221. *
  1222. * @return AccountTransformer
  1223. */
  1224. public function statusRebloggedBy(Request $request, $id)
  1225. {
  1226. abort_if(!$request->user(), 403);
  1227. $this->validate($request, [
  1228. 'limit' => 'nullable|integer|min:1|max:80'
  1229. ]);
  1230. $limit = $request->input('limit') ?? 40;
  1231. $status = Status::whereVisibility('public')->findOrFail($id);
  1232. $shared = $status->sharedBy()->latest()->simplePaginate($limit);
  1233. $resource = new Fractal\Resource\Collection($shared, new AccountTransformer());
  1234. $res = $this->fractal->createData($resource)->toArray();
  1235. return response()->json($res);
  1236. }
  1237. public function createStatus(Request $request)
  1238. {
  1239. abort_if(!$request->user(), 403);
  1240. $this->validate($request, [
  1241. 'status' => 'string',
  1242. 'media_ids' => 'array',
  1243. 'media_ids.*' => 'integer|min:1',
  1244. 'sensitive' => 'nullable|boolean',
  1245. 'visibility' => 'string|in:private,unlisted,public',
  1246. 'in_reply_to_id' => 'integer'
  1247. ]);
  1248. if(!$request->filled('media_ids') && !$request->filled('in_reply_to_id')) {
  1249. abort(403, 'Empty statuses are not allowed');
  1250. }
  1251. }
  1252. }