Skip to content

Commit 7ee6ba7

Browse files
committed
Add logo.dev for business emails
1 parent c052df1 commit 7ee6ba7

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

clients/apps/web/next.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const baseCSP = `
2424
frame-src 'self' https://*.js.stripe.com https://js.stripe.com https://hooks.stripe.com https://customer-wl21dabnj6qtvcai.cloudflarestream.com videodelivery.net *.cloudflarestream.com;
2525
script-src 'self' 'unsafe-eval' 'unsafe-inline' https://*.js.stripe.com https://js.stripe.com https://maps.googleapis.com https://www.googletagmanager.com https://chat.cdn-plain.com https://embed.cloudflarestream.com;
2626
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
27-
img-src 'self' blob: data: https://www.gravatar.com https://lh3.googleusercontent.com https://avatars.githubusercontent.com ${S3_PUBLIC_IMAGES_BUCKET_ORIGIN} https://prod-uk-services-workspac-workspacefilespublicbuck-vs4gjqpqjkh6.s3.amazonaws.com https://prod-uk-services-attachm-attachmentsbucket28b3ccf-uwfssb4vt2us.s3.eu-west-2.amazonaws.com https://i0.wp.com;
27+
img-src 'self' blob: data: https://www.gravatar.com https://img.logo.dev https://lh3.googleusercontent.com https://avatars.githubusercontent.com ${S3_PUBLIC_IMAGES_BUCKET_ORIGIN} https://prod-uk-services-workspac-workspacefilespublicbuck-vs4gjqpqjkh6.s3.amazonaws.com https://prod-uk-services-attachm-attachmentsbucket28b3ccf-uwfssb4vt2us.s3.eu-west-2.amazonaws.com https://i0.wp.com;
2828
font-src 'self';
2929
object-src 'none';
3030
base-uri 'self';

server/polar/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ class Settings(BaseSettings):
222222
# Loops
223223
LOOPS_API_KEY: str | None = None
224224

225+
# Logo.dev (for company logo avatars)
226+
LOGO_DEV_TOKEN: str | None = None
227+
225228
# Logfire
226229
LOGFIRE_TOKEN: str | None = None
227230
LOGFIRE_IGNORED_ACTORS: set[str] = {

server/polar/customer/schemas/customer.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from fastapi import Path
77
from pydantic import UUID4, Field, computed_field
88

9+
from polar.config import settings
910
from polar.kit.address import Address, AddressInput
1011
from polar.kit.email import EmailStrDNS
1112
from polar.kit.metadata import (
@@ -40,6 +41,23 @@
4041
_name_description = "The name of the customer."
4142
_name_example = "John Doe"
4243

44+
_personal_email_domains: set[str] = {
45+
"gmail.com",
46+
"yahoo.com",
47+
"hotmail.com",
48+
"outlook.com",
49+
"aol.com",
50+
"icloud.com",
51+
"mail.com",
52+
"protonmail.com",
53+
"zoho.com",
54+
"gmx.com",
55+
"yandex.com",
56+
"msn.com",
57+
"live.com",
58+
"qq.com",
59+
}
60+
4361
CustomerNameInput = Annotated[
4462
str,
4563
MaxLen(256),
@@ -127,8 +145,13 @@ class CustomerBase(MetadataOutputMixin, TimestampedSchema, IDSchema):
127145

128146
@computed_field(examples=["https://www.gravatar.com/avatar/xxx?d=404"])
129147
def avatar_url(self) -> str:
130-
email_hash = hashlib.sha256(self.email.lower().encode()).hexdigest()
131-
return f"https://www.gravatar.com/avatar/{email_hash}?d=404"
148+
domain = self.email.split("@")[-1].lower()
149+
150+
if not settings.LOGO_DEV_TOKEN or domain in _personal_email_domains:
151+
email_hash = hashlib.sha256(self.email.lower().encode()).hexdigest()
152+
return f"https://www.gravatar.com/avatar/{email_hash}?d=404"
153+
154+
return f"https://img.logo.dev/{domain}?token={settings.LOGO_DEV_TOKEN}&fallback=404"
132155

133156

134157
class Customer(CustomerBase):

0 commit comments

Comments
 (0)