dotrino-content 0.3.7 → 0.3.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ops.js +13 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotrino-content",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Nodo de contenido del ecosistema Dotrino: guarda los bytes del usuario direccionados por su hash (cid), en su propia maquina y, si el dueno quiere, respaldados en su propio bucket (R2, Backblaze, Hetzner, Storj o S3). Lo publico sale por URL directa; lo privado, cifrado y solo por la red Dotrino.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/ops.js CHANGED
@@ -47,11 +47,24 @@ const fail = (rid, code, error) => ({ rid, ok: false, code, error })
47
47
  * llegue: ni campos de más ni textos sin fin.
48
48
  * @returns {{name?:string,title?:string,description?:string}|null}
49
49
  */
50
+ /** Cuántos enlaces lleva una tarjeta, y cuánto puede medir cada uno. */
51
+ const MAX_LINKS = 4
52
+ const MAX_LINK_LEN = 300
53
+
50
54
  function cleanMeta (src) {
51
55
  if (!src || typeof src !== 'object') return null
52
56
  const out = Object.fromEntries(['name', 'title', 'description']
53
57
  .map((k) => [k, typeof src[k] === 'string' ? src[k].trim().slice(0, 300) : null])
54
58
  .filter(([, v]) => v))
59
+ // Los ENLACES del contenido (en un eco, la fuente de la que habla). Solo http(s)
60
+ // y contados: `meta` lo escribe quien publica y la tarjeta lo pinta como `href`,
61
+ // así que aquí se filtra en vez de creerse.
62
+ const links = (Array.isArray(src.links) ? src.links : [])
63
+ .filter((u) => typeof u === 'string')
64
+ .map((u) => u.trim())
65
+ .filter((u) => /^https?:\/\//i.test(u) && u.length <= MAX_LINK_LEN)
66
+ .slice(0, MAX_LINKS)
67
+ if (links.length) out.links = links
55
68
  return Object.keys(out).length ? out : null
56
69
  }
57
70