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.
|
|
<?php
namespace App\Http\Controllers;
use App\SearchDisplace\Ingest\SendDocument; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Storage; use Illuminate\Http\UploadedFile; use GuzzleHttp\Exception\BadResponseException; use Illuminate\Support\Str; use Symfony\Component\Process\Process;
class FileController extends Controller { /** * * @return JsonResponse */ public function create(): JsonResponse { try { /** @var UploadedFile $file */ $file = request()->file('file'); $time = time(); $fileId = $time . '_' . pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
$sendDocument = new SendDocument();
$sendDocument->execute($file->getRealPath(), $fileId);
return response()->json([ 'id' => $fileId, 'file_name' => $file->getClientOriginalName(), ]); } catch (BadResponseException $e) { return response()->json([ 'message' => $e->getMessage(), 'response' => $e->getResponse() ], 400); } catch (\Exception $e) { return response()->json([ 'message' => $e->getMessage(), ], 400); } }
/** * */ public function convert(): JsonResponse { $mdFileContent = request()->input('content'); $tmpFileId = (string) Str::uuid();
Storage::disk('local')->put('tmp/' . $tmpFileId . '.md', $mdFileContent); $tmpMdFilePath = Storage::path('tmp/' . $tmpFileId . '.md');
$pandoc = new Process([ 'pandoc', '-f', 'markdown', '-t', 'odt', $tmpMdFilePath ]);
$pandoc->start();
while ($pandoc->isRunning()) { //
}
$odtFileContent = $pandoc->getOutput(); Storage::disk('local')->put('tmp/' . $tmpFileId . '.odt', $odtFileContent);
return response()->json([ 'path' => 'tmp/' . $tmpFileId . '.odt' ]); }
/** * * @param string $path * @return mixed */ public function download(string $path) { return Storage::download($path); } }
|