forked from noxious/server
120 lines
3.0 KiB
TypeScript
120 lines
3.0 KiB
TypeScript
import type { Request, Response } from 'express'
|
|
|
|
import { BaseController } from '@/application/base/baseController'
|
|
import CharacterHairRepository from '@/repositories/characterHairRepository'
|
|
import CharacterTypeRepository from '@/repositories/characterTypeRepository'
|
|
import MapObjectRepository from '@/repositories/mapObjectRepository'
|
|
import MapRepository from '@/repositories/mapRepository'
|
|
import SpriteRepository from '@/repositories/spriteRepository'
|
|
import TileRepository from '@/repositories/tileRepository'
|
|
|
|
export class CacheController extends BaseController {
|
|
/**
|
|
* Serve a list of tiles and send as JSON
|
|
* @param req
|
|
* @param res
|
|
*/
|
|
public async tiles(req: Request, res: Response) {
|
|
const items: any[] = []
|
|
|
|
const tileRepository = new TileRepository()
|
|
const tiles = await tileRepository.getAll()
|
|
|
|
for (const tile of tiles) {
|
|
items.push(await tile.cache())
|
|
}
|
|
|
|
return this.sendSuccess(res, items)
|
|
}
|
|
|
|
/**
|
|
* Serve a list of maps and send as JSON
|
|
* @param req
|
|
* @param res
|
|
*/
|
|
public async maps(req: Request, res: Response) {
|
|
const items: any[] = []
|
|
|
|
const mapRepository = new MapRepository()
|
|
const maps = await mapRepository.getAll()
|
|
|
|
for (const map of maps) {
|
|
items.push(await map.cache())
|
|
}
|
|
|
|
return this.sendSuccess(res, items)
|
|
}
|
|
|
|
/**
|
|
* Serve a list of map objects and send as JSON
|
|
* @param req
|
|
* @param res
|
|
*/
|
|
public async mapObjects(req: Request, res: Response) {
|
|
const items: any[] = []
|
|
|
|
const mapObjectRepository = new MapObjectRepository()
|
|
const mapObjects = await mapObjectRepository.getAll()
|
|
|
|
for (const mapObject of mapObjects) {
|
|
items.push(await mapObject.cache())
|
|
}
|
|
|
|
return this.sendSuccess(res, items)
|
|
}
|
|
|
|
/**
|
|
* Serve a list of character hairs and send as JSON
|
|
* @param req
|
|
* @param res
|
|
*/
|
|
public async characterHair(req: Request, res: Response) {
|
|
const items: any[] = []
|
|
|
|
const characterHairRepository = new CharacterHairRepository()
|
|
const characterHairs = await characterHairRepository.getAll()
|
|
|
|
for (const characterHair of characterHairs) {
|
|
items.push(await characterHair.cache())
|
|
}
|
|
|
|
return this.sendSuccess(res, items)
|
|
}
|
|
|
|
/**
|
|
* Serve a list of character types and send as JSON
|
|
* @param req
|
|
* @param res
|
|
*/
|
|
public async characterTypes(req: Request, res: Response) {
|
|
const items: any[] = []
|
|
|
|
const characterTypeRepository = new CharacterTypeRepository()
|
|
const characterTypes = await characterTypeRepository.getAll()
|
|
|
|
for (const characterType of characterTypes) {
|
|
items.push(await characterType.cache())
|
|
}
|
|
|
|
return this.sendSuccess(res, items)
|
|
}
|
|
|
|
/**
|
|
* Serve a list of sprites and send as JSON
|
|
* @param req
|
|
* @param res
|
|
*/
|
|
public async sprites(req: Request, res: Response) {
|
|
const items: any[] = []
|
|
|
|
const spriteRepository = new SpriteRepository()
|
|
const sprites = await spriteRepository.getAll()
|
|
|
|
for (const sprite of sprites) {
|
|
items.push(await sprite.cache())
|
|
}
|
|
|
|
return this.sendSuccess(res, items)
|
|
}
|
|
}
|