mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-11 18:56:23 +00:00
Compare commits
3 Commits
550b9bf0b9
...
devel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdc89c4394 | ||
|
|
64967c07ad | ||
|
|
c2cbe14b0d |
@@ -244,10 +244,6 @@ CACHES = {
|
||||
},
|
||||
}
|
||||
|
||||
# This is 5 minutes caching for generated/resized images,
|
||||
# so the sites don't hit ivatar so much - it's what's set in the HTTP header
|
||||
CACHE_IMAGES_MAX_AGE = 5 * 60
|
||||
|
||||
CACHE_RESPONSE = True
|
||||
|
||||
# Trusted URLs for default redirection
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
Default: useful variables for the base page templates.
|
||||
"""
|
||||
|
||||
from django.conf import settings
|
||||
from ipware import get_client_ip # type: ignore
|
||||
from ivatar.settings import IVATAR_VERSION, SITE_NAME, MAX_PHOTO_SIZE
|
||||
from ivatar.settings import BASE_URL, SECURE_BASE_URL
|
||||
from ivatar.settings import MAX_NUM_UNCONFIRMED_EMAILS
|
||||
|
||||
|
||||
def basepage(request):
|
||||
@@ -20,18 +18,21 @@ def basepage(request):
|
||||
] # pragma: no cover
|
||||
client_ip = get_client_ip(request)[0]
|
||||
context["client_ip"] = client_ip
|
||||
context["ivatar_version"] = IVATAR_VERSION
|
||||
context["site_name"] = SITE_NAME
|
||||
context["ivatar_version"] = getattr(settings, "IVATAR_VERSION", "2.0")
|
||||
context["site_name"] = getattr(settings, "SITE_NAME", "libravatar")
|
||||
context["site_url"] = request.build_absolute_uri("/")[:-1]
|
||||
context["max_file_size"] = MAX_PHOTO_SIZE
|
||||
context["BASE_URL"] = BASE_URL
|
||||
context["SECURE_BASE_URL"] = SECURE_BASE_URL
|
||||
context["max_file_size"] = getattr(settings, "MAX_PHOTO_SIZE", 10485760)
|
||||
context["BASE_URL"] = getattr(settings, "BASE_URL", "http://localhost:8000/avatar/")
|
||||
context["SECURE_BASE_URL"] = getattr(
|
||||
settings, "SECURE_BASE_URL", "https://localhost:8000/avatar/"
|
||||
)
|
||||
context["max_emails"] = False
|
||||
|
||||
if request.user:
|
||||
if not request.user.is_anonymous:
|
||||
unconfirmed = request.user.unconfirmedemail_set.count()
|
||||
if unconfirmed >= MAX_NUM_UNCONFIRMED_EMAILS:
|
||||
max_unconfirmed = getattr(settings, "MAX_NUM_UNCONFIRMED_EMAILS", 5)
|
||||
if unconfirmed >= max_unconfirmed:
|
||||
context["max_emails"] = True
|
||||
|
||||
return context
|
||||
|
||||
@@ -22,7 +22,8 @@ from opentelemetry.instrumentation.pymysql import PyMySQLInstrumentor
|
||||
from opentelemetry.instrumentation.requests import RequestsInstrumentor
|
||||
from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor
|
||||
|
||||
from .settings import VERSION as IVATAR_VERSION
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
# Note: Memcached instrumentation not available in OpenTelemetry Python
|
||||
|
||||
@@ -61,10 +62,21 @@ class OpenTelemetryConfig:
|
||||
|
||||
def _create_resource(self) -> Resource:
|
||||
"""Create OpenTelemetry resource with service information."""
|
||||
# Get IVATAR_VERSION from environment or settings, handling case where
|
||||
# Django settings might not be configured yet
|
||||
ivatar_version = os.environ.get("IVATAR_VERSION")
|
||||
if not ivatar_version:
|
||||
# Try to access settings, but handle case where Django isn't configured
|
||||
try:
|
||||
ivatar_version = getattr(settings, "IVATAR_VERSION", "2.0")
|
||||
except ImproperlyConfigured:
|
||||
# Django settings not configured yet, use default
|
||||
ivatar_version = "2.0"
|
||||
|
||||
return Resource.create(
|
||||
{
|
||||
"service.name": self.service_name,
|
||||
"service.version": os.environ.get("IVATAR_VERSION", IVATAR_VERSION),
|
||||
"service.version": ivatar_version,
|
||||
"service.namespace": "libravatar",
|
||||
"deployment.environment": self.environment,
|
||||
"service.instance.id": os.environ.get("HOSTNAME", "unknown"),
|
||||
|
||||
@@ -31,7 +31,6 @@ from .pagan_optimized import create_optimized_pagan
|
||||
|
||||
from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY, DEFAULT_AVATAR_SIZE
|
||||
from ivatar.settings import CACHE_RESPONSE
|
||||
from ivatar.settings import CACHE_IMAGES_MAX_AGE
|
||||
from ivatar.settings import TRUSTED_DEFAULT_URLS
|
||||
from ivatar.settings import (
|
||||
DEFAULT_GRAVATARPROXY,
|
||||
@@ -335,7 +334,6 @@ class AvatarImageView(TemplateView):
|
||||
)
|
||||
|
||||
response = CachingHttpResponse(uri, data, content_type=f"image/{imgformat}")
|
||||
response["Cache-Control"] = "max-age=%i" % CACHE_IMAGES_MAX_AGE
|
||||
# Remove Vary header for images since language doesn't matter
|
||||
response["Vary"] = ""
|
||||
return response
|
||||
@@ -355,7 +353,6 @@ class AvatarImageView(TemplateView):
|
||||
def _return_cached_response(self, data, uri):
|
||||
data.seek(0)
|
||||
response = CachingHttpResponse(uri, data, content_type="image/png")
|
||||
response["Cache-Control"] = "max-age=%i" % CACHE_IMAGES_MAX_AGE
|
||||
# Remove Vary header for images since language doesn't matter
|
||||
response["Vary"] = ""
|
||||
return response
|
||||
@@ -461,7 +458,6 @@ class GravatarProxyView(View):
|
||||
response = HttpResponse(
|
||||
data.read(), content_type=f"image/{file_format(img.format)}"
|
||||
)
|
||||
response["Cache-Control"] = "max-age=%i" % CACHE_IMAGES_MAX_AGE
|
||||
# Remove Vary header for images since language doesn't matter
|
||||
response["Vary"] = ""
|
||||
return response
|
||||
@@ -590,7 +586,6 @@ class BlueskyProxyView(View):
|
||||
response = HttpResponse(
|
||||
data.read(), content_type=f"image/{file_format(format)}"
|
||||
)
|
||||
response["Cache-Control"] = "max-age=%i" % CACHE_IMAGES_MAX_AGE
|
||||
# Remove Vary header for images since language doesn't matter
|
||||
response["Vary"] = ""
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user