Skip to content

Commit

Permalink
Update /cat (#25)
Browse files Browse the repository at this point in the history
Ignore decoding specific file types
  • Loading branch information
teymurgahramanov authored Apr 27, 2024
1 parent 8e07458 commit 474d34b
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,23 @@ def cat():
"""
data = {}
for root, dirs, files in os.walk("data"):
for file in files:
filepath = os.path.abspath(os.path.join(root, file))
with open(filepath, 'rb') as f:
content = f.read()
checksum = hashlib.md5(content).hexdigest()
data[filepath] = {}
data[filepath]['checksum'] = checksum
data[filepath]['content'] = content.decode("utf-8")
for file in files:
filepath = os.path.abspath(os.path.join(root, file))
ignored_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.ico', '.svg'}
_, ext = os.path.splitext(filepath)
with open(filepath, 'rb') as f:
content = f.read()
checksum = hashlib.md5(content).hexdigest()
data[filepath] = {}
data[filepath]['checksum'] = checksum
if ext.lower() in ignored_extensions:
data[filepath]['content'] = '-'
continue
try:
data[filepath]['content'] = content.decode('utf-8')
except:
data[filepath]['content'] = '-'
pass
return jsonify(data)

@routes_blueprint.route('/database')
Expand Down

0 comments on commit 474d34b

Please sign in to comment.