input('query', false); if (!$query) { return response()->json([]); } $tags = Tag::byUser(auth()->user()->id) ->where('name', 'like', '%' . escapeSearchQuery($query) . '%') ->orderBy('name') ->get(); if (!$tags->isEmpty()) { // Properly format the results to be used by Selectize $tags = $tags->map(function ($item) { return [ 'value' => $item->name, 'text' => $item->name, ]; }); } return response()->json($tags); } /** * Returns all lists that match a given query, preformatted for Selectize. * * @param Request $request * @return JsonResponse */ public function getLists(Request $request): JsonResponse { $query = $request->input('query', false); if (!$query) { return response()->json([]); } $tags = LinkList::byUser(auth()->user()->id) ->where('name', 'like', '%' . escapeSearchQuery($query) . '%') ->orderBy('name') ->get(); if (!$tags->isEmpty()) { // Properly format the results to be used by Selectize $tags = $tags->map(function ($item) { return [ 'value' => $item->name, 'text' => $item->name, ]; }); } return response()->json($tags); } /** * Returns a boolean flag which indicates that there already is a link * present for the given URL. * * @param Request $request * @return JsonResponse */ public function searchExistingUrls(Request $request): JsonResponse { $query = $request->input('query', false); if (!$query) { return response()->json([]); } $link = Link::byUser(auth()->user()->id) ->where('url', trim($query)) ->where('id', '!=', $request->input('ignore_id', 0)) ->first(); return response()->json([ 'linkFound' => $link !== null, 'editLink' => $link ? route('links.edit', ['link' => $link]) : null, ]); } /** * Simple endpoint for the system settings page which runs an update check * and returns the result to the frontend. * * @return JsonResponse */ public static function checkForUpdates(): JsonResponse { $updateCheck = UpdateHelper::checkForUpdates(true); return response()->json(['checkResult' => $updateCheck]); } /** * Returns the HTML for a given URL to prevent CORS issues in the frontend * implementation. * * @param Request $request * @return Response */ public function htmlForUrl(Request $request): Response { $request->validate([ 'url' => ['url'], ]); $url = $request->input('url'); $newRequest = Http::timeout(3); if (config('html-meta.user_agents', false)) { $agents = config('html-meta.user_agents'); $newRequest->withHeaders(['User-Agent' => $agents[array_rand($agents)]]); } $response = $newRequest->get($url); if ($response->successful()) { return response($response->body()); } return response(null); } }