Skip to content

Commit

Permalink
Merge pull request #2 from Shenjiaqi/master
Browse files Browse the repository at this point in the history
Update to v1.0.0
  • Loading branch information
Shenjiaqi authored Mar 9, 2017
2 parents e5e29a2 + aa8272e commit e62659b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

php ./examples/galaxy-fds.php (注意: 需要在样例中设置正确的App Key和Secret)

##### Release Notes:
* 20170309 - v1.0.0
* Fix metadata not set in completeMultipartUpload
* Add setEndpoint in FDSClientConfiguration

FDS PHP SDK User Guide
========================
Expand Down
19 changes: 16 additions & 3 deletions src/FDS/FDSClientConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FDSClientConfiguration {
const URI_CDN_SUFFIX = "fds.api.mi-img.com";
const DEFAULT_RETRY_NUM = 3;
const DEFAULT_CONNECTION_TIMEOUT_SECS = 30;
const DEFAULT_MAX_BATCH_DELETE_SIZE = 100;
const DEFAULT_MAX_BATCH_DELETE_SIZE = 1000;

private $region_name;
private $enable_https;
Expand All @@ -29,6 +29,7 @@ class FDSClientConfiguration {
private $retry;
private $connection_timeout_secs;
private $batch_delete_size;
private $endpoint;

private $enable_unit_test_mode;
private $base_uri_for_unit_test;
Expand All @@ -41,6 +42,7 @@ public function __construct() {
$this->enable_md5_calculate = false;
$this->enable_debug = false;
$this->enable_metrics = false;
$this->endpoint = "";

$this->enable_unit_test_mode = false;
$this->base_uri_for_unit_test = "";
Expand Down Expand Up @@ -100,6 +102,14 @@ public function setBaseUriforunittest($base_uri_for_unit_test) {
$this->base_uri_for_unit_test = $base_uri_for_unit_test;
}

public function setEndpoint($endpoint) {
$this->endpoint = $endpoint;
}

public function getEndpoint($endpoint) {
return $this->endpoint;
}

public function getBaseUri() {
return $this->buildBaseUri(false);
}
Expand All @@ -122,7 +132,10 @@ public function buildBaseUri($enableCdn) {
}

$uri = $this->enable_https ? self::URI_HTTPS_PREFIX : self::URI_HTTP_PREFIX;
if ($enableCdn) {

if (!empty($this->endpoint)) {
$uri .= $this->endpoint;
} else if ($enableCdn) {
$uri .= self::URI_CDN . '.' . $this->region_name . '.' . self::URI_CDN_SUFFIX;
} else {
$uri .= $this->region_name . '.' . self::URI_SUFFIX;
Expand Down Expand Up @@ -175,4 +188,4 @@ public function setBatchDeleteSize($size) {
$this->batch_delete_size = min($size, SELF::DEFAULT_MAX_BATCH_DELETE_SIZE);
$this->batch_delete_size = max(1, $this->batch_delete_size);
}
}
}
4 changes: 2 additions & 2 deletions src/FDS/GalaxyFDS.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function deleteObject($bucket_name, $object_name);
*
* @param string $bucket_name The name of the bucket
* @param $object_name_list array of names to delete, count($object_name_list)
* should less than 100
* should less than 1k
* @return array of failure reason:
* (...,
* (
Expand Down Expand Up @@ -362,4 +362,4 @@ public function generatePresignedUri($bucket_name, $object_name, $expiration,
* @throws GalaxyFDSClientException
*/
public function generateDownloadObjectUri($bucket_name, $object_name);
}
}
2 changes: 1 addition & 1 deletion src/FDS/GalaxyFDSClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ public function completeMultipartUpload($bucket_name, $object_name,
$upload_id, $metadata, $upload_part_result_list) {
$uri = $this->fds_config->getBaseUri() . $bucket_name . "/" . $object_name .
"?uploadId=" . $upload_id;
$headers = $this->prepareRequestHeader($uri, Http::PUT, Mime::JSON);
$headers = $this->prepareRequestHeader($uri, Http::PUT, Mime::JSON, $metadata);

$response = $this->invoke(Action::CompleteMultipartUpload, $uri, $headers,
Http::PUT, null, json_encode($upload_part_result_list));
Expand Down
11 changes: 10 additions & 1 deletion tests/FDS/FDSClientConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FDSClientConfigurationTest extends \PHPUnit_Framework_TestCase {

public function testDefaultConfigurationValue() {
$fds_config = new FDSClientConfiguration();
$this->assertEquals("", $fds_config->getRegionName());
$this->assertEquals("cnbj0", $fds_config->getRegionName());
$this->assertEquals(true, $fds_config->isHttpsEnabled());
$this->assertEquals(false, $fds_config->isCdnEnabledForUpload());
$this->assertEquals(true, $fds_config->isCdnEnabledForDownload());
Expand Down Expand Up @@ -69,5 +69,14 @@ public function testBuildBaseUri() {
$fds_config->enableHttps(false);
$this->assertEquals("http://" . $region_name . '.' . self::URI_SUFFIX . '/',
$fds_config->buildBaseUri(false));

$endpoint = "cnbj1.api.xiaomi.net";
$fds_config->enableHttps(false);
$fds_config->setEndpoint($endpoint);
$this->assertEquals("http://" . $endpoint . "/", $fds_config->buildBaseUri(false));
$this->assertEquals("http://" . $endpoint . "/", $fds_config->buildBaseUri(true));
$fds_config->enableHttps(true);
$this->assertEquals("https://" . $endpoint . "/", $fds_config->buildBaseUri(false));
$this->assertEquals("https://" . $endpoint . "/", $fds_config->buildBaseUri(true));
}
}
29 changes: 29 additions & 0 deletions tests/FDS/GalaxyFDSClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use FDS\model\Grant;
use FDS\model\Grantee;
use FDS\model\Permission;
use FDS\model\UploadPartResultList;
use Httpful\Request;

class GalaxyFDSClientTest extends \PHPUnit_Framework_TestCase {
Expand Down Expand Up @@ -422,6 +423,34 @@ public function testPresigedUri() {
$this->assertEquals($content_type, $object->getObjectMetadata()->getContentType());
}

/**
* @depends testCreateBucket
*/
public function testMultipartUpload() {
$object_name = "multipart-upload";
$content = "multipart-upload";
$initMultipartUploadResult = self::$fds_client->initMultipartUpload(self::$bucket_name, $object_name);

$uploadPartResult = self::$fds_client->uploadPart(self::$bucket_name,
$object_name, $initMultipartUploadResult->getUploadId(), 1, $content);


$uploadPartResultArray = array();
array_push($uploadPartResultArray, $uploadPartResult);
$uploadPartResultList = new UploadPartResultList();
$uploadPartResultList->setUploadPartResultList($uploadPartResultArray);
$metadata = new FDSObjectMetadata();
$metadata->setContentType("text/html");

self::$fds_client->completeMultipartUpload(self::$bucket_name, $object_name,
$initMultipartUploadResult->getUploadId(), $metadata, $uploadPartResultList);

$object = self::$fds_client->getObject(self::$bucket_name, $object_name);
$actualObjectContent = $object->getObjectContent();
$this->assertEquals($content, $actualObjectContent);
$this->assertEquals("text/html", $object->getObjectMetadata()->getContentType());
}

private function emptyBucket() {
self::$fds_client->deleteObjectsByPrefix(self::$bucket_name, "");
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Httpful/HttpfulTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class HttpfulTest extends \PHPUnit_Framework_TestCase
{
const TEST_SERVER = TEST_SERVER;
const TEST_URL = '127.0.0.1:8008';
const TEST_URL = 'http://127.0.0.1:8008';
const TEST_URL_400 = 'http://127.0.0.1:8008/400';

const SAMPLE_JSON_HEADER =
Expand Down

0 comments on commit e62659b

Please sign in to comment.