moell 10 months ago
parent
commit
590be4a946

+ 24 - 0
app/Http/Controllers/API/FileController.php

@@ -12,6 +12,7 @@ use App\Http\Resources\API\FileUploadSuccessResource;
 use App\Models\Enums\FileObjectType;
 use App\Models\File;
 use App\Models\Folder;
+use App\Services\File\BIM\BIMFactory;
 use App\Services\File\DownloadService;
 use App\Services\File\FileHideService;
 use App\Services\File\Upload\FilesUploadService;
@@ -178,4 +179,27 @@ class FileController extends Controller
 
         return $this->noContent();
     }
+
+    public function bimView(string $id)
+    {
+        $file = File::query()->where('is_bim', 1)->findOrFail($id);
+
+        $fileObjectType = FileObjectType::from($file->object_type);
+        $object = $fileObjectType->modelBuilderAllowed($file->object_id)->find($file->object_id);
+        if(! $object){
+            return $this->badRequest(sprintf("File ID: %s, no permission to access", $file->id));
+        }
+
+        $bimFile = $file->bimFile;
+        $result = BIMFactory::make($bimFile->bim_driver)->viewDataSetModel([
+            $bimFile->bim_data_set_id
+        ]);
+
+        return $this->success([
+            'data' => [
+                'bim_driver' => $bimFile->bim_driver,
+                'bim_view' => $result
+            ]
+        ]);
+    }
 }

+ 5 - 0
app/Models/File.php

@@ -27,4 +27,9 @@ class File extends Model
     {
         return $this->belongsTo(Folder::class);
     }
+
+    public function bimFile(): \Illuminate\Database\Eloquent\Relations\HasOne
+    {
+        return $this->hasOne(BimFile::class);
+    }
 }

+ 3 - 1
app/Services/File/BIM/BlackHole/BlackHole.php

@@ -48,7 +48,9 @@ class BlackHole implements BIMContact
     public function viewDataSetModel(array $dataSetIDS)
     {
         $result = Client::getInstance()->post("/blackHole3D/project/dataSet/viewDataSetModel", [
-            'dataSetIds' => $dataSetIDS
+            'json' => [
+                'dataSetIds' => $dataSetIDS
+            ]
         ]);
 
         return $result['data'] ?? [];

+ 1 - 0
routes/api.php

@@ -172,6 +172,7 @@ Route::middleware(['auth:sanctum'])->group(function () {
         Route::delete("file/{file}/destroy", [API\FileController::class, "destroy"])->name("file.destroy");
         Route::post("file/keep-directory-upload", [API\FileController::class, "keepDirectoryUpload"])->name("file.keep-directory-upload");
         Route::delete("file/{file}/hide", [API\FileController::class, "hide"])->name("file.hide");
+        Route::get("file-bim-view/{file}", [API\FileController::class, "bimView"])->name("file.bim-view");
 
         Route::get("notification", [API\NotificationController::class, "index"])->name("notification.index");
         Route::get("notification/unread", [API\NotificationController::class, "unread"])->name("notification.unread");