cdn prefix
This commit is contained in:
parent
d403125757
commit
53fdb52ee8
2 changed files with 25 additions and 0 deletions
|
@ -14,6 +14,7 @@ from oxdjango.shortcuts import json_response, render_to_json_response
|
||||||
from oxdjango.decorators import login_required_json
|
from oxdjango.decorators import login_required_json
|
||||||
|
|
||||||
import ox
|
import ox
|
||||||
|
import ox.geo
|
||||||
from ox.utils import json, ET
|
from ox.utils import json, ET
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
@ -163,6 +164,22 @@ def init(request, data):
|
||||||
if request.META.get('HTTP_X_PREFIX') == 'NO':
|
if request.META.get('HTTP_X_PREFIX') == 'NO':
|
||||||
config['site']['videoprefix'] = ''
|
config['site']['videoprefix'] = ''
|
||||||
config['site']['mediaprefix'] = ''
|
config['site']['mediaprefix'] = ''
|
||||||
|
elif settings.CDN_PREFIX:
|
||||||
|
try:
|
||||||
|
city, country = get_location(get_ip(request))
|
||||||
|
info = ox.geo.get_country(country)
|
||||||
|
prefix = None
|
||||||
|
for key in ('name', 'region', 'continent'):
|
||||||
|
location = info.get(key)
|
||||||
|
if location in settings.CDN_PREFIX:
|
||||||
|
prefix = settings.CDN_PREFIX[location]
|
||||||
|
break
|
||||||
|
if prefix:
|
||||||
|
config['site']['videoprefix'] = prefix['video']
|
||||||
|
config['site']['mediaprefix'] = prefix['media']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
response['data']['site'] = config
|
response['data']['site'] = config
|
||||||
response['data']['user'] = init_user(request.user, request)
|
response['data']['user'] = init_user(request.user, request)
|
||||||
request.session['last_init'] = str(datetime.now())
|
request.session['last_init'] = str(datetime.now())
|
||||||
|
|
|
@ -225,6 +225,14 @@ VIDEO_PREFIX = ''
|
||||||
MEDIA_PREFIX = ''
|
MEDIA_PREFIX = ''
|
||||||
#VIDEO_PREFIX = '//media.example.com'
|
#VIDEO_PREFIX = '//media.example.com'
|
||||||
#SESSION_COOKIE_DOMAIN = '.example.com'
|
#SESSION_COOKIE_DOMAIN = '.example.com'
|
||||||
|
CDN_PREFIX = {}
|
||||||
|
# set video prefix baesd on country/region/continent
|
||||||
|
'''
|
||||||
|
CDN_PREFIX = {
|
||||||
|
'India': {'media': 'https://media.in.example.com', 'video': 'https://{uid}.in.example.com'},
|
||||||
|
'Northern Africa': {'media': 'https://media.eg.example.com', 'video': 'https://{uid}.eg.example.com'},
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
SESSION_COOKIE_AGE = 60*24*60*60
|
SESSION_COOKIE_AGE = 60*24*60*60
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue