pixelfed/app/Http/Controllers/ApiController.php

94 lines
2.8 KiB
PHP
Raw Normal View History

2018-06-04 01:39:38 +00:00
<?php
namespace App\Http\Controllers;
2018-08-10 05:04:21 +00:00
use App\Http\Controllers\Api\BaseApiController;
2019-04-28 23:48:53 +00:00
use App\{
Like,
Profile
};
2018-08-28 03:07:36 +00:00
use Auth;
use Cache;
use Illuminate\Http\Request;
2019-04-28 23:48:53 +00:00
use App\Services\SuggestionService;
2018-06-04 01:39:38 +00:00
2018-08-10 05:04:21 +00:00
class ApiController extends BaseApiController
2018-06-04 01:39:38 +00:00
{
2019-02-25 18:56:24 +00:00
// todo: deprecate and remove
2018-06-04 01:39:38 +00:00
public function hydrateLikes(Request $request)
{
2019-03-25 03:34:25 +00:00
return response()->json([]);
}
2018-06-04 01:39:38 +00:00
2019-03-25 03:34:25 +00:00
public function siteConfiguration(Request $request)
{
$res = Cache::remember('api:site:configuration', now()->addMinutes(30), function() {
return [
'uploader' => [
'max_photo_size' => config('pixelfed.max_photo_size'),
'max_caption_length' => config('pixelfed.max_caption_length'),
'album_limit' => config('pixelfed.max_album_length'),
'image_quality' => config('pixelfed.image_quality'),
'optimize_image' => config('pixelfed.optimize_image'),
'optimize_video' => config('pixelfed.optimize_video'),
2019-03-25 03:34:25 +00:00
'media_types' => config('pixelfed.media_types'),
'enforce_account_limit' => config('pixelfed.enforce_account_limit')
2019-04-18 01:40:35 +00:00
],
2019-04-21 02:00:59 +00:00
2019-04-18 01:40:35 +00:00
'activitypub' => [
'enabled' => config('pixelfed.activitypub_enabled'),
'remote_follow' => config('pixelfed.remote_follow_enabled')
2019-04-21 02:00:59 +00:00
],
'ab' => [
2019-04-26 05:24:59 +00:00
'lc' => config('exp.lc'),
'rec' => config('exp.rec'),
2019-04-21 02:00:59 +00:00
],
2019-03-25 03:34:25 +00:00
];
});
2018-08-10 05:04:21 +00:00
return response()->json($res);
}
2019-04-28 23:48:53 +00:00
public function userRecommendations(Request $request)
{
abort_if(!Auth::check(), 403);
abort_if(!config('exp.rec'), 400);
$id = Auth::user()->profile->id;
$following = Cache::get('profile:following:'.$id, []);
$ids = SuggestionService::get();
$res = Cache::remember('api:local:exp:rec:'.$id, now()->addMinutes(5), function() use($id, $following, $ids) {
array_push($following, $id);
return Profile::select(
'id',
'username'
)
->whereNotIn('id', $following)
->whereIn('id', $ids)
->whereIsPrivate(0)
->whereNull('status')
->whereNull('domain')
->inRandomOrder()
->take(4)
->get()
->map(function($item, $key) {
return [
'id' => $item->id,
'avatar' => $item->avatarUrl(),
'username' => $item->username,
'message' => 'Recommended for You'
];
});
});
return response()->json($res->all());
}
2018-06-04 01:39:38 +00:00
}