Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix batch rs host #424

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/rs_change_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
// 参考文档:https://developer.qiniu.com/kodo/api/3710/chtype

$key = "qiniu.mp4";
$fileType = 1; // 0 表示标准存储;1 表示低频存储;2 表示归档存储;3 表示深度归档存储;4 表示归档直读存储;
// 0 表示标准存储;
// 1 表示低频存储;
// 2 表示归档存储;
// 3 表示深度归档存储;
// 4 表示归档直读存储;
$fileType = 1;

list($ret, $err) = $bucketManager->changeType($bucket, $key, $fileType);
if ($err != null) {
Expand Down
23 changes: 21 additions & 2 deletions 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 @@ -830,7 +831,12 @@ public function fetch($url, $bucket, $key = null)
* @param string $callbackbody 回调Body
* @param string $callbackbodytype 回调Body内容类型,默认为"application/x-www-form-urlencoded"
* @param string $callbackhost 回调时使用的Host
* @param int $file_type 存储文件类型 0:标准存储(默认),1:低频存储,2:归档存储,3:深度归档存储,4:归档直读存储
* @param int $file_type 存储文件类型
* 0:标准存储(默认)
* 1:低频存储
* 2:归档存储
* 3:深度归档存储
* 4:归档直读存储
* @param bool $ignore_same_key 如果空间中已经存在同名文件则放弃本次抓取
* @return array
* @link https://developer.qiniu.com/kodo/api/4097/asynch-fetch
Expand Down Expand Up @@ -943,7 +949,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
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);
}
}
Loading