mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-03-28 11:39:26 +01:00
74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
import { MapService } from '#services/map_service'
|
|
import {
|
|
filenameParamValidator,
|
|
remoteDownloadValidator,
|
|
remoteDownloadValidatorOptional,
|
|
} from '#validators/common'
|
|
import { inject } from '@adonisjs/core'
|
|
import type { HttpContext } from '@adonisjs/core/http'
|
|
|
|
@inject()
|
|
export default class MapsController {
|
|
constructor(private mapService: MapService) {}
|
|
|
|
async index({ inertia }: HttpContext) {
|
|
return inertia.render('maps')
|
|
}
|
|
|
|
async checkBaseAssets({}: HttpContext) {
|
|
const exists = await this.mapService.checkBaseAssetsExist()
|
|
return { exists }
|
|
}
|
|
|
|
async downloadBaseAssets({ request }: HttpContext) {
|
|
const payload = await request.validateUsing(remoteDownloadValidatorOptional)
|
|
await this.mapService.downloadBaseAssets(payload.url)
|
|
return { success: true }
|
|
}
|
|
|
|
async downloadRemote({ request }: HttpContext) {
|
|
const payload = await request.validateUsing(remoteDownloadValidator)
|
|
const filename = await this.mapService.downloadRemote(payload.url)
|
|
return {
|
|
message: 'Download started successfully',
|
|
filename,
|
|
url: payload.url,
|
|
}
|
|
}
|
|
|
|
// For providing a "preflight" check in the UI before actually starting a background download
|
|
async downloadRemotePreflight({ request }: HttpContext) {
|
|
const payload = await request.validateUsing(remoteDownloadValidator)
|
|
const info = await this.mapService.downloadRemotePreflight(payload.url)
|
|
return info
|
|
}
|
|
|
|
async listRegions({}: HttpContext) {
|
|
return await this.mapService.listRegions()
|
|
}
|
|
|
|
async styles({ response }: HttpContext) {
|
|
const styles = await this.mapService.generateStylesJSON()
|
|
return response.json(styles)
|
|
}
|
|
|
|
async delete({ request, response }: HttpContext) {
|
|
const payload = await request.validateUsing(filenameParamValidator)
|
|
|
|
try {
|
|
await this.mapService.delete(payload.params.filename)
|
|
} catch (error) {
|
|
if (error.message === 'not_found') {
|
|
return response.status(404).send({
|
|
message: `Map file with key ${payload.params.filename} not found`,
|
|
})
|
|
}
|
|
throw error // Re-throw any other errors and let the global error handler catch
|
|
}
|
|
|
|
return {
|
|
message: 'Map file deleted successfully',
|
|
}
|
|
}
|
|
}
|