# -*- coding: utf-8 -*-

from qiniustorage import backends
from django.utils.encoding import filepath_to_uri
from six.moves.urllib_parse import urljoin


class QiniuStorage(backends.QiniuStorage):
    def url(self, name):
        name = self._normalize_name(self._clean_name(name))
        name = filepath_to_uri(name)

        expire_str = name.split('/', 1)

        try:
            expire = int(expire_str[0])
        except (TypeError, ValueError):
            expire = 3600
            pass

        protocol = 'https://' if self.secure_url else 'http://'
        url = urljoin(protocol + self.bucket_domain, name)
        return self.auth.private_download_url(url, expires=expire)

    pass

@@ -145,16 +145,48 @@
 urljoin%0A
+from django.conf import settings
 %0A%0Aclass 
@@ -363,170 +363,99 @@
 pire
-_str = name.split('/', 1)%0A%0A        try:%0A            expire = int(expire_str%5B0%5D)%0A        except (TypeError, ValueError):%0A            expire = 3600%0A            pass
+ = 3600 if not hasattr(settings, 'QINIU_PREVIEW_EXPIRE') else settings.QINIU_PREVIEW_EXPIRE
 %0A%0A  

improve expire rule