@signalk/freeboard-sk 2.14.1 → 2.14.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/CHANGELOG.md +11 -0
- package/package.json +1 -1
- package/plugin/flags/flags-service.js +132 -0
- package/plugin/flags/mid.js +1745 -0
- package/public/{78.778bc513ef05d303.js → 78.d4c5c5157ba92d44.js} +1 -1
- package/public/assets/help/index.html +92 -20
- package/public/assets/img/{ais_active.svg → vessels/ais_active.svg} +5 -5
- package/public/assets/img/{ais_buddy.svg → vessels/ais_buddy.svg} +5 -5
- package/public/assets/img/{ais_cargo.svg → vessels/ais_cargo.svg} +5 -5
- package/public/assets/img/{ais_highspeed.svg → vessels/ais_highspeed.svg} +5 -5
- package/public/assets/img/{ais_inactive.svg → vessels/ais_inactive.svg} +5 -5
- package/public/assets/img/{ais_other.svg → vessels/ais_other.svg} +5 -5
- package/public/assets/img/{ais_passenger.svg → vessels/ais_passenger.svg} +5 -5
- package/public/assets/img/{ais_special.svg → vessels/ais_special.svg} +5 -5
- package/public/assets/img/{ais_tanker.svg → vessels/ais_tanker.svg} +5 -5
- package/public/index.html +1 -1
- package/public/main.6a114cd0db11071e.js +1 -0
- package/public/{runtime.967450e88d316117.js → runtime.6237108b22a63408.js} +1 -1
- package/public/main.1246be1fcbe738bc.js +0 -1
- /package/public/assets/img/{ais_flag.svg → vessels/ais_flag.svg} +0 -0
- /package/public/assets/img/{ais_self.png → vessels/ais_self.png} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# CHANGELOG: Freeboard
|
|
2
2
|
|
|
3
|
+
### v2.14.3
|
|
4
|
+
|
|
5
|
+
- **Fixed**: Only displaying on track on map when multiple selected. (#273)
|
|
6
|
+
- **Updated**: Vessel properties displays country flag _(requires `signalk-flags` plugin)_. (#253)
|
|
7
|
+
|
|
8
|
+
### v2.14.2
|
|
9
|
+
|
|
10
|
+
- **Update**: Hide More / Less buttoon when Alert does not have addittional properties (#272)
|
|
11
|
+
- **Fixed**: Refresh of charts list after the addition of a new chart source. (#266)
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
### v2.14.1
|
|
4
15
|
|
|
5
16
|
- **Fixed**: Unhandled error when Track resource has an undefined name property. (#262)
|
package/package.json
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initFlags = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const promises_1 = require("fs/promises");
|
|
6
|
+
const mid_1 = require("./mid");
|
|
7
|
+
let server;
|
|
8
|
+
let pluginId;
|
|
9
|
+
const FLAGS_API_PATH = '/signalk/v2/api/resources/flags';
|
|
10
|
+
let IMG_BASE_PATH = '';
|
|
11
|
+
const initFlags = (app, id) => {
|
|
12
|
+
server = app;
|
|
13
|
+
pluginId = id;
|
|
14
|
+
initFs();
|
|
15
|
+
initFlagsEndpoints();
|
|
16
|
+
};
|
|
17
|
+
exports.initFlags = initFlags;
|
|
18
|
+
// check path to flag resources
|
|
19
|
+
const initFs = async () => {
|
|
20
|
+
const p = __dirname.split('/');
|
|
21
|
+
const sp = p.slice(0, p.indexOf('plugin')).join('/');
|
|
22
|
+
IMG_BASE_PATH = `${sp}/node_modules/flag-icons/flags`;
|
|
23
|
+
try {
|
|
24
|
+
// check path exists
|
|
25
|
+
await (0, promises_1.access)(IMG_BASE_PATH, fs_1.constants.R_OK);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
server.setPluginError(`Flags path NOT found!`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const initFlagsEndpoints = () => {
|
|
32
|
+
server.debug(`** Registering Flag resources endpoint(s) **`);
|
|
33
|
+
server.get(`${FLAGS_API_PATH}`, async (req, res) => {
|
|
34
|
+
server.debug(`** ${req.method} ${req.path}`);
|
|
35
|
+
try {
|
|
36
|
+
const list = await listResponse();
|
|
37
|
+
res.status(200).json({
|
|
38
|
+
aspects: ['1x1', '4x3'],
|
|
39
|
+
flags: list
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
res.status(400).json({
|
|
44
|
+
state: 'FAILED',
|
|
45
|
+
statusCode: 400,
|
|
46
|
+
message: e.message
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
server.get(`${FLAGS_API_PATH}/mid/:mid`, (req, res) => {
|
|
51
|
+
server.debug(`** ${req.method} ${req.path}`);
|
|
52
|
+
iconByMid(req.params.mid, req.params.aspect, res);
|
|
53
|
+
});
|
|
54
|
+
server.get(`${FLAGS_API_PATH}/:aspect/:icon`, (req, res) => {
|
|
55
|
+
server.debug(`** ${req.method} ${req.path}`);
|
|
56
|
+
iconResponse(req.params.icon, req.params.aspect, res);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Build list of flag ids
|
|
61
|
+
* @param aspect Aspect ratio '1x1' or '4x3'
|
|
62
|
+
* @returns array of flag ids
|
|
63
|
+
*/
|
|
64
|
+
const listResponse = async (aspect = '1x1') => {
|
|
65
|
+
const entries = await (0, promises_1.readdir)(`${IMG_BASE_PATH}/${aspect}`, {
|
|
66
|
+
withFileTypes: true
|
|
67
|
+
});
|
|
68
|
+
return entries.map((entry) => {
|
|
69
|
+
if (entry.isFile()) {
|
|
70
|
+
return entry.name.split('.')[0];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Send file response for the specified flag id
|
|
76
|
+
* @param aspect Aspect ratio '1x1' or '4x3'
|
|
77
|
+
* @returns svg file contents
|
|
78
|
+
*/
|
|
79
|
+
const iconResponse = async (id, aspect = '1x1', res) => {
|
|
80
|
+
const flag = `${IMG_BASE_PATH}/${aspect}/${id}.svg`;
|
|
81
|
+
try {
|
|
82
|
+
// check path exists
|
|
83
|
+
await (0, promises_1.access)(flag, fs_1.constants.R_OK);
|
|
84
|
+
res.sendFile(flag, (err) => {
|
|
85
|
+
if (err) {
|
|
86
|
+
res.status(400).json({
|
|
87
|
+
state: 'FAILED',
|
|
88
|
+
statusCode: 400,
|
|
89
|
+
message: err.message
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
res.status(400).json({
|
|
96
|
+
state: 'FAILED',
|
|
97
|
+
statusCode: 400,
|
|
98
|
+
message: `Flag (${id}) NOT found!`
|
|
99
|
+
});
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Send file response for the supplied mid
|
|
105
|
+
* @param aspect Aspect ratio '1x1' or '4x3'
|
|
106
|
+
* @returns svg file contents
|
|
107
|
+
*/
|
|
108
|
+
const iconByMid = async (mid, aspect = '4x3', res) => {
|
|
109
|
+
const code = mid_1.MID[mid][0]?.toLowerCase();
|
|
110
|
+
const flag = `${IMG_BASE_PATH}/${aspect}/${code}.svg`;
|
|
111
|
+
try {
|
|
112
|
+
// check path exists
|
|
113
|
+
await (0, promises_1.access)(flag, fs_1.constants.R_OK);
|
|
114
|
+
res.sendFile(flag, (err) => {
|
|
115
|
+
if (err) {
|
|
116
|
+
res.status(400).json({
|
|
117
|
+
state: 'FAILED',
|
|
118
|
+
statusCode: 400,
|
|
119
|
+
message: err.message
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
res.status(400).json({
|
|
126
|
+
state: 'FAILED',
|
|
127
|
+
statusCode: 400,
|
|
128
|
+
message: `Flag (${mid}) NOT found!`
|
|
129
|
+
});
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
};
|