Skip to content

Commit ec643c5

Browse files
andrelandgrafkentcdodds
authored andcommitted
fmt and review comments
1 parent 64d45ff commit ec643c5

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

app/components/user-dropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function UserDropdown() {
3030
className="h-8 w-8 rounded-full object-cover"
3131
alt={user.name ?? user.username}
3232
src={getUserImgSrc(user.image?.id)}
33-
width={416}
34-
height={416}
33+
width={256}
34+
height={256}
3535
/>
3636
<span className="text-body-sm font-bold">
3737
{user.name ?? user.username}

app/routes/resources+/images.tsx

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,37 @@ import { getImgResponse } from 'openimg/node'
22
import { type Route } from './+types/images.ts'
33
import { getDomainUrl } from '#app/utils/misc.tsx'
44

5-
function isUrl(src: string) {
6-
try {
7-
new URL(src)
8-
return true
9-
} catch {
10-
return false
11-
}
12-
}
13-
145
export async function loader({ request }: Route.LoaderArgs) {
156
const domain = getDomainUrl(request)
167
const headers = new Headers()
178
headers.set('Cache-Control', 'public, max-age=31536000, immutable')
189
return getImgResponse(request, {
1910
headers,
20-
allowlistedOrigins: [domain],
11+
allowlistedOrigins: [domain],
2112
getImgSource: ({ params }) => {
2213
if (params.src.startsWith('/resources')) {
23-
// Fetch image from resource endpoint
14+
// Fetch image from resource endpoint
2415
return {
2516
type: 'fetch',
2617
url: domain + params.src,
2718
}
2819
}
29-
if (isUrl(params.src)) {
30-
// Fetch image from external URL; will be matched against allowlist
20+
if (URL.canParse(params.src)) {
21+
// Fetch image from external URL; will be matched against allowlist
3122
return {
3223
type: 'fetch',
3324
url: params.src,
3425
}
3526
}
36-
// Retrieve image from filesystem (public folder)
37-
if(params.src.startsWith('/assets')) {
38-
// Files managed by Vite
39-
return {
40-
type: 'fs',
41-
path: '.' + params.src,
42-
}
43-
}
44-
// Fallback to files in public folder
27+
// Retrieve image from filesystem (public folder)
28+
if (params.src.startsWith('/assets')) {
29+
// Files managed by Vite
30+
return {
31+
type: 'fs',
32+
path: '.' + params.src,
33+
}
34+
}
35+
// Fallback to files in public folder
4536
return {
4637
type: 'fs',
4738
path: './public' + params.src,

0 commit comments

Comments
 (0)