-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(devbox): icon database support #6673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ import { destroyDriver } from '@/hooks/driver'; | |
| interface TemplateCardProps { | ||
| isPublic?: boolean; | ||
| iconId: string; | ||
| icon?: string | null; | ||
| isDisabled?: boolean; | ||
| inPublicStore?: boolean; | ||
| templateRepositoryName: string; | ||
|
|
@@ -53,6 +54,7 @@ interface TemplateCardProps { | |
| const TemplateCard = ({ | ||
| isPublic, | ||
| iconId, | ||
| icon, | ||
| templateRepositoryName, | ||
| templateRepositoryDescription, | ||
| templateRepositoryUid, | ||
|
|
@@ -111,18 +113,32 @@ const TemplateCard = ({ | |
| }; | ||
|
|
||
| const loadImages = async () => { | ||
| await preloadImage(`/images/runtime/${iconId}.svg`); | ||
| const fallbackSrc = iconId ? `/images/runtime/${iconId}.svg` : '/images/runtime/custom.svg'; | ||
| const src = (() => { | ||
| if (icon) { | ||
| const trimmed = icon.trim(); | ||
| if (/^<svg[\s>]/i.test(trimmed)) { | ||
| return `data:image/svg+xml;utf8,${encodeURIComponent(trimmed)}`; | ||
| } | ||
| if (/^https:\/\//i.test(trimmed)) { | ||
| return trimmed; | ||
| } | ||
| } | ||
| return fallbackSrc; | ||
| })(); | ||
|
Comment on lines
+117
to
+128
|
||
| await preloadImage(src); | ||
| setImageLoaded(true); | ||
| }; | ||
|
|
||
| loadImages(); | ||
| }, [iconId]); | ||
| }, [iconId, icon]); | ||
|
|
||
| const handleSelectTemplate = () => { | ||
| setStartedTemplate({ | ||
| uid: templateRepositoryUid, | ||
| name: templateRepositoryName, | ||
| iconId, | ||
| icon, | ||
| templateUid: selectedVersion, | ||
| description: templateRepositoryDescription | ||
| }); | ||
|
|
@@ -152,6 +168,7 @@ const TemplateCard = ({ | |
| {!imageLoaded && <Skeleton className="absolute inset-0 h-8 w-8 rounded-lg" />} | ||
| <RuntimeIcon | ||
| iconId={iconId} | ||
| icon={icon} | ||
| alt={templateRepositoryName} | ||
| width={32} | ||
| height={32} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,11 @@ import { authSessionWithJWT } from '@/services/backend/auth'; | |||||||||||||||||||
| import { jsonRes } from '@/services/backend/response'; | ||||||||||||||||||||
| import { devboxDB } from '@/services/db/init'; | ||||||||||||||||||||
| import { getRegionUid } from '@/utils/env'; | ||||||||||||||||||||
| import { updateTemplateRepositorySchema } from '@/utils/validate'; | ||||||||||||||||||||
| import { | ||||||||||||||||||||
| normalizeTemplateIcon, | ||||||||||||||||||||
| updateTemplateRepositorySchema, | ||||||||||||||||||||
| validateTemplateIcon | ||||||||||||||||||||
| } from '@/utils/validate'; | ||||||||||||||||||||
| import { NextRequest } from 'next/server'; | ||||||||||||||||||||
| import { z } from 'zod'; | ||||||||||||||||||||
| export async function POST(req: NextRequest) { | ||||||||||||||||||||
|
|
@@ -18,6 +22,15 @@ export async function POST(req: NextRequest) { | |||||||||||||||||||
| }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| const query = updateTemplateRepositorySchema.parse(queryRaw); | ||||||||||||||||||||
| const hasIconInput = query.icon !== undefined; | ||||||||||||||||||||
| const iconCheck = validateTemplateIcon(query.icon); | ||||||||||||||||||||
| if (!iconCheck.ok) { | ||||||||||||||||||||
| return jsonRes({ | ||||||||||||||||||||
| code: 400, | ||||||||||||||||||||
| error: iconCheck.error | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| const normalizedIcon = normalizeTemplateIcon(query.icon); | ||||||||||||||||||||
| const { payload } = await authSessionWithJWT(headerList); | ||||||||||||||||||||
| const templateRepository = await devboxDB.templateRepository.findUnique({ | ||||||||||||||||||||
| where: { | ||||||||||||||||||||
|
|
@@ -89,7 +102,8 @@ export async function POST(req: NextRequest) { | |||||||||||||||||||
| data: { | ||||||||||||||||||||
| description: query.description, | ||||||||||||||||||||
| name: query.templateRepositoryName, | ||||||||||||||||||||
| isPublic: query.isPublic | ||||||||||||||||||||
| isPublic: query.isPublic, | ||||||||||||||||||||
|
||||||||||||||||||||
| isPublic: query.isPublic, | |
| isPublic: query.isPublic, | |
| // NOTE: `hasIconInput` is used to distinguish "no icon field in request" | |
| // from "icon explicitly provided (possibly as null)". | |
| // - If hasIconInput is false, we omit `icon` so the DB value is untouched. | |
| // - If hasIconInput is true, we always include `icon: normalizedIcon`; | |
| // `normalizedIcon` may be null to explicitly clear the stored icon. | |
| // This preserves partial-update semantics despite using | |
| // `z.string().nullable().optional()` in the schema. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,7 @@ export async function POST( | |
| select: { | ||
| uid: true, | ||
| iconId: true, | ||
| icon: true, | ||
| name: true, | ||
| kind: true | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,7 @@ export async function POST( | |
| select: { | ||
| uid: true, | ||
| iconId: true, | ||
| icon: true, | ||
| name: true, | ||
| kind: true | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same data URI encoding issue exists here as in RuntimeIcon. The format
data:image/svg+xml;utf8,should bedata:image/svg+xml;charset=utf-8,ordata:image/svg+xml,to be standards-compliant.Since this logic is duplicated from RuntimeIcon (see related maintainability comment), fixing it in one place would require fixing it in both places, which reinforces the need to extract this into a shared utility function.