|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Services\File\Upload;
|
|
|
|
|
|
use App\Http\Resources\API\FileUploadSuccessResource;
|
|
|
+use App\Models\BimFile;
|
|
|
use App\Models\ContainerContent;
|
|
|
use App\Models\Enums\FileObjectType;
|
|
|
use App\Models\File;
|
|
@@ -42,21 +43,25 @@ trait FilesUploadTrait
|
|
|
|
|
|
protected function uploadFile(Request $request, UploadedFile $file): array
|
|
|
{
|
|
|
- /*$pathname = $file->storeAs(
|
|
|
+ $pathname = $file->storeAs(
|
|
|
sprintf("c%s/%s/%s", Auth::user()->company_id, $request->get("object_type"), date("Ymd")),
|
|
|
sprintf("%s.%s", md5(uniqid()), $file->extension())
|
|
|
- );*/
|
|
|
+ );
|
|
|
|
|
|
- $pathname = "/test/test.jpg";
|
|
|
+ $data = [
|
|
|
+ 'bim' => [],
|
|
|
+ ];
|
|
|
|
|
|
$extension = $file->extension() ? $file->extension() : pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
|
|
|
+ $isBimFile = 0;
|
|
|
if (in_array($extension, config("bim.extensions")) && $request->object_type == FileObjectType::CONTAINER->value) {
|
|
|
- $this->uploadToBIM($file);
|
|
|
+ $isBimFile = true;
|
|
|
+ $data['bim'] = BIMFactory::make()->uploadFile($file);
|
|
|
}
|
|
|
|
|
|
throw_validation_if(! $pathname, "File upload failed.");
|
|
|
|
|
|
- return [
|
|
|
+ $data['file'] = [
|
|
|
'pathname' => $pathname,
|
|
|
'title' => $file->getClientOriginalName(),
|
|
|
'size' => $file->getSize(),
|
|
@@ -67,29 +72,33 @@ trait FilesUploadTrait
|
|
|
'company_id' => Auth::user()->company_id,
|
|
|
'source' => $request->get("source", 1),
|
|
|
'uuid' => $request->get("uuid"),
|
|
|
+ 'is_bim' => $isBimFile,
|
|
|
];
|
|
|
+
|
|
|
+ return $data;
|
|
|
}
|
|
|
|
|
|
protected function storeFiles(array $items)
|
|
|
{
|
|
|
$uploadedFiles = [];
|
|
|
foreach ($items as $item) {
|
|
|
- if ($item['object_id'] && $item['source'] == 1||$item['uuid'] && $item['source']== 1) {
|
|
|
+ $fileInfo = $item['file'];
|
|
|
+ if ($fileInfo['object_id'] && $fileInfo['source'] == 1||$fileInfo['uuid'] && $fileInfo['source']== 1) {
|
|
|
$version = File::query()
|
|
|
- ->where('object_type', $item['object_type'])
|
|
|
- ->where('object_id', $item['object_id'])
|
|
|
- ->where("title", $item['title'])
|
|
|
+ ->where('object_type', $fileInfo['object_type'])
|
|
|
+ ->where('object_id', $fileInfo['object_id'])
|
|
|
+ ->where("title", $fileInfo['title'])
|
|
|
->where("source", 1)
|
|
|
- ->where("folder_id", $item['folder_id'] ?? 0)
|
|
|
+ ->where("folder_id", $fileInfo['folder_id'] ?? 0)
|
|
|
->count();
|
|
|
- $item['version'] = $version + 1;
|
|
|
- $item['is_latest_version'] = 1;
|
|
|
+ $fileInfo['version'] = $version + 1;
|
|
|
+ $fileInfo['is_latest_version'] = 1;
|
|
|
|
|
|
File::query()
|
|
|
- ->where('object_type', $item['object_type'])
|
|
|
- ->where('object_id', $item['object_id'])
|
|
|
- ->where("title", $item['title'])
|
|
|
- ->where("folder_id", $item['folder_id'] ?? 0)
|
|
|
+ ->where('object_type', $fileInfo['object_type'])
|
|
|
+ ->where('object_id', $fileInfo['object_id'])
|
|
|
+ ->where("title", $fileInfo['title'])
|
|
|
+ ->where("folder_id", $fileInfo['folder_id'] ?? 0)
|
|
|
->where("source", 1)
|
|
|
->where("is_latest_version", 1)
|
|
|
->update([
|
|
@@ -97,7 +106,14 @@ trait FilesUploadTrait
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- $file = File::query()->create($item);
|
|
|
+ $file = File::query()->create($fileInfo);
|
|
|
+
|
|
|
+ if (isset($item['bim']) && $item['bim']) {
|
|
|
+ BimFile::query()->create([
|
|
|
+ 'file_id' => $file->id,
|
|
|
+ ...$item['bim']
|
|
|
+ ]);
|
|
|
+ }
|
|
|
|
|
|
$uploadedFiles[] = new FileUploadSuccessResource($file);
|
|
|
}
|
|
@@ -107,10 +123,6 @@ trait FilesUploadTrait
|
|
|
return $uploadedFiles;
|
|
|
}
|
|
|
|
|
|
- protected function uploadToBIM(UploadedFile $file)
|
|
|
- {
|
|
|
- BIMFactory::make()->uploadFile($file);
|
|
|
- }
|
|
|
|
|
|
protected function updateObjectVersion()
|
|
|
{
|