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.

50 lines
1.4 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. $documentContent = $handler->getAfterIngest($id);
  12. $handler->destroy($id);
  13. return response()->json([
  14. 'content' => $documentContent,
  15. 'ingest_status' => !! $documentContent ? 'success' : 'fail',
  16. ], 200);
  17. } catch (\Exception $exception) {
  18. return response()->json([
  19. 'message' => $exception->getMessage(),
  20. ], 400);
  21. }
  22. }
  23. public function store()
  24. {
  25. request()->validate([
  26. 'content' => 'required', // String or file.
  27. 'searchers' => 'required|array', // Check if matches all rules, must have 'key' and 'replace_with'.
  28. ]);
  29. $searchAndDisplace = new SearchAndDisplace(request()->input('content'), [
  30. 'searchers' => request()->input('searchers'),
  31. ]);
  32. try {
  33. return response()->json($searchAndDisplace->execute(), 200);
  34. } catch (\Exception $exception) {
  35. return response()->json([
  36. 'message' => $exception->getMessage(),
  37. 'trace' => $exception->getTrace(),
  38. ], 400);
  39. }
  40. }
  41. }