mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Update ApiController, fixes #1705
This commit is contained in:
parent
788f76cf35
commit
139c6651bf
1 changed files with 16 additions and 12 deletions
|
@ -83,12 +83,15 @@ class ApiController extends BaseApiController
|
|||
{
|
||||
abort_if(!Auth::check(), 403);
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string'
|
||||
'q' => 'required|string|max:100'
|
||||
]);
|
||||
$q = filter_var($request->input('q'), FILTER_SANITIZE_STRING);
|
||||
$hash = hash('sha256', $q);
|
||||
$key = 'search:location:id:' . $hash;
|
||||
$places = Cache::remember($key, now()->addMinutes(15), function() use($q) {
|
||||
$q = '%' . $q . '%';
|
||||
$places = Place::where('name', 'like', $q)
|
||||
->take(25)
|
||||
return Place::where('name', 'like', $q)
|
||||
->take(80)
|
||||
->get()
|
||||
->map(function($r) {
|
||||
return [
|
||||
|
@ -98,6 +101,7 @@ class ApiController extends BaseApiController
|
|||
'url' => $r->url()
|
||||
];
|
||||
});
|
||||
});
|
||||
return $places;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue