My 13th reason (2.0)
This commit is contained in:
parent
0a371037eb
commit
9949b51f3f
@ -14,25 +14,13 @@ import zoneRepository from '../repositories/zoneRepository'
|
||||
import zoneManager from '../managers/zoneManager'
|
||||
|
||||
async function addHttpRoutes(app: Application) {
|
||||
app.get('/assets', async (req: Request, res: Response) => {
|
||||
/**
|
||||
* Get all base sprite, assets
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
app.get('/assets/sprites', async (req: Request, res: Response) => {
|
||||
let assets: TAsset[] = []
|
||||
const tiles = await tileRepository.getAll()
|
||||
tiles.forEach((tile) => {
|
||||
assets.push({
|
||||
key: tile.id,
|
||||
url: '/assets/tiles/' + tile.id + '.png',
|
||||
group: 'tiles'
|
||||
})
|
||||
})
|
||||
|
||||
const objects = await objectRepository.getAll()
|
||||
objects.forEach((object) => {
|
||||
assets.push({
|
||||
key: object.id,
|
||||
url: '/assets/objects/' + object.id + '.png',
|
||||
group: 'objects'
|
||||
})
|
||||
})
|
||||
|
||||
const sprites = await spriteRepository.getAll()
|
||||
// sprites all contain spriteActions, loop through these
|
||||
@ -51,7 +39,12 @@ async function addHttpRoutes(app: Application) {
|
||||
res.json(assets)
|
||||
})
|
||||
|
||||
app.get('/assets/:zoneId', async (req: Request, res: Response) => {
|
||||
/**
|
||||
* Get assets for a specific zone
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
app.get('/assets/zone/:zoneId', async (req: Request, res: Response) => {
|
||||
const zoneId = req.params.zoneId
|
||||
if(!zoneId || parseInt(zoneId) === 0) {
|
||||
return res.status(400).json({ message: 'Invalid zone ID' })
|
||||
@ -78,6 +71,11 @@ async function addHttpRoutes(app: Application) {
|
||||
]);
|
||||
})
|
||||
|
||||
/**
|
||||
* Get a specific asset
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
app.get('/assets/:type/:spriteId?/:file', (req: Request, res: Response) => {
|
||||
const assetType = req.params.type
|
||||
const spriteId = req.params.spriteId
|
||||
@ -91,18 +89,23 @@ async function addHttpRoutes(app: Application) {
|
||||
}
|
||||
|
||||
if (!fs.existsSync(assetPath)) {
|
||||
console.error(`File not found: ${assetPath}`)
|
||||
logger.error(`File not found: ${assetPath}`)
|
||||
return res.status(404).send('Asset not found')
|
||||
}
|
||||
|
||||
res.sendFile(assetPath, (err) => {
|
||||
if (err) {
|
||||
console.error('Error sending file:', err)
|
||||
logger.error('Error sending file:', err)
|
||||
res.status(500).send('Error downloading the asset')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Login
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
app.post('/login', async (req: Request, res: Response) => {
|
||||
const { username, password } = req.body
|
||||
|
||||
@ -123,6 +126,11 @@ async function addHttpRoutes(app: Application) {
|
||||
return res.status(400).json({ message: 'Failed to login' })
|
||||
})
|
||||
|
||||
/**
|
||||
* Register
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
app.post('/register', async (req: Request, res: Response) => {
|
||||
const { username, password } = req.body
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user