|
|
|
@ -9,7 +9,7 @@ import random |
|
|
|
|
import time |
|
|
|
|
from threading import Thread |
|
|
|
|
from django.core.cache import cache |
|
|
|
|
|
|
|
|
|
from fir_ser.settings import CACHE_KEY_TEMPLATE |
|
|
|
|
|
|
|
|
|
''' |
|
|
|
|
user = cache.get(token) |
|
|
|
@ -20,15 +20,22 @@ from django.core.cache import cache |
|
|
|
|
class DownloadToken(object): |
|
|
|
|
|
|
|
|
|
def make_token(self,release_id,time_limit=60): |
|
|
|
|
random_str = uuid.uuid1().__str__().split("-")[0:-1] |
|
|
|
|
user_ran_str = uuid.uuid5(uuid.NAMESPACE_DNS, release_id).__str__().split("-") |
|
|
|
|
user_ran_str.extend(random_str) |
|
|
|
|
new_str = "".join(user_ran_str) |
|
|
|
|
cache.set(new_str, { |
|
|
|
|
"atime":time.time()+time_limit, |
|
|
|
|
"data":release_id |
|
|
|
|
}, time_limit) |
|
|
|
|
return new_str |
|
|
|
|
|
|
|
|
|
token_key = "%s%s"%(CACHE_KEY_TEMPLATE.get("make_token_key"),release_id) |
|
|
|
|
make_token_key = cache.get(token_key) |
|
|
|
|
if make_token_key: |
|
|
|
|
return cache.get(make_token_key) |
|
|
|
|
else: |
|
|
|
|
random_str = uuid.uuid1().__str__().split("-")[0:-1] |
|
|
|
|
user_ran_str = uuid.uuid5(uuid.NAMESPACE_DNS, release_id).__str__().split("-") |
|
|
|
|
user_ran_str.extend(random_str) |
|
|
|
|
new_str = "".join(user_ran_str) |
|
|
|
|
cache.set(new_str, { |
|
|
|
|
"atime":time.time()+time_limit, |
|
|
|
|
"data":release_id |
|
|
|
|
}, time_limit) |
|
|
|
|
cache.set(token_key,new_str,time_limit-1) |
|
|
|
|
return new_str |
|
|
|
|
|
|
|
|
|
def verify_token(self,token,release_id): |
|
|
|
|
try: |
|
|
|
|