Fixed user-generated static resources paths.

This commit is contained in:
s3lph 2018-07-11 16:57:38 +02:00
parent 8da58950ad
commit 68a228e95f
8 changed files with 15 additions and 15 deletions

View file

@ -13,4 +13,4 @@ if __name__ == '__main__':
port = int(sys.argv[1])
# Start the web server
MatematWebserver(port=port, staticroot='/var/matemat/upload').start()
MatematWebserver(port=port, staticroot='./static').start()

View file

@ -78,8 +78,8 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No
if 'avatar' not in args:
return
avatar = bytes(args.avatar)
os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True)
with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f:
os.makedirs('./static/upload/thumbnails/users/', exist_ok=True)
with open(f'./static/upload/thumbnails/users/{user.id}.png', 'wb') as f:
f.write(avatar)
except UnicodeDecodeError:
@ -111,8 +111,8 @@ def handle_admin_change(args: RequestArguments, db: MatematDatabase):
newproduct = db.create_product(name, price_member, price_non_member)
if 'image' in args:
image = bytes(args.image)
os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True)
with open(f'/var/matemat/upload/thumbnails/products/{newproduct.id}.png', 'wb') as f:
os.makedirs('./static/upload/thumbnails/products/', exist_ok=True)
with open(f'./static/upload/thumbnails/products/{newproduct.id}.png', 'wb') as f:
f.write(image)
elif change == 'restock':

View file

@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase)
if change == 'del':
db.delete_product(product)
try:
os.remove(f'/var/matemat/upload/thumbnails/products/{product.id}.png')
os.remove(f'./static/upload/thumbnails/products/{product.id}.png')
except FileNotFoundError:
pass
@ -76,6 +76,6 @@ def handle_change(args: RequestArguments, product: Product, db: MatematDatabase)
if 'image' in args:
image = bytes(args.image)
if len(image) > 0:
os.makedirs('/var/matemat/upload/thumbnails/products/', exist_ok=True)
with open(f'/var/matemat/upload/thumbnails/products/{product.id}.png', 'wb') as f:
os.makedirs('./static/upload/thumbnails/products/', exist_ok=True)
with open(f'./static/upload/thumbnails/products/{product.id}.png', 'wb') as f:
f.write(image)

View file

@ -47,7 +47,7 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No
if change == 'del':
db.delete_user(user)
try:
os.remove(f'/var/matemat/upload/thumbnails/users/{user.id}.png')
os.remove(f'./static/upload/thumbnails/users/{user.id}.png')
except FileNotFoundError:
pass
@ -83,6 +83,6 @@ def handle_change(args: RequestArguments, user: User, db: MatematDatabase) -> No
if 'avatar' in args:
avatar = bytes(args.avatar)
if len(avatar) > 0:
os.makedirs('/var/matemat/upload/thumbnails/users/', exist_ok=True)
with open(f'/var/matemat/upload/thumbnails/users/{user.id}.png', 'wb') as f:
os.makedirs('./static/upload/thumbnails/users/', exist_ok=True)
with open(f'./static/upload/thumbnails/users/{user.id}.png', 'wb') as f:
f.write(avatar)

View file

@ -24,7 +24,7 @@
<input id="modproduct-balance" name="stock" type="text" value="{{ product.stock }}" /><br/>
<label for="modproduct-image">
<img height="150" src="/img/thumbnails/products/{{ product.id }}.png" alt="Image of {{ product.name }}" />
<img height="150" src="/upload/thumbnails/products/{{ product.id }}.png" alt="Image of {{ product.name }}" />
</label><br/>
<input id="modproduct-image" type="file" name="image" accept="image/png" /><br/>

View file

@ -30,7 +30,7 @@
<input id="moduser-account-balance" name="balance" type="text" value="{{ user.balance }}" /><br/>
<label for="moduser-account-avatar">
<img height="150" src="/img/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" />
<img height="150" src="/upload/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" />
</label><br/>
<input id="moduser-account-avatar" type="file" name="avatar" accept="image/png" /><br/>

View file

@ -26,7 +26,7 @@ Your balance: {{ authuser.balance }}
{% endif %}
; Stock: {{ product.stock }}</span><br/>
<div class="imgcontainer">
<img src="/img/thumbnails/products/{{ product.id }}.png" alt="Picture of {{ product.name }}" />
<img src="/upload/thumbnails/products/{{ product.id }}.png" alt="Picture of {{ product.name }}" />
</div>
</a>
</div>

View file

@ -11,7 +11,7 @@
<a href="/touchkey?uid={{ user.id }}&username={{ user.name }}">
<span class="thumblist-title">{{ user.name }}</span><br/>
<div class="imgcontainer">
<img src="/img/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" />
<img src="/upload/thumbnails/users/{{ user.id }}.png" alt="Avatar of {{ user.name }}" />
</div>
</a>
</div>