You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
flyapps/fir_ser/api/utils/storage/localApi.py

40 lines
1.1 KiB

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# project: 3月
# author: liuyu
# date: 2020/3/18
'''
本地存储api
'''
from api.utils.TokenManager import DownloadToken
from fir_ser import settings
import os
5 years ago
class LocalStorage(object):
5 years ago
def __init__(self, domain_name, is_https):
self.domain_name = domain_name
self.is_https = is_https
5 years ago
def get_upload_token(self, name, expires):
dtoken = DownloadToken()
5 years ago
return dtoken.make_token(name, expires)
5 years ago
def get_download_url(self, name, expires=600, force_new=False):
dtoken = DownloadToken()
5 years ago
base_url = '/'.join([self.domain_name, 'download', name])
uri = 'http://'
if self.is_https:
5 years ago
uri = 'https://'
5 years ago
download_url = "%s%s?%s=%s" % (
uri, base_url, settings.DATA_DOWNLOAD_KEY, dtoken.make_token(name, expires, force_new=force_new))
return download_url
5 years ago
def del_file(self, name):
try:
os.remove(os.path.join(settings.MEDIA_ROOT, name))
return True
except Exception as e:
print(e)
return False