|
@@ -35,12 +35,23 @@ trait FilesUploadTrait
|
|
|
}
|
|
|
|
|
|
$filesSize = 0;
|
|
|
- foreach ($request->file("files") as $file) {
|
|
|
- throw_validation_if(!$file->isValid(), "File upload failed.");
|
|
|
|
|
|
- $filesSize += $file->getSize();
|
|
|
+ $files = $request->file("files");//文件流
|
|
|
+ if ($files) {
|
|
|
+ foreach ($files as $file) {
|
|
|
+ throw_validation_if(!$file->isValid(), "File upload failed.");
|
|
|
+
|
|
|
+ $filesSize += $file->getSize();
|
|
|
+ }
|
|
|
+ } else {//文件路径
|
|
|
+ $files = $request->get('files', []);
|
|
|
+
|
|
|
+ foreach ($files as $file) {
|
|
|
+ $filesSize += (int) ($file['size'] ?? 0);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
throw_validation_if(
|
|
|
$filesSize + Auth::user()->company->used_storage_capacity > Auth::user()->company->storage_size,
|
|
|
"Storage capacity is insufficient, please contact the administrator."
|
|
@@ -49,6 +60,44 @@ trait FilesUploadTrait
|
|
|
return $filesSize;
|
|
|
}
|
|
|
|
|
|
+ protected function returnUploadResult(string $extension, string $fileName, string $path = '', int $size = 0, Request $request)
|
|
|
+ {
|
|
|
+ $modelType = $request->input('model_type', '');
|
|
|
+
|
|
|
+ if ($this->isBIM($extension) || $modelType == 'osgb' && $request->object_type == FileObjectType::CONTAINER->value) {
|
|
|
+ $bimFileBO = new BimFileBO($extension, $fileName, $modelType);
|
|
|
+ if (!empty($path)) {
|
|
|
+ $bimFileBO->modelDownloadUrl = Storage::url($path);
|
|
|
+ }
|
|
|
+ $bimFileBO->setPointCloudConfigJson($request->input('pointCloudConfigJson', []));
|
|
|
+
|
|
|
+ $data['bim'] = BIMFactory::make()->uploadFile($file ?? null, $bimFileBO);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['file'] = [
|
|
|
+ 'pathname' => $path,
|
|
|
+ 'title' => $fileName,
|
|
|
+ 'size' => $size,
|
|
|
+ 'extension' => $extension,
|
|
|
+ 'object_type' => $request->object_type,
|
|
|
+ 'object_id' => $request->object_id,
|
|
|
+ 'created_by' => Auth::id(),
|
|
|
+ 'company_id' => Auth::user()->company_id,
|
|
|
+ 'source' => $request->get("source", 1),
|
|
|
+ 'uuid' => $request->get("uuid"),
|
|
|
+ 'is_bim' => count($data['bim']) > 0 ? 1 : 0,
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function uploadFileWithPath(Request $request, string $path, string $fileName, int $size = 0)
|
|
|
+ {
|
|
|
+ $extension = pathinfo($path, PATHINFO_EXTENSION);
|
|
|
+
|
|
|
+ return $this->returnUploadResult($extension, $fileName, $path, $size, $request);
|
|
|
+ }
|
|
|
+
|
|
|
protected function uploadFile(Request $request, UploadedFile $file, ?ProgressBar $progressBar = null): array
|
|
|
{
|
|
|
$extension = $file->getClientOriginalExtension()
|
|
@@ -61,23 +110,18 @@ trait FilesUploadTrait
|
|
|
sprintf("%s.%s", md5(uniqid()), $extension),
|
|
|
$progressBar
|
|
|
);
|
|
|
- $modelDownloadUrl = Storage::url($pathname);
|
|
|
|
|
|
$data = [
|
|
|
'bim' => [],
|
|
|
];
|
|
|
|
|
|
- $isBimFile = 0;
|
|
|
$modelType = $request->input('model_type', '');
|
|
|
|
|
|
if ($this->isBIM($extension) || $modelType == 'osgb' && $request->object_type == FileObjectType::CONTAINER->value) {
|
|
|
$bimFileBO = new BimFileBO($extension, $file->getClientOriginalName(), $modelType);
|
|
|
- // $bimFileBO->modelDownloadUrl = $modelDownloadUrl;
|
|
|
$bimFileBO->setPointCloudConfigJson($request->input('pointCloudConfigJson', []));
|
|
|
|
|
|
$data['bim'] = BIMFactory::make()->uploadFile($file, $bimFileBO);
|
|
|
-
|
|
|
- $isBimFile = true;
|
|
|
}
|
|
|
|
|
|
$data['file'] = [
|
|
@@ -91,7 +135,7 @@ trait FilesUploadTrait
|
|
|
'company_id' => Auth::user()->company_id,
|
|
|
'source' => $request->get("source", 1),
|
|
|
'uuid' => $request->get("uuid"),
|
|
|
- 'is_bim' => $isBimFile,
|
|
|
+ 'is_bim' => count($data['bim']) > 0 ? 1 : 0,
|
|
|
];
|
|
|
|
|
|
return $data;
|