@opengis/gis 0.2.176 → 0.2.178

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/README.md +181 -181
  2. package/dist/{CardIcon-c1Q2M3wQ.js → CardIcon-CMRD1LLh.js} +1 -1
  3. package/dist/{EntityTablePage-B5gpkH4S.js → EntityTablePage-XNNCltAN.js} +2 -2
  4. package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-DnGSvmMU.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BqUjKTDY.js} +1 -1
  5. package/dist/{HeaderActions.vue_vue_type_script_setup_true_lang-C2B61JP6.js → HeaderActions.vue_vue_type_script_setup_true_lang-BXQ3hKwa.js} +1 -1
  6. package/dist/{MapSettings-6-Xru5Q8.js → MapSettings-P3h-vHn3.js} +2 -2
  7. package/dist/{RastersTablePage-CXNOcTy-.js → RastersTablePage-DnhGZLiH.js} +2 -2
  8. package/dist/{cartocss-BFVqWvfP.js → cartocss-BkrOeQg4.js} +6 -6
  9. package/dist/{import-utils-uxk4LdUJ.js → import-utils-BCATsbB5.js} +1 -1
  10. package/dist/{index-CahlV-Xs.js → index-cUagVqgA.js} +39 -39
  11. package/dist/index.css +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.umd.cjs +5 -5
  14. package/dist/{raster-CEi56f0P.js → raster-CP0tUp3j.js} +3 -3
  15. package/dist/{register-NFAGBNa3.js → register-Cr-uQcby.js} +3 -3
  16. package/dist/{service-BYspag8U.js → service-DwJaKrOd.js} +6 -6
  17. package/dist/{vs-datatable-CHcBr6zy.js → vs-datatable-B9WoVk-b.js} +2 -2
  18. package/module/gis/cls/service_type.json +42 -42
  19. package/module/gis/form/gis.registers.form.json +127 -127
  20. package/module/test/map/addr.json +302 -302
  21. package/module/test/map/addr1.yml +23 -23
  22. package/module/test/select/address.str_id.sql +3 -3
  23. package/package.json +77 -77
  24. package/plugin.js +64 -64
  25. package/server/migrations/array_intersect.sql +13 -13
  26. package/server/migrations/cartocss.sql +27 -27
  27. package/server/migrations/group_list.sql +74 -74
  28. package/server/migrations/maps.sql +30 -30
  29. package/server/migrations/metadata.sql +415 -415
  30. package/server/migrations/ogc.sql +106 -106
  31. package/server/migrations/rasters.sql +265 -265
  32. package/server/migrations/services.sql +247 -247
  33. package/server/migrations/services_users_rel.sql +22 -22
  34. package/server/migrations/widgets.sql +20 -20
  35. package/server/plugins/crons.js +21 -21
  36. package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
  37. package/server/plugins/mapnik/funcs/mapnik.js +151 -151
  38. package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
  39. package/server/plugins/mapnik/map.proto +437 -437
  40. package/server/plugins/vite.js +74 -74
  41. package/server/routes/cartocss/cartocss.route.js +31 -31
  42. package/server/routes/cartocss/cartocss.route.test.js +78 -78
  43. package/server/routes/cartocss/cartocss.schema.js +73 -73
  44. package/server/routes/cartocss/functions/add.cartocss.js +39 -39
  45. package/server/routes/cartocss/functions/get.cartocss.js +57 -57
  46. package/server/routes/gis/functions/checkXML.js +107 -107
  47. package/server/routes/gis/functions/dashboard.js +24 -24
  48. package/server/routes/gis/gis.route.js +26 -26
  49. package/server/routes/gis/gis.route.test.js +33 -33
  50. package/server/routes/map/functions/clearTiles.js +35 -35
  51. package/server/routes/map/functions/geojson.js +187 -187
  52. package/server/routes/map/functions/gis.convert.js +65 -65
  53. package/server/routes/map/functions/gis.icon.js +220 -220
  54. package/server/routes/map/functions/jsonData.js +206 -206
  55. package/server/routes/map/functions/layerList.js +102 -102
  56. package/server/routes/map/functions/map.js +122 -122
  57. package/server/routes/map/functions/mapCatalog.js +72 -72
  58. package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
  59. package/server/routes/map/functions/mapFeatures.js +133 -133
  60. package/server/routes/map/functions/mapFormat.js +232 -232
  61. package/server/routes/map/functions/mapTiles.js +162 -162
  62. package/server/routes/map/functions/maps.js +15 -15
  63. package/server/routes/map/functions/marker_icon.js +43 -43
  64. package/server/routes/map/functions/parseGeoFile.js +85 -85
  65. package/server/routes/map/functions/pointHeight.js +51 -51
  66. package/server/routes/map/functions/vtile.js +174 -174
  67. package/server/routes/map/functions/vtile1.js +185 -185
  68. package/server/routes/map/map.route.js +280 -280
  69. package/server/routes/map/map.route.test.js +503 -503
  70. package/server/routes/map/map.schema.js +356 -356
  71. package/server/routes/map/pin/circle1.svg +76 -76
  72. package/server/routes/map/pin/circle2.svg +18 -18
  73. package/server/routes/map/pin/none.svg +12 -12
  74. package/server/routes/map/pin/pin.svg +14 -14
  75. package/server/routes/map/pin/pin1.svg +16 -16
  76. package/server/routes/map/pin/pin2.svg +7 -7
  77. package/server/routes/map/pin/pin3.svg +34 -34
  78. package/server/routes/map/pin/pin4.svg +14 -14
  79. package/server/routes/map/pin/pin5.svg +7 -7
  80. package/server/routes/map/pin/pin6.svg +12 -12
  81. package/server/routes/map/pin/pin7.svg +12 -12
  82. package/server/routes/mapnik/functions/cartoBounds.js +32 -32
  83. package/server/routes/mapnik/functions/clearTiles.js +103 -103
  84. package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
  85. package/server/routes/mapnik/functions/createXml.js +76 -76
  86. package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
  87. package/server/routes/mapnik/functions/fileSearch.js +35 -35
  88. package/server/routes/mapnik/functions/fileStat.js +28 -28
  89. package/server/routes/mapnik/functions/pretile.js +138 -138
  90. package/server/routes/mapnik/functions/rasterInfo.js +66 -66
  91. package/server/routes/mapnik/functions/readDir.js +22 -22
  92. package/server/routes/mapnik/functions/rtile.js +164 -164
  93. package/server/routes/mapnik/functions/uploadRaster.js +152 -152
  94. package/server/routes/mapnik/functions/uploadXML.js +140 -140
  95. package/server/routes/mapnik/mapnik.route.js +102 -102
  96. package/server/routes/mapnik/mapnik.route.test.js +370 -370
  97. package/server/routes/mapnik/mapnik.schema.mjs +195 -195
  98. package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
  99. package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
  100. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
  101. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
  102. package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
  103. package/server/routes/maps/functions/add.map.js +42 -42
  104. package/server/routes/maps/functions/del.map.js +17 -17
  105. package/server/routes/maps/functions/get.map.js +119 -119
  106. package/server/routes/maps/maps.route.js +58 -58
  107. package/server/routes/maps/maps.route.test.js +231 -231
  108. package/server/routes/maps/maps.schema.js +9 -9
  109. package/server/routes/metadata/functions/editMetadata.js +35 -35
  110. package/server/routes/metadata/functions/metadataXML.js +19 -19
  111. package/server/routes/metadata/metadata.route.js +26 -26
  112. package/server/routes/metadata/metadata.route.test.js +46 -46
  113. package/server/routes/metadata/metadata.schema.js +53 -53
  114. package/server/routes/ogc/functions/map.info.point.js +117 -117
  115. package/server/routes/ogc/ogc.route.js +21 -21
  116. package/server/routes/ogc/ogc.route.test.js +53 -53
  117. package/server/routes/ogc/ogc.schema.js +16 -16
  118. package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
  119. package/server/routes/permissions/functions/catalog.permissions.js +12 -12
  120. package/server/routes/permissions/functions/get.permissions.js +59 -59
  121. package/server/routes/permissions/functions/gis.catalog.js +80 -80
  122. package/server/routes/permissions/permissions.route.js +35 -35
  123. package/server/routes/permissions/permissions.route.test.js +35 -35
  124. package/server/routes/permissions/permissions.schema.js +43 -43
  125. package/server/routes/registers/functions/add.registry.js +37 -37
  126. package/server/routes/registers/functions/classifiers.js +100 -100
  127. package/server/routes/registers/functions/columns.js +3 -3
  128. package/server/routes/registers/functions/content.type.js +9 -9
  129. package/server/routes/registers/functions/del.registry.js +14 -14
  130. package/server/routes/registers/functions/get.info.js +93 -93
  131. package/server/routes/registers/functions/getFilterSQLParametrized/formatValue.js +312 -0
  132. package/server/routes/registers/functions/getFilterSQLParametrized/getFilterQuery.js +126 -0
  133. package/server/routes/registers/functions/getFilterSQLParametrized/getRangeQuery.js +353 -0
  134. package/server/routes/registers/functions/getFilterSQLParametrized/index.js +81 -0
  135. package/server/routes/registers/functions/getTableColumnMeta.js +125 -0
  136. package/server/routes/registers/functions/gis.export.js +159 -159
  137. package/server/routes/registers/functions/gis.registry.js +71 -71
  138. package/server/routes/registers/functions/gis.registry.list.js +61 -61
  139. package/server/routes/registers/functions/gis.suggest.js +275 -0
  140. package/server/routes/registers/functions/handleRegistryRequest.js +175 -147
  141. package/server/routes/registers/functions/map.registry.js +87 -87
  142. package/server/routes/registers/registers.route.js +91 -80
  143. package/server/routes/registers/registers.route.test.js +173 -144
  144. package/server/routes/registers/registers.schema.js +275 -246
  145. package/server/routes/root.mjs +3 -3
  146. package/server/routes/services/functions/add.service.js +62 -62
  147. package/server/routes/services/functions/create.route.js +93 -93
  148. package/server/routes/services/functions/del.service.js +12 -12
  149. package/server/routes/services/functions/get.layer.geom.js +27 -27
  150. package/server/routes/services/functions/get.service.users.js +76 -76
  151. package/server/routes/services/functions/get.services.col.js +34 -34
  152. package/server/routes/services/functions/get.services.js +89 -89
  153. package/server/routes/services/functions/legend.auto.js +77 -77
  154. package/server/routes/services/services.route.js +76 -76
  155. package/server/routes/services/services.route.test.js +167 -167
  156. package/server/routes/services/services.schema.js +285 -278
  157. package/server/routes/widgets/functions/add.widget.js +38 -38
  158. package/server/routes/widgets/functions/del.widget.js +17 -17
  159. package/server/routes/widgets/functions/get.widget.js +41 -41
  160. package/server/routes/widgets/widgets.route.js +61 -61
  161. package/server/routes/widgets/widgets.route.test.js +144 -144
  162. package/server/routes/widgets/widgets.schema.js +24 -24
  163. package/server/shared/listFiles.js +14 -14
  164. package/utils.js +13 -13
