Skip to content

Commit 8074af5

Browse files
authored
fix batch rs host (#424)
1 parent fd5a85c commit 8074af5

File tree

4 files changed

+76
-3
lines changed

4 files changed

+76
-3
lines changed

examples/rs_change_type.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
// 参考文档:https://developer.qiniu.com/kodo/api/3710/chtype
2222

2323
$key = "qiniu.mp4";
24-
$fileType = 1; // 0 表示标准存储;1 表示低频存储;2 表示归档存储;3 表示深度归档存储;4 表示归档直读存储;
24+
// 0 表示标准存储;
25+
// 1 表示低频存储;
26+
// 2 表示归档存储;
27+
// 3 表示深度归档存储;
28+
// 4 表示归档直读存储;
29+
$fileType = 1;
2530

2631
list($ret, $err) = $bucketManager->changeType($bucket, $key, $fileType);
2732
if ($err != null) {

src/Qiniu/Storage/BucketManager.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Qiniu\Http\Error;
88
use Qiniu\Http\Client;
99
use Qiniu\Http\Proxy;
10+
use Qiniu\Http\Response;
1011

1112
/**
1213
* 主要涉及了空间资源管理及批量操作接口的实现,具体的接口规格可以参考
@@ -830,7 +831,12 @@ public function fetch($url, $bucket, $key = null)
830831
* @param string $callbackbody 回调Body
831832
* @param string $callbackbodytype 回调Body内容类型,默认为"application/x-www-form-urlencoded"
832833
* @param string $callbackhost 回调时使用的Host
833-
* @param int $file_type 存储文件类型 0:标准存储(默认),1:低频存储,2:归档存储,3:深度归档存储,4:归档直读存储
834+
* @param int $file_type 存储文件类型
835+
* 0:标准存储(默认)
836+
* 1:低频存储
837+
* 2:归档存储
838+
* 3:深度归档存储
839+
* 4:归档直读存储
834840
* @param bool $ignore_same_key 如果空间中已经存在同名文件则放弃本次抓取
835841
* @return array
836842
* @link https://developer.qiniu.com/kodo/api/4097/asynch-fetch
@@ -943,7 +949,20 @@ public function batch($operations)
943949
$scheme = "https://";
944950
}
945951
$params = 'op=' . implode('&op=', $operations);
946-
return $this->postV2($scheme . Config::RS_HOST . '/batch', $params);
952+
$errResp = new Response(0, 0);
953+
if (count($operations) <= 0) {
954+
$errResp->error = 'empty operations';
955+
return array(null, new Error($scheme . '/batch', $errResp));
956+
}
957+
$bucket = '';
958+
foreach ($operations as $op) {
959+
$segments = explode('/', $op);
960+
if (count($segments) < 3) {
961+
continue;
962+
}
963+
list($bucket,) = \Qiniu\decodeEntry($segments[2]);
964+
}
965+
return $this->rsPost($bucket, '/batch', $params);
947966
}
948967

949968
/**

src/Qiniu/functions.php

+10
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ function entry($bucket, $key = null)
140140
return base64_urlSafeEncode($en);
141141
}
142142

143+
function decodeEntry($entry)
144+
{
145+
$en = base64_urlSafeDecode($entry);
146+
$en = explode(':', $en);
147+
if (count($en) == 1) {
148+
return array($en[0], null);
149+
}
150+
return array($en[0], $en[1]);
151+
}
152+
143153
/**
144154
* array 辅助方法,无值时不set
145155
*

tests/Qiniu/Tests/EntryTest.php

+39
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,43 @@ public function testKeyNeedReplaceSlashSymbol()
4646
$encodeEntryURI = Qiniu\entry($bucket, $key);
4747
$this->assertEquals('cWluaXVwaG90b3M6MDEydHM_YQ==', $encodeEntryURI);
4848
}
49+
public function testDecodeEntry()
50+
{
51+
$entry = 'cWluaXVwaG90b3M6Z29nb3BoZXIuanBn';
52+
list($bucket, $key) = Qiniu\decodeEntry($entry);
53+
$this->assertEquals('qiniuphotos', $bucket);
54+
$this->assertEquals('gogopher.jpg', $key);
55+
}
56+
57+
public function testDecodeEntryWithEmptyKey()
58+
{
59+
$entry = 'cWluaXVwaG90b3M6';
60+
list($bucket, $key) = Qiniu\decodeEntry($entry);
61+
$this->assertEquals('qiniuphotos', $bucket);
62+
$this->assertEquals('', $key);
63+
}
64+
65+
public function testDecodeEntryWithNullKey()
66+
{
67+
$entry = 'cWluaXVwaG90b3M=';
68+
list($bucket, $key) = Qiniu\decodeEntry($entry);
69+
$this->assertEquals('qiniuphotos', $bucket);
70+
$this->assertNull($key);
71+
}
72+
73+
public function testDecodeEntryWithPlusSymbol()
74+
{
75+
$entry = 'cWluaXVwaG90b3M6MDEydHM-YQ==';
76+
list($bucket, $key) = Qiniu\decodeEntry($entry);
77+
$this->assertEquals('qiniuphotos', $bucket);
78+
$this->assertEquals('012ts>a', $key);
79+
}
80+
81+
public function testDecodeEntryWithSlashSymbol()
82+
{
83+
$entry = 'cWluaXVwaG90b3M6MDEydHM_YQ==';
84+
list($bucket, $key) = Qiniu\decodeEntry($entry);
85+
$this->assertEquals('qiniuphotos', $bucket);
86+
$this->assertEquals('012ts?a', $key);
87+
}
4988
}

0 commit comments

Comments
 (0)