Skip to content

Commit 12a6f22

Browse files
committed
feat: [wip] new maps system
1 parent bff5136 commit 12a6f22

38 files changed

+2150
-484
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { MapService } from '#services/map_service'
2+
import {
3+
filenameValidator,
4+
remoteDownloadValidator,
5+
remoteDownloadValidatorOptional,
6+
} from '#validators/common'
7+
import { inject } from '@adonisjs/core'
8+
import type { HttpContext } from '@adonisjs/core/http'
9+
10+
@inject()
11+
export default class MapsController {
12+
constructor(private mapService: MapService) {}
13+
14+
async index({ inertia }: HttpContext) {
15+
return inertia.render('maps')
16+
}
17+
18+
async checkBaseAssets({}: HttpContext) {
19+
const exists = await this.mapService.checkBaseAssetsExist()
20+
return { exists }
21+
}
22+
23+
async downloadBaseAssets({ request }: HttpContext) {
24+
const payload = await request.validateUsing(remoteDownloadValidatorOptional)
25+
await this.mapService.downloadBaseAssets(payload.url)
26+
return { success: true }
27+
}
28+
29+
async downloadRemote({ request }: HttpContext) {
30+
const payload = await request.validateUsing(remoteDownloadValidator)
31+
const filename = await this.mapService.downloadRemote(payload.url)
32+
return {
33+
message: 'Download started successfully',
34+
filename,
35+
url: payload.url,
36+
}
37+
}
38+
39+
async listRegions({}: HttpContext) {
40+
return await this.mapService.listRegions()
41+
}
42+
43+
async styles({ response }: HttpContext) {
44+
const styles = await this.mapService.generateStylesJSON()
45+
return response.json(styles)
46+
}
47+
48+
async delete({ request, response }: HttpContext) {
49+
const payload = await request.validateUsing(filenameValidator)
50+
51+
try {
52+
await this.mapService.delete(payload.filename)
53+
} catch (error) {
54+
if (error.message === 'not_found') {
55+
return response.status(404).send({
56+
message: `Map file with key ${payload.filename} not found`,
57+
})
58+
}
59+
throw error // Re-throw any other errors and let the global error handler catch
60+
}
61+
62+
return {
63+
message: 'Map file deleted successfully',
64+
}
65+
}
66+
}

admin/app/controllers/settings_controller.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MapService } from '#services/map_service';
12
import { SystemService } from '#services/system_service';
23
import { inject } from '@adonisjs/core';
34
import type { HttpContext } from '@adonisjs/core/http'
@@ -6,6 +7,7 @@ import type { HttpContext } from '@adonisjs/core/http'
67
export default class SettingsController {
78
constructor(
89
private systemService: SystemService,
10+
private mapService: MapService
911
) { }
1012

1113
async system({ inertia }: HttpContext) {
@@ -25,11 +27,22 @@ export default class SettingsController {
2527
}
2628
});
2729
}
28-
30+
2931
async legal({ inertia }: HttpContext) {
3032
return inertia.render('settings/legal');
3133
}
3234

35+
async maps({ inertia }: HttpContext) {
36+
const baseAssetsCheck = await this.mapService.checkBaseAssetsExist();
37+
const regionFiles = await this.mapService.listRegions();
38+
return inertia.render('settings/maps', {
39+
maps: {
40+
baseAssetsExist: baseAssetsCheck,
41+
regionFiles: regionFiles.files
42+
}
43+
});
44+
}
45+
3346
async zim({ inertia }: HttpContext) {
3447
return inertia.render('settings/zim/index')
3548
}
Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
1-
import { ZimService } from '#services/zim_service';
2-
import { inject } from '@adonisjs/core';
1+
import { ZimService } from '#services/zim_service'
2+
import { filenameValidator, remoteDownloadValidator } from '#validators/common'
3+
import { inject } from '@adonisjs/core'
34
import type { HttpContext } from '@adonisjs/core/http'
45

56
@inject()
67
export default class ZimController {
7-
constructor(
8-
private zimService: ZimService
9-
) { }
8+
constructor(private zimService: ZimService) {}
109

11-
async list({ }: HttpContext) {
12-
return await this.zimService.list();
13-
}
10+
async list({}: HttpContext) {
11+
return await this.zimService.list()
12+
}
1413

15-
async listRemote({ request }: HttpContext) {
16-
const { start = 0, count = 12 } = request.qs();
17-
return await this.zimService.listRemote({ start, count });
18-
}
14+
async listRemote({ request }: HttpContext) {
15+
const { start = 0, count = 12 } = request.qs()
16+
return await this.zimService.listRemote({ start, count })
17+
}
1918

20-
async downloadRemote({ request, response }: HttpContext) {
21-
const { url } = request.body()
22-
const filename = await this.zimService.downloadRemote(url);
19+
async downloadRemote({ request }: HttpContext) {
20+
const payload = await request.validateUsing(remoteDownloadValidator)
21+
const filename = await this.zimService.downloadRemote(payload.url)
2322

24-
response.status(200).send({
25-
message: 'Download started successfully',
26-
filename,
27-
url
28-
});
23+
return {
24+
message: 'Download started successfully',
25+
filename,
26+
url: payload.url,
27+
}
28+
}
29+
30+
async delete({ request, response }: HttpContext) {
31+
const payload = await request.validateUsing(filenameValidator)
32+
33+
try {
34+
await this.zimService.delete(payload.filename)
35+
} catch (error) {
36+
if (error.message === 'not_found') {
37+
return response.status(404).send({
38+
message: `ZIM file with key ${payload.filename} not found`,
39+
})
40+
}
41+
throw error // Re-throw any other errors and let the global error handler catch
2942
}
3043

31-
async delete({ request, response }: HttpContext) {
32-
const { key } = request.params();
33-
34-
try {
35-
await this.zimService.delete(key);
36-
} catch (error) {
37-
if (error.message === 'not_found') {
38-
return response.status(404).send({
39-
message: `ZIM file with key ${key} not found`
40-
});
41-
}
42-
throw error; // Re-throw any other errors and let the global error handler catch
43-
}
44-
45-
response.status(200).send({
46-
message: 'ZIM file deleted successfully'
47-
});
44+
return {
45+
message: 'ZIM file deleted successfully',
4846
}
49-
}
47+
}
48+
}

0 commit comments

Comments
 (0)