Set the company logo from a link

Angular · Angular · intermediate · modification

Admins asked to set the company logo by pasting a link instead of downloading the file first. `LogoImportService` (`src/app/settings/logo-import.service.ts`) checks the link is https, downloads it with `HttpClient` as a `Blob` (without opting into cross-origin credentials, 15 s timeout) and checks its declared type and its size. `LogoImportComponent` (`src/app/settings/logo-import.component.ts`) shows the preview from an object URL, which it releases when the preview is replaced or the page closes, and saves the logo through `BrandingService.uploadLogo`. `settings.routes.ts` adds the admin-only route, and the Branding page (`branding-settings.component.ts`) gets a "Use a logo from a link" link to it next to the existing upload field. Until now `authInterceptor` (`src/app/core/auth.interceptor.ts`) added the token to every request, because the app only ever called its own API; the logo download goes to other hosts, so the interceptor now adds the token only to URLs under `environment.apiBaseUrl`.

Angular 21 CRM web app served from `https://app.acme-crm.com`, rendered in the browser only (no SSR): standalone components, signals, zoneless change detection, `OnPush`, theme tokens from `styles.scss`. `app.config.ts` (unchanged) registers `provideHttpClient(withInterceptors([authInterceptor]))` with the default XHR backend. `src/environments/environment.ts` (unchanged) sets `apiBaseUrl: 'https://api.acme-crm.com'`, with no trailing slash, the same in every build. Every API service builds absolute URLs from it (`${environment.apiBaseUrl}/v1/contacts`); the app makes no relative-URL calls to the API, and its own static files need no token. `AuthService.token` (`src/app/core/auth.service.ts`, unchanged) is a signal holding the account's API token in memory after sign-in, `null` when signed out: a long-lived token that can read and change all of the account's CRM data. The API authenticates with this `Authorization: Bearer` header only (no cookies) and allows CORS from `https://app.acme-crm.com`. `adminGuard` (unchanged) lets only account admins through. `BrandingService.uploadLogo(blob)` (unchanged) posts the file as multipart to `${environment.apiBaseUrl}/v1/branding/logo`, which checks the size again on the server and decodes the file, rejecting anything that is not a valid PNG, JPEG or WebP image whatever its declared type (the page then shows its "couldn't save" error). A link whose bytes do not match the declared type can show a broken preview until then; that is accepted. Logo links usually come from outside the company (a design agency, a partner's press kit, a link in an email), and admins are not expected to judge who runs the host. A cross-origin image download with `HttpClient` works only when the image host sends CORS headers; links on hosts that do not get the "couldn't load" error, an accepted limitation since uploading from the computer still works. Downloading the whole file before checking its size is accepted: it runs in the admin's own browser and the 15 s timeout cuts it off.

Requirements

Files touched

Review this PR

Angular practice