jqh 4 年之前
父节点
当前提交
d7bd93f749
共有 4 个文件被更改,包括 20 次插入20 次删除
  1. 1 1
      src/Form/Concerns/HasFiles.php
  2. 3 3
      src/Middleware/WebUploader.php
  3. 15 15
      src/Support/WebUploader.php
  4. 1 1
      src/Traits/HasUploadedFile.php

+ 1 - 1
src/Form/Concerns/HasFiles.php

@@ -25,7 +25,7 @@ trait HasFiles
     protected function handleUploadFile($data)
     {
         $column = $data['upload_column'] ?? null;
-        $file = app('admin.web-uploader')->getCompleteUploadedFile() ?: ($data[WebUploader::FILE_NAME] ?? null);
+        $file = app('admin.web-uploader')->getUploadedFile() ?: ($data[WebUploader::FILE_NAME] ?? null);
 
         if (! $column || ! $file instanceof UploadedFile) {
             return;

+ 3 - 3
src/Middleware/WebUploader.php

@@ -22,7 +22,7 @@ class WebUploader
         }
 
         try {
-            if (! $file = $webUploader->getCompleteUploadedFile()) {
+            if (! $file = $webUploader->getUploadedFile()) {
                 // 分块未上传完毕,返回已合并成功信息
                 return response()->json(['merge' => 1]);
             }
@@ -30,12 +30,12 @@ class WebUploader
             $response = $next($request);
 
             // 移除临时文件
-            $webUploader->deleteTempFile();
+            $webUploader->deleteTemporaryFile();
 
             return $response;
         } catch (\Throwable $e) {
             // 移除临时文件
-            $webUploader->deleteTempFile();
+            $webUploader->deleteTemporaryFile();
 
             throw $e;
         }

+ 15 - 15
src/Support/WebUploader.php

@@ -19,9 +19,9 @@ class WebUploader
 {
     const FILE_NAME = '_file_';
 
-    public $tempDirectory = 'tmp';
+    public $temporaryDirectory = 'tmp';
 
-    protected $tempFilePath;
+    protected $temporaryFilePath;
 
     protected $completeFile;
 
@@ -71,7 +71,7 @@ class WebUploader
      *
      * @return UploadedFile|void
      */
-    public function getCompleteUploadedFile()
+    public function getUploadedFile()
     {
         $file = $this->file;
 
@@ -93,16 +93,16 @@ class WebUploader
     /**
      * 移除临时文件以及文件夹.
      */
-    public function deleteTempFile()
+    public function deleteTemporaryFile()
     {
-        if (! $this->tempFilePath) {
+        if (! $this->temporaryFilePath) {
             return;
         }
-        @unlink($this->tempFilePath);
+        @unlink($this->temporaryFilePath);
 
         if (
             ! Finder::create()
-                ->in($dir = dirname($this->tempFilePath))
+                ->in($dir = dirname($this->temporaryFilePath))
                 ->files()
                 ->count()
         ) {
@@ -119,7 +119,7 @@ class WebUploader
      */
     protected function mergeChunks(UploadedFile $file)
     {
-        $tmpDir = $this->getTempPath($this->_id);
+        $tmpDir = $this->getTemporaryPath($this->_id);
         $newFilename = $this->generateChunkFileName($file);
 
         // 移动当前分块到临时目录.
@@ -130,12 +130,12 @@ class WebUploader
             return false;
         }
 
-        $this->tempFilePath = $tmpDir.'/'.$newFilename.'.tmp';
+        $this->temporaryFilePath = $tmpDir.'/'.$newFilename.'.tmp';
 
-        $this->putTempFileContent($this->tempFilePath, $tmpDir, $newFilename);
+        $this->putTempFileContent($this->temporaryFilePath, $tmpDir, $newFilename);
 
         return new UploadedFile(
-            $this->tempFilePath,
+            $this->temporaryFilePath,
             $file->getClientOriginalName(),
             null,
             null,
@@ -223,9 +223,9 @@ class WebUploader
      *
      * @return string
      */
-    public function getTempPath($path)
+    public function getTemporaryPath($path)
     {
-        return $this->getTempDirectory().'/'.$path;
+        return $this->getTemporaryDirectory().'/'.$path;
     }
 
     /**
@@ -233,9 +233,9 @@ class WebUploader
      *
      * @return string
      */
-    public function getTempDirectory()
+    public function getTemporaryDirectory()
     {
-        $dir = storage_path($this->tempDirectory);
+        $dir = storage_path($this->temporaryDirectory);
 
         if (! is_dir($dir)) {
             app('files')->makeDirectory($dir, 0755, true);

+ 1 - 1
src/Traits/HasUploadedFile.php

@@ -31,7 +31,7 @@ trait HasUploadedFile
      */
     public function file()
     {
-        return $this->uploader()->getCompleteUploadedFile();
+        return $this->uploader()->getUploadedFile();
     }
 
     /**