signalk-flags 1.1.1 → 1.1.2
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.
- package/package.json +5 -5
- package/plugin/index.js +11 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signalk-flags",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Country Flags plugin for Signal K server.",
|
|
5
5
|
"main": "plugin/index.js",
|
|
6
6
|
"signalk": {
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
"build": "tsc",
|
|
20
20
|
"build-declaration": "tsc --declaration --allowJs false",
|
|
21
21
|
"watch": "npm run build -- -w",
|
|
22
|
-
"test": "
|
|
22
|
+
"test": "mocha",
|
|
23
23
|
"start": "npm run build -- -w",
|
|
24
24
|
"format": "prettier --write src/*",
|
|
25
|
-
"prepublishOnly": "tsc"
|
|
25
|
+
"prepublishOnly": "tsc",
|
|
26
|
+
"prepack": "tsc"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@signalk/server-api": "2.
|
|
29
|
+
"@signalk/server-api": "^2.30.0",
|
|
29
30
|
"flag-icons": "^7.3.2"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@types/baconjs": "^0.7.34",
|
|
33
33
|
"@types/express": "^5.0.6",
|
|
34
34
|
"prettier": "^3.8.4",
|
|
35
35
|
"typescript": "^6.0.3"
|
package/plugin/index.js
CHANGED
|
@@ -32,15 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
37
|
};
|
|
@@ -174,7 +165,7 @@ module.exports = (server) => {
|
|
|
174
165
|
/**
|
|
175
166
|
* Check filesystem path(s)
|
|
176
167
|
*/
|
|
177
|
-
const initFs = () =>
|
|
168
|
+
const initFs = async () => {
|
|
178
169
|
const p = path_1.default.resolve(server.getDataDirPath()).split('/');
|
|
179
170
|
const sp = p.slice(0, p.indexOf('.signalk') + 1).join('/');
|
|
180
171
|
// dev env
|
|
@@ -182,7 +173,7 @@ module.exports = (server) => {
|
|
|
182
173
|
// prod env
|
|
183
174
|
const PRD_PATH = path_1.default.join(sp, 'node_modules', 'flag-icons', 'flags');
|
|
184
175
|
try {
|
|
185
|
-
|
|
176
|
+
await (0, promises_1.access)(PRD_PATH, fs_1.constants.W_OK | fs_1.constants.R_OK);
|
|
186
177
|
server.debug(`${PRD_PATH} - OK...Flag images found.`);
|
|
187
178
|
IMG_BASE_PATH = PRD_PATH;
|
|
188
179
|
}
|
|
@@ -190,7 +181,7 @@ module.exports = (server) => {
|
|
|
190
181
|
server.debug(`${PRD_PATH} does NOT exist!`);
|
|
191
182
|
server.debug(`Trying secondary path....${DEV_PATH}`);
|
|
192
183
|
try {
|
|
193
|
-
|
|
184
|
+
await (0, promises_1.access)(DEV_PATH, fs_1.constants.W_OK | fs_1.constants.R_OK);
|
|
194
185
|
server.debug(`${DEV_PATH} - OK...Flag images found.`);
|
|
195
186
|
IMG_BASE_PATH = DEV_PATH;
|
|
196
187
|
}
|
|
@@ -198,7 +189,7 @@ module.exports = (server) => {
|
|
|
198
189
|
server.debug(`${DEV_PATH} does NOT exist either!`);
|
|
199
190
|
}
|
|
200
191
|
}
|
|
201
|
-
}
|
|
192
|
+
};
|
|
202
193
|
/**
|
|
203
194
|
* Initialise flag resource endpoints
|
|
204
195
|
*/
|
|
@@ -218,11 +209,11 @@ module.exports = (server) => {
|
|
|
218
209
|
* @param aspect Aspect ratio default= '4x3'
|
|
219
210
|
* @returns svg file contents
|
|
220
211
|
*/
|
|
221
|
-
const iconFromCountryCode =
|
|
212
|
+
const iconFromCountryCode = async (code, aspect = '4x3', res) => {
|
|
222
213
|
try {
|
|
223
214
|
const flag = `${IMG_BASE_PATH}/${aspect}/${code.toLowerCase()}.svg`;
|
|
224
215
|
// check flag file exists
|
|
225
|
-
|
|
216
|
+
await (0, promises_1.access)(flag, fs_1.constants.R_OK);
|
|
226
217
|
res.sendFile(flag, (err) => {
|
|
227
218
|
if (err) {
|
|
228
219
|
res.status(400).json({
|
|
@@ -241,18 +232,18 @@ module.exports = (server) => {
|
|
|
241
232
|
});
|
|
242
233
|
return;
|
|
243
234
|
}
|
|
244
|
-
}
|
|
235
|
+
};
|
|
245
236
|
/**
|
|
246
237
|
* Send flag derived from the supplied MMSI
|
|
247
238
|
* @param aspect Flag icon aspect ratio '1x1' or '4x3'
|
|
248
239
|
* @returns svg file contents
|
|
249
240
|
*/
|
|
250
|
-
const iconFromMmsi =
|
|
241
|
+
const iconFromMmsi = async (mmsi, aspect = '4x3', res) => {
|
|
251
242
|
try {
|
|
252
243
|
const country = countryFromMmsi(mmsi);
|
|
253
|
-
const flag = `${IMG_BASE_PATH}/${aspect}/${country
|
|
244
|
+
const flag = `${IMG_BASE_PATH}/${aspect}/${country?.alpha2.toLowerCase()}.svg`;
|
|
254
245
|
// check flag file exists
|
|
255
|
-
|
|
246
|
+
await (0, promises_1.access)(flag, fs_1.constants.R_OK);
|
|
256
247
|
res.sendFile(flag, (err) => {
|
|
257
248
|
if (err) {
|
|
258
249
|
res.status(400).json({
|
|
@@ -271,7 +262,7 @@ module.exports = (server) => {
|
|
|
271
262
|
});
|
|
272
263
|
return;
|
|
273
264
|
}
|
|
274
|
-
}
|
|
265
|
+
};
|
|
275
266
|
/**
|
|
276
267
|
* Get country details from supplied MMSI
|
|
277
268
|
* @param mmsi Maritime mobile service identifier
|