-class RootApp(TemplateTreeFileApp):
- @classmethod
- def scan_files(cls, base_dir):
- for path in base_dir.iterdir():
- if not path.is_dir() and not cls.is_ignored_filename(path):
- yield path
-
- def __init__(self, app, base_dir, base_uri="/", secret=None):
- from .utils import get_redis_pass
-
- self.secret = secret or token_urlsafe(64)
- super().__init__(app, base_dir, base_uri)
- self.conn = StrictRedis(username="default", password=get_redis_pass("/etc/redis/redis.conf"))
-
- async def setup(self):
- await self.conn.set("client_id", 0)
-
- def scramble(self, value):
- if isinstance(value, str):
- value = value.encode()
- secret = self.secret
- if isinstance(secret, str):
- secret = secret.encode()
- return urlsafe_b64encode(
- pbkdf2_hmac("sha512", value, secret, 221100)
- ).rstrip(b"=").decode("ascii")
-
- def uri_tail(self, path: Path) -> str:
- return self.scramble(super().uri_tail(path))
-
-