From 8d8a4577d2dbf24130093de260809ad62224709a Mon Sep 17 00:00:00 2001 From: LoveEevee Date: Wed, 18 Mar 2020 06:54:42 +0300 Subject: [PATCH] Admin: Fix hashing if songs baseurl is not absolute --- app.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 8a710e1..d1713a3 100644 --- a/app.py +++ b/app.py @@ -52,10 +52,16 @@ def generate_hash(id, form): urls.append('%s%s/%s.osu' % (config.SONGS_BASEURL, id, diff)) for url in urls: - resp = requests.get(url) - if resp.status_code != 200: - raise HashException('Invalid response from %s (status code %s)' % (resp.url, resp.status_code)) - md5.update(resp.content) + if url.startswith("http://") or url.startswith("https://"): + resp = requests.get(url) + if resp.status_code != 200: + raise HashException('Invalid response from %s (status code %s)' % (resp.url, resp.status_code)) + md5.update(resp.content) + else: + if url.startswith("/"): + url = url[1:] + with open(os.path.join("public", url), "rb") as file: + md5.update(file.read()) return base64.b64encode(md5.digest())[:-2].decode('utf-8')