file upload
This commit is contained in:
@@ -7,7 +7,6 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Lucent\Channel\ChannelService;
|
use Lucent\Channel\ChannelService;
|
||||||
use Lucent\File\FileService;
|
use Lucent\File\FileService;
|
||||||
use Lucent\File\FileUploadResult;
|
|
||||||
use Lucent\Query\Query;
|
use Lucent\Query\Query;
|
||||||
use Lucent\Record\InputData\RecordInputData;
|
use Lucent\Record\InputData\RecordInputData;
|
||||||
use Lucent\Record\RecordService;
|
use Lucent\Record\RecordService;
|
||||||
@@ -47,23 +46,12 @@ class FileController extends Controller
|
|||||||
$schema = $this->channelService->channel->schemas->firstWhere("name", $request->input("schema"));
|
$schema = $this->channelService->channel->schemas->firstWhere("name", $request->input("schema"));
|
||||||
$files = $request->file('files');
|
$files = $request->file('files');
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
$uploadResults = collect($files)->map(fn($file) => $this->fileService->upload($schema, $file))->toArray();
|
$this->recordService->createFromUploadedFile($file, new RecordInputData(
|
||||||
collect($uploadResults)
|
schemaName: $schema->name,
|
||||||
->filter(fn(FileUploadResult $res) => !$res->isDuplicate)
|
status: Status::PUBLISHED,
|
||||||
->values()
|
), []);
|
||||||
->map(function (FileUploadResult $uploadResult) use ($schema) {
|
}
|
||||||
return $this->recordService->create(
|
|
||||||
new RecordInputData(
|
|
||||||
schemaName: $schema->name,
|
|
||||||
status: Status::PUBLISHED,
|
|
||||||
|
|
||||||
),
|
|
||||||
file: $uploadResult->recordFile,
|
|
||||||
);
|
|
||||||
|
|
||||||
})->toArray();
|
|
||||||
|
|
||||||
|
|
||||||
$graph = $this->query
|
$graph = $this->query
|
||||||
->filter([
|
->filter([
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ readonly class RecordService
|
|||||||
throw new LucentException("You can't upload a file to a regular record");
|
throw new LucentException("You can't upload a file to a regular record");
|
||||||
}
|
}
|
||||||
$fileData = $this->fileService->createFromUrl($schema, $url);
|
$fileData = $this->fileService->createFromUrl($schema, $url);
|
||||||
|
if ($fileData->isDuplicate) {
|
||||||
|
return $fileData->duplicateId;
|
||||||
|
}
|
||||||
return $this->create($data, $fileData->recordFile, $edges);
|
return $this->create($data, $fileData->recordFile, $edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,13 +67,16 @@ readonly class RecordService
|
|||||||
UploadedFile $uploadedFile,
|
UploadedFile $uploadedFile,
|
||||||
RecordInputData $data,
|
RecordInputData $data,
|
||||||
array $edges
|
array $edges
|
||||||
)
|
): string
|
||||||
{
|
{
|
||||||
$schema = $this->channelService->getSchema($data->schemaName)->get();
|
$schema = $this->channelService->getSchema($data->schemaName)->get();
|
||||||
if ($schema->type !== Type::FILES) {
|
if ($schema->type !== Type::FILES) {
|
||||||
throw new LucentException("You can't upload a file to a regular record");
|
throw new LucentException("You can't upload a file to a regular record");
|
||||||
}
|
}
|
||||||
$fileData = $this->fileService->upload($schema, $uploadedFile);
|
$fileData = $this->fileService->upload($schema, $uploadedFile);
|
||||||
|
if ($fileData->isDuplicate) {
|
||||||
|
return $fileData->duplicateId;
|
||||||
|
}
|
||||||
return $this->create($data, $fileData->recordFile, $edges);
|
return $this->create($data, $fileData->recordFile, $edges);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +84,7 @@ readonly class RecordService
|
|||||||
FileData $fileData,
|
FileData $fileData,
|
||||||
RecordInputData $data,
|
RecordInputData $data,
|
||||||
array $edges
|
array $edges
|
||||||
)
|
): string
|
||||||
{
|
{
|
||||||
$schema = $this->channelService->getSchema($data->schemaName)->get();
|
$schema = $this->channelService->getSchema($data->schemaName)->get();
|
||||||
if ($schema->type !== Type::FILES) {
|
if ($schema->type !== Type::FILES) {
|
||||||
|
|||||||
Reference in New Issue
Block a user