From 31b092c3111f568471dcec3201c8f92205aaf51b Mon Sep 17 00:00:00 2001 From: Gosowong <1329847115@qq.com> Date: Thu, 8 Jun 2023 15:58:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8D=8E=E4=B8=BA=E4=BA=91=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=B8=B8=E8=A7=81=E6=A1=B6=E7=AD=96=E7=95=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/config/SystemStorageServices.php | 2 +- .../services/upload/extend/obs/Client.php | 47 ++++++++++++++++++- crmeb/crmeb/services/upload/storage/Obs.php | 13 +++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/crmeb/app/services/system/config/SystemStorageServices.php b/crmeb/app/services/system/config/SystemStorageServices.php index 97f22d1be..b4861ced5 100644 --- a/crmeb/app/services/system/config/SystemStorageServices.php +++ b/crmeb/app/services/system/config/SystemStorageServices.php @@ -448,7 +448,7 @@ class SystemStorageServices extends BaseServices $storage = $this->dao->get(['id' => $id], ['domain', 'cdn']); $rule = [ FormBuilder::input('domain', '空间域名', $storage['domain']), - FormBuilder::input('cdn', 'cdn域名', $storage['cnd']), + FormBuilder::input('cdn', 'cdn域名', $storage['cdn']), ]; return create_form('修改空间域名', $rule, '/system/config/storage/domain/' . $id); } diff --git a/crmeb/crmeb/services/upload/extend/obs/Client.php b/crmeb/crmeb/services/upload/extend/obs/Client.php index 3fec47ae5..fb3129c3b 100644 --- a/crmeb/crmeb/services/upload/extend/obs/Client.php +++ b/crmeb/crmeb/services/upload/extend/obs/Client.php @@ -235,6 +235,30 @@ class Client extends BaseClient return $this->response($res); } + /** + * 设置桶的策略 + * @param string $bucket + * @param string $region + * @param array $data + * @return mixed + * + * @date 2023/06/08 + * @author yyw + */ + public function putPolicy(string $bucket, string $region, array $data) + { + $header = [ + 'Host' => $this->getRequestUrl($bucket, $region), + "Content-Type" => "application/json" + ]; + $res = $this->request('https://' . $header['Host'] . '/?policy', 'PUT', [ + 'bucket' => $bucket, + 'json' => $data + ], $header); + + return $this->response($res); + } + /** * 创建桶 * @param string $bucket @@ -340,7 +364,7 @@ class Client extends BaseClient 'Content-Length' => strlen($xml), 'Content-MD5' => base64_encode(md5($xml, true)) ]; - $res = $this->request('https://' . $header['Host'] . '/cors', 'PUT', [ + $res = $this->request('https://' . $header['Host'] . '/?cors', 'PUT', [ 'bucket' => $bucket, 'body' => $xml ], $header); @@ -348,6 +372,27 @@ class Client extends BaseClient return $this->response($res); } + /** + * 删除跨域 + * @param string $bucket + * @param string $region + * @return mixed + * + * @date 2023/06/08 + * @author yyw + */ + public function deleteBucketCors(string $bucket, string $region) + { + $header = [ + 'Host' => $this->getRequestUrl($bucket, $region), + ]; + $res = $this->request('https://' . $header['Host'] . '/?cors', 'DELETE', [ + 'bucket' => $bucket, + ], $header); + + return $this->response($res); + } + /** * @param $res * @return mixed diff --git a/crmeb/crmeb/services/upload/storage/Obs.php b/crmeb/crmeb/services/upload/storage/Obs.php index 686b5c63f..8d1bfcf53 100644 --- a/crmeb/crmeb/services/upload/storage/Obs.php +++ b/crmeb/crmeb/services/upload/storage/Obs.php @@ -166,6 +166,19 @@ class Obs extends BaseUpload //创建桶 try { $app->createBucket($name, $region, $acl); + $data = [ + 'Statement' => [ + 'Sid' => '公共读' . $name, + 'Effect' => 'Allow1', + 'Principal' => [ + 'ID' => ['*'] + ], + 'Action' => ['HeadBucket', 'GetBucketLocation', 'ListBucketVersions', 'GetObject', 'RestoreObject', 'GetObjectVersion'], + 'Resource' => [$name, $name . '/*'] + ] + ]; + + $app->putPolicy($name, $region, $data); } catch (\Throwable $e) { return $this->setError('COS:' . $e->getMessage()); }