diff --git a/indexer.py b/indexer.py index 815b702..d04ebed 100755 --- a/indexer.py +++ b/indexer.py @@ -13,6 +13,7 @@ import os import sys import time +import base64 import hashlib import config @@ -63,7 +64,8 @@ def clean(path, root = True): if not root and not os.listdir(path): print('remove dir:', path) os.rmdir(path) - +def mangle(path): + return base64.b64encode(hashlib.sha256((config.salt + ':' + path).encode()).digest()).decode()[:20].replace('/', '_').replace('+', '-') class Node: @@ -77,7 +79,7 @@ class Node: self.ext = '' if self.isdir else nameext(name)[1] self.path = join(parent.path, name) if parent else name self.date = os.path.getmtime(src) - self.mangle = config.mangle + hashlib.md5((config.salt + ':' + self.path).encode()).hexdigest() + '.' + self.ext + self.mangle = config.mangle + mangle(self.path) + '.' + self.ext self.hide = hide or (parent and parent.hide) self.url = join(config.url, self.path) self.mangleurl = join(config.url, self.mangle)