account refactor
This commit is contained in:
@@ -5,8 +5,6 @@ namespace Lucent\Http\Controller;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Lucent\Channel\ChannelRepo;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\File\FileUploadResult;
|
||||
use Lucent\Query\Query;
|
||||
@@ -34,65 +32,10 @@ class FileController extends Controller
|
||||
return $disk->download($request->input("path"));
|
||||
}
|
||||
|
||||
public function get(Request $request)
|
||||
{
|
||||
$manager = new ImageManager(['driver' => 'imagick']);
|
||||
$filesystem = loadDisk();
|
||||
$path = $request->route("path");
|
||||
|
||||
if ($filesystem->exists($path)) {
|
||||
$image = $manager->make($filesystem->get($path));
|
||||
return $image->response();
|
||||
}
|
||||
$arr = explode(".", $path);
|
||||
$ext = end($arr);
|
||||
$pathWithoutExtension = str_replace("." . $ext, "", $path);
|
||||
|
||||
$pathArguments = (function ($path) {
|
||||
$pathWithArgumentsAr = explode("-", $path);
|
||||
return collect($pathWithArgumentsAr)
|
||||
->filter(fn($ar) => str_contains($ar, "_"))
|
||||
->reduce(function ($carry, $arg) {
|
||||
[$k, $v] = explode("_", $arg);
|
||||
$carry[$k] = $v;
|
||||
return $carry;
|
||||
});
|
||||
|
||||
})($pathWithoutExtension);
|
||||
|
||||
$originalPath = (function ($path) use ($ext) {
|
||||
$arr = explode("-o-", $path);
|
||||
return $arr[0] . "." . $ext;
|
||||
})($path);
|
||||
$image = $manager->make($filesystem->get($originalPath));
|
||||
if (empty($pathArguments["mode"])) {
|
||||
|
||||
if (empty($pathArguments["w"])) {
|
||||
$image->resize(null, $pathArguments["h"], function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
} elseif (empty($pathArguments["h"])) {
|
||||
$image->resize($pathArguments["w"], null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
} else {
|
||||
$image->resize($pathArguments["w"], $pathArguments["h"]);
|
||||
}
|
||||
} else if ($pathArguments["mode"] === "fit") {
|
||||
$image->fit($pathArguments["w"], $pathArguments["h"]);
|
||||
}
|
||||
|
||||
$disk = loadDisk();
|
||||
// $disk->put("cache/" . $path, $image);
|
||||
$image->save(storage_path("app/public/cache/" . $path));
|
||||
return $image->response();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function upload(Request $request)
|
||||
{
|
||||
$validator = Validator::make(request()->all(), [
|
||||
$validator = Validator::make($request->all(), [
|
||||
'files.*' => 'required|file|max:100000',
|
||||
]);
|
||||
|
||||
@@ -100,7 +43,7 @@ class FileController extends Controller
|
||||
return fail($validator->errors()->first());
|
||||
}
|
||||
$schema = $this->channelService->channel->schemas->firstWhere("name", $request->input("schema"));
|
||||
$files = request()->file('files');
|
||||
$files = $request->file('files');
|
||||
|
||||
|
||||
$uploadResults = collect($files)->map(fn($file) => uploadFile($schema, $file))->toArray();
|
||||
@@ -128,8 +71,6 @@ class FileController extends Controller
|
||||
->limit(15)
|
||||
->skip(0)
|
||||
->sort("-_sys.updatedAt")
|
||||
->childrenDepth(0)
|
||||
->parentsDepth(0)
|
||||
->run();
|
||||
|
||||
return ok($graph->records->toArray());
|
||||
|
||||
Reference in New Issue
Block a user