Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

3 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\SearchDisplace\Documents\DocumentFile;
  4. use App\SearchDisplace\SearchAndDisplace;
  5. class SearchAndDisplaceController extends Controller
  6. {
  7. public function show($id)
  8. {
  9. $handler = new DocumentFile();
  10. try {
  11. $result = $handler->getAfterIngest($id);
  12. if ($result['status'] !== 'processing') {
  13. // $handler->destroy($id);
  14. }
  15. return response()->json($result, 200);
  16. } catch (\Exception $exception) {
  17. return response()->json([
  18. 'message' => $exception->getMessage(),
  19. ], 400);
  20. }
  21. }
  22. public function store()
  23. {
  24. request()->validate([
  25. 'content' => 'required', // String or file.
  26. 'searchers' => 'required|array',
  27. 'searchers.*.key' => 'required',
  28. 'searchers.*.type' => 'required|in:replace,displace',
  29. 'searchers.*.vale' => 'nullable',
  30. 'searchOnly' => 'nullable|boolean'
  31. ]);
  32. $searchOnly = request()->input('searchOnly') ?? false;
  33. $searchAndDisplace = new SearchAndDisplace(
  34. request()->input('content'),
  35. [
  36. 'searchers' => request()->input('searchers'),
  37. ],
  38. $searchOnly
  39. );
  40. try {
  41. return response()->json($searchAndDisplace->execute(), 200);
  42. } catch (\Exception $exception) {
  43. return response()->json([
  44. 'message' => $exception->getMessage(),
  45. 'trace' => $exception->getTrace(),
  46. ], 400);
  47. }
  48. }
  49. }