Skip to content

Commit

Permalink
Avoid too long filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Feb 20, 2025
1 parent e8ba604 commit bec67f0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions odds/backend/scanner/website/website_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ async def scrape(self, url: str) -> list[str]:
title = None
final_url = None
key = url.split('://')[1].replace('/', '_').replace(':', '_').replace('.', '_').replace('?', '_').replace('&', '_')
if len(key) > 240:
maxlen = 255 - len('.clean.html')
croplen = maxlen - 12 - 1
if len(key) > maxlen:
hash = sha256(key.encode()).hexdigest()[:12]
fkey = f'{key[:240]}_{hash}'
fkey = f'{key[:croplen]}_{hash}'
else:
fkey = key
cache_file = self.CACHE / f'{fkey}.json'
Expand Down

0 comments on commit bec67f0

Please sign in to comment.