WIP uploading files
This commit is contained in:
@@ -15,19 +15,14 @@ use Lucent\Record\Status;
|
||||
use function Lucent\Response\fail;
|
||||
use function Lucent\Response\ok;
|
||||
|
||||
|
||||
class FileController extends Controller
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private readonly ChannelService $channelService,
|
||||
private readonly RecordService $recordService,
|
||||
private readonly FileService $fileService,
|
||||
private readonly Query $query
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
private readonly RecordService $recordService,
|
||||
private readonly FileService $fileService,
|
||||
private readonly Query $query,
|
||||
) {}
|
||||
|
||||
public function fromDisk(Request $request, string $disk)
|
||||
{
|
||||
@@ -38,7 +33,7 @@ class FileController extends Controller
|
||||
|
||||
public function thumb(Request $request, string $disk)
|
||||
{
|
||||
$imagePath = "thumbs/".$request->route("any");
|
||||
$imagePath = "thumbs/" . $request->route("any");
|
||||
$disk = $this->fileService->loadDisk($disk);
|
||||
return response()->file($disk->path($imagePath));
|
||||
}
|
||||
@@ -49,34 +44,21 @@ class FileController extends Controller
|
||||
return $disk->download($request->input("path"));
|
||||
}
|
||||
|
||||
|
||||
public function upload(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'files.*' => 'required|file|max:100000',
|
||||
"files.*" => "required|file|max:100000",
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return fail($validator->errors()->first());
|
||||
}
|
||||
$schema = $this->channelService->channel->schemas->firstWhere("name", $request->input("schema"));
|
||||
$files = $request->file('files');
|
||||
$recordId = $request->input("recordId");
|
||||
$files = $request->file("files");
|
||||
|
||||
foreach ($files as $file) {
|
||||
$this->recordService->createFromUploadedFile($file, new RecordInputData(
|
||||
schemaName: $schema->name,
|
||||
status: Status::PUBLISHED,
|
||||
), []);
|
||||
}
|
||||
|
||||
$graph = $this->query
|
||||
->filter([
|
||||
"schema" => $schema->name
|
||||
])
|
||||
->limit(15)
|
||||
->skip(0)
|
||||
->sort("-_sys.updatedAt")
|
||||
->run();
|
||||
|
||||
return ok($graph->records->toArray());
|
||||
return ok(
|
||||
collect($files)
|
||||
->map(fn($file) => $this->fileService->upload($recordId, $file))
|
||||
->toArray(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user