From 6ec84175d48e66fa8c54ea3db649202e64d7963c Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 28 Aug 2019 10:15:35 +0800 Subject: [PATCH] checkifupdate --- ahserver/filestorage.py | 19 ++++++++++--------- ahserver/processorResource.py | 9 +++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ahserver/filestorage.py b/ahserver/filestorage.py index 073e370..840039a 100755 --- a/ahserver/filestorage.py +++ b/ahserver/filestorage.py @@ -19,29 +19,30 @@ class FileStorage: p = os.path.join(self.root,path) return p - def _name2path(name): + def _name2path(self,name): name = os.path.basename(name) paths=[191,193,197,199,97] v = int(time.time()*1000000) # b = name.encode('utf8') if not isinstance(name,bytes) else name # v = int.from_bytes(b,byteorder='big',signed=False) path = os.path.abspath(os.path.join(self.root, - v % paths[0], - v % paths[1], - v % paths[2], - v % paths[3], - v % paths[4], + str(v % paths[0]), + str(v % paths[1]), + str(v % paths[2]), + str(v % paths[3]), + str(v % paths[4]), name)) return path - async def save(name,read_data): - p = self.name2path(name) + async def save(self,name,read_data): + p = self._name2path(name) _mkdir(os.path.dirname(p)) - async with aiofile.open(p,mode='rb') as f: + async with aiofile.AIOFile(p,'wb') as f: while 1: d = await read_data() if not d: break await f.write(d) + await f.fsync() return p[len(self.root):] diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index 021bc00..eb10d4a 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -28,6 +28,7 @@ from .serverenv import ServerEnv from .url2file import Url2File from .filestorage import FileStorage from .restful import DBCrud +from .filedownload import file_download, path_decode def getHeaderLang(request): al = request.headers.get('Accept-Language') @@ -174,6 +175,14 @@ class ProcessorResource(StaticResource): id = pp[2] crud = DBCrud(request,dbname,tablename,id=id) return await crud.dispatch() + if config.website.download and path.startswith(config.website.download): + pp = path.split('/')[2:] + if len(pp)<1: + raise HTTPNotFound + dp = '/'.join(pp) + path = path_decode(dp) + print('path=',path) + return await file_download(path) for word, handlername in self.y_processors: if path.endswith(word):