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