Skip to content

Commit e717136

Browse files
authored
Merge pull request #391 from leancloud/develop/smiao
支持华东及美国节点的 app-router
2 parents b07da4a + 2b4ebc8 commit e717136

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

leancloud/app_router.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,26 @@ def __init__(self, app_id, region):
2020
self.session = requests.Session()
2121
self.lock = threading.Lock()
2222
self.expired_at = 0
23+
24+
prefix = app_id[:8].lower()
25+
domain = 'lncld.net'
26+
2327
if region == 'US':
24-
self.hosts['api'] = 'us-api.leancloud.cn'
25-
self.hosts['engine'] = 'us-api.leancloud.cn'
26-
self.hosts['stats'] = 'us-api.leancloud.cn'
27-
self.hosts['push'] = 'us-api.leancloud.cn'
28+
domain = 'lncldglobal.com'
2829
elif region == 'CN':
2930
if app_id.endswith('-9Nh9j0Va'):
30-
self.hosts['api'] = 'e1-api.leancloud.cn'
31-
self.hosts['engine'] = 'e1-api.leancloud.cn'
32-
self.hosts['stats'] = 'e1-api.leancloud.cn'
33-
self.hosts['push'] = 'e1-api.leancloud.cn'
31+
domain = 'lncldapi.com'
3432
else:
35-
prefix = app_id[:8].lower()
36-
self.hosts['api'] = '{}.api.lncld.net'.format(prefix)
37-
self.hosts['engine'] = '{}.engine.lncld.net'.format(prefix)
38-
self.hosts['stats'] = '{}.stats.lncld.net'.format(prefix)
39-
self.hosts['push'] = '{}.push.lncld.net'.format(prefix)
33+
domain = 'lncld.net'
4034
else:
4135
raise RuntimeError('invalid region: {}'.format(region))
4236

43-
def get(self, type_):
44-
if self.region == 'US':
45-
# US region dose not support app router stuff
46-
return self.hosts[type_]
37+
self.hosts['api'] = '{}.api.{}'.format(prefix, domain)
38+
self.hosts['engine'] = '{}.engine.{}'.format(prefix, domain)
39+
self.hosts['stats'] = '{}.stats.{}'.format(prefix, domain)
40+
self.hosts['push'] = '{}.push.{}'.format(prefix, domain)
4741

42+
def get(self, type_):
4843
with self.lock:
4944
if time.time() > self.expired_at:
5045
self.expired_at += 600

tests/test_file.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,15 @@ def test_fetch(): # type: () -> None
173173
f.save()
174174
fetched = File.create_without_data(f.id)
175175
fetched.fetch()
176+
177+
normalized_f_url = f.url.split('/')[-1]
178+
normalized_fetched_url = f.url.split('/')[-1]
179+
176180
assert fetched.id == f.id
177181
assert fetched.metadata == f.metadata
178182
assert fetched.name == f.name
179-
assert fetched.url == f.url
180183
assert fetched.size == f.size
181-
assert fetched.url == f.url
184+
assert fetched.url == f.url or normalized_fetched_url == normalized_f_url
182185
f.destroy()
183186

184187

0 commit comments

Comments
 (0)