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
59 lines
1.6 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\SearchDisplace\Documents\DocumentFile;
|
|
use App\SearchDisplace\SearchAndDisplace;
|
|
|
|
class SearchAndDisplaceController extends Controller
|
|
{
|
|
public function show($id)
|
|
{
|
|
$handler = new DocumentFile();
|
|
|
|
try {
|
|
$result = $handler->getAfterIngest($id);
|
|
|
|
if ($result['status'] !== 'processing') {
|
|
// $handler->destroy($id);
|
|
}
|
|
|
|
return response()->json($result, 200);
|
|
} catch (\Exception $exception) {
|
|
return response()->json([
|
|
'message' => $exception->getMessage(),
|
|
], 400);
|
|
}
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
request()->validate([
|
|
'content' => 'required', // String or file.
|
|
'searchers' => 'required|array',
|
|
'searchers.*.key' => 'required',
|
|
'searchers.*.type' => 'required|in:replace,displace',
|
|
'searchers.*.vale' => 'nullable',
|
|
'searchOnly' => 'nullable|boolean'
|
|
]);
|
|
|
|
$searchOnly = request()->input('searchOnly') ?? false;
|
|
|
|
$searchAndDisplace = new SearchAndDisplace(
|
|
request()->input('content'),
|
|
[
|
|
'searchers' => request()->input('searchers'),
|
|
],
|
|
$searchOnly
|
|
);
|
|
|
|
try {
|
|
return response()->json($searchAndDisplace->execute(), 200);
|
|
} catch (\Exception $exception) {
|
|
return response()->json([
|
|
'message' => $exception->getMessage(),
|
|
'trace' => $exception->getTrace(),
|
|
], 400);
|
|
}
|
|
}
|
|
}
|