Skip to content

Commit

Permalink
moved icons and userimages to data folder
Browse files Browse the repository at this point in the history
  • Loading branch information
clemenstyp committed Mar 22, 2024
1 parent 6928341 commit 42be1f1
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 79 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Expand Up @@ -17,10 +17,10 @@ sqlite
*.bak
/.vs
CoffeeDB.db
/static/images/
!/static/images/.gitkeep
/static/icons/
!/static/icons/.gitkeep
/data/user/
!/data/user/.gitkeep
/data/icons/
!/data/icons/.gitkeep
/data/CoffeeDB.db
docker-compose.override.yaml
.pylintrc
Expand Down
17 changes: 4 additions & 13 deletions Snackbar/Frontpage/Titlepage.py
Expand Up @@ -6,7 +6,7 @@
from werkzeug.utils import secure_filename

from Snackbar import app, db
from Snackbar.Helper.Appearance import monster_image, image_from_folder
from Snackbar.Helper.Appearance import monster_image, icon_from_folder
from Snackbar.Helper.Database import get_users_with_leaders
from Snackbar.models import User

Expand Down Expand Up @@ -40,25 +40,16 @@ def initial():


@app.route('/image/')
def default_image():
userID = request.args.get('userID')
return monster_image(None, userID)


@app.route('/image/<filename>')
def image(filename):
def image(filename=None):
userID = request.args.get('userID')
return monster_image(filename, userID)


@app.route('/icon/')
def default_icon():
return get_icon(None)


@app.route('/icon/<icon>')
def get_icon(icon):
return image_from_folder(icon, app.config['ICON_FOLDER'], "static/unknown_icon.svg")
def get_icon(icon=None):
return icon_from_folder(icon)


@app.route('/change_image', methods=(['POST']))
Expand Down
28 changes: 8 additions & 20 deletions Snackbar/Helper/Appearance.py
Expand Up @@ -51,7 +51,7 @@ def monster_image(filename: str, userID):
if filename is None:
return monster_image_for_id(userID)

fullpath = os.path.join(current_app.root_path, app.config['IMAGE_FOLDER'])
fullpath = app.config['IMAGE_FOLDER']

full_file_path = safe_join(fullpath, filename)
if not os.path.isabs(full_file_path):
Expand All @@ -72,23 +72,9 @@ def monster_image_for_id(userID):
userID = "example@example.org"

use_gravatar = True
returnValue = send_from_directory(directory=current_app.root_path, path="static/unknown_image.png",
returnValue = send_from_directory(directory=app.config['STATIC_FOLDER'], path="unknown_image.png",
as_attachment=False)

# mail_parts = userID.split("@")
# if len(mail_parts) == 2:
# prefix = mail_parts[0]
# domain = mail_parts[1]
# if domain == "fit.fraunhofer.de":
# use_gravatar = False
# requestURL = "https://chat.fit.fraunhofer.de/avatar/" + prefix
# try:
# proxyResponse = requests.get(requestURL, timeout=5)
#
# returnValue = Response(proxyResponse)
# except:
# pass

if use_gravatar:
userHash = hashlib.md5(str(userID).encode('utf-8').lower()).hexdigest()
if userHash in imageCache:
Expand Down Expand Up @@ -136,18 +122,20 @@ def get_monster_id_from_gravatar(userHash):
return returnValue


def image_from_folder(filename, image_folder, the_default_image):
def icon_from_folder(filename):
if filename is None:
return send_from_directory(directory=current_app.root_path, path=the_default_image, as_attachment=False)
return send_from_directory(directory=app.config['STATIC_FOLDER'], path="unknown_icon.svg", as_attachment=False)

fullpath = os.path.join(current_app.root_path, image_folder)
fullpath = app.config['ICON_FOLDER']

full_file_path = safe_join(fullpath, filename)
if not os.path.isabs(full_file_path):
full_file_path = os.path.join(current_app.root_path, full_file_path)
try:
if not os.path.isfile(full_file_path):
return send_from_directory(directory=current_app.root_path, path=the_default_image, as_attachment=False)
icon_path = os.path.join(app.config['STATIC_FOLDER'], "unknown_icon.svg")
return send_from_directory(directory=app.config['STATIC_FOLDER'], path="unknown_icon.svg",
as_attachment=False)
except (TypeError, ValueError):
pass

Expand Down
6 changes: 3 additions & 3 deletions Snackbar/__init__.py
Expand Up @@ -20,9 +20,9 @@

app.config['SQLALCHEMY_DATABASE_URI'] = database_url
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['STATIC_FOLDER'] = 'static'
app.config['IMAGE_FOLDER'] = 'static/images'
app.config['ICON_FOLDER'] = 'static/icons'
app.config['STATIC_FOLDER'] = os.path.join(root_folder, "static")
app.config['IMAGE_FOLDER'] = os.path.join(app.instance_path, 'user')
app.config['ICON_FOLDER'] = os.path.join(app.instance_path, 'icons')
app.config['DEBUG'] = False

if not os.path.exists(app.config['IMAGE_FOLDER']):
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
40 changes: 1 addition & 39 deletions static/unknown_icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 42be1f1

Please sign in to comment.