Skip to content

add zone and fix query host #386

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

Merged
merged 3 commits into from
Aug 29, 2022
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
127 changes: 127 additions & 0 deletions src/Qiniu/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ public function getUpHost($accessKey, $bucket)
return $scheme . $host;
}

public function getUpHostV2($accessKey, $bucket)
{
list($region, $err) = $this->getRegionV2($accessKey, $bucket);
if ($err != null) {
return array(null, $err);
}

if ($this->useHTTPS === true) {
$scheme = "https://";
} else {
$scheme = "http://";
}

$host = $region->srcUpHosts[0];
if ($this->useCdnDomains === true) {
$host = $region->cdnUpHosts[0];
}

return array($scheme . $host, null);
}

public function getUpBackupHost($accessKey, $bucket)
{
$region = $this->getRegion($accessKey, $bucket);
Expand All @@ -70,6 +91,27 @@ public function getUpBackupHost($accessKey, $bucket)
return $scheme . $host;
}

public function getUpBackupHostV2($accessKey, $bucket)
{
list($region, $err) = $this->getRegionV2($accessKey, $bucket);
if ($err != null) {
return array(null, $err);
}

if ($this->useHTTPS === true) {
$scheme = "https://";
} else {
$scheme = "http://";
}

$host = $region->cdnUpHosts[0];
if ($this->useCdnDomains === true) {
$host = $region->srcUpHosts[0];
}

return array($scheme . $host, null);
}

public function getRsHost($accessKey, $bucket)
{
$region = $this->getRegion($accessKey, $bucket);
Expand All @@ -83,6 +125,22 @@ public function getRsHost($accessKey, $bucket)
return $scheme . $region->rsHost;
}

public function getRsHostV2($accessKey, $bucket)
{
list($region, $err) = $this->getRegionV2($accessKey, $bucket);
if ($err != null) {
return array(null, $err);
}

if ($this->useHTTPS === true) {
$scheme = "https://";
} else {
$scheme = "http://";
}

return array($scheme . $region->rsHost, null);
}

public function getRsfHost($accessKey, $bucket)
{
$region = $this->getRegion($accessKey, $bucket);
Expand All @@ -96,6 +154,22 @@ public function getRsfHost($accessKey, $bucket)
return $scheme . $region->rsfHost;
}

public function getRsfHostV2($accessKey, $bucket)
{
list($region, $err) = $this->getRegionV2($accessKey, $bucket);
if ($err != null) {
return array(null, $err);
}

if ($this->useHTTPS === true) {
$scheme = "https://";
} else {
$scheme = "http://";
}

return array($scheme . $region->rsfHost, null);
}

public function getIovipHost($accessKey, $bucket)
{
$region = $this->getRegion($accessKey, $bucket);
Expand All @@ -109,6 +183,22 @@ public function getIovipHost($accessKey, $bucket)
return $scheme . $region->iovipHost;
}

public function getIovipHostV2($accessKey, $bucket)
{
list($region, $err) = $this->getRegionV2($accessKey, $bucket);
if ($err != null) {
return array(null, $err);
}

if ($this->useHTTPS === true) {
$scheme = "https://";
} else {
$scheme = "http://";
}

return array($scheme . $region->iovipHost, null);
}

public function getApiHost($accessKey, $bucket)
{
$region = $this->getRegion($accessKey, $bucket);
Expand All @@ -122,6 +212,22 @@ public function getApiHost($accessKey, $bucket)
return $scheme . $region->apiHost;
}

public function getApiHostV2($accessKey, $bucket)
{
list($region, $err) = $this->getRegionV2($accessKey, $bucket);
if ($err != null) {
return array(null, $err);
}

if ($this->useHTTPS === true) {
$scheme = "https://";
} else {
$scheme = "http://";
}

return array($scheme . $region->apiHost, null);
}

private function getRegion($accessKey, $bucket)
{
$cacheId = "$accessKey:$bucket";
Expand All @@ -143,4 +249,25 @@ private function getRegion($accessKey, $bucket)
}
return $region;
}

private function getRegionV2($accessKey, $bucket)
{
$cacheId = "$accessKey:$bucket";

if (isset($this->regionCache[$cacheId])) {
$region = $this->regionCache[$cacheId];
} elseif (isset($this->zone)) {
$region = $this->zone;
$this->regionCache[$cacheId] = $region;
} else {
$region = Zone::queryZone($accessKey, $bucket);
if (is_array($region)) {
list($region, $err) = $region;
return array($region, $err);
}
$this->regionCache[$cacheId] = $region;
}

return array($region, null);
}
}
35 changes: 35 additions & 0 deletions src/Qiniu/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ public static function regionHuanan()
return $regionHuanan;
}

//华东2 机房
public static function regionHuadong2()
{
return new Region(
array('up-cn-east-2.qiniup.com'),
array('upload-cn-east-2.qiniup.com'),
"rs-cn-east-2.qiniuapi.com",
"rsf-cn-east-2.qiniuapi.com",
"api-cn-east-2.qiniuapi.com",
"iovip-cn-east-2.qiniuio.com"
);
}

//北美机房
public static function regionNorthAmerica()
{
Expand Down Expand Up @@ -137,6 +150,20 @@ public static function regionSingapore()
return $regionSingapore;
}

//首尔
public static function regionSeoul()
{
//首尔
return new Region(
array('up-ap-northeast-1.qiniup.com'),
array('upload-ap-northeast-1.qiniup.com'),
"rs-ap-northeast-1.qiniuapi.com",
"rsf-ap-northeast-1.qiniuapi.com",
"api-ap-northeast-1.qiniuapi.com",
"iovip-ap-northeast-1.qiniuio.com"
);
}

/*
* GET /v2/query?ak=<ak>&&bucket=<bucket>
**/
Expand Down Expand Up @@ -177,6 +204,10 @@ public static function queryRegion($ak, $bucket)
$Region->rsHost = "rs-z2.qbox.me";
$Region->rsfHost = "rsf-z2.qbox.me";
$Region->apiHost = "api-z2.qiniu.com";
} elseif (strstr($Region->iovipHost, "cn-east-2") !== false) {
$Region->rsHost = "rs-cn-east-2.qiniuapi.com";
$Region->rsfHost = "rsf-cn-east-2.qiniuapi.com";
$Region->apiHost = "api-cn-east-2.qiniuapi.com";
} elseif (strstr($Region->iovipHost, "na0") !== false) {
$Region->rsHost = "rs-na0.qbox.me";
$Region->rsfHost = "rsf-na0.qbox.me";
Expand All @@ -185,6 +216,10 @@ public static function queryRegion($ak, $bucket)
$Region->rsHost = "rs-as0.qbox.me";
$Region->rsfHost = "rsf-as0.qbox.me";
$Region->apiHost = "api-as0.qiniu.com";
} elseif (strstr($Region->iovipHost, "ap-northeast-1") !== false) {
$Region->rsHost = "rs-ap-northeast-1.qiniuapi.com";
$Region->rsfHost = "rsf-ap-northeast-1.qiniuapi.com";
$Region->apiHost = "api-ap-northeast-1.qiniuapi.com";
} else {
$Region->rsHost = "rs.qbox.me";
$Region->rsfHost = "rsf.qbox.me";
Expand Down
Loading