Просмотр исходного кода

fix: 修改云储存同步问题

Gosowong 2 лет назад
Родитель
Сommit
7e9ed57c40

+ 37 - 0
crmeb/app/services/system/config/SystemStorageServices.php

@@ -368,6 +368,34 @@ class SystemStorageServices extends BaseServices
                     }
                 }
                 break;
+            case 5:// cos 京东云
+            case 6:// cos 华为云
+            case 7:// cos 天翼云
+                $upload = UploadService::init($type);
+                $list = $upload->listbuckets();
+                if (!empty($list['Name'])) {
+                    $newList = $list;
+                    $list = [];
+                    $list[] = $newList;
+                }
+                $config = $this->getStorageConfig($type);
+                foreach ($list as $item) {
+                    if (!$this->dao->count(['name' => $item['Name'], 'access_key' => $config['accessKey']])) {
+                        $data[] = [
+                            'type' => $type,
+                            'access_key' => $config['accessKey'],
+                            'name' => $item['Name'],
+                            'region' => $item['Location'],
+                            'acl' => 'public-read',
+                            'status' => 0,
+                            'domain' => sys_config('tengxun_appid') ? $this->getDomain($type, $item['Name'], $item['Location']) : '',
+                            'is_delete' => 0,
+                            'add_time' => strtotime($item['CreationDate']),
+                            'update_time' => time()
+                        ];
+                    }
+                }
+                break;
         }
         if ($data) {
             $this->dao->saveAll($data);
@@ -413,6 +441,15 @@ class SystemStorageServices extends BaseServices
             case 4:// cos 腾讯云
                 $domainName = 'https://' . $name . ($appid ? '-' . $appid : '') . '.cos.' . $reagion . '.myqcloud.com';
                 break;
+            case 5:// cos 京东云
+                $domainName = 'https://' . $name . '.cos.' . $reagion . '.jdcloud-oss.com';
+                break;
+            case 6:// cos 华为云
+                $domainName = 'https://' . $name . '.cos.' . $reagion . '.myhuaweicloud.com';
+                break;
+            case 7:// cos 天翼云
+                $domainName = 'https://' . $name . '.cos.' . $reagion . '.ctyun.cn';
+                break;
         }
         return $domainName;
     }

+ 5 - 34
crmeb/crmeb/services/upload/storage/Jdoss.php

@@ -147,7 +147,7 @@ class Jdoss extends BaseUpload
                 'Key' => $key,
                 'SourceFile' => $fileHandle->getRealPath()
             ]);
-            if (!isset($uploadInfo['info']['url'])) {
+            if (!isset($uploadInfo['ObjectURL'])) {
                 return $this->setError('Upload failure');
             }
             $this->fileInfo->uploadInfo = $uploadInfo;
@@ -157,7 +157,7 @@ class Jdoss extends BaseUpload
             $this->fileInfo->filePathWater = $this->water($this->fileInfo->filePath);
             $this->authThumb && $this->thumb($this->fileInfo->filePath);
             return $this->fileInfo;
-        } catch (UploadException $e) {
+        } catch (\Throwable $e) {
             return $this->setError($e->getMessage());
         }
     }
@@ -185,7 +185,7 @@ class Jdoss extends BaseUpload
             $this->fileInfo->filePathWater = $this->water($this->fileInfo->filePath);
             $this->thumb($this->fileInfo->filePath);
             return $this->fileInfo;
-        } catch (UploadException $e) {
+        } catch (\Throwable $e) {
             return $this->setError($e->getMessage());
         }
     }
@@ -207,7 +207,7 @@ class Jdoss extends BaseUpload
     {
         try {
             $res = $this->app()->listBuckets();
-            return $res['Buckets']['Bucket'] ?? [];
+            return $res['ListAllMyBucketsResult']['Buckets'] ?? [];
         } catch (\Throwable $e) {
             return [];
         }
@@ -290,7 +290,7 @@ class Jdoss extends BaseUpload
     {
         try {
             $this->storageRegion = $region;
-            $res = $this->app()->getBucketWebsite([
+            $res = $this->app()->getBucketPolicy([
                 'Bucket' => $name
             ]);
             return $res['DomainName'] ?? [];
@@ -429,33 +429,4 @@ class Jdoss extends BaseUpload
         }
         return $waterPath;
     }
-
-    public function setError(?string $error = null)
-    {
-        $this->error = $error ?: '未知错误';
-        if (env('APP_DEBUG')) {
-            throw new UploadException($this->xmlToArr($this->error));
-        } else {
-            return false;
-        }
-    }
-
-    function xmlToArr($errorXml)
-    {
-
-        $pattern = '/<statusCode>(\d+)<\/statusCode><Code>(.*?)<\/Code><Message>(.*?)<\/Message><Resource>(.*?)<\/Resource><RequestId>(.*?)<\/RequestId>/';
-
-        preg_match($pattern, $errorXml, $matches);
-
-        $error = [
-            'statusCode' => $matches[1],
-            'Code' => $matches[2],
-            'Message' => $matches[3],
-            'Resource' => $matches[4],
-            'RequestId' => $matches[5]
-        ];
-
-        return $error;
-
-    }
 }

+ 2 - 2
crmeb/crmeb/services/upload/storage/Obs.php

@@ -148,7 +148,7 @@ class Obs extends BaseUpload
         try {
             $this->storageRegion = $region;
             $res = $this->app()->listBuckets();
-            return $res['Buckets']['Bucket'] ?? [];
+            return $res['Buckets'] ?? [];
         } catch (\Throwable $e) {
             return [];
         }
@@ -169,7 +169,7 @@ class Obs extends BaseUpload
             $data = [
                 'Statement' => [
                     'Sid' => '公共读' . $name,
-                    'Effect' => 'Allow1',
+                    'Effect' => 'Allow',
                     'Principal' => [
                         'ID' => ['*']
                     ],