##// END OF EJS Templates
Added domain image for linux.org.ru, added ability to make images for third-level domains when it is an org.ru, com.ua, co.uk etc domain
neko259 -
r1724:70ff8482 default
parent child Browse files
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -5,8 +5,8 b' from django.contrib.staticfiles.template'
5 from django.core.files.images import get_image_dimensions
5 from django.core.files.images import get_image_dimensions
6 from django.template.defaultfilters import filesizeformat
6 from django.template.defaultfilters import filesizeformat
7
7
8 from boards.utils import get_domain
8
9
9 REGEX_DOMAIN = re.compile(r'(\w+\.)*(\w+\.\w+)')
10
10
11 FILE_STUB_IMAGE = 'images/file.png'
11 FILE_STUB_IMAGE = 'images/file.png'
12 FILE_STUB_URL = 'url'
12 FILE_STUB_URL = 'url'
@@ -172,7 +172,7 b' class UrlViewer(AbstractViewer):'
172 def get_format_view(self):
172 def get_format_view(self):
173 protocol = self.url.split('://')[0]
173 protocol = self.url.split('://')[0]
174 full_domain = self.url.split('/')[2]
174 full_domain = self.url.split('/')[2]
175 domain = REGEX_DOMAIN.search(full_domain).group(2)
175 domain = get_domain(full_domain)
176
176
177 if protocol in URL_PROTOCOLS:
177 if protocol in URL_PROTOCOLS:
178 url_image_name = URL_PROTOCOLS.get(protocol)
178 url_image_name = URL_PROTOCOLS.get(protocol)
@@ -32,6 +32,10 b" ANON_IP = '127.0.0.1'"
32
32
33 FILE_EXTENSION_DELIMITER = '.'
33 FILE_EXTENSION_DELIMITER = '.'
34
34
35 KNOWN_DOMAINS = (
36 'org.ru',
37 )
38
35
39
36 def is_anonymous_mode():
40 def is_anonymous_mode():
37 return get_bool(SETTING_MESSAGES, SETTING_ANON_MODE)
41 return get_bool(SETTING_MESSAGES, SETTING_ANON_MODE)
@@ -143,3 +147,24 b' def get_file_mimetype(file) -> str:'
143 elif type(file_type) == bytes:
147 elif type(file_type) == bytes:
144 file_type = file_type.decode()
148 file_type = file_type.decode()
145 return file_type
149 return file_type
150
151
152 def get_domain(url: str) -> str:
153 """
154 Gets domain from an URL with random number of domain levels.
155 """
156 levels = url.split('.')
157 top = levels[-1]
158 second = levels[-2]
159
160 has_third_level = len(levels) > 2
161 if has_third_level:
162 third = levels[-3]
163
164 if has_third_level and ('{}.{}'.format(second, top) in KNOWN_DOMAINS):
165 result = '{}.{}.{}'.format(third, second, top)
166 else:
167 result = '{}.{}'.format(second, top)
168
169 return result
170
General Comments 0
You need to be logged in to leave comments. Login now