generated from w3hc/genji
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* set branding * comment w3m * adapt link * rm contract * fix button * add API calls * fix urls
- Loading branch information
Showing
14 changed files
with
323 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
type StoryCard = { | ||
step: number | ||
desc: string | ||
options: string[] | ||
paths: number[] | ||
} | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<StoryCard | { error: string }>) { | ||
const { id } = req.query | ||
|
||
if (!id || Array.isArray(id)) { | ||
return res.status(400).json({ error: 'Invalid id parameter' }) | ||
} | ||
|
||
try { | ||
const response = await fetch(`https://avventura.jcloud-ver-jpe.ik-server.com/steps/${id}`) | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch story card') | ||
} | ||
const data: StoryCard = await response.json() | ||
res.status(200).json(data) | ||
} catch (error) { | ||
console.error('Error fetching story card:', error) | ||
res.status(500).json({ error: 'Failed to fetch story card' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
type CurrentStepResponse = { | ||
currentStep: number | ||
error?: string | ||
} | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<CurrentStepResponse>) { | ||
if (req.method !== 'GET') { | ||
return res.status(405).json({ currentStep: 0, error: 'Method not allowed' }) | ||
} | ||
|
||
try { | ||
// Call your Nest.js API to get the current game state | ||
const response = await fetch('https://avventura.jcloud-ver-jpe.ik-server.com/games/1') | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch game state') | ||
} | ||
|
||
const gameData = await response.json() | ||
res.status(200).json({ currentStep: gameData.currentStep }) | ||
} catch (error) { | ||
console.error('Error fetching current step:', error) | ||
res.status(500).json({ currentStep: 0, error: 'Failed to fetch current step' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
type UpdateResponse = { | ||
success: boolean | ||
error?: string | ||
} | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<UpdateResponse>) { | ||
if (req.method !== 'POST') { | ||
return res.status(405).json({ success: false, error: 'Method not allowed' }) | ||
} | ||
|
||
const { nextStep } = req.body | ||
|
||
if (!nextStep || typeof nextStep !== 'number') { | ||
return res.status(400).json({ success: false, error: 'Invalid nextStep' }) | ||
} | ||
|
||
console.log('next step:', nextStep) | ||
try { | ||
const response = await fetch('https://avventura.jcloud-ver-jpe.ik-server.com/games/1/next-step', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ nextStep }), | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to update game state from API route') | ||
} | ||
|
||
res.status(200).json({ success: true }) | ||
} catch (error) { | ||
console.error('Error updating game state:', error) | ||
res.status(500).json({ success: false, error: 'Failed to update game state' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.