Unlink avatars from prod static

This commit is contained in:
Reckless_Satoshi 2022-02-12 07:46:58 -08:00
parent d257848940
commit 04c9466c3e
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 16 additions and 17 deletions

View File

@ -6,6 +6,7 @@ from django.template.defaultfilters import truncatechars
from django.dispatch import receiver
from django.utils.html import mark_safe
import uuid
from django.conf import settings
from decouple import config
from pathlib import Path
@ -209,7 +210,6 @@ def delete_lnpayment_at_order_deletion(sender, instance, **kwargs):
pass
class Profile(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE)
# Total trades
@ -227,7 +227,7 @@ class Profile(models.Model):
orders_disputes_started = models.CharField(max_length=999, null=True, default=None, validators=[validate_comma_separated_integer_list], blank=True) # Will only store ID of orders
# RoboHash
avatar = models.ImageField(default="static/assets/misc/unknown_avatar.png", verbose_name='Avatar', blank=True)
avatar = models.ImageField(default=(settings.STATIC_ROOT+"unknown_avatar.png"), verbose_name='Avatar', blank=True)
# Penalty expiration (only used then taking/cancelling repeatedly orders in the book before comitting bond)
penalty_expiration = models.DateTimeField(null=True,default=None, blank=True)
@ -247,7 +247,7 @@ class Profile(models.Model):
@receiver(pre_delete, sender=User)
def del_avatar_from_disk(sender, instance, **kwargs):
try:
avatar_file=Path('frontend/' + instance.profile.avatar.url)
avatar_file=Path(settings.AVATAR_ROOT + instance.profile.avatar.url)
avatar_file.unlink()
except:
pass
@ -258,7 +258,7 @@ class Profile(models.Model):
# to display avatars in admin panel
def get_avatar(self):
if not self.avatar:
return 'static/assets/misc/unknown_avatar.png'
return settings.STATIC_ROOT + 'unknown_avatar.png'
return self.avatar.url
# method to create a fake table field in read only mode

View File

@ -23,6 +23,7 @@ import hashlib
from pathlib import Path
from datetime import timedelta, datetime
from django.utils import timezone
from django.conf import settings
from decouple import config
EXP_MAKER_BOND_INVOICE = int(config('EXP_MAKER_BOND_INVOICE'))
@ -30,10 +31,7 @@ FEE = float(config('FEE'))
RETRY_TIME = int(config('RETRY_TIME'))
avatar_path = Path('/usr/src/static/assets/avatars')
if os.environ.get('DEVELOPMENT'):
avatar_path = Path('frontend/static/assets/avatars')
avatar_path = Path(settings.AVATAR_ROOT)
avatar_path.mkdir(parents=True, exist_ok=True)
# Create your views here.
@ -417,7 +415,7 @@ class UserView(APIView):
if len(User.objects.filter(username=nickname)) == 0:
User.objects.create_user(username=nickname, password=token, is_staff=False)
user = authenticate(request, username=nickname, password=token)
user.profile.avatar = str(image_path)[9:] # removes frontend/ from url (ugly, to be fixed)
user.profile.avatar = nickname + '.png'
login(request, user)
return Response(context, status=status.HTTP_201_CREATED)

View File

@ -93,13 +93,13 @@ export default class BottomBar extends Component {
<ListItemIcon><DnsIcon/></ListItemIcon>
{this.state.network == 'testnet'?
<ListItemText secondary={this.state.node_alias}>
<a href={"https://1ml.com/testnet/node/"
<a target="_blank" href={"https://1ml.com/testnet/node/"
+ this.state.node_id}>{this.state.node_id.slice(0, 12)+"... (1ML)"}
</a>
</ListItemText>
:
<ListItemText secondary={this.state.node_alias}>
<a href={"https://1ml.com/node/"
<a target="_blank" href={"https://1ml.com/node/"
+ this.state.node_id}>{this.state.node_id.slice(0, 12)+"... (1ML)"}
</a>
</ListItemText>
@ -110,7 +110,7 @@ export default class BottomBar extends Component {
<ListItem>
<ListItemIcon><WebIcon/></ListItemIcon>
<ListItemText secondary={this.state.alternative_name}>
<a href={"https://"+this.alternative_site}>{this.state.alternative_site.slice(0, 12)+"...onion"}
<a target="_blank" href={"https://"+this.alternative_site}>{this.state.alternative_site.slice(0, 12)+"...onion"}
</a>
</ListItemText>
</ListItem>
@ -119,7 +119,7 @@ export default class BottomBar extends Component {
<ListItem>
<ListItemIcon><GitHubIcon/></ListItemIcon>
<ListItemText secondary="Currently running commit hash">
<a href={"https://github.com/Reckless-Satoshi/robosats/tree/"
<a target="_blank" href={"https://github.com/Reckless-Satoshi/robosats/tree/"
+ this.state.robosats_running_commit_hash}>{this.state.robosats_running_commit_hash.slice(0, 12)+"..."}
</a>
</ListItemText>

File diff suppressed because one or more lines are too long

View File

@ -26,14 +26,15 @@ STATIC_URL = '/static/'
SECRET_KEY = config('SECRET_KEY')
DEBUG = False
STATIC_URL = '/static/'
STATIC_URL = 'static/'
STATIC_ROOT ='/usr/src/static/'
# SECURITY WARNING: don't run with debug turned on in production!
if os.environ.get('DEVELOPMENT'):
DEBUG = True
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'frontend/static/')
STATIC_ROOT = 'frontend/static/'
AVATAR_ROOT = STATIC_ROOT + 'assets/avatars/'
ALLOWED_HOSTS = [config('HOST_NAME'),'127.0.0.1']