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.

148 lines
5.6 KiB

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Contracts\Container\BindingResolutionException;
  4. use Illuminate\Http\JsonResponse;
  5. use Illuminate\Support\Facades\Storage;
  6. use Illuminate\Http\UploadedFile;
  7. use GuzzleHttp\Client;
  8. class FileController extends Controller
  9. {
  10. /**
  11. *
  12. * @return JsonResponse
  13. *
  14. * @throws BindingResolutionException
  15. */
  16. public function create(): JsonResponse
  17. {
  18. /** @var UploadedFile $file */
  19. $file = request()->file('file');
  20. $time = time();
  21. $fileName = $time . '-' . $file->getClientOriginalName();
  22. $fileId = $time . pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
  23. $path = Storage::putFileAs('files/', $file, $fileName);
  24. $guzzle = new Client();
  25. /** @var \Psr\Http\Message\ResponseInterface $response */
  26. $response = $guzzle->request('POST', 'http://ingest.sandd/ingest', [
  27. 'multipart' => [
  28. [
  29. 'name' => 'body',
  30. 'contents' => json_encode([ 'id' => $fileId ]),
  31. 'headers' => [ 'Content-Type' => 'application/json' ]
  32. ],
  33. [
  34. 'name' => 'document',
  35. 'contents' => fopen($file->getPathname(), 'r')
  36. ]
  37. ]
  38. ]);
  39. return response()->json([
  40. 'file' => $file->getClientOriginalName(),
  41. 'id' => $fileId,
  42. 'path' => $path,
  43. ]);
  44. }
  45. /**
  46. *
  47. * @param string $id
  48. *
  49. * @return JsonResponse
  50. *
  51. * @throws BindingResolutionException
  52. */
  53. public function get(string $id): JsonResponse
  54. {
  55. $success = rand(0, 1);
  56. if ($success == 1) {
  57. $text = <<<EOT
  58. ## About Laravel
  59. Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
  60. - [Simple, fast routing engine](https://laravel.com/docs/routing).
  61. - [Powerful dependency injection container](https://laravel.com/docs/container).
  62. - Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
  63. - Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
  64. - Database agnostic [schema migrations](https://laravel.com/docs/migrations).
  65. - [Robust background job processing](https://laravel.com/docs/queues).
  66. - [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
  67. Laravel is accessible, powerful, and provides tools required for large, robust applications.
  68. ## Learning Laravel
  69. Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
  70. If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
  71. ## Laravel Sponsors
  72. We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell).
  73. - **[Vehikl](https://vehikl.com/)**
  74. - **[Tighten Co.](https://tighten.co)**
  75. - **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
  76. - **[64 Robots](https://64robots.com)**
  77. - **[Cubet Techno Labs](https://cubettech.com)**
  78. - **[Cyber-Duck](https://cyber-duck.co.uk)**
  79. - **[British Software Development](https://www.britishsoftware.co)**
  80. - **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)**
  81. - **[DevSquad](https://devsquad.com)**
  82. - [UserInsights](https://userinsights.com)
  83. - [Fragrantica](https://www.fragrantica.com)
  84. - [SOFTonSOFA](https://softonsofa.com/)
  85. - [User10](https://user10.com)
  86. - [Soumettre.fr](https://soumettre.fr/)
  87. - [CodeBrisk](https://codebrisk.com)
  88. - [1Forge](https://1forge.com)
  89. - [TECPRESSO](https://tecpresso.co.jp/)
  90. - [Runtime Converter](http://runtimeconverter.com/)
  91. - [WebL'Agence](https://weblagence.com/)
  92. - [Invoice Ninja](https://www.invoiceninja.com)
  93. - [iMi digital](https://www.imi-digital.de/)
  94. - [Earthlink](https://www.earthlink.ro/)
  95. - [Steadfast Collective](https://steadfastcollective.com/)
  96. - [We Are The Robots Inc.](https://watr.mx/)
  97. - [Understand.io](https://www.understand.io/)
  98. - [Abdel Elrafa](https://abdelelrafa.com)
  99. - [Hyper Host](https://hyper.host)
  100. - [Appoly](https://www.appoly.co.uk)
  101. - [OP.GG](https://op.gg)
  102. ## Contributing
  103. Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
  104. ## Code of Conduct
  105. In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
  106. ## Security Vulnerabilities
  107. If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
  108. ## License
  109. The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
  110. EOT;
  111. return response()->json([
  112. 'text' => $text,
  113. 'ready' => true
  114. ]);
  115. }
  116. return response()->json([
  117. 'ready' => false
  118. ]);
  119. }
  120. }