Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,31 @@ function mapOutputFileToTemplateType(outputFile: string): string {

export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ fileName: string }> }
{ params }: { params: { ide: string; framework: string; fileName: string } }
) {
try {
const { fileName } = await params
const { ide, framework, fileName } = params
const body = await request.json()
const responses: WizardResponses = body

// Determine template configuration based on the request
let templateConfig

const frameworkFromPath = framework && !['general', 'none', 'undefined'].includes(framework)
? framework
: undefined

if (ide) {
const templateKeyFromParams: TemplateKey = {
ide,
templateType: mapOutputFileToTemplateType(fileName),
framework: frameworkFromPath
}
templateConfig = getTemplateConfig(templateKeyFromParams)
}

// Check if this is a combination-based request
if (responses.preferredIde && responses.outputFile) {
if (!templateConfig && responses.preferredIde && responses.outputFile) {
const templateKey: TemplateKey = {
ide: responses.preferredIde,
templateType: mapOutputFileToTemplateType(responses.outputFile),
Expand Down Expand Up @@ -109,4 +122,4 @@ export async function POST(
{ status: 500 }
)
}
}
}
21 changes: 14 additions & 7 deletions components/instructions-wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,21 @@ export function InstructionsWizard({ onClose }: InstructionsWizardProps) {

// Call the API to generate the instructions file
if (questionsAndAnswers.outputFile) {
const ideSegment = questionsAndAnswers.preferredIde ?? 'unknown'
const frameworkSegment = questionsAndAnswers.frameworkSelection ?? 'general'
const fileNameSegment = questionsAndAnswers.outputFile

try {
const response = await fetch(`/api/generate/${questionsAndAnswers.outputFile}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(questionsAndAnswers),
})
const response = await fetch(
`/api/generate/${encodeURIComponent(ideSegment)}/${encodeURIComponent(frameworkSegment)}/${encodeURIComponent(fileNameSegment)}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(questionsAndAnswers),
}
)

if (response.ok) {
const data = await response.json()
Expand Down
Loading