favicon getter works

This commit is contained in:
Christoph J. Scherr 2023-06-05 21:22:52 +02:00
parent 9c5d78ac2c
commit 289d3cb824
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
2 changed files with 22 additions and 2 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.19 on 2023-06-05 17:48
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('start', '0006_alter_searchable_title_en'),
]
operations = [
migrations.AddField(
model_name='link',
name='favicon',
field=models.ImageField(blank=True, upload_to='img/links/favicons'),
),
]

View File

@ -106,6 +106,8 @@ class Link(Searchable):
regenerate a object
Implements the abstract method of Searchable
Searches for a favicon in the urr, if one is found, it will be stored in MEDIA_ROOT
"""
logger.info(f"regenerating {self.__class__.__name__} object: {self}")
self.suburl = f"/links#{self.title_en}"
@ -119,11 +121,11 @@ class Link(Searchable):
filename: str = f"favicon-{random.randint(0x1000, 0xffff)}.{icons[0].format}"
logger.debug(response)
logger.debug(filename)
with open(f"{settings.FILE_UPLOAD_TEMP_DIR}/{filename}", 'wb') as image:
with open(f"{settings.MEDIA_ROOT}/{filename}", 'wb') as image:
for chunk in response.iter_content(1024):
image.write(chunk)
logger.debug(image)
with open(f"{settings.FILE_UPLOAD_TEMP_DIR}/{filename}", 'rb') as image:
with open(f"{settings.MEDIA_ROOT}/{filename}", 'rb') as image:
self.favicon.save(filename, File(image))
#self.favicon.save(f"favicon-{self.title_en}", favicon.get(self.url, timeout=2))