nixamp 0.11.0 → 0.11.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/dist/enrich.d.ts CHANGED
@@ -16,6 +16,12 @@ export declare const MIN_SCORE = 0.5;
16
16
  export declare const PREFIX_SCORE = 0.42;
17
17
  /** How many answers the cache keeps before the oldest go. */
18
18
  export declare const MAX_ENTRIES = 5000;
19
+ /**
20
+ * Which rules wrote the cache. Answers chosen by older rules are dropped on
21
+ * load: 0.11.0 remembered "Oppenheimer" as the row without the poster for
22
+ * seven days, and an update that chose better could not be seen through it.
23
+ */
24
+ export declare const CACHE_VERSION = 2;
19
25
  export type EnrichKind = "auto" | "title" | "channel" | "fixture";
20
26
  export interface Enriched {
21
27
  /** What nichedb says it is. */
package/dist/enrich.js CHANGED
@@ -34,6 +34,12 @@ export const MIN_SCORE = 0.5;
34
34
  export const PREFIX_SCORE = 0.42;
35
35
  /** How many answers the cache keeps before the oldest go. */
36
36
  export const MAX_ENTRIES = 5000;
37
+ /**
38
+ * Which rules wrote the cache. Answers chosen by older rules are dropped on
39
+ * load: 0.11.0 remembered "Oppenheimer" as the row without the poster for
40
+ * seven days, and an update that chose better could not be seen through it.
41
+ */
42
+ export const CACHE_VERSION = 2;
37
43
  /** The collection and kind a name is asked about, from what the caller knows. */
38
44
  export function whereToAsk(kind, parsedKind) {
39
45
  const k = kind === "auto" ? parsedKind ?? "" : kind;
@@ -79,11 +85,15 @@ export function pickBest(answer, asked) {
79
85
  (askedPlain.startsWith(`${titlePlain} `) || titlePlain.startsWith(`${askedPlain} `));
80
86
  if (!exact && score < (prefix ? PREFIX_SCORE : MIN_SCORE))
81
87
  continue;
82
- // An exact title beats any score; among the rest, the score decides.
88
+ // An exact title beats any score; among exact titles the one with a
89
+ // picture wins, since nichedb keeps both the IMDb row and the TMDB row of
90
+ // a film and only one has the poster; among the rest, the score decides.
83
91
  if (!best)
84
92
  best = item;
85
93
  else if (exact && !isExact(best))
86
94
  best = item;
95
+ else if (exact && isExact(best) && !best.image_url && item.image_url)
96
+ best = item;
87
97
  else if (!isExact(best) && score > Number(best.score ?? 0))
88
98
  best = item;
89
99
  }
@@ -213,7 +223,10 @@ export class Enricher {
213
223
  return;
214
224
  try {
215
225
  const parsed = JSON.parse(readFileSync(this.options.cacheFile, "utf8"));
216
- for (const [k, v] of Object.entries(parsed)) {
226
+ // A file from older rules is a file of answers those rules chose.
227
+ if (parsed.v !== CACHE_VERSION)
228
+ return;
229
+ for (const [k, v] of Object.entries(parsed.entries ?? {})) {
217
230
  if (v && typeof v.at === "number")
218
231
  this.cache.set(k, v);
219
232
  }
@@ -238,7 +251,7 @@ export class Enricher {
238
251
  try {
239
252
  mkdirSync(dirname(this.options.cacheFile), { recursive: true });
240
253
  const tmp = `${this.options.cacheFile}.tmp`;
241
- writeFileSync(tmp, JSON.stringify(Object.fromEntries(this.cache)));
254
+ writeFileSync(tmp, JSON.stringify({ v: CACHE_VERSION, entries: Object.fromEntries(this.cache) }));
242
255
  renameSync(tmp, this.options.cacheFile);
243
256
  this.dirty = false;
244
257
  }
package/dist/server.js CHANGED
@@ -2341,8 +2341,9 @@ export function createHandler(engine, options) {
2341
2341
  response.writeHead(200, {
2342
2342
  ...CORS,
2343
2343
  "content-type": "application/json; charset=utf-8",
2344
- // A miss is worth asking again in a few hours; a hit lasts the day.
2345
- "cache-control": match ? "public, max-age=3600" : "public, max-age=600",
2344
+ // Briefly: the server remembers for days, so the browser need not,
2345
+ // and an hour of browser cache hid a better answer for an hour.
2346
+ "cache-control": match ? "public, max-age=300" : "public, max-age=120",
2346
2347
  });
2347
2348
  response.end(JSON.stringify({ match }));
2348
2349
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nixamp",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "It really whips the terminal's ass. A Winamp-shaped audio player for your terminal.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/enrich.ts CHANGED
@@ -35,6 +35,12 @@ export const MIN_SCORE = 0.5;
35
35
  export const PREFIX_SCORE = 0.42;
36
36
  /** How many answers the cache keeps before the oldest go. */
37
37
  export const MAX_ENTRIES = 5000;
38
+ /**
39
+ * Which rules wrote the cache. Answers chosen by older rules are dropped on
40
+ * load: 0.11.0 remembered "Oppenheimer" as the row without the poster for
41
+ * seven days, and an update that chose better could not be seen through it.
42
+ */
43
+ export const CACHE_VERSION = 2;
38
44
 
39
45
  export type EnrichKind = "auto" | "title" | "channel" | "fixture";
40
46
 
@@ -126,9 +132,12 @@ export function pickBest(answer: MatchAnswer, asked: string): Enriched | null {
126
132
  askedPlain.length >= 4 &&
127
133
  (askedPlain.startsWith(`${titlePlain} `) || titlePlain.startsWith(`${askedPlain} `));
128
134
  if (!exact && score < (prefix ? PREFIX_SCORE : MIN_SCORE)) continue;
129
- // An exact title beats any score; among the rest, the score decides.
135
+ // An exact title beats any score; among exact titles the one with a
136
+ // picture wins, since nichedb keeps both the IMDb row and the TMDB row of
137
+ // a film and only one has the poster; among the rest, the score decides.
130
138
  if (!best) best = item;
131
139
  else if (exact && !isExact(best)) best = item;
140
+ else if (exact && isExact(best) && !best.image_url && item.image_url) best = item;
132
141
  else if (!isExact(best) && score > Number(best.score ?? 0)) best = item;
133
142
  }
134
143
  if (!best) return null;
@@ -260,8 +269,13 @@ export class Enricher {
260
269
  private load(): void {
261
270
  if (!this.options.cacheFile) return;
262
271
  try {
263
- const parsed = JSON.parse(readFileSync(this.options.cacheFile, "utf8")) as Record<string, Cached>;
264
- for (const [k, v] of Object.entries(parsed)) {
272
+ const parsed = JSON.parse(readFileSync(this.options.cacheFile, "utf8")) as {
273
+ v?: number;
274
+ entries?: Record<string, Cached>;
275
+ };
276
+ // A file from older rules is a file of answers those rules chose.
277
+ if (parsed.v !== CACHE_VERSION) return;
278
+ for (const [k, v] of Object.entries(parsed.entries ?? {})) {
265
279
  if (v && typeof v.at === "number") this.cache.set(k, v);
266
280
  }
267
281
  } catch {
@@ -284,7 +298,7 @@ export class Enricher {
284
298
  try {
285
299
  mkdirSync(dirname(this.options.cacheFile), { recursive: true });
286
300
  const tmp = `${this.options.cacheFile}.tmp`;
287
- writeFileSync(tmp, JSON.stringify(Object.fromEntries(this.cache)));
301
+ writeFileSync(tmp, JSON.stringify({ v: CACHE_VERSION, entries: Object.fromEntries(this.cache) }));
288
302
  renameSync(tmp, this.options.cacheFile);
289
303
  this.dirty = false;
290
304
  } catch (error) {
package/src/server.ts CHANGED
@@ -2815,8 +2815,9 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
2815
2815
  response.writeHead(200, {
2816
2816
  ...CORS,
2817
2817
  "content-type": "application/json; charset=utf-8",
2818
- // A miss is worth asking again in a few hours; a hit lasts the day.
2819
- "cache-control": match ? "public, max-age=3600" : "public, max-age=600",
2818
+ // Briefly: the server remembers for days, so the browser need not,
2819
+ // and an hour of browser cache hid a better answer for an hour.
2820
+ "cache-control": match ? "public, max-age=300" : "public, max-age=120",
2820
2821
  });
2821
2822
  response.end(JSON.stringify({ match }));
2822
2823
  return;
package/web/dist/sw.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* nixamp service worker — generated, do not edit */
2
- const CACHE = "nixamp-1789049456452";
2
+ const CACHE = "nixamp-1789050586501";
3
3
  const PRECACHE = [
4
4
  "/",
5
5
  "/apple-touch-icon.png",