|
|
@ -9,7 +9,7 @@ from .aliyunApi import AliYunOss |
|
|
|
from .qiniuApi import QiNiuOss |
|
|
|
from .qiniuApi import QiNiuOss |
|
|
|
from .localApi import LocalStorage |
|
|
|
from .localApi import LocalStorage |
|
|
|
import json,time |
|
|
|
import json,time |
|
|
|
from fir_ser import settings |
|
|
|
from fir_ser.settings import THIRD_PART_CONFIG,CACHE_KEY_TEMPLATE |
|
|
|
from django.core.cache import cache |
|
|
|
from django.core.cache import cache |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -21,16 +21,17 @@ class Storage(object): |
|
|
|
if self.storage: |
|
|
|
if self.storage: |
|
|
|
return self.storage.get_upload_token(filename, expires) |
|
|
|
return self.storage.get_upload_token(filename, expires) |
|
|
|
|
|
|
|
|
|
|
|
def get_download_url(self, filename, expires=900,ftype=None): |
|
|
|
def get_download_url(self,filename, expires=900,ftype=None,key=''): |
|
|
|
if self.storage: |
|
|
|
if self.storage: |
|
|
|
now = time.time() |
|
|
|
now = time.time() |
|
|
|
download_val = cache.get("%s_%s"%('download_url',filename)) |
|
|
|
down_key = "_".join([key.lower(),CACHE_KEY_TEMPLATE.get('download_url_key'),filename]) |
|
|
|
|
|
|
|
download_val = cache.get(down_key) |
|
|
|
if download_val: |
|
|
|
if download_val: |
|
|
|
if download_val.get("time") > now - 60: |
|
|
|
if download_val.get("time") > now - 60: |
|
|
|
return download_val.get("download_url") |
|
|
|
return download_val.get("download_url") |
|
|
|
|
|
|
|
|
|
|
|
download_url=self.storage.get_download_url(filename, expires,ftype) |
|
|
|
download_url=self.storage.get_download_url(filename, expires,ftype) |
|
|
|
cache.set("%s_%s"%('download_url',filename),{"download_url":download_url,"time":now+expires},expires) |
|
|
|
cache.set(down_key,{"download_url":download_url,"time":now+expires},expires) |
|
|
|
return download_url |
|
|
|
return download_url |
|
|
|
|
|
|
|
|
|
|
|
def delete_file(self, filename, apptype=None): |
|
|
|
def delete_file(self, filename, apptype=None): |
|
|
@ -63,7 +64,7 @@ class Storage(object): |
|
|
|
if admin_storage: |
|
|
|
if admin_storage: |
|
|
|
return self.get_storage(UserInfo) |
|
|
|
return self.get_storage(UserInfo) |
|
|
|
else: |
|
|
|
else: |
|
|
|
storage_lists = settings.THIRD_PART_CONFIG.get('storage') |
|
|
|
storage_lists = THIRD_PART_CONFIG.get('storage') |
|
|
|
for storage in storage_lists: |
|
|
|
for storage in storage_lists: |
|
|
|
if storage.get("active",None): |
|
|
|
if storage.get("active",None): |
|
|
|
storage_type= storage.get('type',None) |
|
|
|
storage_type= storage.get('type',None) |
|
|
|