@@ -1,371 +1,371 @@
1
- import { readFile } from 'fs/promises';
2
-
3
- import {
4
- describe, test, expect, beforeAll, afterAll
5
- } from 'vitest';
6
-
7
- import { config, getPGAsync, isFileExists, uploadFile } from '@opengis/fastify-table/utils.js';
8
-
9
- import { build, injectWithHeaders } from '../../../test/helper.js';
10
-
11
- const user = { uid: '2', type: 'admin' };
12
-
13
- const testId = 'testRasterId';
14
-
15
- const rasterRelPath = 'test/files/black1x1.tif';
16
-
17
- let pg;
18
-
19
- const cleanUp = async (when) => {
20
- if (!pg) return;
21
- const rowCount = await pg.query('delete from gis.rasters where raster_id=$1', [testId]).then(r => r.rowCount);
22
- console.log(`clean up ${when} finished`, rowCount);
23
- }
24
-
25
- beforeAll(async () => {
26
- await build();
27
- pg = await getPGAsync();
28
- expect(pg).toHaveProperty('pk');
29
- await cleanUp('before');
30
-
31
- const exists = await isFileExists('/files/temp/black1x1.tif');
32
- if (!exists && config.s3) {
33
- // upload raster to s3
34
- const buffer = await readFile(rasterRelPath);
35
- await uploadFile('/files/test/black1x1.tif', buffer);
36
- }
37
-
38
- await pg.query('insert into gis.rasters (raster_id,name,source_path) values($1,$2,$3)', [testId, 'unit-test', '/files/test/black1x1.tif']).catch(err => console.error(err));
39
- });
40
-
41
- afterAll(async () => {
42
- await cleanUp('after');
43
- });
44
-
45
- test('GET /gis-upload-raster/:id (restrict unauthorized)', async () => {
46
- const res = await injectWithHeaders({
47
- method: 'GET',
48
- url: `/api/gis-upload-raster/${testId}`,
49
- });
50
- expect(res.statusCode).toBe(403);
51
- });
52
-
53
- if (config.s3) {
54
- describe('upload raster from s3 to mapnik for processing / tile generation', () => {
55
- test('GET /gis-upload-raster/:id', async () => {
56
- const res = await injectWithHeaders({
57
- method: 'GET',
58
- url: `/api/gis-upload-raster/${testId}`,
59
- headers: { uid: user.uid, user_type: 'regular' },
60
- });
61
- expect(res.statusCode).toBe(200);
62
- expect(res.body).not.toHaveProperty('error');
63
- });
64
- });
65
- }
66
-
67
- test('GET /gis-xml/:id', async () => {
68
- const res = await injectWithHeaders({
69
- method: 'GET',
70
- url: `/api/gis-xml/${testId}`,
71
- query: { nocache: 1 }
72
- });
73
- expect(res.statusCode).toBe(200);
74
- });
75
-
76
- describe('GET /gis-rtile', async () => {
77
- test('WEBP from raster', async () => {
78
- const res = await injectWithHeaders({
79
- method: 'GET',
80
- url: `/api/gis-rtile/${testId}/10/523/391.webp`,
81
- });
82
-
83
- expect(res.statusCode).toBe(200);
84
- expect(res.headers['content-type']).toMatch(/image\/webp/);
85
- expect(res.body.length).toBeGreaterThan(200);
86
- });
87
-
88
- const cartocssId = await pg.query('select cartocss_id from gis.cartocss where config is not null and style is not null and source_path is not null and geom is not null and enabled limit 1').then(r => r.rows?.[0]?.cartocss_id);
89
- expect(cartocssId).toBeTypeOf('string');
90
-
91
- test('WEBP from cartocss', async () => {
92
- const res = await injectWithHeaders({
93
- method: 'GET',
94
- url: `/api/gis-rtile/${cartocssId}/10/523/391.webp`,
95
- });
96
-
97
- expect(res.statusCode).toBe(200);
98
- expect(res.headers['content-type']).toMatch(/image\/webp/);
99
- expect(res.body.length).toBeGreaterThan(200);
100
- });
101
- });
102
-
103
- describe('GET /gis-raster/:id', () => {
104
- test('returns raster metadata', async () => {
105
- const res = await injectWithHeaders({
106
- method: 'GET',
107
- url: `/api/gis-raster/${testId}`,
108
- });
109
- expect(res.statusCode).toBe(200);
110
-
111
- const body = res.json();
112
-
113
- expect(body).toHaveProperty('total_size');
114
- expect(typeof body.total_size).toBe('string');
115
-
116
- expect(body).toHaveProperty('extension');
117
- expect(typeof body.extension).toBe('string');
118
-
119
- expect(body).toHaveProperty('srid');
120
- expect(typeof body.srid).toBe('string');
121
-
122
- expect(body).toHaveProperty('proj4');
123
- if (!body.srid) {
124
- expect(typeof body.proj4).toBe('string');
125
- }
126
-
127
- expect(body).toHaveProperty('extent');
128
- expect(Array.isArray(body.extent)).toBe(true);
129
- body.extent.forEach(val => expect(typeof val).toBe('number'));
130
-
131
- expect(body).toHaveProperty('files');
132
- expect(Array.isArray(body.files)).toBe(true);
133
- // Optional: check FileItem structure
134
- if (body.files.length) {
135
- const fileItem = body.files[0];
136
- expect(fileItem).toHaveProperty('name');
137
- expect(fileItem).toHaveProperty('size');
138
- }
139
-
140
- expect(body).toHaveProperty('width');
141
- expect(typeof body.width).toBe('string');
142
-
143
- expect(body).toHaveProperty('height');
144
- expect(typeof body.height).toBe('string');
145
-
146
- expect(body).toHaveProperty('bands_count');
147
- expect(typeof body.bands_count).toBe('string');
148
-
149
- expect(body).toHaveProperty('resolution');
150
- expect(typeof body.resolution).toBe('string');
151
-
152
- expect(body).toHaveProperty('bands');
153
- expect(Array.isArray(body.bands)).toBe(true);
154
- body.bands.forEach(b => expect(typeof b).toBe('string'));
155
-
156
- expect(body).toHaveProperty('color_depth');
157
- expect(typeof body.color_depth).toBe('string');
158
-
159
- expect(body).toHaveProperty('compression');
160
- expect(typeof body.compression).toBe('string');
161
- });
162
- });
163
-
164
- describe('Create xml for all rasters without existing one', () => {
165
- test('GET /gis-create-xml/:id? (restrict unauthorized)', async () => {
166
- const res = await injectWithHeaders({
167
- method: 'GET',
168
- url: `/api/gis-create-xml`,
169
- });
170
- expect(res.statusCode).toBe(403);
171
- });
172
- test('GET /gis-create-xml/:id?', async () => {
173
- const res = await injectWithHeaders({
174
- method: 'GET',
175
- url: `/api/gis-create-xml`,
176
- headers: { uid: user.uid, user_type: user.type },
177
- });
178
- expect(res.statusCode).toBe(200);
179
- expect(res.body).toBe('all finished');
180
- });
181
- });
182
-
183
- describe('GIS File system API', () => {
184
- test('lists directory (restrict unauthorized)', async () => {
185
- const res = await injectWithHeaders({
186
- method: 'GET',
187
- url: '/api/gis-files',
188
- });
189
- expect(res.statusCode).toBe(403);
190
- });
191
-
192
- test('lists directory (restrict non-admin)', async () => {
193
- const res = await injectWithHeaders({
194
- method: 'GET',
195
- url: '/api/gis-files',
196
- headers: { uid: user.uid, user_type: 'regular' },
197
- });
198
- expect(res.statusCode).toBe(403);
199
- });
200
-
201
- test('lists directory', async () => {
202
- const res = await injectWithHeaders({
203
- method: 'GET',
204
- url: '/api/gis-files',
205
- headers: { uid: user.uid, user_type: user.type },
206
- });
207
- expect(res.statusCode).toBe(200);
208
-
209
- const body = res.json();
210
- expect(body).toHaveProperty('exists');
211
- expect(body).toHaveProperty('count');
212
- expect(body).toHaveProperty('data');
213
- expect(Array.isArray(body.data)).toBe(true);
214
- expect(body.data[0]).toHaveProperty('name');
215
- expect(body.data[0]).toHaveProperty('type');
216
- expect(body.data[0]).toHaveProperty('size');
217
- });
218
-
219
- test('search files by key (restrict unauthorized)', async () => {
220
- const res = await injectWithHeaders({
221
- method: 'GET',
222
- url: '/api/gis-file-search?key=tif',
223
- });
224
- expect(res.statusCode).toBe(403);
225
- });
226
-
227
- test('search files by key (restrict non-admin)', async () => {
228
- const res = await injectWithHeaders({
229
- method: 'GET',
230
- url: '/api/gis-file-search?key=tif',
231
- headers: { uid: user.uid, user_type: 'regular' },
232
- });
233
- expect(res.statusCode).toBe(403);
234
- });
235
-
236
- test('search files by key', async () => {
237
- const res = await injectWithHeaders({
238
- method: 'GET',
239
- url: '/api/gis-file-search?key=tif',
240
- headers: { uid: user.uid, user_type: user.type },
241
- });
242
- expect(res.statusCode).toBe(200);
243
-
244
- const body = res.json();
245
-
246
- expect(Array.isArray(body.data)).toBe(true);
247
- });
248
-
249
- test('gets file info', async () => {
250
- const res = await injectWithHeaders({
251
- method: 'GET',
252
- url: '/api/gis-file-search?key=tif',
253
- headers: { uid: user.uid, user_type: user.type },
254
- });
255
- expect(res.statusCode).toBe(200);
256
-
257
- const body1 = res.json();
258
-
259
- const { dir, name: rasterName } = body1.data.find(el => el.name.endsWith('.tif'));
260
- expect(rasterName).toBeTypeOf('string');
261
- const rasterPath = [dir, rasterName].filter(Boolean).join('/');
262
-
263
- // unauthorized
264
- const res1 = await injectWithHeaders({
265
- method: 'GET',
266
- url: '/api/gis-file-info',
267
- query: {
268
- path: rasterPath
269
- }
270
- });
271
- expect(res1.statusCode).toBe(403);
272
-
273
- // non-admin
274
- const res2 = await injectWithHeaders({
275
- method: 'GET',
276
- url: '/api/gis-file-info',
277
- query: {
278
- path: rasterPath
279
- },
280
- headers: { uid: user.uid, user_type: 'regular' },
281
- });
282
- expect(res2.statusCode).toBe(403);
283
-
284
- const res3 = await injectWithHeaders({
285
- method: 'GET',
286
- url: '/api/gis-file-info',
287
- query: {
288
- path: rasterPath
289
- },
290
- headers: { uid: user.uid, user_type: user.type },
291
- });
292
- expect(res3.statusCode).toBe(200);
293
-
294
- const body = res3.json().data;
295
-
296
- expect(body).toHaveProperty('exists');
297
- // expect(body.exists).toBeTruthy();
298
- expect(body.exists).toBeOneOf([true, false]);
299
- expect(body).toHaveProperty('size');
300
- expect(body).toHaveProperty('mdate');
301
- expect(body).toHaveProperty('adate');
302
- expect(body).toHaveProperty('cdate');
303
- expect(body).toHaveProperty('name');
304
- });
305
-
306
- test('search files by size', async () => {
307
- const res = await injectWithHeaders({
308
- method: 'GET',
309
- url: '/api/gis-file-search?size=1024',
310
- headers: { uid: user.uid, user_type: user.type },
311
- });
312
-
313
- expect(res.statusCode).toBe(200);
314
- });
315
-
316
- test('search files by period', async () => {
317
- const res = await injectWithHeaders({
318
- method: 'GET',
319
- url: '/api/gis-file-search?period=1w',
320
- headers: { uid: user.uid, user_type: user.type },
321
- });
322
-
323
- expect(res.statusCode).toBe(200);
324
- });
325
- });
326
-
327
- test('GET /gis-pretile/:id', async () => {
328
- // unaunthorized
329
- const res1 = await injectWithHeaders({
330
- method: 'GET',
331
- url: `/api/gis-pretile/${testId}`,
332
- query: { zoom: 13 }
333
- });
334
- expect(res1.statusCode).toBe(403);
335
-
336
- const res = await injectWithHeaders({
337
- method: 'GET',
338
- url: `/api/gis-pretile/${testId}`,
339
- query: { zoom: 13 },
340
- headers: { uid: user.uid, user_type: user.type },
341
- });
342
- expect(res.statusCode).toBe(200);
343
- expect(res.body).toBe('OK');
344
- });
345
-
346
- test('GET /gis-clear-rtile/:id', async () => {
347
- // unaunthorized
348
- const res1 = await injectWithHeaders({
349
- method: 'GET',
350
- url: `/api/gis-clear-rtile/${testId}`,
351
- });
352
- expect(res1.statusCode).toBe(403);
353
-
354
- // non-admin
355
- const res2 = await injectWithHeaders({
356
- method: 'GET',
357
- url: `/api/gis-clear-rtile/${testId}`,
358
- headers: { uid: user.uid, user_type: 'regular' },
359
- });
360
- expect(res2.statusCode).toBe(403);
361
-
362
- const res = await injectWithHeaders({
363
- method: 'GET',
364
- url: `/api/gis-clear-rtile/${testId}`,
365
- headers: { uid: user.uid, user_type: user.type },
366
- });
367
- const body = res.json();
368
-
369
- expect(['ok', 'skip', 'tiles directory not found']).toContain(body.message);
370
-
1
+ import { readFile } from 'fs/promises';
2
+
3
+ import {
4
+ describe, test, expect, beforeAll, afterAll
5
+ } from 'vitest';
6
+
7
+ import { config, getPGAsync, isFileExists, uploadFile } from '@opengis/fastify-table/utils.js';
8
+
9
+ import { build, injectWithHeaders } from '../../../test/helper.js';
10
+
11
+ const user = { uid: '2', type: 'admin' };
12
+
13
+ const testId = 'testRasterId';
14
+
15
+ const rasterRelPath = 'test/files/black1x1.tif';
16
+
17
+ let pg;
18
+
19
+ const cleanUp = async (when) => {
20
+ if (!pg) return;
21
+ const rowCount = await pg.query('delete from gis.rasters where raster_id=$1', [testId]).then(r => r.rowCount);
22
+ console.log(`clean up ${when} finished`, rowCount);
23
+ }
24
+
25
+ beforeAll(async () => {
26
+ await build();
27
+ pg = await getPGAsync();
28
+ expect(pg).toHaveProperty('pk');
29
+ await cleanUp('before');
30
+
31
+ const exists = await isFileExists('/files/temp/black1x1.tif');
32
+ if (!exists && config.s3) {
33
+ // upload raster to s3
34
+ const buffer = await readFile(rasterRelPath);
35
+ await uploadFile('/files/test/black1x1.tif', buffer);
36
+ }
37
+
38
+ await pg.query('insert into gis.rasters (raster_id,name,source_path) values($1,$2,$3)', [testId, 'unit-test', '/files/test/black1x1.tif']).catch(err => console.error(err));
39
+ });
40
+
41
+ afterAll(async () => {
42
+ await cleanUp('after');
43
+ });
44
+
45
+ test('GET /gis-upload-raster/:id (restrict unauthorized)', async () => {
46
+ const res = await injectWithHeaders({
47
+ method: 'GET',
48
+ url: `/api/gis-upload-raster/${testId}`,
49
+ });
50
+ expect(res.statusCode).toBe(403);
51
+ });
52
+
53
+ if (config.s3) {
54
+ describe('upload raster from s3 to mapnik for processing / tile generation', () => {
55
+ test('GET /gis-upload-raster/:id', async () => {
56
+ const res = await injectWithHeaders({
57
+ method: 'GET',
58
+ url: `/api/gis-upload-raster/${testId}`,
59
+ headers: { uid: user.uid, user_type: 'regular' },
60
+ });
61
+ expect(res.statusCode).toBe(200);
62
+ expect(res.body).not.toHaveProperty('error');
63
+ });
64
+ });
65
+ }
66
+
67
+ test('GET /gis-xml/:id', async () => {
68
+ const res = await injectWithHeaders({
69
+ method: 'GET',
70
+ url: `/api/gis-xml/${testId}`,
71
+ query: { nocache: 1 }
72
+ });
73
+ expect(res.statusCode).toBe(200);
74
+ });
75
+
76
+ describe('GET /gis-rtile', async () => {
77
+ test('WEBP from raster', async () => {
78
+ const res = await injectWithHeaders({
79
+ method: 'GET',
80
+ url: `/api/gis-rtile/${testId}/10/523/391.webp`,
81
+ });
82
+
83
+ expect(res.statusCode).toBe(200);
84
+ expect(res.headers['content-type']).toMatch(/image\/webp/);
85
+ expect(res.body.length).toBeGreaterThan(200);
86
+ });
87
+
88
+ const cartocssId = await pg.query('select cartocss_id from gis.cartocss where config is not null and style is not null and source_path is not null and geom is not null and enabled limit 1').then(r => r.rows?.[0]?.cartocss_id);
89
+ expect(cartocssId).toBeTypeOf('string');
90
+
91
+ test('WEBP from cartocss', async () => {
92
+ const res = await injectWithHeaders({
93
+ method: 'GET',
94
+ url: `/api/gis-rtile/${cartocssId}/10/523/391.webp`,
95
+ });
96
+
97
+ expect(res.statusCode).toBe(200);
98
+ expect(res.headers['content-type']).toMatch(/image\/webp/);
99
+ expect(res.body.length).toBeGreaterThan(200);
100
+ });
101
+ });
102
+
103
+ describe('GET /gis-raster/:id', () => {
104
+ test('returns raster metadata', async () => {
105
+ const res = await injectWithHeaders({
106
+ method: 'GET',
107
+ url: `/api/gis-raster/${testId}`,
108
+ });
109
+ expect(res.statusCode).toBe(200);
110
+
111
+ const body = res.json();
112
+
113
+ expect(body).toHaveProperty('total_size');
114
+ expect(typeof body.total_size).toBe('string');
115
+
116
+ expect(body).toHaveProperty('extension');
117
+ expect(typeof body.extension).toBe('string');
118
+
119
+ expect(body).toHaveProperty('srid');
120
+ expect(typeof body.srid).toBe('string');
121
+
122
+ expect(body).toHaveProperty('proj4');
123
+ if (!body.srid) {
124
+ expect(typeof body.proj4).toBe('string');
125
+ }
126
+
127
+ expect(body).toHaveProperty('extent');
128
+ expect(Array.isArray(body.extent)).toBe(true);
129
+ body.extent.forEach(val => expect(typeof val).toBe('number'));
130
+
131
+ expect(body).toHaveProperty('files');
132
+ expect(Array.isArray(body.files)).toBe(true);
133
+ // Optional: check FileItem structure
134
+ if (body.files.length) {
135
+ const fileItem = body.files[0];
136
+ expect(fileItem).toHaveProperty('name');
137
+ expect(fileItem).toHaveProperty('size');
138
+ }
139
+
140
+ expect(body).toHaveProperty('width');
141
+ expect(typeof body.width).toBe('string');
142
+
143
+ expect(body).toHaveProperty('height');
144
+ expect(typeof body.height).toBe('string');
145
+
146
+ expect(body).toHaveProperty('bands_count');
147
+ expect(typeof body.bands_count).toBe('string');
148
+
149
+ expect(body).toHaveProperty('resolution');
150
+ expect(typeof body.resolution).toBe('string');
151
+
152
+ expect(body).toHaveProperty('bands');
153
+ expect(Array.isArray(body.bands)).toBe(true);
154
+ body.bands.forEach(b => expect(typeof b).toBe('string'));
155
+
156
+ expect(body).toHaveProperty('color_depth');
157
+ expect(typeof body.color_depth).toBe('string');
158
+
159
+ expect(body).toHaveProperty('compression');
160
+ expect(typeof body.compression).toBe('string');
161
+ });
162
+ });
163
+
164
+ describe('Create xml for all rasters without existing one', () => {
165
+ test('GET /gis-create-xml/:id? (restrict unauthorized)', async () => {
166
+ const res = await injectWithHeaders({
167
+ method: 'GET',
168
+ url: `/api/gis-create-xml`,
169
+ });
170
+ expect(res.statusCode).toBe(403);
171
+ });
172
+ test('GET /gis-create-xml/:id?', async () => {
173
+ const res = await injectWithHeaders({
174
+ method: 'GET',
175
+ url: `/api/gis-create-xml`,
176
+ headers: { uid: user.uid, user_type: user.type },
177
+ });
178
+ expect(res.statusCode).toBe(200);
179
+ expect(res.body).toBe('all finished');
180
+ });
181
+ });
182
+
183
+ describe('GIS File system API', () => {
184
+ test('lists directory (restrict unauthorized)', async () => {
185
+ const res = await injectWithHeaders({
186
+ method: 'GET',
187
+ url: '/api/gis-files',
188
+ });
189
+ expect(res.statusCode).toBe(403);
190
+ });
191
+
192
+ test('lists directory (restrict non-admin)', async () => {
193
+ const res = await injectWithHeaders({
194
+ method: 'GET',
195
+ url: '/api/gis-files',
196
+ headers: { uid: user.uid, user_type: 'regular' },
197
+ });
198
+ expect(res.statusCode).toBe(403);
199
+ });
200
+
201
+ test('lists directory', async () => {
202
+ const res = await injectWithHeaders({
203
+ method: 'GET',
204
+ url: '/api/gis-files',
205
+ headers: { uid: user.uid, user_type: user.type },
206
+ });
207
+ expect(res.statusCode).toBe(200);
208
+
209
+ const body = res.json();
210
+ expect(body).toHaveProperty('exists');
211
+ expect(body).toHaveProperty('count');
212
+ expect(body).toHaveProperty('data');
213
+ expect(Array.isArray(body.data)).toBe(true);
214
+ expect(body.data[0]).toHaveProperty('name');
215
+ expect(body.data[0]).toHaveProperty('type');
216
+ expect(body.data[0]).toHaveProperty('size');
217
+ });
218
+
219
+ test('search files by key (restrict unauthorized)', async () => {
220
+ const res = await injectWithHeaders({
221
+ method: 'GET',
222
+ url: '/api/gis-file-search?key=tif',
223
+ });
224
+ expect(res.statusCode).toBe(403);
225
+ });
226
+
227
+ test('search files by key (restrict non-admin)', async () => {
228
+ const res = await injectWithHeaders({
229
+ method: 'GET',
230
+ url: '/api/gis-file-search?key=tif',
231
+ headers: { uid: user.uid, user_type: 'regular' },
232
+ });
233
+ expect(res.statusCode).toBe(403);
234
+ });
235
+
236
+ test('search files by key', async () => {
237
+ const res = await injectWithHeaders({
238
+ method: 'GET',
239
+ url: '/api/gis-file-search?key=tif',
240
+ headers: { uid: user.uid, user_type: user.type },
241
+ });
242
+ expect(res.statusCode).toBe(200);
243
+
244
+ const body = res.json();
245
+
246
+ expect(Array.isArray(body.data)).toBe(true);
247
+ });
248
+
249
+ test('gets file info', async () => {
250
+ const res = await injectWithHeaders({
251
+ method: 'GET',
252
+ url: '/api/gis-file-search?key=tif',
253
+ headers: { uid: user.uid, user_type: user.type },
254
+ });
255
+ expect(res.statusCode).toBe(200);
256
+
257
+ const body1 = res.json();
258
+
259
+ const { dir, name: rasterName } = body1.data.find(el => el.name.endsWith('.tif'));
260
+ expect(rasterName).toBeTypeOf('string');
261
+ const rasterPath = [dir, rasterName].filter(Boolean).join('/');
262
+
263
+ // unauthorized
264
+ const res1 = await injectWithHeaders({
265
+ method: 'GET',
266
+ url: '/api/gis-file-info',
267
+ query: {
268
+ path: rasterPath
269
+ }
270
+ });
271
+ expect(res1.statusCode).toBe(403);
272
+
273
+ // non-admin
274
+ const res2 = await injectWithHeaders({
275
+ method: 'GET',
276
+ url: '/api/gis-file-info',
277
+ query: {
278
+ path: rasterPath
279
+ },
280
+ headers: { uid: user.uid, user_type: 'regular' },
281
+ });
282
+ expect(res2.statusCode).toBe(403);
283
+
284
+ const res3 = await injectWithHeaders({
285
+ method: 'GET',
286
+ url: '/api/gis-file-info',
287
+ query: {
288
+ path: rasterPath
289
+ },
290
+ headers: { uid: user.uid, user_type: user.type },
291
+ });
292
+ expect(res3.statusCode).toBe(200);
293
+
294
+ const body = res3.json().data;
295
+
296
+ expect(body).toHaveProperty('exists');
297
+ // expect(body.exists).toBeTruthy();
298
+ expect(body.exists).toBeOneOf([true, false]);
299
+ expect(body).toHaveProperty('size');
300
+ expect(body).toHaveProperty('mdate');
301
+ expect(body).toHaveProperty('adate');
302
+ expect(body).toHaveProperty('cdate');
303
+ expect(body).toHaveProperty('name');
304
+ });
305
+
306
+ test('search files by size', async () => {
307
+ const res = await injectWithHeaders({
308
+ method: 'GET',
309
+ url: '/api/gis-file-search?size=1024',
310
+ headers: { uid: user.uid, user_type: user.type },
311
+ });
312
+
313
+ expect(res.statusCode).toBe(200);
314
+ });
315
+
316
+ test('search files by period', async () => {
317
+ const res = await injectWithHeaders({
318
+ method: 'GET',
319
+ url: '/api/gis-file-search?period=1w',
320
+ headers: { uid: user.uid, user_type: user.type },
321
+ });
322
+
323
+ expect(res.statusCode).toBe(200);
324
+ });
325
+ });
326
+
327
+ test('GET /gis-pretile/:id', async () => {
328
+ // unaunthorized
329
+ const res1 = await injectWithHeaders({
330
+ method: 'GET',
331
+ url: `/api/gis-pretile/${testId}`,
332
+ query: { zoom: 13 }
333
+ });
334
+ expect(res1.statusCode).toBe(403);
335
+
336
+ const res = await injectWithHeaders({
337
+ method: 'GET',
338
+ url: `/api/gis-pretile/${testId}`,
339
+ query: { zoom: 13 },
340
+ headers: { uid: user.uid, user_type: user.type },
341
+ });
342
+ expect(res.statusCode).toBe(200);
343
+ expect(res.body).toBe('OK');
344
+ });
345
+
346
+ test('GET /gis-clear-rtile/:id', async () => {
347
+ // unaunthorized
348
+ const res1 = await injectWithHeaders({
349
+ method: 'GET',
350
+ url: `/api/gis-clear-rtile/${testId}`,
351
+ });
352
+ expect(res1.statusCode).toBe(403);
353
+
354
+ // non-admin
355
+ const res2 = await injectWithHeaders({
356
+ method: 'GET',
357
+ url: `/api/gis-clear-rtile/${testId}`,
358
+ headers: { uid: user.uid, user_type: 'regular' },
359
+ });
360
+ expect(res2.statusCode).toBe(403);
361
+
362
+ const res = await injectWithHeaders({
363
+ method: 'GET',
364
+ url: `/api/gis-clear-rtile/${testId}`,
365
+ headers: { uid: user.uid, user_type: user.type },
366
+ });
367
+ const body = res.json();
368
+
369
+ expect(['ok', 'skip', 'tiles directory not found']).toContain(body.message);
370
+
371
371
  });