Skip to content

Commit

Permalink
fix batch rs host
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 committed Dec 7, 2023
1 parent 9ee81f0 commit 6849886
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Qiniu/Storage/BucketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Qiniu\Http\Error;
use Qiniu\Http\Client;
use Qiniu\Http\Proxy;
use Qiniu\Http\Response;

/**
* 主要涉及了空间资源管理及批量操作接口的实现,具体的接口规格可以参考
Expand Down Expand Up @@ -924,7 +925,20 @@ public function batch($operations)
$scheme = "https://";
}
$params = 'op=' . implode('&op=', $operations);
return $this->postV2($scheme . Config::RS_HOST . '/batch', $params);
$errResp = new Response(0, 0);
if (count($operations) <= 0) {
$errResp->error = 'empty operations';
return array(null, new Error($scheme . '/batch', $errResp));
}
$bucket = '';
foreach ($operations as $op) {
$segments = explode('/', $op);
if (count($segments) < 3) {
continue;
}
list($bucket,) = \Qiniu\decodeEntry($segments[2]);
}
return $this->rsPost($bucket, '/batch', $params);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Qiniu/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ function entry($bucket, $key = null)
return base64_urlSafeEncode($en);
}

function decodeEntry($entry)
{
$en = base64_urlSafeDecode($entry);
$en = explode(':', $en);
if (count($en) == 1) {
return array($en[0], null);
}
return array($en[0], $en[1]);
}

/**
* array 辅助方法,无值时不set
*
Expand Down
1 change: 1 addition & 0 deletions tests/Qiniu/Tests/BucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static function prepareEnvironment()

global $testAuth;
$config = new Config();
$config->setUcHost('kodo-qa.bucket.jfcs-k8s-qa2.qiniu.io');
self::$bucketManager = new BucketManager($testAuth, $config);

global $dummyAuth;
Expand Down
39 changes: 39 additions & 0 deletions tests/Qiniu/Tests/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,43 @@ public function testKeyNeedReplaceSlashSymbol()
$encodeEntryURI = Qiniu\entry($bucket, $key);
$this->assertEquals('cWluaXVwaG90b3M6MDEydHM_YQ==', $encodeEntryURI);
}
public function testDecodeEntry()
{
$entry = 'cWluaXVwaG90b3M6Z29nb3BoZXIuanBn';
list($bucket, $key) = Qiniu\decodeEntry($entry);
$this->assertEquals('qiniuphotos', $bucket);
$this->assertEquals('gogopher.jpg', $key);
}

public function testDecodeEntryWithEmptyKey()
{
$entry = 'cWluaXVwaG90b3M6';
list($bucket, $key) = Qiniu\decodeEntry($entry);
$this->assertEquals('qiniuphotos', $bucket);
$this->assertEquals('', $key);
}

public function testDecodeEntryWithNullKey()
{
$entry = 'cWluaXVwaG90b3M=';
list($bucket, $key) = Qiniu\decodeEntry($entry);
$this->assertEquals('qiniuphotos', $bucket);
$this->assertNull($key);
}

public function testDecodeEntryWithPlusSymbol()
{
$entry = 'cWluaXVwaG90b3M6MDEydHM-YQ==';
list($bucket, $key) = Qiniu\decodeEntry($entry);
$this->assertEquals('qiniuphotos', $bucket);
$this->assertEquals('012ts>a', $key);
}

public function testDecodeEntryWithSlashSymbol()
{
$entry = 'cWluaXVwaG90b3M6MDEydHM_YQ==';
list($bucket, $key) = Qiniu\decodeEntry($entry);
$this->assertEquals('qiniuphotos', $bucket);
$this->assertEquals('012ts?a', $key);
}
}

0 comments on commit 6849886

Please sign in to comment.