tokenwait 0.1.0 → 0.1.1
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/bin/status.js +2 -6
- package/lib/api.js +2 -1
- package/lib/util.js +17 -0
- package/package.json +1 -1
package/bin/status.js
CHANGED
|
@@ -29,17 +29,13 @@ function main() {
|
|
|
29
29
|
orig = (r.stdout || '').replace(/\s+$/, '');
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const { p, readJson,
|
|
32
|
+
const { p, readJson, adLine } = require('../lib/util');
|
|
33
33
|
const { pick } = require('../lib/rotation');
|
|
34
34
|
const worker = require('../lib/worker');
|
|
35
35
|
const ads = readJson(p('ads.json'), null);
|
|
36
36
|
const cfg = readJson(p('config.json'), {});
|
|
37
|
-
let line = '';
|
|
38
37
|
const ad = ads && pick(ads.ads, Date.now(), cfg.rotate_seconds || 30);
|
|
39
|
-
|
|
40
|
-
const host = hostOf(ad.url);
|
|
41
|
-
line = 'Sponsored · ' + ad.text + (host ? ' (' + host + ')' : '');
|
|
42
|
-
}
|
|
38
|
+
const line = adLine(ad, ads && ads.label);
|
|
43
39
|
if (worker.adsStale()) worker.spawnWorker();
|
|
44
40
|
|
|
45
41
|
let out;
|
package/lib/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
// Клиент API сервера. Ключ установки — ~/.tokenwait/credentials.json (права 600),
|
|
3
3
|
// общий для CLI и расширений IDE: одна машина = одна установка.
|
|
4
|
-
const { p, readJson, writeJson, DEFAULT_SERVER } = require('./util');
|
|
4
|
+
const { p, readJson, writeJson, DEFAULT_SERVER, adLabel } = require('./util');
|
|
5
5
|
const { normalizeAds } = require('./rotation');
|
|
6
6
|
|
|
7
7
|
class HttpError extends Error {
|
|
@@ -61,6 +61,7 @@ async function fetchAds() {
|
|
|
61
61
|
ttl_seconds: Math.min(Math.max(Number(r.ttl_seconds) || 600, 60), 3600),
|
|
62
62
|
impression_seconds: Math.min(Math.max(Number(r.impression_seconds) || 5, 1), 60),
|
|
63
63
|
report_seconds: Math.min(Math.max(Number(r.report_seconds) || 60, 30), 3600),
|
|
64
|
+
label: adLabel(r.label),
|
|
64
65
|
ads: normalizeAds(r.ads),
|
|
65
66
|
};
|
|
66
67
|
writeJson(p('ads.json'), data);
|
package/lib/util.js
CHANGED
|
@@ -5,6 +5,20 @@ const os = require('os');
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
|
|
7
7
|
const DEFAULT_SERVER = 'https://tokenwait.dev-line.workers.dev';
|
|
8
|
+
const DEFAULT_LABEL = 'TokenWait · Ad';
|
|
9
|
+
|
|
10
|
+
/** Подпись объявления: с сервера, но всегда с явной пометкой рекламы. */
|
|
11
|
+
function adLabel(label) {
|
|
12
|
+
const s = sanitizeText(label, 30) || DEFAULT_LABEL;
|
|
13
|
+
return /\b(ad|ads|sponsored|advert\w*|promo\w*)\b|реклам/i.test(s) ? s : s + ' · Ad';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Строка показа: «TokenWait · Ad · текст (сайт)». */
|
|
17
|
+
function adLine(ad, label) {
|
|
18
|
+
if (!ad || !ad.text) return '';
|
|
19
|
+
const host = hostOf(ad.url);
|
|
20
|
+
return adLabel(label) + ' · ' + ad.text + (host ? ' (' + host + ')' : '');
|
|
21
|
+
}
|
|
8
22
|
|
|
9
23
|
function home() {
|
|
10
24
|
return process.env.TOKENWAIT_HOME || path.join(os.homedir(), '.tokenwait');
|
|
@@ -168,6 +182,9 @@ function q(p) {
|
|
|
168
182
|
|
|
169
183
|
module.exports = {
|
|
170
184
|
DEFAULT_SERVER,
|
|
185
|
+
DEFAULT_LABEL,
|
|
186
|
+
adLabel,
|
|
187
|
+
adLine,
|
|
171
188
|
home,
|
|
172
189
|
p,
|
|
173
190
|
readJson,
|
package/package.json
CHANGED