Merge remote-tracking branch 'origin/main' into feature/#182-reset-password
# Conflicts: # src/utilities/http.ts
This commit is contained in:
@ -6,7 +6,10 @@ import { loginAccountSchema, registerAccountSchema, resetPasswordSchema } from '
|
||||
import fs from 'fs'
|
||||
import { httpLogger } from './logger'
|
||||
import { getPublicPath } from './storage'
|
||||
import zoneRepository from '../repositories/zoneRepository'
|
||||
import TileRepository from '../repositories/tileRepository'
|
||||
import { AssetData } from './types'
|
||||
import ZoneRepository from '../repositories/zoneRepository'
|
||||
import SpriteRepository from '../repositories/spriteRepository'
|
||||
|
||||
async function addHttpRoutes(app: Application) {
|
||||
/**
|
||||
@ -87,37 +90,90 @@ async function addHttpRoutes(app: Application) {
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
// app.get('/assets/tiles/:zoneId', async (req: Request, res: Response) => {
|
||||
// const zoneId = req.params.zoneId
|
||||
//
|
||||
// // Check if zoneId is valid number
|
||||
// if (!zoneId || parseInt(zoneId) === 0) {
|
||||
// return res.status(400).json({ message: 'Invalid zone ID' })
|
||||
// }
|
||||
//
|
||||
// // Get zone by id
|
||||
// const zone = await zoneRepository.getById(parseInt(zoneId))
|
||||
// if (!zone) {
|
||||
// return res.status(404).json({ message: 'Zone not found' })
|
||||
// }
|
||||
//
|
||||
// let tiles = zone.tiles;
|
||||
//
|
||||
// // Convert to array
|
||||
// tiles = JSON.parse(JSON.stringify(tiles)) as string[]
|
||||
//
|
||||
// // Flatten the array
|
||||
// tiles = [...new Set(tiles.flat())]
|
||||
//
|
||||
// // Remove duplicates
|
||||
// tiles = tiles.filter((value, index, self) => self.indexOf(value) === index);
|
||||
//
|
||||
// // Return the array
|
||||
// res.json(tiles)
|
||||
// })
|
||||
app.get('/assets/list_tiles', async (req: Request, res: Response) => {
|
||||
// Get all tiles
|
||||
let assets: AssetData[] = []
|
||||
const tiles = await TileRepository.getAll()
|
||||
for (const tile of tiles) {
|
||||
assets.push({
|
||||
key: tile.id,
|
||||
data: '/assets/tiles/' + tile.id + '.png',
|
||||
group: 'tiles',
|
||||
updatedAt: tile.updatedAt
|
||||
} as AssetData)
|
||||
}
|
||||
|
||||
// Return the array
|
||||
res.json(assets)
|
||||
})
|
||||
|
||||
/**
|
||||
* Get a specific asset
|
||||
* Get all tiles from a zone and serve as AssetData array
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
app.get('/assets/list_tiles/:zoneId', async (req: Request, res: Response) => {
|
||||
const zoneId = req.params.zoneId
|
||||
|
||||
// Check if zoneId is valid number
|
||||
if (!zoneId || parseInt(zoneId) === 0) {
|
||||
return res.status(400).json({ message: 'Invalid zone ID' })
|
||||
}
|
||||
|
||||
// Get zone by id
|
||||
const zone = await ZoneRepository.getById(parseInt(zoneId))
|
||||
if (!zone) {
|
||||
return res.status(404).json({ message: 'Zone not found' })
|
||||
}
|
||||
|
||||
// Get all tiles
|
||||
let assets: AssetData[] = []
|
||||
const tiles = await TileRepository.getByZoneId(parseInt(zoneId))
|
||||
for (const tile of tiles) {
|
||||
assets.push({
|
||||
key: tile.id,
|
||||
data: '/assets/tiles/' + tile.id + '.png',
|
||||
group: 'tiles',
|
||||
updatedAt: tile.updatedAt
|
||||
} as AssetData)
|
||||
}
|
||||
|
||||
// Return the array
|
||||
res.json(assets)
|
||||
})
|
||||
|
||||
app.get('/assets/list_sprite_actions/:spriteId', async (req: Request, res: Response) => {
|
||||
const spriteId = req.params.spriteId
|
||||
// Check if spriteId is valid number
|
||||
if (!spriteId || parseInt(spriteId) === 0) {
|
||||
return res.status(400).json({ message: 'Invalid sprite ID' })
|
||||
}
|
||||
// Get sprite by id
|
||||
const sprite = await SpriteRepository.getById(spriteId)
|
||||
if (!sprite) {
|
||||
return res.status(404).json({ message: 'Sprite not found' })
|
||||
}
|
||||
|
||||
let assets: AssetData[] = []
|
||||
sprite.spriteActions.forEach((spriteAction) => {
|
||||
assets.push({
|
||||
key: sprite.id + '-' + spriteAction.action,
|
||||
data: '/assets/sprites/' + sprite.id + '/' + spriteAction.action + '.png',
|
||||
group: spriteAction.isAnimated ? 'sprite_animations' : 'sprites',
|
||||
updatedAt: sprite.updatedAt,
|
||||
isAnimated: spriteAction.isAnimated,
|
||||
frameCount: JSON.parse(JSON.stringify(spriteAction.sprites)).length,
|
||||
frameWidth: spriteAction.frameWidth,
|
||||
frameHeight: spriteAction.frameHeight
|
||||
})
|
||||
})
|
||||
|
||||
// Return the array
|
||||
res.json(assets)
|
||||
})
|
||||
|
||||
/**
|
||||
* Download asset file
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
|
Reference in New Issue
Block a user