u-wave-announce 0.5.2 → 0.5.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 +1 -1
- package/src/plugin.js +22 -5
- package/src/signatures.js +2 -0
- package/test.js +2 -0
package/package.json
CHANGED
package/src/plugin.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
1
3
|
const { promisify } = require('util');
|
|
2
4
|
const randomBytes = promisify(require('crypto').randomBytes);
|
|
3
5
|
const fetch = require('node-fetch');
|
|
@@ -6,6 +8,16 @@ const debug = require('debug')('uwave:announce');
|
|
|
6
8
|
const sodium = require('./signatures');
|
|
7
9
|
const pkg = require('../package.json');
|
|
8
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Fallback logger implementation for üWave Core versions that do
|
|
13
|
+
* not come with a logger yet.
|
|
14
|
+
*/
|
|
15
|
+
const debugLogger = {
|
|
16
|
+
debug,
|
|
17
|
+
info: debug,
|
|
18
|
+
error: debug,
|
|
19
|
+
};
|
|
20
|
+
|
|
9
21
|
const optionsSchema = {
|
|
10
22
|
type: 'object',
|
|
11
23
|
title: 'Announce',
|
|
@@ -151,6 +163,11 @@ async function getOrGenerateSeed(uw) {
|
|
|
151
163
|
async function announcePlugin(uw, staticOptions) {
|
|
152
164
|
uw.config.register(optionsSchema['uw:key'], optionsSchema);
|
|
153
165
|
|
|
166
|
+
// üWave Core 0.5.0 and up have a `pino` logger
|
|
167
|
+
const logger = uw.logger
|
|
168
|
+
? uw.logger.child({ ns: 'uwave:announce' })
|
|
169
|
+
: debugLogger;
|
|
170
|
+
|
|
154
171
|
const seed = staticOptions.seed || await getOrGenerateSeed(uw);
|
|
155
172
|
// This takes up to a few 100 ms but it is a one-time startup cost…
|
|
156
173
|
// Maybe it makes sense to cache this, or to not block the rest of
|
|
@@ -160,17 +177,17 @@ async function announcePlugin(uw, staticOptions) {
|
|
|
160
177
|
async function announce() {
|
|
161
178
|
const options = await uw.config.get(optionsSchema['uw:key']);
|
|
162
179
|
if (typeof options !== 'object') {
|
|
163
|
-
debug('announcing not configured, skipping');
|
|
180
|
+
logger.debug('announcing not configured, skipping');
|
|
164
181
|
return;
|
|
165
182
|
}
|
|
166
183
|
if (!options.enabled) {
|
|
167
|
-
debug('announcing disabled, skipping');
|
|
184
|
+
logger.debug('announcing disabled, skipping');
|
|
168
185
|
return;
|
|
169
186
|
}
|
|
170
187
|
|
|
171
188
|
const hubHost = options.hub || 'https://announce.u-wave.net';
|
|
172
189
|
const announceUrl = `${stripSlashes(hubHost)}/announce/${Buffer.from(publicKey).toString('hex')}`;
|
|
173
|
-
|
|
190
|
+
logger.info('announcing to', announceUrl);
|
|
174
191
|
|
|
175
192
|
const announcement = await getAnnounceData(uw, options);
|
|
176
193
|
const data = JSON.stringify(announcement);
|
|
@@ -189,8 +206,8 @@ async function announcePlugin(uw, staticOptions) {
|
|
|
189
206
|
});
|
|
190
207
|
}
|
|
191
208
|
|
|
192
|
-
function onError(
|
|
193
|
-
|
|
209
|
+
function onError(error) {
|
|
210
|
+
logger.error({ err: error });
|
|
194
211
|
}
|
|
195
212
|
|
|
196
213
|
let interval;
|
package/src/signatures.js
CHANGED