@phosart/common 0.4.37 → 0.4.38

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.
@@ -1 +1 @@
1
- {"version":3,"file":"artist.d.ts","sourceRoot":"","sources":["../../src/lib/server/artist.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGxE,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC;AAEjE,wBAAsB,OAAO,yBAoB5B;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAetE"}
1
+ {"version":3,"file":"artist.d.ts","sourceRoot":"","sources":["../../src/lib/server/artist.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAKxE,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC;AAEjE,wBAAsB,OAAO,yBAoC5B;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAetE"}
@@ -3,9 +3,11 @@ import * as fs from 'node:fs/promises';
3
3
  import * as path from 'node:path';
4
4
  import * as yaml from 'yaml';
5
5
  import { Artist } from "./models/Artist.js";
6
- import { cacheVersion, getCache } from "./util.js";
6
+ import { cacheVersion, getCache, getLogLevel } from "./util.js";
7
7
  import { normalizeArtist } from "../util/art.js";
8
8
  import { galleries } from "./gallery.js";
9
+ import { Logger } from 'tslog';
10
+ const ArtistLog = new Logger({ minLevel: getLogLevel() });
9
11
  export async function artists() {
10
12
  const cached = getCache().artistCache;
11
13
  const nextVersion = await cacheVersion();
@@ -19,7 +21,21 @@ export async function artists() {
19
21
  catch {
20
22
  return {};
21
23
  }
22
- await Promise.all(Object.values(artists).map((v) => Artist.parseAsync(v)));
24
+ (await Promise.all(Object.values(artists).map((v) => Artist.parseAsync(v)))).map((a) => ({
25
+ ...a,
26
+ links: Object.fromEntries(Object.entries(a.links).map(([k, v]) => {
27
+ if (!v.includes('://')) {
28
+ v = 'https://' + v;
29
+ }
30
+ try {
31
+ v = new URL(v).toString();
32
+ }
33
+ catch (e) {
34
+ ArtistLog.error(`Failed to process URL for artist @${k}:`, e);
35
+ }
36
+ return [k, v];
37
+ }))
38
+ }));
23
39
  getCache().artistCache.cache = artists;
24
40
  getCache().artistCache.version = nextVersion;
25
41
  return artists;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phosart/common",
3
- "version": "0.4.37",
3
+ "version": "0.4.38",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",
@@ -4,9 +4,11 @@ import * as path from 'node:path';
4
4
  import * as yaml from 'yaml';
5
5
  import type { z } from 'zod';
6
6
  import { Artist } from './models/Artist.ts';
7
- import { cacheVersion, getCache } from './util.ts';
7
+ import { cacheVersion, getCache, getLogLevel } from './util.ts';
8
8
  import { normalizeArtist, type NormalizedArtist } from '../util/art.ts';
9
9
  import { galleries } from './gallery.ts';
10
+ import { Logger } from 'tslog';
11
+ const ArtistLog = new Logger({ minLevel: getLogLevel() });
10
12
 
11
13
  export type ArtistCache = Record<string, z.infer<typeof Artist>>;
12
14
 
@@ -25,7 +27,23 @@ export async function artists() {
25
27
  return {};
26
28
  }
27
29
 
28
- await Promise.all(Object.values(artists).map((v) => Artist.parseAsync(v)));
30
+ (await Promise.all(Object.values(artists).map((v) => Artist.parseAsync(v)))).map((a) => ({
31
+ ...a,
32
+ links: Object.fromEntries(
33
+ Object.entries(a.links).map(([k, v]) => {
34
+ if (!v.includes('://')) {
35
+ v = 'https://' + v;
36
+ }
37
+
38
+ try {
39
+ v = new URL(v).toString();
40
+ } catch (e: unknown) {
41
+ ArtistLog.error(`Failed to process URL for artist @${k}:`, e);
42
+ }
43
+ return [k, v];
44
+ })
45
+ )
46
+ }));
29
47
 
30
48
  getCache().artistCache.cache = artists;
31
49
  getCache().artistCache.version = nextVersion;