Skip to content

Commit c1a5c2c

Browse files
committed
added to workspace templates page as well
1 parent 9b2dd22 commit c1a5c2c

File tree

3 files changed

+87
-9
lines changed
  • apps/sim/app
    • api/templates/[id]/og-image
    • workspace/[workspaceId]
      • templates/[id]
      • w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/template

3 files changed

+87
-9
lines changed

apps/sim/app/api/templates/[id]/og-image/route.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
6767
context: 'og-images',
6868
preserveKey: true,
6969
customKey: storageKey,
70-
metadata: {
71-
templateId: id,
72-
uploadedAt: new Date().toISOString(),
73-
purpose: 'og-image',
74-
},
7570
})
7671

7772
const baseUrl = getBaseUrl()

apps/sim/app/workspace/[workspaceId]/templates/[id]/page.tsx

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,98 @@
1+
import { db } from '@sim/db'
2+
import { templateCreators, templates } from '@sim/db/schema'
3+
import { eq } from 'drizzle-orm'
4+
import type { Metadata } from 'next'
15
import { redirect } from 'next/navigation'
26
import { getSession } from '@/lib/auth'
7+
import { getBaseUrl } from '@/lib/core/utils/urls'
8+
import { createLogger } from '@/lib/logs/console/logger'
39
import { verifyWorkspaceMembership } from '@/app/api/workflows/utils'
410
import TemplateDetails from '@/app/templates/[id]/template'
511

12+
const logger = createLogger('WorkspaceTemplateMetadata')
13+
614
interface TemplatePageProps {
715
params: Promise<{
816
workspaceId: string
917
id: string
1018
}>
1119
}
1220

21+
/**
22+
* Generate dynamic metadata for workspace template pages.
23+
* This provides OpenGraph images for social media sharing.
24+
*/
25+
export async function generateMetadata({
26+
params,
27+
}: {
28+
params: Promise<{ workspaceId: string; id: string }>
29+
}): Promise<Metadata> {
30+
const { workspaceId, id } = await params
31+
32+
try {
33+
const result = await db
34+
.select({
35+
template: templates,
36+
creator: templateCreators,
37+
})
38+
.from(templates)
39+
.leftJoin(templateCreators, eq(templates.creatorId, templateCreators.id))
40+
.where(eq(templates.id, id))
41+
.limit(1)
42+
43+
if (result.length === 0) {
44+
return {
45+
title: 'Template Not Found',
46+
description: 'The requested template could not be found.',
47+
}
48+
}
49+
50+
const { template, creator } = result[0]
51+
const baseUrl = getBaseUrl()
52+
53+
const details = template.details as { tagline?: string; about?: string } | null
54+
const description = details?.tagline || 'AI workflow template on Sim'
55+
56+
const hasOgImage = !!template.ogImageUrl
57+
const ogImageUrl = template.ogImageUrl || `${baseUrl}/logo/primary/rounded.png`
58+
59+
return {
60+
title: template.name,
61+
description,
62+
openGraph: {
63+
title: template.name,
64+
description,
65+
type: 'website',
66+
url: `${baseUrl}/workspace/${workspaceId}/templates/${id}`,
67+
siteName: 'Sim',
68+
images: [
69+
{
70+
url: ogImageUrl,
71+
width: hasOgImage ? 1200 : 512,
72+
height: hasOgImage ? 630 : 512,
73+
alt: `${template.name} - Workflow Preview`,
74+
},
75+
],
76+
},
77+
twitter: {
78+
card: hasOgImage ? 'summary_large_image' : 'summary',
79+
title: template.name,
80+
description,
81+
images: [ogImageUrl],
82+
creator: creator?.details
83+
? ((creator.details as Record<string, unknown>).xHandle as string) || undefined
84+
: undefined,
85+
},
86+
}
87+
} catch (error) {
88+
logger.error('Failed to generate workspace template metadata:', error)
89+
return {
90+
title: 'Template',
91+
description: 'AI workflow template on Sim',
92+
}
93+
}
94+
}
95+
1396
/**
1497
* Workspace-scoped template detail page.
1598
* Requires authentication and workspace membership to access.
@@ -19,12 +102,10 @@ export default async function TemplatePage({ params }: TemplatePageProps) {
19102
const { workspaceId, id } = await params
20103
const session = await getSession()
21104

22-
// Redirect unauthenticated users to public template detail page
23105
if (!session?.user?.id) {
24106
redirect(`/templates/${id}`)
25107
}
26108

27-
// Verify workspace membership
28109
const hasPermission = await verifyWorkspaceMembership(session.user.id, workspaceId)
29110
if (!hasPermission) {
30111
redirect('/')

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/template/template.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,13 @@ const OGCaptureContainer = React.forwardRef<HTMLDivElement>((_, ref) => {
495495
>
496496
<WorkflowPreview
497497
workflowState={workflowState}
498-
showSubBlocks={true}
498+
showSubBlocks={false}
499499
height='100%'
500500
width='100%'
501501
isPannable={false}
502-
defaultZoom={0.5}
502+
defaultZoom={0.8}
503+
fitPadding={0.2}
504+
lightweight
503505
/>
504506
</div>
505507
)

0 commit comments

Comments
 (0)