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