def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.root = Path(options.root).expanduser() self.db = Mongo('dl') self.rd = Redis() self.email = AioEmail(smtp='smtp.exmail.qq.com', sender='*****@*****.**', user='******', pwd="xGrS"+"2Kch"[::-1]+"Hx4y95mF") self.http = CurlAsyncHTTPClient() self.cache = collections.defaultdict(dict) self.config = config
class Application(Application): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.root = Path(options.root).expanduser() self.db = Mongo('dl') self.rd = Redis() self.email = AioEmail(smtp='smtp.exmail.qq.com', sender='*****@*****.**', user='******', pwd="xGrS"+"2Kch"[::-1]+"Hx4y95mF") self.http = CurlAsyncHTTPClient() self.cache = collections.defaultdict(dict) self.config = config def scan_dir(self, root, dirname): root = Path(root) if not root.exists(): return [] st_mtime = root.stat().st_mtime if root in self.cache[dirname] and st_mtime == self.cache[dirname][root][0]: entries = self.cache[dirname][root][1] else: entries = [] for item in root.iterdir(): if not item.exists(): continue if not options.all and item.name.startswith('.'): continue path = item.relative_to(self.root / dirname) stat = item.stat() filesize = stat.st_size if filesize / (1024 * 1024 * 1024.0) >= 1: size = '%.1f GB' % (filesize / (1024 * 1024 * 1024.0)) elif filesize / (1024 * 1024.0) >= 1: size = '%.1f MB' % (filesize / (1024 * 1024.0)) else: size = '%.1f KB' % (filesize / 1024.0) mtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(stat.st_mtime)) sum = int(self.rd.get("FILELIST:"+str(path))) if self.rd.exists("FILELIST:"+str(path)) else 0 entries.append([path, mtime, size, item.is_dir(),sum]) entries.sort(key=lambda x: str(x[1]).lower(), reverse=True) self.cache[dirname][root] = [st_mtime, entries] return entries def scan_thread(self): for root, _, _ in os.walk(self.path): if root == '.': self.scan_dir(root) else: root = root.lstrip('./') if not options.all and any([p.startswith('.') for p in root.split('/')]): continue self.scan_dir(root) def scan(self): t = threading.Thread(target=self.scan_thread) t.daemon = True t.start()
from pathlib import Path from bson import ObjectId import markdown import tornado.escape import tornado.httpserver import tornado.ioloop import tornado.web import yaml from tornado.concurrent import run_on_executor from .blueprint import Blueprint from .common import BaseHandler bp = Blueprint(__name__) rd = Redis() @bp.route('/') class HomeHandler(BaseHandler): def get(self): self.redirect(f'/public') @bp.route(r'/(public|home)') @bp.route(r'/share/?(.*)') class IndexHandler(tornado.web.StaticFileHandler, BaseHandler): executor = ThreadPoolExecutor(5) default = { 'ppt.png': ['.ppt', '.pptx'], 'word.png': ['.doc', '.docx'],