signalk-flags 1.1.1 → 1.1.3
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 +15 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signalk-flags",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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
|
};
|
|
@@ -141,7 +132,10 @@ module.exports = (server) => {
|
|
|
141
132
|
return;
|
|
142
133
|
}
|
|
143
134
|
u.values.forEach((v) => {
|
|
144
|
-
if (v.path === '' &&
|
|
135
|
+
if (v.path === '' &&
|
|
136
|
+
v.value !== null &&
|
|
137
|
+
typeof v.value === 'object' &&
|
|
138
|
+
'mmsi' in v.value) {
|
|
145
139
|
// if doesn't already have flag property
|
|
146
140
|
const vf = server.getPath(`${context}.flag`);
|
|
147
141
|
if (!vf) {
|
|
@@ -174,7 +168,7 @@ module.exports = (server) => {
|
|
|
174
168
|
/**
|
|
175
169
|
* Check filesystem path(s)
|
|
176
170
|
*/
|
|
177
|
-
const initFs = () =>
|
|
171
|
+
const initFs = async () => {
|
|
178
172
|
const p = path_1.default.resolve(server.getDataDirPath()).split('/');
|
|
179
173
|
const sp = p.slice(0, p.indexOf('.signalk') + 1).join('/');
|
|
180
174
|
// dev env
|
|
@@ -182,7 +176,7 @@ module.exports = (server) => {
|
|
|
182
176
|
// prod env
|
|
183
177
|
const PRD_PATH = path_1.default.join(sp, 'node_modules', 'flag-icons', 'flags');
|
|
184
178
|
try {
|
|
185
|
-
|
|
179
|
+
await (0, promises_1.access)(PRD_PATH, fs_1.constants.W_OK | fs_1.constants.R_OK);
|
|
186
180
|
server.debug(`${PRD_PATH} - OK...Flag images found.`);
|
|
187
181
|
IMG_BASE_PATH = PRD_PATH;
|
|
188
182
|
}
|
|
@@ -190,7 +184,7 @@ module.exports = (server) => {
|
|
|
190
184
|
server.debug(`${PRD_PATH} does NOT exist!`);
|
|
191
185
|
server.debug(`Trying secondary path....${DEV_PATH}`);
|
|
192
186
|
try {
|
|
193
|
-
|
|
187
|
+
await (0, promises_1.access)(DEV_PATH, fs_1.constants.W_OK | fs_1.constants.R_OK);
|
|
194
188
|
server.debug(`${DEV_PATH} - OK...Flag images found.`);
|
|
195
189
|
IMG_BASE_PATH = DEV_PATH;
|
|
196
190
|
}
|
|
@@ -198,7 +192,7 @@ module.exports = (server) => {
|
|
|
198
192
|
server.debug(`${DEV_PATH} does NOT exist either!`);
|
|
199
193
|
}
|
|
200
194
|
}
|
|
201
|
-
}
|
|
195
|
+
};
|
|
202
196
|
/**
|
|
203
197
|
* Initialise flag resource endpoints
|
|
204
198
|
*/
|
|
@@ -218,11 +212,11 @@ module.exports = (server) => {
|
|
|
218
212
|
* @param aspect Aspect ratio default= '4x3'
|
|
219
213
|
* @returns svg file contents
|
|
220
214
|
*/
|
|
221
|
-
const iconFromCountryCode =
|
|
215
|
+
const iconFromCountryCode = async (code, aspect = '4x3', res) => {
|
|
222
216
|
try {
|
|
223
217
|
const flag = `${IMG_BASE_PATH}/${aspect}/${code.toLowerCase()}.svg`;
|
|
224
218
|
// check flag file exists
|
|
225
|
-
|
|
219
|
+
await (0, promises_1.access)(flag, fs_1.constants.R_OK);
|
|
226
220
|
res.sendFile(flag, (err) => {
|
|
227
221
|
if (err) {
|
|
228
222
|
res.status(400).json({
|
|
@@ -241,18 +235,18 @@ module.exports = (server) => {
|
|
|
241
235
|
});
|
|
242
236
|
return;
|
|
243
237
|
}
|
|
244
|
-
}
|
|
238
|
+
};
|
|
245
239
|
/**
|
|
246
240
|
* Send flag derived from the supplied MMSI
|
|
247
241
|
* @param aspect Flag icon aspect ratio '1x1' or '4x3'
|
|
248
242
|
* @returns svg file contents
|
|
249
243
|
*/
|
|
250
|
-
const iconFromMmsi =
|
|
244
|
+
const iconFromMmsi = async (mmsi, aspect = '4x3', res) => {
|
|
251
245
|
try {
|
|
252
246
|
const country = countryFromMmsi(mmsi);
|
|
253
|
-
const flag = `${IMG_BASE_PATH}/${aspect}/${country
|
|
247
|
+
const flag = `${IMG_BASE_PATH}/${aspect}/${country?.alpha2.toLowerCase()}.svg`;
|
|
254
248
|
// check flag file exists
|
|
255
|
-
|
|
249
|
+
await (0, promises_1.access)(flag, fs_1.constants.R_OK);
|
|
256
250
|
res.sendFile(flag, (err) => {
|
|
257
251
|
if (err) {
|
|
258
252
|
res.status(400).json({
|
|
@@ -271,7 +265,7 @@ module.exports = (server) => {
|
|
|
271
265
|
});
|
|
272
266
|
return;
|
|
273
267
|
}
|
|
274
|
-
}
|
|
268
|
+
};
|
|
275
269
|
/**
|
|
276
270
|
* Get country details from supplied MMSI
|
|
277
271
|
* @param mmsi Maritime mobile service identifier
|