Commit 8d8a4577 authored by LoveEevee's avatar LoveEevee

Admin: Fix hashing if songs baseurl is not absolute

parent 54a98b77
...@@ -52,10 +52,16 @@ def generate_hash(id, form): ...@@ -52,10 +52,16 @@ def generate_hash(id, form):
urls.append('%s%s/%s.osu' % (config.SONGS_BASEURL, id, diff)) urls.append('%s%s/%s.osu' % (config.SONGS_BASEURL, id, diff))
for url in urls: for url in urls:
resp = requests.get(url) if url.startswith("http://") or url.startswith("https://"):
if resp.status_code != 200: resp = requests.get(url)
raise HashException('Invalid response from %s (status code %s)' % (resp.url, resp.status_code)) if resp.status_code != 200:
md5.update(resp.content) 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') return base64.b64encode(md5.digest())[:-2].decode('utf-8')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment