@seedprotocol/feed 0.4.21 → 0.4.22
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/getFeedItems.d.ts.map +1 -1
- package/dist/hydrateArweaveRichText.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1136 -993
- package/dist/index.js.map +1 -1
- package/dist/rss/generateRssXml.d.ts.map +1 -1
- package/dist/services/arweaveImageService.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { BaseArweaveClient as
|
|
2
|
-
import { classifyMediaRef as
|
|
3
|
-
import { gql as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { generateJsonFeed as
|
|
7
|
-
import { create as
|
|
8
|
-
import { createHash as
|
|
9
|
-
import { promises as
|
|
10
|
-
import { join as
|
|
11
|
-
import
|
|
1
|
+
import { BaseArweaveClient as _e, isKnownArweaveGatewayHostname as Ve, getSeedsBySchemaName as Ke, withExcludeRevokedFilter as Ie, EasClient as $e, getItemVersionsFromEas as Ye, getItemPropertiesFromEas as qe, pickLatestPropertyAttestationsByRefAndSchema as Ze, setSchemaUidForSchemaDefinition as Qe, DEFAULT_ARWEAVE_GATEWAYS as Me, ensureReadGatewaySelected as et, client as L, DEFAULT_ARWEAVE_HOST as tt } from "@seedprotocol/sdk";
|
|
2
|
+
import { classifyMediaRef as En, getFeedItemStringField as _n, normalizeFeedItemFields as In, resolveMediaRef as $n } from "@seedprotocol/sdk";
|
|
3
|
+
import { gql as nt } from "graphql-request";
|
|
4
|
+
import U from "pluralize";
|
|
5
|
+
import rt from "rss-parser";
|
|
6
|
+
import { generateJsonFeed as ot, generateAtomFeed as st } from "feedsmith";
|
|
7
|
+
import { create as at } from "xmlbuilder2";
|
|
8
|
+
import { createHash as it } from "crypto";
|
|
9
|
+
import { promises as E } from "fs";
|
|
10
|
+
import { join as F } from "path";
|
|
11
|
+
import ue from "image-size";
|
|
12
12
|
function j(t) {
|
|
13
|
-
return `https://${
|
|
13
|
+
return `https://${_e.getHost()}/${t}`;
|
|
14
14
|
}
|
|
15
15
|
function G() {
|
|
16
|
-
const t = process.env.FEED_ITEM_URL_BASE?.trim() || "https://optimism-sepolia.easscan.org", e = process.env.FEED_ITEM_URL_PATH?.trim() || "attestation/view", n = process.env.FEED_SITE_URL?.trim() || "https://seedprotocol.io", s = process.env.FEED_EXPAND_RELATIONS?.toLowerCase() !== "false",
|
|
17
|
-
return { itemUrlBase: t, itemUrlPath: e, siteUrl: n, expandRelations: s, pageSize:
|
|
16
|
+
const t = process.env.FEED_ITEM_URL_BASE?.trim() || "https://optimism-sepolia.easscan.org", e = process.env.FEED_ITEM_URL_PATH?.trim() || "attestation/view", n = process.env.FEED_SITE_URL?.trim() || "https://seedprotocol.io", s = process.env.FEED_EXPAND_RELATIONS?.toLowerCase() !== "false", o = parseInt(process.env.FEED_PAGE_SIZE || "25", 10), i = process.env.FEED_INCLUDE_DATA_URI_HTML_ITEMS?.toLowerCase() === "true" ? "include_items" : "omit_items";
|
|
17
|
+
return { itemUrlBase: t, itemUrlPath: e, siteUrl: n, expandRelations: s, pageSize: o, richTextDataUriImages: i };
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
function
|
|
21
|
-
const e =
|
|
19
|
+
const ct = /^(.+?)([A-Z][a-zA-Z]+)Ids$/;
|
|
20
|
+
function le(t) {
|
|
21
|
+
const e = ct.exec(t);
|
|
22
22
|
if (e) {
|
|
23
23
|
const n = e[1];
|
|
24
|
-
if (n) return
|
|
24
|
+
if (n) return U(n);
|
|
25
25
|
}
|
|
26
26
|
if (t.endsWith("_ids")) {
|
|
27
27
|
const n = t.slice(0, -4), s = n.split("_").filter(Boolean);
|
|
28
28
|
if (s.length >= 2) {
|
|
29
|
-
const
|
|
30
|
-
return
|
|
29
|
+
const o = s[0];
|
|
30
|
+
return o.endsWith("s") ? o : U(o);
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return U(n);
|
|
33
33
|
}
|
|
34
34
|
return t;
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function Fe(t, e) {
|
|
37
37
|
for (const n of Object.keys(t))
|
|
38
|
-
n !== e &&
|
|
38
|
+
n !== e && le(n) === e && delete t[n];
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function be(t) {
|
|
41
41
|
if (Array.isArray(t) || typeof t != "string") return t;
|
|
42
42
|
const e = t.trim();
|
|
43
43
|
if (!e.startsWith("[")) return t;
|
|
@@ -48,7 +48,7 @@ function Ie(t) {
|
|
|
48
48
|
}
|
|
49
49
|
return t;
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function lt(t) {
|
|
52
52
|
const e = t.storageTransactionId ?? t.storage_transaction_id;
|
|
53
53
|
if (e && typeof e == "string" && e.trim())
|
|
54
54
|
try {
|
|
@@ -56,52 +56,52 @@ function tt(t) {
|
|
|
56
56
|
} catch {
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
const
|
|
60
|
-
function
|
|
59
|
+
const dt = /* @__PURE__ */ new Set(["html", "file", "json"]), Ue = "_feedFieldStorageModels", ve = "_feedListElementStorageModels";
|
|
60
|
+
function Q(t) {
|
|
61
61
|
return t.trim().toLowerCase();
|
|
62
62
|
}
|
|
63
63
|
function B(t) {
|
|
64
|
-
return
|
|
64
|
+
return dt.has(Q(t));
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
const e =
|
|
66
|
+
function he(t) {
|
|
67
|
+
const e = Q(t);
|
|
68
68
|
return e === "html" ? 0 : e === "file" ? 1 : e === "json" ? 2 : 99;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
const e = t[
|
|
70
|
+
function ee(t) {
|
|
71
|
+
const e = t[Ue];
|
|
72
72
|
if (e !== null && typeof e == "object" && !Array.isArray(e))
|
|
73
73
|
return e;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
76
|
-
const e = t[
|
|
75
|
+
function te(t) {
|
|
76
|
+
const e = t[ve];
|
|
77
77
|
if (e !== null && typeof e == "object" && !Array.isArray(e))
|
|
78
78
|
return e;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
const s =
|
|
82
|
-
let
|
|
83
|
-
|
|
80
|
+
function ge(t, e, n) {
|
|
81
|
+
const s = Q(n);
|
|
82
|
+
let o = ee(t);
|
|
83
|
+
o || (o = {}, t[Ue] = o), o[e] = s;
|
|
84
84
|
}
|
|
85
|
-
function
|
|
86
|
-
let s =
|
|
87
|
-
s || (s = {}, t[
|
|
85
|
+
function ft(t, e, n) {
|
|
86
|
+
let s = te(t);
|
|
87
|
+
s || (s = {}, t[ve] = s), s[e] = n.map(Q);
|
|
88
88
|
}
|
|
89
|
-
const
|
|
90
|
-
function
|
|
89
|
+
const ut = ["html", "Html", "body", "Body", "content", "Content"], ht = 8e6;
|
|
90
|
+
function xe(t) {
|
|
91
91
|
const e = t.trim();
|
|
92
92
|
if (!e.startsWith("http://") && !e.startsWith("https://")) return !1;
|
|
93
93
|
try {
|
|
94
|
-
const n = new URL(e), s = n.hostname.toLowerCase(),
|
|
95
|
-
if (s !==
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
98
|
-
const
|
|
99
|
-
return /^[A-Za-z0-9_-]{43}$/.test(
|
|
94
|
+
const n = new URL(e), s = n.hostname.toLowerCase(), o = _e.getHost().toLowerCase();
|
|
95
|
+
if (s !== o && !Ve(s)) return !1;
|
|
96
|
+
const i = n.pathname.replace(/^\//, "").split("/").filter(Boolean);
|
|
97
|
+
if (i.length !== 1) return !1;
|
|
98
|
+
const r = i[0];
|
|
99
|
+
return /^[A-Za-z0-9_-]{43}$/.test(r);
|
|
100
100
|
} catch {
|
|
101
101
|
return !1;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
async function
|
|
104
|
+
async function ke(t) {
|
|
105
105
|
try {
|
|
106
106
|
const e = await fetch(t, {
|
|
107
107
|
headers: { Accept: "text/html, text/plain, text/markdown, application/json, */*" },
|
|
@@ -111,58 +111,58 @@ async function Fe(t) {
|
|
|
111
111
|
const n = e.headers.get("content-type") ?? "";
|
|
112
112
|
if (/^(image|video|audio)\//i.test(n)) return null;
|
|
113
113
|
const s = await e.arrayBuffer();
|
|
114
|
-
if (s.byteLength >
|
|
115
|
-
const
|
|
116
|
-
return
|
|
114
|
+
if (s.byteLength > ht) return null;
|
|
115
|
+
const o = new TextDecoder("utf-8", { fatal: !1 }).decode(s);
|
|
116
|
+
return o.length === 0 || o.includes("\0") ? null : o;
|
|
117
117
|
} catch {
|
|
118
118
|
return null;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
async function
|
|
121
|
+
async function gt(t, e) {
|
|
122
122
|
const n = t[e];
|
|
123
|
-
if (typeof n != "string" || n.trim() === "" || !
|
|
124
|
-
const s = await
|
|
123
|
+
if (typeof n != "string" || n.trim() === "" || !xe(n)) return;
|
|
124
|
+
const s = await ke(n);
|
|
125
125
|
s !== null && (t[e] = s);
|
|
126
126
|
}
|
|
127
|
-
async function
|
|
127
|
+
async function pt(t) {
|
|
128
128
|
for (const e of t) {
|
|
129
|
-
const n = /* @__PURE__ */ new Set([...
|
|
129
|
+
const n = /* @__PURE__ */ new Set([...ut]), s = ee(e);
|
|
130
130
|
if (s)
|
|
131
|
-
for (const [
|
|
132
|
-
B(
|
|
133
|
-
for (const
|
|
134
|
-
await
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
137
|
-
for (const [
|
|
138
|
-
const
|
|
139
|
-
if (!Array.isArray(
|
|
140
|
-
const c = Math.min(
|
|
141
|
-
for (let
|
|
142
|
-
if (!B(
|
|
143
|
-
const
|
|
144
|
-
if (typeof
|
|
145
|
-
const
|
|
146
|
-
|
|
131
|
+
for (const [i, r] of Object.entries(s))
|
|
132
|
+
B(r) && n.add(i);
|
|
133
|
+
for (const i of n)
|
|
134
|
+
await gt(e, i);
|
|
135
|
+
const o = te(e);
|
|
136
|
+
if (o)
|
|
137
|
+
for (const [i, r] of Object.entries(o)) {
|
|
138
|
+
const a = e[i];
|
|
139
|
+
if (!Array.isArray(a)) continue;
|
|
140
|
+
const c = Math.min(r.length, a.length);
|
|
141
|
+
for (let l = 0; l < c; l++) {
|
|
142
|
+
if (!B(r[l])) continue;
|
|
143
|
+
const d = a[l];
|
|
144
|
+
if (typeof d != "string" || !xe(d)) continue;
|
|
145
|
+
const h = await ke(d);
|
|
146
|
+
h !== null && (a[l] = h);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
function
|
|
151
|
+
function mt(t) {
|
|
152
152
|
const e = typeof t == "string" ? t.trim() : "";
|
|
153
153
|
if (!e)
|
|
154
154
|
return { ok: !1, reason: "empty" };
|
|
155
155
|
let n;
|
|
156
156
|
try {
|
|
157
157
|
n = JSON.parse(e);
|
|
158
|
-
} catch (
|
|
159
|
-
return { ok: !1, reason: "parse", error:
|
|
158
|
+
} catch (o) {
|
|
159
|
+
return { ok: !1, reason: "parse", error: o };
|
|
160
160
|
}
|
|
161
161
|
return !Array.isArray(n) || n.length === 0 || !n[0]?.value ? { ok: !1, reason: "shape" } : { ok: !0, metadata: n[0].value };
|
|
162
162
|
}
|
|
163
|
-
const J = "image",
|
|
163
|
+
const J = "image", O = [
|
|
164
164
|
"0x0000000000000000000000000000000000000000000000000000000000000020"
|
|
165
|
-
],
|
|
165
|
+
], Re = nt`
|
|
166
166
|
query GetSeeds($where: AttestationWhereInput!, $take: Int, $skip: Int) {
|
|
167
167
|
itemSeeds: attestations(where: $where, orderBy: [{ timeCreated: desc }], take: $take, skip: $skip) {
|
|
168
168
|
id
|
|
@@ -180,123 +180,123 @@ const J = "image", N = [
|
|
|
180
180
|
isOffchain
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
`,
|
|
184
|
-
const e = new Date(t * 1e3), n = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], s = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
|
|
185
|
-
return `${
|
|
186
|
-
},
|
|
183
|
+
`, W = (t) => t.replace(/_([a-z])/g, (e, n) => n.toUpperCase()), yt = (t) => {
|
|
184
|
+
const e = new Date(t * 1e3), n = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], s = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], o = n[e.getUTCDay()], i = s[e.getUTCMonth()], r = e.getUTCFullYear(), a = e.getUTCDate().toString().padStart(2, "0"), c = e.getUTCHours().toString().padStart(2, "0"), l = e.getUTCMinutes().toString().padStart(2, "0"), d = e.getUTCSeconds().toString().padStart(2, "0");
|
|
185
|
+
return `${o}, ${a} ${i} ${r} ${c}:${l}:${d} GMT`;
|
|
186
|
+
}, wt = (t) => t === "image" ? "images" : t === "post" ? "posts" : t.toLowerCase() + "s", Ct = (t) => {
|
|
187
187
|
const [e, n, s] = t.split("_");
|
|
188
188
|
if (!e || !n) return null;
|
|
189
|
-
const
|
|
190
|
-
return { propertyName: e.endsWith("s") ? e : e + "s", modelName: n, isList:
|
|
191
|
-
},
|
|
192
|
-
const { itemUrlBase:
|
|
189
|
+
const o = s === "ids";
|
|
190
|
+
return { propertyName: e.endsWith("s") ? e : e + "s", modelName: n, isList: o };
|
|
191
|
+
}, oe = (t, e, n, s) => {
|
|
192
|
+
const { itemUrlBase: o, itemUrlPath: i, siteUrl: r } = s;
|
|
193
193
|
!t.title && !t.Title ? (t.title = e, t.Title = e) : t.title && !t.Title ? t.Title = t.title : t.Title && !t.title && (t.title = t.Title);
|
|
194
|
-
const
|
|
195
|
-
let
|
|
196
|
-
if (
|
|
194
|
+
const a = t.storage_transaction_id && typeof t.storage_transaction_id == "string" && t.storage_transaction_id.trim() !== "" && t.storage_transaction_id !== "undefined" && t.storage_transaction_id !== e ? t.storage_transaction_id.trim() : null, c = t.storageTransactionId && typeof t.storageTransactionId == "string" && t.storageTransactionId.trim() !== "" && t.storageTransactionId !== "undefined" && t.storageTransactionId !== e ? t.storageTransactionId.trim() : null, l = a || c, d = wt(n), h = e && typeof e == "string" && e.trim() !== "" ? e : "unknown";
|
|
195
|
+
let g;
|
|
196
|
+
if (l && l !== e && l.length > 0)
|
|
197
197
|
try {
|
|
198
|
-
|
|
199
|
-
} catch (
|
|
200
|
-
console.error("[feed] [setFeedItemDefaults] Error generating Arweave URL:",
|
|
198
|
+
g = j(l);
|
|
199
|
+
} catch (p) {
|
|
200
|
+
console.error("[feed] [setFeedItemDefaults] Error generating Arweave URL:", p), o != null ? g = `${o.replace(/\/$/, "")}/${(i ?? "attestation/view").replace(/^\//, "")}/${h}` : g = `${r.replace(/\/$/, "")}/${d}/${h}`;
|
|
201
201
|
}
|
|
202
202
|
else
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
!
|
|
206
|
-
const
|
|
207
|
-
if (!
|
|
208
|
-
const
|
|
209
|
-
t.pubDate =
|
|
203
|
+
o != null ? g = `${o.replace(/\/$/, "")}/${(i ?? "attestation/view").replace(/^\//, "")}/${h}` : g = `${r.replace(/\/$/, "")}/${d}/${h}`;
|
|
204
|
+
const f = t.link || t.Link;
|
|
205
|
+
!f || f === "undefined" || typeof f == "string" && f.trim() === "" ? (t.link = g, t.Link = g) : ((!t.link || t.link === "undefined") && (t.link = f), (!t.Link || t.Link === "undefined") && (t.Link = f));
|
|
206
|
+
const y = t.guid || t.Guid;
|
|
207
|
+
if (!y || y === "undefined" || typeof y == "string" && y.trim() === "" ? (t.guid = t.link || g, t.Guid = t.guid) : ((!t.guid || t.guid === "undefined") && (t.guid = y), (!t.Guid || t.Guid === "undefined") && (t.Guid = y)), t.timeCreated && !t.pubDate && !t.PubDate) {
|
|
208
|
+
const p = yt(t.timeCreated);
|
|
209
|
+
t.pubDate = p, t.PubDate = p;
|
|
210
210
|
} else t.pubDate && !t.PubDate ? t.PubDate = t.pubDate : t.PubDate && !t.pubDate && (t.pubDate = t.PubDate);
|
|
211
211
|
!t.seedUid && !t.SeedUid ? (t.seedUid = e, t.SeedUid = e) : t.seedUid && !t.SeedUid ? t.SeedUid = t.seedUid : t.SeedUid && !t.seedUid && (t.seedUid = t.SeedUid), t.attester && !t.Attester ? t.Attester = t.attester : t.Attester && !t.attester && (t.attester = t.Attester);
|
|
212
|
-
},
|
|
213
|
-
function
|
|
214
|
-
|
|
212
|
+
}, M = /* @__PURE__ */ new Map(), Y = /* @__PURE__ */ new Set(), de = /* @__PURE__ */ new Map(), $ = /* @__PURE__ */ new Map(), V = /* @__PURE__ */ new Map(), Le = /* @__PURE__ */ new Map();
|
|
213
|
+
function St() {
|
|
214
|
+
M.clear(), Y.clear(), de.clear(), $.clear(), V.clear(), Le.clear();
|
|
215
215
|
}
|
|
216
|
-
const
|
|
217
|
-
const n =
|
|
216
|
+
const Dt = async (t, e) => {
|
|
217
|
+
const n = mt(t.decodedDataJson);
|
|
218
218
|
if (!n.ok) {
|
|
219
|
-
const { id:
|
|
219
|
+
const { id: p, refUID: w, schemaId: u } = t;
|
|
220
220
|
n.reason === "empty" ? console.warn(
|
|
221
221
|
"[feed] [processItemProperty] empty decodedDataJson for property:",
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
222
|
+
p,
|
|
223
|
+
w,
|
|
224
|
+
u
|
|
225
225
|
) : n.reason === "parse" ? console.warn(
|
|
226
226
|
"[feed] [processItemProperty] failed to parse decodedDataJson for property:",
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
p,
|
|
228
|
+
w,
|
|
229
|
+
u,
|
|
230
230
|
n.error
|
|
231
231
|
) : console.warn(
|
|
232
232
|
"[feed] [processItemProperty] invalid decodedDataJson structure for property:",
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
p,
|
|
234
|
+
w,
|
|
235
|
+
u
|
|
236
236
|
);
|
|
237
237
|
return;
|
|
238
238
|
}
|
|
239
239
|
const s = n.metadata;
|
|
240
|
-
let
|
|
241
|
-
if (!
|
|
240
|
+
let o = s.name;
|
|
241
|
+
if (!o)
|
|
242
242
|
return;
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
text:
|
|
246
|
-
schemaUid:
|
|
243
|
+
const i = t.schemaId;
|
|
244
|
+
Qe({
|
|
245
|
+
text: o,
|
|
246
|
+
schemaUid: i
|
|
247
247
|
});
|
|
248
|
-
let
|
|
249
|
-
const c = s.type,
|
|
250
|
-
if (
|
|
251
|
-
if (
|
|
252
|
-
if (
|
|
253
|
-
const
|
|
254
|
-
|
|
248
|
+
let r = !1, a = !1;
|
|
249
|
+
const c = s.type, l = (c === "bytes32" || c === "bytes32[]") && o !== "storage_transaction_id" && o !== "storage_provider_transaction_id", d = !l && (o.endsWith("_id") || o.endsWith("_ids")) && o !== "storage_transaction_id" && o !== "storage_provider_transaction_id";
|
|
250
|
+
if (l || d)
|
|
251
|
+
if (r = !0, Array.isArray(s.value)) {
|
|
252
|
+
if (a = !0, d) {
|
|
253
|
+
const p = Ct(o);
|
|
254
|
+
p && (o = p.propertyName);
|
|
255
255
|
}
|
|
256
|
-
s.value.forEach((
|
|
257
|
-
|
|
256
|
+
s.value.forEach((p) => {
|
|
257
|
+
O.includes(p) || Y.add(p);
|
|
258
258
|
});
|
|
259
|
-
} else
|
|
260
|
-
let
|
|
261
|
-
|
|
262
|
-
(
|
|
259
|
+
} else O.includes(s.value) || Y.add(s.value);
|
|
260
|
+
let h = s.value;
|
|
261
|
+
r && a && Array.isArray(h) ? h = h.map((p) => String(p)) : typeof h != "string" && (h = JSON.stringify(h)), r && !a && e.find((w) => w.id === s.value)?.schema?.schemaNames, r && a && e.filter(
|
|
262
|
+
(w) => Array.isArray(s.value) && s.value.includes(w.id)
|
|
263
263
|
).length > 0;
|
|
264
|
-
const
|
|
265
|
-
if (!
|
|
264
|
+
const g = de.get(t.refUID);
|
|
265
|
+
if (!g)
|
|
266
266
|
return;
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
},
|
|
272
|
-
const e = t.map((
|
|
273
|
-
for (let
|
|
274
|
-
const
|
|
275
|
-
if (!
|
|
276
|
-
e.push(
|
|
277
|
-
const c =
|
|
278
|
-
|
|
279
|
-
seedUid:
|
|
280
|
-
timeCreated:
|
|
281
|
-
attester:
|
|
267
|
+
const f = $.get(g) || {};
|
|
268
|
+
f[o] = h;
|
|
269
|
+
const y = W(o);
|
|
270
|
+
y !== o && (f[y] = h), $.set(g, f);
|
|
271
|
+
}, pe = async (t) => {
|
|
272
|
+
const e = t.map((r) => r.id);
|
|
273
|
+
for (let r = 0; r < t.length; r++) {
|
|
274
|
+
const a = t[r];
|
|
275
|
+
if (!a) continue;
|
|
276
|
+
e.push(a.id);
|
|
277
|
+
const c = a.schema?.schemaNames?.[0]?.name ?? "unknown";
|
|
278
|
+
M.set(a.id, c), $.has(a.id) || $.set(a.id, {
|
|
279
|
+
seedUid: a.id,
|
|
280
|
+
timeCreated: a.timeCreated,
|
|
281
|
+
attester: a.attester
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
|
-
const n = await
|
|
285
|
-
for (let
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
|
|
284
|
+
const n = await Ye({ seedUids: e });
|
|
285
|
+
for (let r = 0; r < n.length; r++) {
|
|
286
|
+
const a = n[r], c = a.refUID;
|
|
287
|
+
de.set(a.id, c);
|
|
288
|
+
const l = V.get(c) || [];
|
|
289
|
+
V.set(c, [...l, a]);
|
|
290
290
|
}
|
|
291
291
|
const s = [];
|
|
292
|
-
for (const [
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
const
|
|
297
|
-
for (let
|
|
298
|
-
await
|
|
299
|
-
},
|
|
292
|
+
for (const [r, a] of V.entries()) {
|
|
293
|
+
const l = [...a].sort((d, h) => h.timeCreated - d.timeCreated)[0];
|
|
294
|
+
l && (s.push(l.id), Le.set(r, l.id));
|
|
295
|
+
}
|
|
296
|
+
const o = await qe({ versionUids: s }), i = Ze(o);
|
|
297
|
+
for (let r = 0; r < i.length; r++)
|
|
298
|
+
await Dt(i[r], t);
|
|
299
|
+
}, Pe = /* @__PURE__ */ new Set([
|
|
300
300
|
"seedUid",
|
|
301
301
|
"SeedUid",
|
|
302
302
|
"timeCreated",
|
|
@@ -307,69 +307,69 @@ const ut = async (t, e) => {
|
|
|
307
307
|
"storageTransactionId",
|
|
308
308
|
"storageProviderTransactionId"
|
|
309
309
|
]);
|
|
310
|
-
function
|
|
310
|
+
function At(t) {
|
|
311
311
|
const e = Array.from($.entries()).filter(
|
|
312
|
-
([n]) =>
|
|
312
|
+
([n]) => M.get(n) === t
|
|
313
313
|
);
|
|
314
314
|
for (const [, n] of e) {
|
|
315
315
|
const s = Object.keys(n).filter(
|
|
316
|
-
(
|
|
316
|
+
(o) => !o.startsWith("_") && !Pe.has(o)
|
|
317
317
|
);
|
|
318
|
-
for (const
|
|
319
|
-
let
|
|
320
|
-
const
|
|
321
|
-
if (
|
|
322
|
-
const c =
|
|
318
|
+
for (const o of s) {
|
|
319
|
+
let i = n[o];
|
|
320
|
+
const r = be(i);
|
|
321
|
+
if (r !== i && Array.isArray(r) && (n[o] = r, i = r), Array.isArray(i)) {
|
|
322
|
+
const c = i;
|
|
323
323
|
if (!c.some(
|
|
324
|
-
(
|
|
324
|
+
(f) => typeof f == "string" && !O.includes(f) && $.has(f)
|
|
325
325
|
)) continue;
|
|
326
|
-
const
|
|
327
|
-
let
|
|
328
|
-
for (const
|
|
329
|
-
if (typeof
|
|
330
|
-
|
|
326
|
+
const d = [], h = [];
|
|
327
|
+
let g = !1;
|
|
328
|
+
for (const f of c) {
|
|
329
|
+
if (typeof f != "string" || O.includes(f)) {
|
|
330
|
+
d.push(String(f)), h.push("unknown");
|
|
331
331
|
continue;
|
|
332
332
|
}
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
335
|
-
|
|
333
|
+
const y = M.get(f) ?? "unknown";
|
|
334
|
+
if (y === J) {
|
|
335
|
+
d.push(f), h.push(J);
|
|
336
336
|
continue;
|
|
337
337
|
}
|
|
338
|
-
const
|
|
339
|
-
if (
|
|
338
|
+
const p = $.get(f), w = p?.storageTransactionId ?? p?.storage_transaction_id;
|
|
339
|
+
if (w && typeof w == "string" && w.trim())
|
|
340
340
|
try {
|
|
341
|
-
|
|
341
|
+
d.push(j(w)), h.push(y), g = !0;
|
|
342
342
|
} catch {
|
|
343
|
-
|
|
343
|
+
d.push(f), h.push(y);
|
|
344
344
|
}
|
|
345
345
|
else
|
|
346
|
-
|
|
346
|
+
d.push(f), h.push(y);
|
|
347
347
|
}
|
|
348
|
-
if (
|
|
349
|
-
const
|
|
350
|
-
if (n[
|
|
351
|
-
delete n[
|
|
352
|
-
const
|
|
353
|
-
|
|
348
|
+
if (g) {
|
|
349
|
+
const f = le(o);
|
|
350
|
+
if (n[f] = d, ft(n, f, h), Fe(n, f), f !== o) {
|
|
351
|
+
delete n[o];
|
|
352
|
+
const y = W(o);
|
|
353
|
+
y !== o && delete n[y];
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
|
-
} else if (typeof
|
|
357
|
-
if (
|
|
358
|
-
const c = $.get(
|
|
359
|
-
if (
|
|
356
|
+
} else if (typeof i == "string") {
|
|
357
|
+
if (O.includes(i) || !$.has(i)) continue;
|
|
358
|
+
const c = $.get(i);
|
|
359
|
+
if (M.get(i) === J)
|
|
360
360
|
continue;
|
|
361
|
-
const
|
|
362
|
-
if (
|
|
361
|
+
const l = c?.storageTransactionId ?? c?.storage_transaction_id;
|
|
362
|
+
if (l && typeof l == "string" && l.trim())
|
|
363
363
|
try {
|
|
364
|
-
const
|
|
365
|
-
n[
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
if (
|
|
370
|
-
delete n[
|
|
371
|
-
const
|
|
372
|
-
|
|
364
|
+
const d = o.endsWith("_id") ? o.replace(/_id$/, "") : o;
|
|
365
|
+
n[d] = j(l);
|
|
366
|
+
const h = M.get(i) ?? "unknown";
|
|
367
|
+
ge(n, d, h);
|
|
368
|
+
const g = W(d);
|
|
369
|
+
if (g !== d && ge(n, g, h), d !== o) {
|
|
370
|
+
delete n[o];
|
|
371
|
+
const f = W(o);
|
|
372
|
+
f !== o && delete n[f];
|
|
373
373
|
}
|
|
374
374
|
} catch {
|
|
375
375
|
}
|
|
@@ -377,88 +377,88 @@ function gt(t) {
|
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
-
function
|
|
380
|
+
function Tt(t, e, n) {
|
|
381
381
|
if (!n) return;
|
|
382
382
|
const s = Array.from($.entries()).filter(
|
|
383
|
-
([
|
|
383
|
+
([o]) => M.get(o) === t
|
|
384
384
|
);
|
|
385
|
-
for (const [,
|
|
386
|
-
const
|
|
387
|
-
(
|
|
385
|
+
for (const [, o] of s) {
|
|
386
|
+
const i = Object.keys(o).filter(
|
|
387
|
+
(r) => !r.startsWith("_") && !Pe.has(r)
|
|
388
388
|
);
|
|
389
|
-
for (const
|
|
390
|
-
let
|
|
391
|
-
const c =
|
|
392
|
-
c !==
|
|
393
|
-
const
|
|
394
|
-
let
|
|
395
|
-
for (const
|
|
396
|
-
if (typeof
|
|
397
|
-
|
|
389
|
+
for (const r of i) {
|
|
390
|
+
let a = o[r];
|
|
391
|
+
const c = be(a);
|
|
392
|
+
c !== a && Array.isArray(c) && (o[r] = c, a = c);
|
|
393
|
+
const l = Array.isArray(a), d = l ? a : [a], h = [];
|
|
394
|
+
let g = !1;
|
|
395
|
+
for (const f of d) {
|
|
396
|
+
if (typeof f != "string" || O.includes(f)) {
|
|
397
|
+
h.push(f);
|
|
398
398
|
continue;
|
|
399
399
|
}
|
|
400
|
-
const
|
|
401
|
-
if (!
|
|
402
|
-
|
|
400
|
+
const y = $.get(f);
|
|
401
|
+
if (!y) {
|
|
402
|
+
h.push(f);
|
|
403
403
|
continue;
|
|
404
404
|
}
|
|
405
|
-
const
|
|
406
|
-
if (
|
|
407
|
-
const
|
|
408
|
-
|
|
405
|
+
const p = y?.storageTransactionId ?? y?.storage_transaction_id;
|
|
406
|
+
if (M.get(f) === J) {
|
|
407
|
+
const C = M.get(f) ?? "unknown", S = { ...y };
|
|
408
|
+
oe(S, f, C, e), lt(S), h.push(S), g = !0;
|
|
409
409
|
continue;
|
|
410
410
|
}
|
|
411
|
-
if (
|
|
412
|
-
|
|
411
|
+
if (p && typeof p == "string" && p.trim()) {
|
|
412
|
+
h.push(f);
|
|
413
413
|
continue;
|
|
414
414
|
}
|
|
415
|
-
const
|
|
416
|
-
|
|
415
|
+
const u = M.get(f) ?? "unknown", m = { ...y };
|
|
416
|
+
oe(m, f, u, e), h.push(m), g = !0;
|
|
417
417
|
}
|
|
418
|
-
if (
|
|
419
|
-
const
|
|
420
|
-
if (
|
|
421
|
-
delete r
|
|
422
|
-
const
|
|
423
|
-
|
|
418
|
+
if (g) {
|
|
419
|
+
const f = l ? le(r) : r.endsWith("_id") ? r.replace(/_id$/, "") : r;
|
|
420
|
+
if (o[f] = l ? h : h[0], Fe(o, f), f !== r) {
|
|
421
|
+
delete o[r];
|
|
422
|
+
const y = W(r);
|
|
423
|
+
y !== r && delete o[y];
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
|
-
async function
|
|
430
|
-
|
|
431
|
-
const s =
|
|
432
|
-
where:
|
|
429
|
+
async function Ne(t, e, n) {
|
|
430
|
+
St(), await pe(e);
|
|
431
|
+
const s = $e.getEasClient(), o = Array.from(Y), { itemSeeds: i } = await s.request(Re, {
|
|
432
|
+
where: Ie({
|
|
433
433
|
id: {
|
|
434
|
-
in:
|
|
434
|
+
in: o
|
|
435
435
|
}
|
|
436
436
|
}),
|
|
437
|
-
take:
|
|
437
|
+
take: o.length || 1,
|
|
438
438
|
skip: 0
|
|
439
439
|
});
|
|
440
|
-
await
|
|
441
|
-
const
|
|
442
|
-
itemUrlBase:
|
|
443
|
-
itemUrlPath:
|
|
444
|
-
siteUrl:
|
|
440
|
+
await pe(i ?? []), At(t);
|
|
441
|
+
const r = G(), a = {
|
|
442
|
+
itemUrlBase: r.itemUrlBase,
|
|
443
|
+
itemUrlPath: r.itemUrlPath,
|
|
444
|
+
siteUrl: r.siteUrl
|
|
445
445
|
};
|
|
446
|
-
|
|
446
|
+
Tt(
|
|
447
447
|
t,
|
|
448
|
-
|
|
448
|
+
a,
|
|
449
449
|
n
|
|
450
450
|
);
|
|
451
|
-
const c = Array.from($.entries()).filter(([
|
|
452
|
-
const
|
|
453
|
-
return
|
|
451
|
+
const c = Array.from($.entries()).filter(([l]) => M.get(l) === t).map(([, l]) => {
|
|
452
|
+
const d = l.seedUid || l.SeedUid;
|
|
453
|
+
return oe(l, d, t, a), l;
|
|
454
454
|
});
|
|
455
|
-
return await
|
|
455
|
+
return await pt(c), c;
|
|
456
456
|
}
|
|
457
|
-
const
|
|
458
|
-
const n = G(), s = e?.limit ?? 100,
|
|
459
|
-
return
|
|
460
|
-
},
|
|
461
|
-
const s = G(),
|
|
457
|
+
const ne = async (t, e) => {
|
|
458
|
+
const n = G(), s = e?.limit ?? 100, o = e?.skip ?? 0, i = await Ke(t, s, o);
|
|
459
|
+
return await Ne(t, i, n.expandRelations !== !1);
|
|
460
|
+
}, Et = async (t, e, n) => {
|
|
461
|
+
const s = G(), o = new Date(e, n - 1, 1), i = new Date(e, n, 0, 23, 59, 59), r = Math.floor(o.getTime() / 1e3), a = Math.floor(i.getTime() / 1e3) + 1, c = Ie({
|
|
462
462
|
AND: [
|
|
463
463
|
{
|
|
464
464
|
schema: {
|
|
@@ -472,24 +472,24 @@ const te = async (t, e) => {
|
|
|
472
472
|
}
|
|
473
473
|
},
|
|
474
474
|
{
|
|
475
|
-
timeCreated: { gte:
|
|
475
|
+
timeCreated: { gte: r, lt: a }
|
|
476
476
|
}
|
|
477
477
|
]
|
|
478
|
-
}),
|
|
478
|
+
}), l = $e.getEasClient(), { itemSeeds: d } = await l.request(Re, {
|
|
479
479
|
where: c,
|
|
480
480
|
take: 1e3,
|
|
481
481
|
skip: 0
|
|
482
482
|
});
|
|
483
|
-
return
|
|
483
|
+
return Ne(t, d ?? [], s.expandRelations !== !1);
|
|
484
484
|
};
|
|
485
|
-
function
|
|
485
|
+
function _t(t) {
|
|
486
486
|
try {
|
|
487
487
|
return JSON.parse(JSON.stringify(t));
|
|
488
488
|
} catch {
|
|
489
489
|
return { ...t };
|
|
490
490
|
}
|
|
491
491
|
}
|
|
492
|
-
const
|
|
492
|
+
const It = new rt({
|
|
493
493
|
customFields: {
|
|
494
494
|
item: [
|
|
495
495
|
"featureImage",
|
|
@@ -500,20 +500,25 @@ const wt = new Ye({
|
|
|
500
500
|
]
|
|
501
501
|
}
|
|
502
502
|
});
|
|
503
|
-
async function
|
|
504
|
-
const e = await
|
|
503
|
+
async function yn(t) {
|
|
504
|
+
const e = await It.parseString(t);
|
|
505
505
|
return {
|
|
506
506
|
title: e.title,
|
|
507
507
|
link: e.link,
|
|
508
508
|
description: e.description,
|
|
509
|
-
items: (e.items ?? []).map(
|
|
509
|
+
items: (e.items ?? []).map(_t)
|
|
510
510
|
};
|
|
511
511
|
}
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
512
|
+
const H = "http://purl.org/dc/elements/1.1/", q = "http://purl.org/rss/1.0/modules/content/", R = "http://search.yahoo.com/mrss/", $t = {
|
|
513
|
+
publication: {
|
|
514
|
+
prefix: "publication",
|
|
515
|
+
uri: "https://seedprotocol.io/ns/publication/1.0"
|
|
516
|
+
}
|
|
517
|
+
}, Mt = "https://seedprotocol.io/ns/relations", me = /* @__PURE__ */ new Set(["xml", "xmlns", "dc", "media", "content", "atom", "fh"]), Ft = /* @__PURE__ */ new Set(["Title", "Link", "Guid", "PubDate", "SeedUid"]);
|
|
518
|
+
function bt(t, e) {
|
|
519
|
+
return Ft.has(t) ? t.charAt(0).toLowerCase() + t.slice(1) in e : !1;
|
|
515
520
|
}
|
|
516
|
-
const
|
|
521
|
+
const se = [
|
|
517
522
|
"title",
|
|
518
523
|
"link",
|
|
519
524
|
"description",
|
|
@@ -537,7 +542,7 @@ const ue = [
|
|
|
537
542
|
"media:category",
|
|
538
543
|
"media:group"
|
|
539
544
|
];
|
|
540
|
-
function
|
|
545
|
+
function ae(t) {
|
|
541
546
|
if (t instanceof Date)
|
|
542
547
|
return t.toUTCString();
|
|
543
548
|
if (typeof t == "string") {
|
|
@@ -546,261 +551,334 @@ function re(t) {
|
|
|
546
551
|
}
|
|
547
552
|
return String(t);
|
|
548
553
|
}
|
|
549
|
-
function
|
|
554
|
+
function Ut(t) {
|
|
550
555
|
return /[<>&]|]]>/.test(t);
|
|
551
556
|
}
|
|
552
|
-
function
|
|
557
|
+
function I(t, e) {
|
|
553
558
|
const n = String(e);
|
|
554
559
|
if (n !== "")
|
|
555
|
-
if (
|
|
560
|
+
if (Ut(n))
|
|
556
561
|
if (n.includes("]]>")) {
|
|
557
562
|
const s = n.split("]]>");
|
|
558
|
-
for (let
|
|
559
|
-
t.dat(s[
|
|
563
|
+
for (let o = 0; o < s.length; o++)
|
|
564
|
+
t.dat(s[o]), o < s.length - 1 && t.txt("]]>");
|
|
560
565
|
} else
|
|
561
566
|
t.dat(n);
|
|
562
567
|
else
|
|
563
568
|
t.txt(n);
|
|
564
569
|
}
|
|
565
|
-
function
|
|
570
|
+
function b(t) {
|
|
566
571
|
return t !== null && typeof t == "object" && !Array.isArray(t) && !(t instanceof Date);
|
|
567
572
|
}
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
573
|
+
const vt = 4, xt = /* @__PURE__ */ new Set([
|
|
574
|
+
...se,
|
|
575
|
+
"guid",
|
|
576
|
+
"source",
|
|
577
|
+
"dc",
|
|
578
|
+
"content",
|
|
579
|
+
"content:encoded",
|
|
580
|
+
"items"
|
|
581
|
+
]);
|
|
582
|
+
function kt(t) {
|
|
583
|
+
return t.endsWith("s") && t.length > 1 ? t.slice(0, -1) : t;
|
|
584
|
+
}
|
|
585
|
+
function Rt(t) {
|
|
586
|
+
return t.trim().replace(/[^A-Za-z0-9_.-]+/g, "_").replace(/^[^A-Za-z_]+/, "").replace(/^$/, "rel").toLowerCase();
|
|
587
|
+
}
|
|
588
|
+
function Lt(t, e) {
|
|
589
|
+
if (!e.has(t) && !me.has(t))
|
|
590
|
+
return e.add(t), t;
|
|
591
|
+
let n = 2;
|
|
592
|
+
for (; ; ) {
|
|
593
|
+
const s = `${t}${n}`;
|
|
594
|
+
if (!e.has(s) && !me.has(s))
|
|
595
|
+
return e.add(s), s;
|
|
596
|
+
n += 1;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
function ye(t) {
|
|
600
|
+
return Array.isArray(t) && t.length > 0 && t.every((e) => b(e));
|
|
601
|
+
}
|
|
602
|
+
function Pt(t) {
|
|
603
|
+
const e = { ...$t }, n = new Set(
|
|
604
|
+
Object.values(e).map((i) => i.prefix)
|
|
605
|
+
), s = /* @__PURE__ */ new Set();
|
|
606
|
+
for (const i of t)
|
|
607
|
+
for (const [r, a] of Object.entries(i)) {
|
|
608
|
+
const c = r === "author" && b(a) || r === "authors" && ye(a);
|
|
609
|
+
r.startsWith("_") || xt.has(r) && !c || (b(a) || ye(a)) && s.add(kt(r));
|
|
610
|
+
}
|
|
611
|
+
const o = [...s].sort();
|
|
612
|
+
for (const i of o) {
|
|
613
|
+
if (e[i]) continue;
|
|
614
|
+
const r = Rt(i), a = Lt(r, n);
|
|
615
|
+
e[i] = {
|
|
616
|
+
prefix: a,
|
|
617
|
+
uri: `${Mt}/${i}/1.0`
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
return e;
|
|
621
|
+
}
|
|
622
|
+
function X(t, e) {
|
|
623
|
+
if (t in e) return e[t];
|
|
624
|
+
if (t.endsWith("s") && t.length > 1) {
|
|
625
|
+
const n = t.slice(0, -1);
|
|
626
|
+
if (n in e) return e[n];
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
function we(t, e) {
|
|
630
|
+
return e ? `${e.prefix}:${t}` : t;
|
|
631
|
+
}
|
|
632
|
+
function P(t, e, n, s, o = 0, i) {
|
|
633
|
+
const r = t.ele(n);
|
|
634
|
+
for (const [a, c] of Object.entries(e)) {
|
|
635
|
+
if (c == null || a.startsWith("_") || a === "items") continue;
|
|
636
|
+
const l = we(a, i);
|
|
637
|
+
if (o >= vt) {
|
|
638
|
+
const h = r.ele(l);
|
|
639
|
+
I(h, typeof c == "object" ? JSON.stringify(c) : String(c));
|
|
576
640
|
continue;
|
|
577
641
|
}
|
|
578
|
-
if (Array.isArray(
|
|
579
|
-
const
|
|
580
|
-
for (const f of
|
|
642
|
+
if (Array.isArray(c)) {
|
|
643
|
+
const h = a.endsWith("s") && a.length > 1 ? a.slice(0, -1) : a, g = we(h, i);
|
|
644
|
+
for (const f of c)
|
|
581
645
|
if (f != null)
|
|
582
|
-
if (
|
|
583
|
-
|
|
646
|
+
if (b(f))
|
|
647
|
+
P(r, f, g, !1, o + 1, i);
|
|
584
648
|
else {
|
|
585
|
-
const
|
|
586
|
-
|
|
649
|
+
const y = r.ele(g);
|
|
650
|
+
I(y, String(f));
|
|
587
651
|
}
|
|
588
652
|
continue;
|
|
589
653
|
}
|
|
590
|
-
if (
|
|
591
|
-
|
|
654
|
+
if (b(c)) {
|
|
655
|
+
P(
|
|
656
|
+
r,
|
|
657
|
+
c,
|
|
658
|
+
l,
|
|
659
|
+
!1,
|
|
660
|
+
o + 1,
|
|
661
|
+
i
|
|
662
|
+
);
|
|
592
663
|
continue;
|
|
593
664
|
}
|
|
594
|
-
const
|
|
595
|
-
|
|
665
|
+
const d = r.ele(l);
|
|
666
|
+
I(d, String(c));
|
|
596
667
|
}
|
|
597
668
|
if (s) {
|
|
598
|
-
const
|
|
599
|
-
|
|
669
|
+
const a = e.name ?? e.seedUid;
|
|
670
|
+
a && t.ele(H, "creator").txt(String(a));
|
|
600
671
|
}
|
|
601
672
|
}
|
|
602
|
-
function
|
|
673
|
+
function Ce(t, e, n, s, o) {
|
|
603
674
|
if (n == null || e.startsWith("_") || e === "items") return;
|
|
604
675
|
if (e === "guid") {
|
|
605
|
-
const
|
|
606
|
-
if (!
|
|
607
|
-
const
|
|
608
|
-
typeof
|
|
609
|
-
const
|
|
610
|
-
|
|
676
|
+
const r = n, a = r?.value ?? String(n);
|
|
677
|
+
if (!a) return;
|
|
678
|
+
const c = {};
|
|
679
|
+
typeof r?.isPermaLink == "boolean" && (c.isPermaLink = r.isPermaLink ? "true" : "false");
|
|
680
|
+
const l = t.ele("guid", c);
|
|
681
|
+
I(l, a);
|
|
611
682
|
return;
|
|
612
683
|
}
|
|
613
684
|
if (e === "source" && n !== null && typeof n == "object") {
|
|
614
|
-
const
|
|
615
|
-
if (!
|
|
616
|
-
const
|
|
617
|
-
t.ele("source",
|
|
685
|
+
const r = n, a = r.title ?? String(n);
|
|
686
|
+
if (!a) return;
|
|
687
|
+
const c = r.url ? { url: r.url } : {};
|
|
688
|
+
t.ele("source", c).txt(a);
|
|
618
689
|
return;
|
|
619
690
|
}
|
|
620
691
|
if (e === "enclosures" && Array.isArray(n)) {
|
|
621
|
-
for (const
|
|
622
|
-
if (
|
|
623
|
-
const
|
|
624
|
-
url: String(
|
|
625
|
-
type: String(
|
|
692
|
+
for (const r of n)
|
|
693
|
+
if (r && typeof r == "object" && "url" in r) {
|
|
694
|
+
const a = {
|
|
695
|
+
url: String(r.url),
|
|
696
|
+
type: String(r.type ?? "application/octet-stream")
|
|
626
697
|
};
|
|
627
|
-
|
|
698
|
+
r.length != null && (a.length = String(r.length)), t.ele("enclosure", a);
|
|
628
699
|
}
|
|
629
700
|
return;
|
|
630
701
|
}
|
|
631
702
|
if (e === "dc" && n !== null && typeof n == "object") {
|
|
632
|
-
const
|
|
633
|
-
for (const [
|
|
634
|
-
if (
|
|
635
|
-
if (Array.isArray(
|
|
636
|
-
for (const
|
|
637
|
-
if (
|
|
638
|
-
const d = t.ele(
|
|
639
|
-
|
|
703
|
+
const r = n;
|
|
704
|
+
for (const [a, c] of Object.entries(r))
|
|
705
|
+
if (c != null)
|
|
706
|
+
if (Array.isArray(c)) {
|
|
707
|
+
for (const l of c)
|
|
708
|
+
if (l != null) {
|
|
709
|
+
const d = t.ele(H, a);
|
|
710
|
+
l instanceof Date ? d.txt(l.toISOString()) : I(d, String(l));
|
|
640
711
|
}
|
|
641
712
|
} else {
|
|
642
|
-
const
|
|
643
|
-
|
|
713
|
+
const l = t.ele(H, a);
|
|
714
|
+
c instanceof Date ? l.txt(c.toISOString()) : I(l, String(c));
|
|
644
715
|
}
|
|
645
716
|
return;
|
|
646
717
|
}
|
|
647
718
|
if (e === "content:encoded") {
|
|
648
|
-
const
|
|
649
|
-
|
|
719
|
+
const r = t.ele(q, "encoded");
|
|
720
|
+
I(r, String(n));
|
|
650
721
|
return;
|
|
651
722
|
}
|
|
652
723
|
if (e === "content" && typeof n == "string" && !("content:encoded" in s)) {
|
|
653
|
-
const
|
|
654
|
-
|
|
724
|
+
const r = t.ele(q, "encoded");
|
|
725
|
+
I(r, String(n));
|
|
655
726
|
return;
|
|
656
727
|
}
|
|
657
728
|
if (e === "content") return;
|
|
729
|
+
if (e === "media:group" && Array.isArray(n)) {
|
|
730
|
+
for (const r of n)
|
|
731
|
+
if (r && typeof r == "object") {
|
|
732
|
+
const a = t.ele(R, "group");
|
|
733
|
+
for (const [c, l] of Object.entries(r))
|
|
734
|
+
if (l != null && c.startsWith("media:")) {
|
|
735
|
+
const d = c.slice(6);
|
|
736
|
+
if (Array.isArray(l)) {
|
|
737
|
+
for (const h of l)
|
|
738
|
+
if (h && typeof h == "object") {
|
|
739
|
+
const g = a.ele(R, d);
|
|
740
|
+
for (const [f, y] of Object.entries(h))
|
|
741
|
+
y != null && (f === "url" || f === "value" ? I(g, String(y)) : g.att(f, String(y)));
|
|
742
|
+
}
|
|
743
|
+
} else typeof l == "string" && I(a.ele(R, d), l);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
658
748
|
if (e.startsWith("media:") && Array.isArray(n)) {
|
|
659
|
-
const
|
|
660
|
-
for (const
|
|
661
|
-
if (
|
|
662
|
-
const
|
|
663
|
-
let
|
|
664
|
-
for (const [
|
|
665
|
-
|
|
666
|
-
const d = t.ele(
|
|
667
|
-
|
|
749
|
+
const r = e.slice(6);
|
|
750
|
+
for (const a of n) {
|
|
751
|
+
if (a === null || typeof a != "object") continue;
|
|
752
|
+
const c = {};
|
|
753
|
+
let l = null;
|
|
754
|
+
for (const [h, g] of Object.entries(a))
|
|
755
|
+
g != null && (h === "value" ? l = String(g) : c[h] = String(g));
|
|
756
|
+
const d = t.ele(R, r, c);
|
|
757
|
+
l !== null && I(d, l);
|
|
668
758
|
}
|
|
669
759
|
return;
|
|
670
760
|
}
|
|
671
761
|
if (e.startsWith("media:") && typeof n == "string") {
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
if (e === "media:group" && Array.isArray(n)) {
|
|
677
|
-
for (const a of n)
|
|
678
|
-
if (a && typeof a == "object") {
|
|
679
|
-
const o = t.ele(x, "group");
|
|
680
|
-
for (const [i, c] of Object.entries(a))
|
|
681
|
-
if (c != null && i.startsWith("media:")) {
|
|
682
|
-
const d = i.slice(6);
|
|
683
|
-
if (Array.isArray(c)) {
|
|
684
|
-
for (const f of c)
|
|
685
|
-
if (f && typeof f == "object") {
|
|
686
|
-
const p = o.ele(x, d);
|
|
687
|
-
for (const [w, h] of Object.entries(f))
|
|
688
|
-
h != null && (w === "url" || w === "value" ? _(p, String(h)) : p.att(w, String(h)));
|
|
689
|
-
}
|
|
690
|
-
} else typeof c == "string" && _(o.ele(x, d), c);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
762
|
+
const r = e.slice(6), a = t.ele(R, r);
|
|
763
|
+
I(a, n);
|
|
693
764
|
return;
|
|
694
765
|
}
|
|
695
766
|
if (n instanceof Date) {
|
|
696
|
-
t.ele(e).txt(
|
|
767
|
+
t.ele(e).txt(ae(n));
|
|
697
768
|
return;
|
|
698
769
|
}
|
|
699
|
-
if (e === "author" &&
|
|
700
|
-
|
|
770
|
+
if (e === "author" && b(n)) {
|
|
771
|
+
const r = X(e, o);
|
|
772
|
+
P(t, n, "author", !0, 0, r);
|
|
701
773
|
return;
|
|
702
774
|
}
|
|
703
775
|
if (e === "authors" && Array.isArray(n)) {
|
|
776
|
+
const r = X(e, o);
|
|
704
777
|
for (const a of n)
|
|
705
|
-
if (a &&
|
|
706
|
-
|
|
778
|
+
if (a && b(a))
|
|
779
|
+
P(t, a, "author", !0, 0, r);
|
|
707
780
|
else {
|
|
708
|
-
const
|
|
709
|
-
|
|
781
|
+
const c = typeof a == "string" ? a : a && typeof a == "object" && "name" in a ? `${a.email ?? ""} (${a.name ?? ""})`.trim() || a.name : String(a);
|
|
782
|
+
c && t.ele("author").txt(c);
|
|
710
783
|
}
|
|
711
784
|
return;
|
|
712
785
|
}
|
|
713
786
|
if (e === "categories" && Array.isArray(n)) {
|
|
714
|
-
for (const
|
|
715
|
-
const
|
|
716
|
-
if (
|
|
717
|
-
const
|
|
718
|
-
t.ele("category",
|
|
787
|
+
for (const r of n) {
|
|
788
|
+
const a = r && typeof r == "object" && "name" in r ? r.name : String(r);
|
|
789
|
+
if (a) {
|
|
790
|
+
const c = r && typeof r == "object" && "domain" in r && r.domain ? { domain: r.domain } : {};
|
|
791
|
+
t.ele("category", c).txt(a);
|
|
719
792
|
}
|
|
720
793
|
}
|
|
721
794
|
return;
|
|
722
795
|
}
|
|
723
|
-
if (Array.isArray(n) && n.length > 0 && n.every((
|
|
724
|
-
const
|
|
725
|
-
for (const
|
|
726
|
-
|
|
796
|
+
if (Array.isArray(n) && n.length > 0 && n.every((r) => b(r))) {
|
|
797
|
+
const r = e.endsWith("s") ? e.slice(0, -1) : e, a = X(e, o);
|
|
798
|
+
for (const c of n)
|
|
799
|
+
c && P(t, c, r, !1, 0, a);
|
|
727
800
|
return;
|
|
728
801
|
}
|
|
729
|
-
if (Array.isArray(n) && n.every((
|
|
730
|
-
const
|
|
731
|
-
for (const
|
|
732
|
-
if (
|
|
733
|
-
const
|
|
734
|
-
|
|
802
|
+
if (Array.isArray(n) && n.every((r) => typeof r == "string")) {
|
|
803
|
+
const r = e.endsWith("s") ? e.slice(0, -1) : e;
|
|
804
|
+
for (const a of n)
|
|
805
|
+
if (a) {
|
|
806
|
+
const c = t.ele(r);
|
|
807
|
+
I(c, a);
|
|
735
808
|
}
|
|
736
809
|
return;
|
|
737
810
|
}
|
|
738
|
-
if (
|
|
739
|
-
|
|
811
|
+
if (b(n)) {
|
|
812
|
+
const r = X(e, o);
|
|
813
|
+
P(t, n, e, !1, 0, r);
|
|
740
814
|
return;
|
|
741
815
|
}
|
|
742
|
-
const
|
|
743
|
-
|
|
816
|
+
const i = t.ele(e);
|
|
817
|
+
I(i, String(n));
|
|
744
818
|
}
|
|
745
|
-
const
|
|
746
|
-
function
|
|
747
|
-
const e =
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
"xmlns:
|
|
819
|
+
const Se = "http://www.w3.org/2005/Atom", De = "http://purl.org/syndication/history/1.0";
|
|
820
|
+
function Nt(t) {
|
|
821
|
+
const e = at({ version: "1.0", encoding: "UTF-8" }), n = Pt(t.items), s = Object.values(n).reduce(
|
|
822
|
+
(c, l) => (c[`xmlns:${l.prefix}`] = l.uri, c),
|
|
823
|
+
{}
|
|
824
|
+
), o = {
|
|
825
|
+
"xmlns:dc": H,
|
|
826
|
+
"xmlns:content": q,
|
|
827
|
+
"xmlns:media": R,
|
|
828
|
+
"xmlns:atom": Se,
|
|
829
|
+
...s
|
|
752
830
|
};
|
|
753
|
-
t.isArchive && (
|
|
754
|
-
const r = e.ele("rss", { version: "2.0", ...
|
|
755
|
-
"xmlns:dc":
|
|
756
|
-
"xmlns:content":
|
|
757
|
-
"xmlns:media":
|
|
831
|
+
t.isArchive && (o["xmlns:fh"] = De);
|
|
832
|
+
const r = e.ele("rss", { version: "2.0", ...o }).ele("channel", {
|
|
833
|
+
"xmlns:dc": H,
|
|
834
|
+
"xmlns:content": q,
|
|
835
|
+
"xmlns:media": R
|
|
758
836
|
});
|
|
759
|
-
if (r.ele("title").txt(t.title), t.link && r.ele("link").txt(t.link), r.ele("description").txt(t.description), t.language && r.ele("language").txt(t.language), t.copyright && r.ele("copyright").txt(t.copyright), t.webMaster && r.ele("webMaster").txt(t.webMaster), t.pubDate && r.ele("pubDate").txt(
|
|
760
|
-
for (const
|
|
761
|
-
const
|
|
762
|
-
|
|
837
|
+
if (r.ele("title").txt(t.title), t.link && r.ele("link").txt(t.link), r.ele("description").txt(t.description), t.language && r.ele("language").txt(t.language), t.copyright && r.ele("copyright").txt(t.copyright), t.webMaster && r.ele("webMaster").txt(t.webMaster), t.pubDate && r.ele("pubDate").txt(ae(t.pubDate)), t.lastBuildDate && r.ele("lastBuildDate").txt(ae(t.lastBuildDate)), t.links?.length)
|
|
838
|
+
for (const c of t.links) {
|
|
839
|
+
const l = { rel: c.rel, href: c.href };
|
|
840
|
+
c.type && (l.type = c.type), r.ele(Se, "link", l);
|
|
763
841
|
}
|
|
764
|
-
t.isArchive && r.ele(
|
|
765
|
-
const a = new Set(
|
|
766
|
-
for (const
|
|
767
|
-
const
|
|
768
|
-
for (const
|
|
769
|
-
|
|
770
|
-
const
|
|
771
|
-
(
|
|
842
|
+
t.isArchive && r.ele(De, "archive");
|
|
843
|
+
const a = new Set(se);
|
|
844
|
+
for (const c of t.items) {
|
|
845
|
+
const l = r.ele("item"), d = /* @__PURE__ */ new Set();
|
|
846
|
+
for (const g of se)
|
|
847
|
+
g in c && (Ce(l, g, c[g], c, n), d.add(g));
|
|
848
|
+
const h = Object.keys(c).filter(
|
|
849
|
+
(g) => !d.has(g) && !a.has(g) && !g.startsWith("_") && !bt(g, c)
|
|
772
850
|
).sort();
|
|
773
|
-
for (const
|
|
774
|
-
|
|
851
|
+
for (const g of h)
|
|
852
|
+
Ce(l, g, c[g], c, n);
|
|
775
853
|
}
|
|
776
854
|
return e.end({ prettyPrint: !0 });
|
|
777
855
|
}
|
|
778
|
-
function
|
|
856
|
+
function ie(t, e, n) {
|
|
779
857
|
return n?.archive ? `${t}:${e}:archive-${n.archive.year}-${n.archive.month}` : n?.page != null && n.page > 1 ? `${t}:${e}:page-${n.page}` : `${t}:${e}`;
|
|
780
858
|
}
|
|
781
|
-
function
|
|
782
|
-
return `"${
|
|
859
|
+
function Oe(t) {
|
|
860
|
+
return `"${it("md5").update(t).digest("hex").substring(0, 16)}"`;
|
|
783
861
|
}
|
|
784
|
-
function
|
|
785
|
-
const
|
|
786
|
-
return
|
|
862
|
+
function Ot(t, e, n, s) {
|
|
863
|
+
const o = `${t}-${e}-${n}-${s}`;
|
|
864
|
+
return Oe(o);
|
|
787
865
|
}
|
|
788
|
-
function
|
|
789
|
-
const
|
|
790
|
-
return
|
|
866
|
+
function jt(t, e, n, s) {
|
|
867
|
+
const o = `${t}-${e}-${n}-${s}`;
|
|
868
|
+
return Oe(o);
|
|
791
869
|
}
|
|
792
|
-
function
|
|
870
|
+
function Bt(t, e) {
|
|
793
871
|
const n = (s) => s.replace(/^"|"$/g, "");
|
|
794
872
|
return n(t) === n(e);
|
|
795
873
|
}
|
|
796
|
-
function
|
|
874
|
+
function zt(t) {
|
|
797
875
|
return t ? t.split(",").map((e) => e.trim()).filter((e) => e.length > 0) : [];
|
|
798
876
|
}
|
|
799
|
-
function
|
|
800
|
-
const n =
|
|
801
|
-
return n.length === 0 ? !1 : n.includes("*") ? !0 : n.some((s) =>
|
|
877
|
+
function je(t, e) {
|
|
878
|
+
const n = zt(t);
|
|
879
|
+
return n.length === 0 ? !1 : n.includes("*") ? !0 : n.some((s) => Bt(s, e));
|
|
802
880
|
}
|
|
803
|
-
class
|
|
881
|
+
class Wt {
|
|
804
882
|
feedDataCache = /* @__PURE__ */ new Map();
|
|
805
883
|
feedContentCache = /* @__PURE__ */ new Map();
|
|
806
884
|
imageMetadataCache = /* @__PURE__ */ new Map();
|
|
@@ -821,41 +899,41 @@ class Mt {
|
|
|
821
899
|
*/
|
|
822
900
|
setFeedData(e, n) {
|
|
823
901
|
const s = Math.floor(Date.now() / 1e3);
|
|
824
|
-
let
|
|
902
|
+
let o = 0, i = "";
|
|
825
903
|
for (const c of n) {
|
|
826
|
-
const
|
|
827
|
-
|
|
904
|
+
const l = c.timeCreated;
|
|
905
|
+
l && l > o && (o = l, i = c.id || c.seedUid || c.SeedUid || "");
|
|
828
906
|
}
|
|
829
|
-
|
|
830
|
-
const
|
|
907
|
+
o === 0 && (o = s);
|
|
908
|
+
const r = Ot(e, "data", o, n.length), a = {
|
|
831
909
|
items: [...n],
|
|
832
910
|
// Create a copy
|
|
833
|
-
lastProcessedTimestamp:
|
|
834
|
-
lastProcessedItemId:
|
|
911
|
+
lastProcessedTimestamp: o,
|
|
912
|
+
lastProcessedItemId: i,
|
|
835
913
|
lastUpdated: s,
|
|
836
|
-
etag:
|
|
914
|
+
etag: r
|
|
837
915
|
};
|
|
838
|
-
this.feedDataCache.set(e,
|
|
916
|
+
this.feedDataCache.set(e, a);
|
|
839
917
|
}
|
|
840
918
|
/**
|
|
841
919
|
* Get cached feed content for a schema and format
|
|
842
920
|
*/
|
|
843
921
|
getFeedContent(e, n, s) {
|
|
844
|
-
const
|
|
845
|
-
return
|
|
922
|
+
const o = ie(e, n, s), i = this.feedContentCache.get(o);
|
|
923
|
+
return i ? Math.floor(Date.now() / 1e3) > i.expiresAt ? (this.feedContentCache.delete(o), null) : i : null;
|
|
846
924
|
}
|
|
847
925
|
/**
|
|
848
926
|
* Set cached feed content for a schema and format
|
|
849
927
|
*/
|
|
850
|
-
setFeedContent(e, n, s,
|
|
851
|
-
const
|
|
928
|
+
setFeedContent(e, n, s, o, i, r) {
|
|
929
|
+
const a = ie(e, n, i), c = Math.floor(Date.now() / 1e3), l = r ?? this.config.ttl, d = c + l, h = jt(e, n, c, s.length), g = {
|
|
852
930
|
content: s,
|
|
853
|
-
contentType:
|
|
854
|
-
etag:
|
|
931
|
+
contentType: o,
|
|
932
|
+
etag: h,
|
|
855
933
|
lastModified: c,
|
|
856
|
-
expiresAt:
|
|
934
|
+
expiresAt: d
|
|
857
935
|
};
|
|
858
|
-
this.feedContentCache.set(
|
|
936
|
+
this.feedContentCache.set(a, g);
|
|
859
937
|
}
|
|
860
938
|
/**
|
|
861
939
|
* Clear feed data cache for a schema
|
|
@@ -883,12 +961,12 @@ class Mt {
|
|
|
883
961
|
* Set cached image metadata for a transaction ID
|
|
884
962
|
*/
|
|
885
963
|
setImageMetadata(e, n) {
|
|
886
|
-
const s = Math.floor(Date.now() / 1e3),
|
|
964
|
+
const s = Math.floor(Date.now() / 1e3), o = this.config.imageMetadata?.ttl || 604800, i = s + o, r = {
|
|
887
965
|
metadata: n,
|
|
888
966
|
cachedAt: s,
|
|
889
|
-
expiresAt:
|
|
967
|
+
expiresAt: i
|
|
890
968
|
};
|
|
891
|
-
this.imageMetadataCache.set(e,
|
|
969
|
+
this.imageMetadataCache.set(e, r);
|
|
892
970
|
}
|
|
893
971
|
/**
|
|
894
972
|
* Clear all caches
|
|
@@ -903,14 +981,14 @@ class Mt {
|
|
|
903
981
|
async withRefreshLock(e, n) {
|
|
904
982
|
const s = this.refreshLocks.get(e);
|
|
905
983
|
s && (await s, this.getFeedData(e));
|
|
906
|
-
const
|
|
984
|
+
const o = (async () => {
|
|
907
985
|
try {
|
|
908
986
|
return await n();
|
|
909
987
|
} finally {
|
|
910
988
|
this.refreshLocks.delete(e);
|
|
911
989
|
}
|
|
912
990
|
})();
|
|
913
|
-
return this.refreshLocks.set(e,
|
|
991
|
+
return this.refreshLocks.set(e, o), o;
|
|
914
992
|
}
|
|
915
993
|
/**
|
|
916
994
|
* Update configuration
|
|
@@ -930,7 +1008,7 @@ class Mt {
|
|
|
930
1008
|
};
|
|
931
1009
|
}
|
|
932
1010
|
}
|
|
933
|
-
class
|
|
1011
|
+
class Ht {
|
|
934
1012
|
cacheDir;
|
|
935
1013
|
config;
|
|
936
1014
|
constructor(e) {
|
|
@@ -943,7 +1021,7 @@ class Ft {
|
|
|
943
1021
|
*/
|
|
944
1022
|
async ensureCacheDir() {
|
|
945
1023
|
try {
|
|
946
|
-
await
|
|
1024
|
+
await E.mkdir(this.cacheDir, { recursive: !0 });
|
|
947
1025
|
} catch (e) {
|
|
948
1026
|
if (e.code !== "EEXIST")
|
|
949
1027
|
throw e;
|
|
@@ -953,29 +1031,29 @@ class Ft {
|
|
|
953
1031
|
* Get file path for feed data
|
|
954
1032
|
*/
|
|
955
1033
|
getFeedDataPath(e) {
|
|
956
|
-
return
|
|
1034
|
+
return F(this.cacheDir, `${e}.json`);
|
|
957
1035
|
}
|
|
958
1036
|
/**
|
|
959
1037
|
* Get file path for feed content
|
|
960
1038
|
*/
|
|
961
1039
|
getFeedContentPath(e, n, s) {
|
|
962
|
-
const
|
|
963
|
-
return
|
|
1040
|
+
const i = ie(e, n, s).replace(/:/g, "-");
|
|
1041
|
+
return F(this.cacheDir, `${i}.json`);
|
|
964
1042
|
}
|
|
965
1043
|
/**
|
|
966
1044
|
* Get file path for image metadata
|
|
967
1045
|
*/
|
|
968
1046
|
getImageMetadataPath(e) {
|
|
969
|
-
const n =
|
|
970
|
-
return
|
|
1047
|
+
const n = F(this.cacheDir, "image-metadata");
|
|
1048
|
+
return F(n, `${e}.json`);
|
|
971
1049
|
}
|
|
972
1050
|
/**
|
|
973
1051
|
* Ensure image metadata directory exists
|
|
974
1052
|
*/
|
|
975
1053
|
async ensureImageMetadataDir() {
|
|
976
1054
|
try {
|
|
977
|
-
const e =
|
|
978
|
-
await
|
|
1055
|
+
const e = F(this.cacheDir, "image-metadata");
|
|
1056
|
+
await E.mkdir(e, { recursive: !0 });
|
|
979
1057
|
} catch (e) {
|
|
980
1058
|
if (e.code !== "EEXIST")
|
|
981
1059
|
throw e;
|
|
@@ -986,8 +1064,8 @@ class Ft {
|
|
|
986
1064
|
*/
|
|
987
1065
|
async getFeedData(e) {
|
|
988
1066
|
try {
|
|
989
|
-
const n = this.getFeedDataPath(e), s = await
|
|
990
|
-
return Math.floor(Date.now() / 1e3) -
|
|
1067
|
+
const n = this.getFeedDataPath(e), s = await E.readFile(n, "utf-8"), o = JSON.parse(s);
|
|
1068
|
+
return Math.floor(Date.now() / 1e3) - o.lastUpdated > this.config.ttl ? (await this.clearFeedData(e), null) : o;
|
|
991
1069
|
} catch (n) {
|
|
992
1070
|
return n.code === "ENOENT" || console.error(`Error reading feed data cache for ${e}:`, n), null;
|
|
993
1071
|
}
|
|
@@ -999,7 +1077,7 @@ class Ft {
|
|
|
999
1077
|
try {
|
|
1000
1078
|
await this.ensureCacheDir();
|
|
1001
1079
|
const s = this.getFeedDataPath(e);
|
|
1002
|
-
await
|
|
1080
|
+
await E.writeFile(s, JSON.stringify(n, null, 2), "utf-8");
|
|
1003
1081
|
} catch (s) {
|
|
1004
1082
|
console.error(`Error writing feed data cache for ${e}:`, s);
|
|
1005
1083
|
}
|
|
@@ -1009,27 +1087,27 @@ class Ft {
|
|
|
1009
1087
|
*/
|
|
1010
1088
|
async getFeedContent(e, n, s) {
|
|
1011
1089
|
try {
|
|
1012
|
-
const
|
|
1013
|
-
return Math.floor(Date.now() / 1e3) >
|
|
1014
|
-
} catch (
|
|
1015
|
-
return
|
|
1090
|
+
const o = this.getFeedContentPath(e, n, s), i = await E.readFile(o, "utf-8"), r = JSON.parse(i);
|
|
1091
|
+
return Math.floor(Date.now() / 1e3) > r.expiresAt ? (await this.clearFeedContent(e, n, s), null) : r;
|
|
1092
|
+
} catch (o) {
|
|
1093
|
+
return o.code === "ENOENT" || console.error(
|
|
1016
1094
|
`Error reading feed content cache for ${e}:${n}:`,
|
|
1017
|
-
|
|
1095
|
+
o
|
|
1018
1096
|
), null;
|
|
1019
1097
|
}
|
|
1020
1098
|
}
|
|
1021
1099
|
/**
|
|
1022
1100
|
* Set cached feed content for a schema and format
|
|
1023
1101
|
*/
|
|
1024
|
-
async setFeedContent(e, n, s,
|
|
1102
|
+
async setFeedContent(e, n, s, o) {
|
|
1025
1103
|
try {
|
|
1026
1104
|
await this.ensureCacheDir();
|
|
1027
|
-
const
|
|
1028
|
-
await
|
|
1029
|
-
} catch (
|
|
1105
|
+
const i = this.getFeedContentPath(e, n, o);
|
|
1106
|
+
await E.writeFile(i, JSON.stringify(s, null, 2), "utf-8");
|
|
1107
|
+
} catch (i) {
|
|
1030
1108
|
console.error(
|
|
1031
1109
|
`Error writing feed content cache for ${e}:${n}:`,
|
|
1032
|
-
|
|
1110
|
+
i
|
|
1033
1111
|
);
|
|
1034
1112
|
}
|
|
1035
1113
|
}
|
|
@@ -1039,7 +1117,7 @@ class Ft {
|
|
|
1039
1117
|
async clearFeedData(e) {
|
|
1040
1118
|
try {
|
|
1041
1119
|
const n = this.getFeedDataPath(e);
|
|
1042
|
-
await
|
|
1120
|
+
await E.unlink(n);
|
|
1043
1121
|
} catch (n) {
|
|
1044
1122
|
n.code !== "ENOENT" && console.error(`Error clearing feed data cache for ${e}:`, n);
|
|
1045
1123
|
}
|
|
@@ -1049,12 +1127,12 @@ class Ft {
|
|
|
1049
1127
|
*/
|
|
1050
1128
|
async clearFeedContent(e, n, s) {
|
|
1051
1129
|
try {
|
|
1052
|
-
const
|
|
1053
|
-
await
|
|
1054
|
-
} catch (
|
|
1055
|
-
|
|
1130
|
+
const o = this.getFeedContentPath(e, n, s);
|
|
1131
|
+
await E.unlink(o);
|
|
1132
|
+
} catch (o) {
|
|
1133
|
+
o.code !== "ENOENT" && console.error(
|
|
1056
1134
|
`Error clearing feed content cache for ${e}:${n}:`,
|
|
1057
|
-
|
|
1135
|
+
o
|
|
1058
1136
|
);
|
|
1059
1137
|
}
|
|
1060
1138
|
}
|
|
@@ -1063,9 +1141,9 @@ class Ft {
|
|
|
1063
1141
|
*/
|
|
1064
1142
|
async clearAllContentCache(e) {
|
|
1065
1143
|
try {
|
|
1066
|
-
const n = await
|
|
1067
|
-
for (const
|
|
1068
|
-
|
|
1144
|
+
const n = await E.readdir(this.cacheDir), s = `${e}-`, o = ".json";
|
|
1145
|
+
for (const i of n)
|
|
1146
|
+
i.startsWith(s) && i.endsWith(o) && i !== `${e}.json` && await E.unlink(F(this.cacheDir, i));
|
|
1069
1147
|
} catch (n) {
|
|
1070
1148
|
console.error(`Error clearing all content cache for ${e}:`, n);
|
|
1071
1149
|
}
|
|
@@ -1075,8 +1153,8 @@ class Ft {
|
|
|
1075
1153
|
*/
|
|
1076
1154
|
async getImageMetadata(e) {
|
|
1077
1155
|
try {
|
|
1078
|
-
const n = this.getImageMetadataPath(e), s = await
|
|
1079
|
-
return Math.floor(Date.now() / 1e3) >
|
|
1156
|
+
const n = this.getImageMetadataPath(e), s = await E.readFile(n, "utf-8"), o = JSON.parse(s);
|
|
1157
|
+
return Math.floor(Date.now() / 1e3) > o.expiresAt ? (await this.clearImageMetadata(e), null) : o.metadata;
|
|
1080
1158
|
} catch (n) {
|
|
1081
1159
|
return n.code === "ENOENT" || console.error(`Error reading image metadata cache for ${e}:`, n), null;
|
|
1082
1160
|
}
|
|
@@ -1087,12 +1165,12 @@ class Ft {
|
|
|
1087
1165
|
async setImageMetadata(e, n) {
|
|
1088
1166
|
try {
|
|
1089
1167
|
await this.ensureImageMetadataDir();
|
|
1090
|
-
const s = this.getImageMetadataPath(e),
|
|
1168
|
+
const s = this.getImageMetadataPath(e), o = Math.floor(Date.now() / 1e3), i = this.config.imageMetadata?.ttl || 604800, r = o + i, a = {
|
|
1091
1169
|
metadata: n,
|
|
1092
|
-
cachedAt:
|
|
1093
|
-
expiresAt:
|
|
1170
|
+
cachedAt: o,
|
|
1171
|
+
expiresAt: r
|
|
1094
1172
|
};
|
|
1095
|
-
await
|
|
1173
|
+
await E.writeFile(s, JSON.stringify(a, null, 2), "utf-8");
|
|
1096
1174
|
} catch (s) {
|
|
1097
1175
|
console.error(`Error writing image metadata cache for ${e}:`, s);
|
|
1098
1176
|
}
|
|
@@ -1103,7 +1181,7 @@ class Ft {
|
|
|
1103
1181
|
async clearImageMetadata(e) {
|
|
1104
1182
|
try {
|
|
1105
1183
|
const n = this.getImageMetadataPath(e);
|
|
1106
|
-
await
|
|
1184
|
+
await E.unlink(n);
|
|
1107
1185
|
} catch (n) {
|
|
1108
1186
|
n.code !== "ENOENT" && console.error(`Error clearing image metadata cache for ${e}:`, n);
|
|
1109
1187
|
}
|
|
@@ -1113,14 +1191,14 @@ class Ft {
|
|
|
1113
1191
|
*/
|
|
1114
1192
|
async clearAll() {
|
|
1115
1193
|
try {
|
|
1116
|
-
const e = await
|
|
1194
|
+
const e = await E.readdir(this.cacheDir);
|
|
1117
1195
|
for (const s of e)
|
|
1118
|
-
s.endsWith(".json") && await
|
|
1119
|
-
const n =
|
|
1196
|
+
s.endsWith(".json") && await E.unlink(F(this.cacheDir, s));
|
|
1197
|
+
const n = F(this.cacheDir, "image-metadata");
|
|
1120
1198
|
try {
|
|
1121
|
-
const s = await
|
|
1122
|
-
for (const
|
|
1123
|
-
|
|
1199
|
+
const s = await E.readdir(n);
|
|
1200
|
+
for (const o of s)
|
|
1201
|
+
o.endsWith(".json") && await E.unlink(F(n, o));
|
|
1124
1202
|
} catch {
|
|
1125
1203
|
}
|
|
1126
1204
|
} catch (e) {
|
|
@@ -1128,7 +1206,7 @@ class Ft {
|
|
|
1128
1206
|
}
|
|
1129
1207
|
}
|
|
1130
1208
|
}
|
|
1131
|
-
class
|
|
1209
|
+
class Gt {
|
|
1132
1210
|
memoryCache;
|
|
1133
1211
|
fileCache;
|
|
1134
1212
|
config;
|
|
@@ -1139,7 +1217,7 @@ class Ut {
|
|
|
1139
1217
|
errors: 0
|
|
1140
1218
|
};
|
|
1141
1219
|
constructor(e) {
|
|
1142
|
-
this.config = e, this.memoryCache = new
|
|
1220
|
+
this.config = e, this.memoryCache = new Wt(e), this.fileCache = new Ht(e);
|
|
1143
1221
|
}
|
|
1144
1222
|
/**
|
|
1145
1223
|
* Get cached feed data for a schema
|
|
@@ -1177,18 +1255,18 @@ class Ut {
|
|
|
1177
1255
|
if (!this.config.enabled)
|
|
1178
1256
|
return null;
|
|
1179
1257
|
try {
|
|
1180
|
-
let
|
|
1181
|
-
return
|
|
1258
|
+
let o = this.memoryCache.getFeedContent(e, n, s);
|
|
1259
|
+
return o ? (this.stats.hits++, o) : (o = await this.fileCache.getFeedContent(e, n, s), o ? (this.memoryCache.setFeedContent(
|
|
1182
1260
|
e,
|
|
1183
1261
|
n,
|
|
1184
|
-
|
|
1185
|
-
|
|
1262
|
+
o.content,
|
|
1263
|
+
o.contentType,
|
|
1186
1264
|
s
|
|
1187
|
-
), this.stats.hits++,
|
|
1188
|
-
} catch (
|
|
1265
|
+
), this.stats.hits++, o) : (this.stats.misses++, null));
|
|
1266
|
+
} catch (o) {
|
|
1189
1267
|
return console.error(
|
|
1190
1268
|
`Error getting feed content cache for ${e}:${n}:`,
|
|
1191
|
-
|
|
1269
|
+
o
|
|
1192
1270
|
), this.stats.errors++, null;
|
|
1193
1271
|
}
|
|
1194
1272
|
}
|
|
@@ -1196,24 +1274,24 @@ class Ut {
|
|
|
1196
1274
|
* Set cached feed content for a schema and format
|
|
1197
1275
|
* Updates both memory and file cache
|
|
1198
1276
|
*/
|
|
1199
|
-
async setFeedContent(e, n, s,
|
|
1277
|
+
async setFeedContent(e, n, s, o, i) {
|
|
1200
1278
|
if (this.config.enabled)
|
|
1201
1279
|
try {
|
|
1202
|
-
let
|
|
1203
|
-
|
|
1280
|
+
let r;
|
|
1281
|
+
i?.archive ? r = this.config.archiveTtl ?? 86400 : i?.page != null && i.page > 1 && (r = this.config.pageTtl ?? 300), this.memoryCache.setFeedContent(
|
|
1204
1282
|
e,
|
|
1205
1283
|
n,
|
|
1206
1284
|
s,
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1285
|
+
o,
|
|
1286
|
+
i,
|
|
1287
|
+
r
|
|
1210
1288
|
);
|
|
1211
|
-
const
|
|
1212
|
-
|
|
1213
|
-
} catch (
|
|
1289
|
+
const a = this.memoryCache.getFeedContent(e, n, i);
|
|
1290
|
+
a && await this.fileCache.setFeedContent(e, n, a, i);
|
|
1291
|
+
} catch (r) {
|
|
1214
1292
|
console.error(
|
|
1215
1293
|
`Error setting feed content cache for ${e}:${n}:`,
|
|
1216
|
-
|
|
1294
|
+
r
|
|
1217
1295
|
), this.stats.errors++;
|
|
1218
1296
|
}
|
|
1219
1297
|
}
|
|
@@ -1242,27 +1320,27 @@ class Ut {
|
|
|
1242
1320
|
*/
|
|
1243
1321
|
mergeItems(e, n) {
|
|
1244
1322
|
const s = /* @__PURE__ */ new Map();
|
|
1245
|
-
for (const
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1323
|
+
for (const i of e) {
|
|
1324
|
+
const r = i.id || i.seedUid || i.SeedUid || "";
|
|
1325
|
+
r && s.set(r, i);
|
|
1248
1326
|
}
|
|
1249
|
-
for (const
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1327
|
+
for (const i of n) {
|
|
1328
|
+
const r = i.id || i.seedUid || i.SeedUid || "";
|
|
1329
|
+
r ? s.set(r, i) : s.set(`temp-${Date.now()}-${Math.random()}`, i);
|
|
1252
1330
|
}
|
|
1253
|
-
const
|
|
1254
|
-
return
|
|
1255
|
-
const
|
|
1256
|
-
return (
|
|
1257
|
-
}),
|
|
1331
|
+
const o = Array.from(s.values());
|
|
1332
|
+
return o.sort((i, r) => {
|
|
1333
|
+
const a = i.timeCreated || 0;
|
|
1334
|
+
return (r.timeCreated || 0) - a;
|
|
1335
|
+
}), o;
|
|
1258
1336
|
}
|
|
1259
1337
|
/**
|
|
1260
1338
|
* Filter items to only include those newer than the given timestamp
|
|
1261
1339
|
*/
|
|
1262
1340
|
filterNewItems(e, n) {
|
|
1263
1341
|
return e.filter((s) => {
|
|
1264
|
-
const
|
|
1265
|
-
return
|
|
1342
|
+
const o = s.timeCreated;
|
|
1343
|
+
return o && o > n;
|
|
1266
1344
|
});
|
|
1267
1345
|
}
|
|
1268
1346
|
/**
|
|
@@ -1318,33 +1396,33 @@ class Ut {
|
|
|
1318
1396
|
};
|
|
1319
1397
|
}
|
|
1320
1398
|
}
|
|
1321
|
-
function
|
|
1322
|
-
const t = parseInt(process.env.CACHE_TTL || "3600", 10), e = process.env.CACHE_DIR || "./cache", n = process.env.CACHE_ENABLED === "false" || process.env.CACHE_ENABLED === "0" || process.env.CACHE_ENABLED === "no" || process.env.CACHE_ENABLED === "off", s = process.env.CACHE_ENABLED === "true" || process.env.CACHE_ENABLED === "1" || process.env.CACHE_ENABLED === "yes",
|
|
1323
|
-
let
|
|
1324
|
-
n ?
|
|
1325
|
-
const
|
|
1399
|
+
function fe() {
|
|
1400
|
+
const t = parseInt(process.env.CACHE_TTL || "3600", 10), e = process.env.CACHE_DIR || "./cache", n = process.env.CACHE_ENABLED === "false" || process.env.CACHE_ENABLED === "0" || process.env.CACHE_ENABLED === "no" || process.env.CACHE_ENABLED === "off", s = process.env.CACHE_ENABLED === "true" || process.env.CACHE_ENABLED === "1" || process.env.CACHE_ENABLED === "yes", o = process.env.NODE_ENV === "development";
|
|
1401
|
+
let i;
|
|
1402
|
+
n ? i = !1 : s ? i = !0 : o ? i = !1 : i = !0;
|
|
1403
|
+
const r = process.env.CACHE_BACKGROUND_REFRESH === "true", a = parseInt(
|
|
1326
1404
|
process.env.CACHE_REFRESH_INTERVAL || "300",
|
|
1327
1405
|
10
|
|
1328
1406
|
);
|
|
1329
|
-
|
|
1330
|
-
const c = process.env.IMAGE_METADATA_ENABLED !== "false",
|
|
1407
|
+
i || console.log(`⚠️ Cache is DISABLED (${n ? "CACHE_ENABLED=false" : o ? "NODE_ENV=development" : "CACHE_ENABLED=false"})`);
|
|
1408
|
+
const c = process.env.IMAGE_METADATA_ENABLED !== "false", l = parseInt(process.env.IMAGE_METADATA_TTL || "604800", 10), d = process.env.IMAGE_METADATA_GATEWAYS ? process.env.IMAGE_METADATA_GATEWAYS.split(",").map((p) => p.trim()) : [...Me], h = parseInt(process.env.IMAGE_METADATA_TIMEOUT || "5000", 10), g = {
|
|
1331
1409
|
enabled: c,
|
|
1332
|
-
ttl:
|
|
1333
|
-
gateways:
|
|
1334
|
-
timeout:
|
|
1335
|
-
},
|
|
1410
|
+
ttl: l,
|
|
1411
|
+
gateways: d,
|
|
1412
|
+
timeout: h
|
|
1413
|
+
}, f = parseInt(process.env.CACHE_PAGE_TTL || "300", 10), y = parseInt(process.env.CACHE_ARCHIVE_TTL || "86400", 10);
|
|
1336
1414
|
return {
|
|
1337
1415
|
ttl: t,
|
|
1338
1416
|
cacheDir: e,
|
|
1339
|
-
enabled:
|
|
1340
|
-
backgroundRefresh:
|
|
1341
|
-
refreshInterval:
|
|
1342
|
-
imageMetadata:
|
|
1343
|
-
pageTtl:
|
|
1344
|
-
archiveTtl:
|
|
1417
|
+
enabled: i,
|
|
1418
|
+
backgroundRefresh: r,
|
|
1419
|
+
refreshInterval: a,
|
|
1420
|
+
imageMetadata: g,
|
|
1421
|
+
pageTtl: f,
|
|
1422
|
+
archiveTtl: y
|
|
1345
1423
|
};
|
|
1346
1424
|
}
|
|
1347
|
-
class
|
|
1425
|
+
class Ae {
|
|
1348
1426
|
config;
|
|
1349
1427
|
constructor(e) {
|
|
1350
1428
|
this.config = e;
|
|
@@ -1353,14 +1431,16 @@ class ye {
|
|
|
1353
1431
|
* Detect if an Arweave transaction ID links to an image and extract metadata
|
|
1354
1432
|
*/
|
|
1355
1433
|
async detectImage(e) {
|
|
1356
|
-
|
|
1434
|
+
await et().catch(() => {
|
|
1435
|
+
});
|
|
1436
|
+
const n = this.config.gateways || [...Me];
|
|
1357
1437
|
for (const s of n)
|
|
1358
1438
|
try {
|
|
1359
|
-
const
|
|
1360
|
-
if (
|
|
1361
|
-
return
|
|
1362
|
-
} catch (
|
|
1363
|
-
console.warn(`Failed to fetch from gateway ${s} for transaction ${e}:`,
|
|
1439
|
+
const o = `https://${s}/${e}`, i = await this.getImageMetadata(o);
|
|
1440
|
+
if (i.isImage)
|
|
1441
|
+
return i;
|
|
1442
|
+
} catch (o) {
|
|
1443
|
+
console.warn(`Failed to fetch from gateway ${s} for transaction ${e}:`, o);
|
|
1364
1444
|
continue;
|
|
1365
1445
|
}
|
|
1366
1446
|
return {
|
|
@@ -1376,30 +1456,30 @@ class ye {
|
|
|
1376
1456
|
const n = await this.fetchWithTimeout(e, { method: "HEAD" });
|
|
1377
1457
|
if (!n.ok)
|
|
1378
1458
|
return { isImage: !1, url: e };
|
|
1379
|
-
const s = n.headers.get("content-type") || "",
|
|
1459
|
+
const s = n.headers.get("content-type") || "", o = n.headers.get("content-length");
|
|
1380
1460
|
if (!this.isImageContentType(s))
|
|
1381
1461
|
return {
|
|
1382
1462
|
isImage: !1,
|
|
1383
1463
|
url: e,
|
|
1384
1464
|
mimeType: s || void 0,
|
|
1385
|
-
size:
|
|
1465
|
+
size: o ? parseInt(o, 10) : void 0
|
|
1386
1466
|
};
|
|
1387
|
-
const
|
|
1467
|
+
const i = await this.fetchWithTimeout(e, {
|
|
1388
1468
|
headers: {
|
|
1389
1469
|
Range: "bytes=0-8192"
|
|
1390
1470
|
// First 8KB should be enough for most image headers
|
|
1391
1471
|
}
|
|
1392
1472
|
});
|
|
1393
|
-
if (!
|
|
1394
|
-
return await this.getImageMetadataFromFullRequest(e, s,
|
|
1395
|
-
const
|
|
1473
|
+
if (!i.ok)
|
|
1474
|
+
return await this.getImageMetadataFromFullRequest(e, s, o);
|
|
1475
|
+
const r = Buffer.from(await i.arrayBuffer()), a = this.extractImageDimensions(r, s), c = this.getImageFormat(s, r);
|
|
1396
1476
|
return {
|
|
1397
1477
|
isImage: !0,
|
|
1398
1478
|
url: e,
|
|
1399
1479
|
mimeType: s,
|
|
1400
|
-
width:
|
|
1401
|
-
height:
|
|
1402
|
-
size:
|
|
1480
|
+
width: a.width,
|
|
1481
|
+
height: a.height,
|
|
1482
|
+
size: o ? parseInt(o, 10) : void 0,
|
|
1403
1483
|
format: c
|
|
1404
1484
|
};
|
|
1405
1485
|
} catch (n) {
|
|
@@ -1411,21 +1491,21 @@ class ye {
|
|
|
1411
1491
|
*/
|
|
1412
1492
|
async getImageMetadataFromFullRequest(e, n, s) {
|
|
1413
1493
|
try {
|
|
1414
|
-
const
|
|
1415
|
-
if (!
|
|
1494
|
+
const o = await this.fetchWithTimeout(e);
|
|
1495
|
+
if (!o.ok)
|
|
1416
1496
|
return { isImage: !1, url: e };
|
|
1417
|
-
const
|
|
1497
|
+
const i = Buffer.from(await o.arrayBuffer()), r = this.extractImageDimensions(i, n), a = this.getImageFormat(n, i);
|
|
1418
1498
|
return {
|
|
1419
1499
|
isImage: !0,
|
|
1420
1500
|
url: e,
|
|
1421
1501
|
mimeType: n,
|
|
1422
|
-
width:
|
|
1423
|
-
height:
|
|
1424
|
-
size:
|
|
1425
|
-
format:
|
|
1502
|
+
width: r.width,
|
|
1503
|
+
height: r.height,
|
|
1504
|
+
size: i.length,
|
|
1505
|
+
format: a
|
|
1426
1506
|
};
|
|
1427
|
-
} catch (
|
|
1428
|
-
return console.warn(`Error in full request for ${e}:`,
|
|
1507
|
+
} catch (o) {
|
|
1508
|
+
return console.warn(`Error in full request for ${e}:`, o), { isImage: !1, url: e };
|
|
1429
1509
|
}
|
|
1430
1510
|
}
|
|
1431
1511
|
/**
|
|
@@ -1439,7 +1519,7 @@ class ye {
|
|
|
1439
1519
|
*/
|
|
1440
1520
|
extractImageDimensions(e, n) {
|
|
1441
1521
|
try {
|
|
1442
|
-
const s =
|
|
1522
|
+
const s = ue(e);
|
|
1443
1523
|
if (s.width && s.height)
|
|
1444
1524
|
return {
|
|
1445
1525
|
width: s.width,
|
|
@@ -1457,12 +1537,12 @@ class ye {
|
|
|
1457
1537
|
if (e) {
|
|
1458
1538
|
const s = e.toLowerCase().match(/image\/([^;]+)/);
|
|
1459
1539
|
if (s && s[1]) {
|
|
1460
|
-
const
|
|
1461
|
-
return
|
|
1540
|
+
const o = s[1].toLowerCase();
|
|
1541
|
+
return o === "jpeg" ? "jpeg" : o === "png" ? "png" : o === "gif" ? "gif" : o === "webp" ? "webp" : o === "svg+xml" ? "svg" : o;
|
|
1462
1542
|
}
|
|
1463
1543
|
}
|
|
1464
1544
|
try {
|
|
1465
|
-
const s =
|
|
1545
|
+
const s = ue(n);
|
|
1466
1546
|
if (s.type)
|
|
1467
1547
|
return s.type.toLowerCase();
|
|
1468
1548
|
} catch {
|
|
@@ -1472,19 +1552,19 @@ class ye {
|
|
|
1472
1552
|
* Fetch with timeout
|
|
1473
1553
|
*/
|
|
1474
1554
|
async fetchWithTimeout(e, n = {}) {
|
|
1475
|
-
const s = new AbortController(),
|
|
1555
|
+
const s = new AbortController(), o = setTimeout(() => s.abort(), this.config.timeout);
|
|
1476
1556
|
try {
|
|
1477
|
-
const
|
|
1557
|
+
const i = await fetch(e, {
|
|
1478
1558
|
...n,
|
|
1479
1559
|
signal: s.signal
|
|
1480
1560
|
});
|
|
1481
|
-
return clearTimeout(
|
|
1482
|
-
} catch (
|
|
1483
|
-
throw clearTimeout(
|
|
1561
|
+
return clearTimeout(o), i;
|
|
1562
|
+
} catch (i) {
|
|
1563
|
+
throw clearTimeout(o), i instanceof Error && i.name === "AbortError" ? new Error(`Request timeout after ${this.config.timeout}ms`) : i;
|
|
1484
1564
|
}
|
|
1485
1565
|
}
|
|
1486
1566
|
}
|
|
1487
|
-
function
|
|
1567
|
+
function ce(t, e) {
|
|
1488
1568
|
for (const n of e) {
|
|
1489
1569
|
const s = t[n];
|
|
1490
1570
|
if (typeof s == "string" && s.trim() !== "")
|
|
@@ -1492,83 +1572,83 @@ function se(t, e) {
|
|
|
1492
1572
|
}
|
|
1493
1573
|
return "";
|
|
1494
1574
|
}
|
|
1495
|
-
const
|
|
1496
|
-
function
|
|
1497
|
-
const n =
|
|
1575
|
+
const Be = ["summary", "Summary", "description", "Description", "text", "Text"], ze = ["html", "Html", "body", "Body", "content", "Content"], Xt = ["summary", "Summary", "description", "Description", "text", "Text"];
|
|
1576
|
+
function Te(t, e) {
|
|
1577
|
+
const n = he(t.model) - he(e.model);
|
|
1498
1578
|
if (n !== 0) return n;
|
|
1499
1579
|
const s = t.key.localeCompare(e.key);
|
|
1500
1580
|
return s !== 0 ? s : t.index - e.index;
|
|
1501
1581
|
}
|
|
1502
|
-
function
|
|
1503
|
-
const e =
|
|
1582
|
+
function Jt(t) {
|
|
1583
|
+
const e = ee(t), n = te(t);
|
|
1504
1584
|
let s = null;
|
|
1505
1585
|
if (e)
|
|
1506
|
-
for (const [
|
|
1507
|
-
if (!B(
|
|
1508
|
-
const
|
|
1509
|
-
if (typeof
|
|
1510
|
-
const
|
|
1511
|
-
(!s ||
|
|
1586
|
+
for (const [o, i] of Object.entries(e)) {
|
|
1587
|
+
if (!B(i)) continue;
|
|
1588
|
+
const r = t[o];
|
|
1589
|
+
if (typeof r != "string" || r.trim() === "") continue;
|
|
1590
|
+
const a = { model: i, key: o, index: 0, value: r };
|
|
1591
|
+
(!s || Te(a, s) < 0) && (s = a);
|
|
1512
1592
|
}
|
|
1513
1593
|
if (n)
|
|
1514
|
-
for (const [
|
|
1515
|
-
const
|
|
1516
|
-
if (!Array.isArray(
|
|
1517
|
-
const
|
|
1518
|
-
for (let c = 0; c <
|
|
1519
|
-
const
|
|
1520
|
-
if (!B(
|
|
1521
|
-
const
|
|
1522
|
-
if (typeof
|
|
1523
|
-
const
|
|
1524
|
-
(!s ||
|
|
1594
|
+
for (const [o, i] of Object.entries(n)) {
|
|
1595
|
+
const r = t[o];
|
|
1596
|
+
if (!Array.isArray(r)) continue;
|
|
1597
|
+
const a = Math.min(i.length, r.length);
|
|
1598
|
+
for (let c = 0; c < a; c++) {
|
|
1599
|
+
const l = i[c];
|
|
1600
|
+
if (!B(l)) continue;
|
|
1601
|
+
const d = r[c];
|
|
1602
|
+
if (typeof d != "string" || d.trim() === "") continue;
|
|
1603
|
+
const h = { model: l, key: o, index: c, value: d };
|
|
1604
|
+
(!s || Te(h, s) < 0) && (s = h);
|
|
1525
1605
|
}
|
|
1526
1606
|
}
|
|
1527
1607
|
return s?.value ?? "";
|
|
1528
1608
|
}
|
|
1529
|
-
function
|
|
1530
|
-
return
|
|
1609
|
+
function Vt(t) {
|
|
1610
|
+
return ce(t, Be);
|
|
1531
1611
|
}
|
|
1532
|
-
function
|
|
1533
|
-
const e =
|
|
1612
|
+
function Kt(t) {
|
|
1613
|
+
const e = Jt(t);
|
|
1534
1614
|
if (e !== "") return e;
|
|
1535
|
-
const n =
|
|
1536
|
-
return n !== "" ? n :
|
|
1615
|
+
const n = ce(t, ze);
|
|
1616
|
+
return n !== "" ? n : ce(t, Xt);
|
|
1537
1617
|
}
|
|
1538
|
-
function
|
|
1618
|
+
function Z(t) {
|
|
1539
1619
|
return typeof t != "string" ? !1 : t.includes("data:image/") && t.includes(";base64,");
|
|
1540
1620
|
}
|
|
1541
|
-
function
|
|
1542
|
-
const e =
|
|
1621
|
+
function Yt(t) {
|
|
1622
|
+
const e = ee(t);
|
|
1543
1623
|
if (e) {
|
|
1544
|
-
for (const [s,
|
|
1545
|
-
if (B(
|
|
1624
|
+
for (const [s, o] of Object.entries(e))
|
|
1625
|
+
if (B(o) && Z(t[s]))
|
|
1546
1626
|
return !0;
|
|
1547
1627
|
}
|
|
1548
|
-
const n =
|
|
1628
|
+
const n = te(t);
|
|
1549
1629
|
if (n)
|
|
1550
|
-
for (const [s,
|
|
1551
|
-
const
|
|
1552
|
-
if (!Array.isArray(
|
|
1553
|
-
const
|
|
1554
|
-
for (let
|
|
1555
|
-
if (B(
|
|
1630
|
+
for (const [s, o] of Object.entries(n)) {
|
|
1631
|
+
const i = t[s];
|
|
1632
|
+
if (!Array.isArray(i)) continue;
|
|
1633
|
+
const r = Math.min(o.length, i.length);
|
|
1634
|
+
for (let a = 0; a < r; a++)
|
|
1635
|
+
if (B(o[a]) && Z(i[a]))
|
|
1556
1636
|
return !0;
|
|
1557
1637
|
}
|
|
1558
1638
|
return !1;
|
|
1559
1639
|
}
|
|
1560
|
-
function
|
|
1561
|
-
if (
|
|
1562
|
-
for (const e of
|
|
1563
|
-
if (
|
|
1564
|
-
for (const e of
|
|
1565
|
-
if (
|
|
1640
|
+
function qt(t) {
|
|
1641
|
+
if (Yt(t)) return !0;
|
|
1642
|
+
for (const e of ze)
|
|
1643
|
+
if (Z(t[e])) return !0;
|
|
1644
|
+
for (const e of Be)
|
|
1645
|
+
if (Z(t[e])) return !0;
|
|
1566
1646
|
return !1;
|
|
1567
1647
|
}
|
|
1568
|
-
function
|
|
1569
|
-
return e === "include_items" ? [...t] : t.filter((n) => !
|
|
1648
|
+
function Zt(t, e = "omit_items") {
|
|
1649
|
+
return e === "include_items" ? [...t] : t.filter((n) => !qt(n));
|
|
1570
1650
|
}
|
|
1571
|
-
function
|
|
1651
|
+
function Qt(t) {
|
|
1572
1652
|
if (t != null) {
|
|
1573
1653
|
if (typeof t == "string") {
|
|
1574
1654
|
if (t.startsWith("http://") || t.startsWith("https://")) return t;
|
|
@@ -1591,41 +1671,145 @@ function Ot(t) {
|
|
|
1591
1671
|
}
|
|
1592
1672
|
}
|
|
1593
1673
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
if (
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1674
|
+
function re(t) {
|
|
1675
|
+
if (typeof t == "number" && Number.isFinite(t) && t > 0) return t;
|
|
1676
|
+
if (typeof t == "string") {
|
|
1677
|
+
const e = Number(t);
|
|
1678
|
+
if (Number.isFinite(e) && e > 0) return e;
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
function We(t) {
|
|
1682
|
+
if (Array.isArray(t)) {
|
|
1683
|
+
for (const n of t) {
|
|
1684
|
+
const s = We(n);
|
|
1685
|
+
if (s) return s;
|
|
1686
|
+
}
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
const e = Qt(t);
|
|
1690
|
+
if (e) {
|
|
1691
|
+
if (t && typeof t == "object" && !Array.isArray(t)) {
|
|
1692
|
+
const n = t, s = typeof n.mimeType == "string" && n.mimeType || typeof n.type == "string" && n.type || typeof n.contentType == "string" && n.contentType || void 0;
|
|
1693
|
+
return {
|
|
1694
|
+
url: e,
|
|
1695
|
+
mimeType: s,
|
|
1696
|
+
width: re(n.width),
|
|
1697
|
+
height: re(n.height),
|
|
1698
|
+
size: re(n.size ?? n.fileSize),
|
|
1699
|
+
format: typeof n.format == "string" ? n.format : void 0
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
return { url: e };
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
function en(t) {
|
|
1706
|
+
if (t._hasImage && t._imageMetadata && typeof t._imageMetadata == "object") {
|
|
1707
|
+
const n = t._imageMetadata;
|
|
1708
|
+
if (n.url)
|
|
1709
|
+
return {
|
|
1710
|
+
url: n.url,
|
|
1711
|
+
mimeType: n.mimeType,
|
|
1712
|
+
width: n.width,
|
|
1713
|
+
height: n.height,
|
|
1714
|
+
size: n.size,
|
|
1715
|
+
format: n.format
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
const e = [
|
|
1719
|
+
"feature_image",
|
|
1720
|
+
"featureImage",
|
|
1721
|
+
"image",
|
|
1722
|
+
"images",
|
|
1723
|
+
"cover_image",
|
|
1724
|
+
"coverImage",
|
|
1725
|
+
"thumbnail",
|
|
1726
|
+
"thumbnail_image",
|
|
1727
|
+
"thumbnailImage"
|
|
1728
|
+
];
|
|
1729
|
+
for (const n of e) {
|
|
1730
|
+
if (!(n in t)) continue;
|
|
1731
|
+
const s = We(t[n]);
|
|
1732
|
+
if (s) return s;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
function tn(t, e, n, s, o, i) {
|
|
1736
|
+
const r = n.mimeType || "image/jpeg";
|
|
1737
|
+
t.enclosures = [
|
|
1738
|
+
{
|
|
1739
|
+
url: n.url,
|
|
1740
|
+
type: r,
|
|
1741
|
+
...n.size ? { length: n.size } : {}
|
|
1742
|
+
}
|
|
1743
|
+
];
|
|
1744
|
+
const a = {
|
|
1745
|
+
url: n.url,
|
|
1746
|
+
type: r,
|
|
1747
|
+
medium: "image"
|
|
1748
|
+
};
|
|
1749
|
+
n.width && (a.width = n.width), n.height && (a.height = n.height), n.size && (a.fileSize = n.size), n.format && (a.format = n.format), t["media:content"] = [a];
|
|
1750
|
+
const c = { url: n.url };
|
|
1751
|
+
n.width && (c.width = n.width), n.height && (c.height = n.height), t["media:thumbnail"] = [c], e.title && (t["media:title"] = e.title);
|
|
1752
|
+
const l = e.description || e.summary || e.title || "";
|
|
1753
|
+
if (l && (t["media:description"] = l), e.title) {
|
|
1754
|
+
const d = [];
|
|
1755
|
+
d.push(...String(e.title).toLowerCase().split(/\s+/).filter((h) => h.length > 3)), e.description && d.push(...String(e.description).toLowerCase().split(/\s+/).filter((h) => h.length > 3)), d.length > 0 && (t["media:keywords"] = [...new Set(d)].slice(0, 10).join(", "));
|
|
1756
|
+
}
|
|
1757
|
+
if (Array.isArray(e.authors) && e.authors.length > 0 ? t["media:credit"] = e.authors.map((d) => ({
|
|
1758
|
+
value: d.name || d.displayName || "Unknown",
|
|
1759
|
+
role: "author"
|
|
1760
|
+
})) : o && (t["media:credit"] = [{ value: o.name, role: "author" }]), i && (t["media:copyright"] = i), s && (t["media:category"] = [
|
|
1761
|
+
{
|
|
1762
|
+
value: s,
|
|
1763
|
+
scheme: "http://www.schema.org/"
|
|
1764
|
+
}
|
|
1765
|
+
]), t["media:group"] = [
|
|
1766
|
+
{
|
|
1767
|
+
"media:content": [a],
|
|
1768
|
+
"media:thumbnail": [c],
|
|
1769
|
+
"media:title": e.title || "Untitled",
|
|
1770
|
+
"media:description": l
|
|
1771
|
+
}
|
|
1772
|
+
], n.url && typeof e.content == "string" && e.content.trim() !== "" && !e.content.includes(n.url)) {
|
|
1773
|
+
const d = `<img src="${n.url}" alt="${e.title || ""}"${n.width ? ` width="${n.width}"` : ""}${n.height ? ` height="${n.height}"` : ""} />`;
|
|
1774
|
+
t["content:encoded"] = `${d}
|
|
1775
|
+
${e.content}`;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
let N, x = null, K = null;
|
|
1779
|
+
function He() {
|
|
1780
|
+
if (!K) {
|
|
1781
|
+
const t = fe();
|
|
1782
|
+
K = new Gt(t);
|
|
1599
1783
|
}
|
|
1600
|
-
return
|
|
1784
|
+
return K;
|
|
1601
1785
|
}
|
|
1602
|
-
function
|
|
1603
|
-
|
|
1786
|
+
function wn() {
|
|
1787
|
+
K = null;
|
|
1604
1788
|
}
|
|
1605
|
-
const
|
|
1606
|
-
if (
|
|
1607
|
-
return
|
|
1608
|
-
if (!
|
|
1609
|
-
return
|
|
1789
|
+
const nn = async () => {
|
|
1790
|
+
if (x)
|
|
1791
|
+
return x;
|
|
1792
|
+
if (!N)
|
|
1793
|
+
return x = (async () => {
|
|
1610
1794
|
try {
|
|
1611
1795
|
console.log("Initializing Seed Protocol client..."), await L.init({ config: {
|
|
1612
1796
|
endpoints: {
|
|
1613
1797
|
filePaths: "app-files",
|
|
1614
1798
|
files: "/app-files"
|
|
1615
1799
|
},
|
|
1616
|
-
arweaveDomain:
|
|
1617
|
-
}, addresses: [] }), console.log("✅ Seed Protocol client initialized successfully"),
|
|
1800
|
+
arweaveDomain: tt
|
|
1801
|
+
}, addresses: [] }), console.log("✅ Seed Protocol client initialized successfully"), N = L, x = null;
|
|
1618
1802
|
} catch (t) {
|
|
1619
|
-
throw console.error("❌ Failed to initialize Seed Protocol client:", t),
|
|
1803
|
+
throw console.error("❌ Failed to initialize Seed Protocol client:", t), x = null, t;
|
|
1620
1804
|
}
|
|
1621
|
-
})(),
|
|
1622
|
-
},
|
|
1805
|
+
})(), x;
|
|
1806
|
+
}, rn = async () => N || (x ? (await x, N) : (await nn(), N)), Cn = async () => {
|
|
1623
1807
|
try {
|
|
1624
1808
|
console.log("Tearing down Seed Protocol client..."), typeof L.stop == "function" && (await L.stop(), console.log("✅ Seed Protocol client stopped")), typeof L.unload == "function" && (await L.unload(), console.log("✅ Seed Protocol client unloaded")), console.log("✅ Seed Protocol client teardown complete");
|
|
1625
1809
|
} catch (t) {
|
|
1626
1810
|
console.error("❌ Failed to teardown Seed Protocol client:", t);
|
|
1627
1811
|
}
|
|
1628
|
-
},
|
|
1812
|
+
}, T = {
|
|
1629
1813
|
title: "Seed Protocol",
|
|
1630
1814
|
description: "Content published via Seed Protocol",
|
|
1631
1815
|
siteUrl: "https://seedprotocol.io",
|
|
@@ -1638,265 +1822,224 @@ const Nt = async () => {
|
|
|
1638
1822
|
link: "https://seedprotocol.io"
|
|
1639
1823
|
}
|
|
1640
1824
|
};
|
|
1641
|
-
async function
|
|
1825
|
+
async function Ee(t, e, n) {
|
|
1642
1826
|
const s = t.filter(
|
|
1643
|
-
(
|
|
1827
|
+
(a) => a.storageTransactionId || a.storage_transaction_id
|
|
1644
1828
|
);
|
|
1645
1829
|
if (s.length === 0)
|
|
1646
1830
|
return t;
|
|
1647
1831
|
console.log(`Enriching ${s.length} items with image metadata`);
|
|
1648
|
-
const
|
|
1649
|
-
const c =
|
|
1650
|
-
if (!c) return
|
|
1832
|
+
const o = s.map(async (a) => {
|
|
1833
|
+
const c = a.storageTransactionId || a.storage_transaction_id;
|
|
1834
|
+
if (!c) return a;
|
|
1651
1835
|
try {
|
|
1652
|
-
let
|
|
1653
|
-
return
|
|
1654
|
-
} catch (
|
|
1655
|
-
return console.warn(`Error enriching item with transaction ${c}:`,
|
|
1836
|
+
let l = await n.getImageMetadata(c);
|
|
1837
|
+
return l || (console.log(`Detecting image for transaction ${c}`), l = await e.detectImage(c), await n.setImageMetadata(c, l)), l.isImage && (a._imageMetadata = l, a._hasImage = !0), a;
|
|
1838
|
+
} catch (l) {
|
|
1839
|
+
return console.warn(`Error enriching item with transaction ${c}:`, l), a;
|
|
1656
1840
|
}
|
|
1657
|
-
}),
|
|
1658
|
-
return
|
|
1659
|
-
const c =
|
|
1660
|
-
c &&
|
|
1661
|
-
}), t.map((
|
|
1662
|
-
const c =
|
|
1663
|
-
return
|
|
1841
|
+
}), i = await Promise.all(o), r = /* @__PURE__ */ new Map();
|
|
1842
|
+
return i.forEach((a) => {
|
|
1843
|
+
const c = a.id || a.seedUid || a.SeedUid || "";
|
|
1844
|
+
c && r.set(c, a);
|
|
1845
|
+
}), t.map((a) => {
|
|
1846
|
+
const c = a.id || a.seedUid || a.SeedUid || "";
|
|
1847
|
+
return r.get(c) || a;
|
|
1664
1848
|
});
|
|
1665
1849
|
}
|
|
1666
|
-
function
|
|
1667
|
-
const { schemaName: n, siteUrl: s, itemUrlBase:
|
|
1668
|
-
return
|
|
1850
|
+
function on(t, e) {
|
|
1851
|
+
const { schemaName: n, siteUrl: s, itemUrlBase: o, itemUrlPath: i, richTextDataUriImages: r = "omit_items" } = e;
|
|
1852
|
+
return Zt(
|
|
1669
1853
|
t,
|
|
1670
|
-
|
|
1854
|
+
r
|
|
1671
1855
|
).map((c) => {
|
|
1672
|
-
const
|
|
1673
|
-
let
|
|
1856
|
+
const l = c.id || c.seedUid || c.SeedUid || c.storageTransactionId || c.storage_transaction_id, d = o != null ? `${o.replace(/\/$/, "")}/${(i ?? "attestation/view").replace(/^\//, "")}/${l}` : `${s}/${U(n)}/${l}`, h = c.link || c.Link || c.import_url || c.importUrl || d;
|
|
1857
|
+
let g;
|
|
1674
1858
|
if (c.pubDate || c.PubDate) {
|
|
1675
|
-
const
|
|
1676
|
-
|
|
1859
|
+
const w = c.pubDate || c.PubDate;
|
|
1860
|
+
g = new Date(w);
|
|
1677
1861
|
} else if (c.timeCreated)
|
|
1678
|
-
|
|
1862
|
+
g = new Date(c.timeCreated * 1e3);
|
|
1679
1863
|
else if (c.publishedAt || c.createdAt || c.updatedAt) {
|
|
1680
|
-
const
|
|
1681
|
-
|
|
1864
|
+
const w = c.publishedAt || c.createdAt || c.updatedAt;
|
|
1865
|
+
g = w && typeof w == "object" && w.constructor === Date ? w : new Date(w);
|
|
1682
1866
|
} else
|
|
1683
|
-
|
|
1684
|
-
const
|
|
1867
|
+
g = /* @__PURE__ */ new Date();
|
|
1868
|
+
const f = Vt(c), y = Kt(c), p = {
|
|
1685
1869
|
...c,
|
|
1686
1870
|
// Preserve all dynamic properties first
|
|
1687
1871
|
// Map to standard feed fields
|
|
1688
|
-
id:
|
|
1872
|
+
id: l,
|
|
1689
1873
|
title: c.title || c.Title || "Untitled",
|
|
1690
|
-
link:
|
|
1691
|
-
description:
|
|
1692
|
-
content:
|
|
1693
|
-
pubDate:
|
|
1694
|
-
date:
|
|
1874
|
+
link: h,
|
|
1875
|
+
description: f,
|
|
1876
|
+
content: y,
|
|
1877
|
+
pubDate: g,
|
|
1878
|
+
date: g,
|
|
1695
1879
|
// Map guid - use full URL when available for proper permalink
|
|
1696
|
-
guid: c.guid || c.Guid || c.link || c.Link ||
|
|
1880
|
+
guid: c.guid || c.Guid || c.link || c.Link || h
|
|
1697
1881
|
};
|
|
1698
|
-
if (typeof
|
|
1699
|
-
const
|
|
1700
|
-
|
|
1882
|
+
if (typeof p.html == "string" && p.Html === void 0 && (p.Html = p.html), typeof p.Html == "string" && p.html === void 0 && (p.html = p.Html), typeof p.body == "string" && p.Body === void 0 && (p.Body = p.body), typeof p.Body == "string" && p.body === void 0 && (p.body = p.Body), c._imageMetadata && c._hasImage) {
|
|
1883
|
+
const w = c._imageMetadata;
|
|
1884
|
+
p._imageMetadata = w, p._hasImage = !0;
|
|
1701
1885
|
}
|
|
1702
|
-
return Object.keys(
|
|
1703
|
-
const
|
|
1704
|
-
if (typeof
|
|
1705
|
-
const
|
|
1706
|
-
isNaN(
|
|
1886
|
+
return Object.keys(p).forEach((w) => {
|
|
1887
|
+
const u = p[w];
|
|
1888
|
+
if (typeof u == "string" && /date|time|published|created|updated/i.test(w) && w !== "pubDate" && w !== "date") {
|
|
1889
|
+
const m = new Date(u);
|
|
1890
|
+
isNaN(m.getTime()) || (p[w] = m);
|
|
1707
1891
|
}
|
|
1708
|
-
}),
|
|
1892
|
+
}), p;
|
|
1709
1893
|
});
|
|
1710
1894
|
}
|
|
1711
|
-
const
|
|
1712
|
-
const c =
|
|
1713
|
-
if (
|
|
1714
|
-
const
|
|
1715
|
-
|
|
1716
|
-
}
|
|
1717
|
-
if (
|
|
1718
|
-
for (const
|
|
1719
|
-
|
|
1720
|
-
const
|
|
1895
|
+
const Ge = (t, e, n, s, o, i, r, a) => {
|
|
1896
|
+
const c = U(e), l = `${T.siteUrl}/${c}/${n}`, d = s ? `${l}?v=${s}` : l, h = `${T.title} - ${sn(c)}`, g = /* @__PURE__ */ new Date(), f = G(), y = [];
|
|
1897
|
+
if (o) {
|
|
1898
|
+
const w = o.baseUrl.replace(/\?.*$/, ""), u = w.includes("?") ? "&" : "?";
|
|
1899
|
+
o.hasNext && y.push({ rel: "next", href: `${w}${u}page=${o.page + 1}` }), o.page > 1 && (y.push({ rel: "previous", href: `${w}${u}page=${o.page - 1}` }), y.push({ rel: "first", href: `${w}${u}page=1` }));
|
|
1900
|
+
}
|
|
1901
|
+
if (i?.length)
|
|
1902
|
+
for (const w of i)
|
|
1903
|
+
y.push({ rel: w.rel, href: w.href });
|
|
1904
|
+
const p = on(t, {
|
|
1721
1905
|
schemaName: e,
|
|
1722
|
-
siteUrl:
|
|
1723
|
-
itemUrlBase:
|
|
1724
|
-
itemUrlPath:
|
|
1725
|
-
richTextDataUriImages:
|
|
1906
|
+
siteUrl: T.siteUrl,
|
|
1907
|
+
itemUrlBase: f.itemUrlBase,
|
|
1908
|
+
itemUrlPath: f.itemUrlPath,
|
|
1909
|
+
richTextDataUriImages: a?.richTextDataUriImages ?? f.richTextDataUriImages
|
|
1726
1910
|
});
|
|
1727
1911
|
switch (n) {
|
|
1728
1912
|
case "atom": {
|
|
1729
|
-
const
|
|
1730
|
-
{ href:
|
|
1731
|
-
{ href:
|
|
1913
|
+
const w = [
|
|
1914
|
+
{ href: d, rel: "self" },
|
|
1915
|
+
{ href: T.siteUrl }
|
|
1732
1916
|
];
|
|
1733
|
-
for (const
|
|
1734
|
-
|
|
1735
|
-
href:
|
|
1736
|
-
rel:
|
|
1737
|
-
type:
|
|
1917
|
+
for (const m of y)
|
|
1918
|
+
w.push({
|
|
1919
|
+
href: m.href,
|
|
1920
|
+
rel: m.rel,
|
|
1921
|
+
type: m.type
|
|
1738
1922
|
});
|
|
1739
|
-
const
|
|
1740
|
-
id:
|
|
1741
|
-
title:
|
|
1742
|
-
updated:
|
|
1743
|
-
links:
|
|
1744
|
-
subtitle:
|
|
1745
|
-
rights:
|
|
1746
|
-
author:
|
|
1747
|
-
name:
|
|
1748
|
-
email:
|
|
1749
|
-
uri:
|
|
1923
|
+
const u = {
|
|
1924
|
+
id: d,
|
|
1925
|
+
title: h,
|
|
1926
|
+
updated: g,
|
|
1927
|
+
links: w,
|
|
1928
|
+
subtitle: T.description,
|
|
1929
|
+
rights: T.copyright,
|
|
1930
|
+
author: T.author ? {
|
|
1931
|
+
name: T.author.name,
|
|
1932
|
+
email: T.author.email,
|
|
1933
|
+
uri: T.author.link
|
|
1750
1934
|
} : void 0,
|
|
1751
|
-
entries:
|
|
1752
|
-
const
|
|
1753
|
-
id:
|
|
1754
|
-
title:
|
|
1755
|
-
updated:
|
|
1756
|
-
links:
|
|
1757
|
-
...
|
|
1935
|
+
entries: p.map((m) => {
|
|
1936
|
+
const C = {
|
|
1937
|
+
id: m.id || m.link,
|
|
1938
|
+
title: m.title || "Untitled",
|
|
1939
|
+
updated: m.date || m.pubDate || g,
|
|
1940
|
+
links: m.link ? [{ href: m.link }] : [],
|
|
1941
|
+
...m
|
|
1758
1942
|
// Preserve all dynamic properties
|
|
1759
1943
|
};
|
|
1760
|
-
if (
|
|
1761
|
-
const
|
|
1762
|
-
if (
|
|
1763
|
-
href:
|
|
1944
|
+
if (m.content && (C.content = m.content), m.description && (C.summary = m.description), m._imageMetadata && m._hasImage) {
|
|
1945
|
+
const S = m._imageMetadata;
|
|
1946
|
+
if (C.links || (C.links = []), C.links.push({
|
|
1947
|
+
href: S.url,
|
|
1764
1948
|
rel: "enclosure",
|
|
1765
|
-
type:
|
|
1766
|
-
length:
|
|
1767
|
-
}),
|
|
1768
|
-
const
|
|
1769
|
-
|
|
1770
|
-
${
|
|
1771
|
-
${
|
|
1949
|
+
type: S.mimeType || "image/jpeg",
|
|
1950
|
+
length: S.size
|
|
1951
|
+
}), S.url && C.content && !C.content.includes(S.url)) {
|
|
1952
|
+
const D = `<img src="${S.url}" alt="${m.title || ""}"${S.width ? ` width="${S.width}"` : ""}${S.height ? ` height="${S.height}"` : ""} />`;
|
|
1953
|
+
C.content = typeof C.content == "string" ? `${D}
|
|
1954
|
+
${C.content}` : { type: "html", value: `${D}
|
|
1955
|
+
${C.content.value || C.content}` };
|
|
1772
1956
|
}
|
|
1773
1957
|
}
|
|
1774
|
-
return
|
|
1958
|
+
return C;
|
|
1775
1959
|
})
|
|
1776
1960
|
};
|
|
1777
|
-
return Promise.resolve(
|
|
1961
|
+
return Promise.resolve(st(u));
|
|
1778
1962
|
}
|
|
1779
1963
|
case "json": {
|
|
1780
|
-
const
|
|
1781
|
-
title:
|
|
1782
|
-
home_page_url:
|
|
1783
|
-
feed_url:
|
|
1784
|
-
...
|
|
1785
|
-
description:
|
|
1786
|
-
author:
|
|
1787
|
-
name:
|
|
1788
|
-
url:
|
|
1964
|
+
const w = o?.hasNext ? `${o.baseUrl.replace(/\?.*$/, "")}?page=${o.page + 1}` : void 0, u = {
|
|
1965
|
+
title: h,
|
|
1966
|
+
home_page_url: T.siteUrl,
|
|
1967
|
+
feed_url: d,
|
|
1968
|
+
...w && { next_url: w },
|
|
1969
|
+
description: T.description,
|
|
1970
|
+
author: T.author ? {
|
|
1971
|
+
name: T.author.name,
|
|
1972
|
+
url: T.author.link
|
|
1789
1973
|
} : void 0,
|
|
1790
|
-
items:
|
|
1791
|
-
const
|
|
1792
|
-
id:
|
|
1793
|
-
...
|
|
1974
|
+
items: p.map((C) => {
|
|
1975
|
+
const S = {
|
|
1976
|
+
id: C.id || C.link,
|
|
1977
|
+
...C
|
|
1794
1978
|
// Preserve all dynamic properties
|
|
1795
1979
|
};
|
|
1796
|
-
if (
|
|
1797
|
-
const
|
|
1798
|
-
if (
|
|
1799
|
-
url:
|
|
1800
|
-
mime_type:
|
|
1801
|
-
size_in_bytes:
|
|
1802
|
-
title:
|
|
1803
|
-
}),
|
|
1804
|
-
const
|
|
1805
|
-
|
|
1806
|
-
${
|
|
1980
|
+
if (C.title && (S.title = C.title), C.link && (S.url = C.link), C.content && (S.content_html = C.content), C.description && (S.summary = C.description), (C.date || C.pubDate) && (S.date_published = C.date || C.pubDate), C._imageMetadata && C._hasImage) {
|
|
1981
|
+
const D = C._imageMetadata;
|
|
1982
|
+
if (S.image = D.url, S.attachments || (S.attachments = []), S.attachments.push({
|
|
1983
|
+
url: D.url,
|
|
1984
|
+
mime_type: D.mimeType || "image/jpeg",
|
|
1985
|
+
size_in_bytes: D.size,
|
|
1986
|
+
title: C.title || "Image"
|
|
1987
|
+
}), D.url && S.content_html && !S.content_html.includes(D.url)) {
|
|
1988
|
+
const k = `<img src="${D.url}" alt="${C.title || ""}"${D.width ? ` width="${D.width}"` : ""}${D.height ? ` height="${D.height}"` : ""} />`;
|
|
1989
|
+
S.content_html = `${k}
|
|
1990
|
+
${S.content_html}`;
|
|
1807
1991
|
}
|
|
1808
1992
|
}
|
|
1809
|
-
return
|
|
1993
|
+
return S;
|
|
1810
1994
|
})
|
|
1811
|
-
},
|
|
1812
|
-
return Promise.resolve(typeof
|
|
1995
|
+
}, m = ot(u);
|
|
1996
|
+
return Promise.resolve(typeof m == "string" ? m : JSON.stringify(m));
|
|
1813
1997
|
}
|
|
1814
1998
|
case "rss":
|
|
1815
1999
|
default: {
|
|
1816
|
-
const
|
|
1817
|
-
title:
|
|
1818
|
-
link:
|
|
1819
|
-
description:
|
|
1820
|
-
links:
|
|
1821
|
-
isArchive:
|
|
1822
|
-
language:
|
|
1823
|
-
copyright:
|
|
1824
|
-
webMaster:
|
|
1825
|
-
pubDate:
|
|
1826
|
-
lastBuildDate:
|
|
1827
|
-
items:
|
|
1828
|
-
const
|
|
1829
|
-
...
|
|
2000
|
+
const w = {
|
|
2001
|
+
title: h,
|
|
2002
|
+
link: T.siteUrl,
|
|
2003
|
+
description: T.description,
|
|
2004
|
+
links: y.length ? y.map((u) => ({ rel: u.rel, href: u.href, type: u.type })) : void 0,
|
|
2005
|
+
isArchive: r ?? !1,
|
|
2006
|
+
language: T.language,
|
|
2007
|
+
copyright: T.copyright,
|
|
2008
|
+
webMaster: T.author?.email,
|
|
2009
|
+
pubDate: g,
|
|
2010
|
+
lastBuildDate: g,
|
|
2011
|
+
items: p.map((u) => {
|
|
2012
|
+
const m = {
|
|
2013
|
+
...u
|
|
1830
2014
|
// Preserve all dynamic properties
|
|
1831
2015
|
};
|
|
1832
|
-
|
|
1833
|
-
value:
|
|
1834
|
-
isPermaLink: typeof
|
|
1835
|
-
} :
|
|
1836
|
-
value:
|
|
1837
|
-
isPermaLink: typeof
|
|
1838
|
-
})
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
};
|
|
1851
|
-
g.width && (D.width = g.width), g.height && (D.height = g.height), g.size && (D.fileSize = g.size), g.format && (D.format = g.format), u["media:content"] = [D];
|
|
1852
|
-
const T = {
|
|
1853
|
-
url: g.url
|
|
1854
|
-
};
|
|
1855
|
-
g.width && (T.width = g.width), g.height && (T.height = g.height), u["media:thumbnail"] = [T], l.title && (u["media:title"] = l.title);
|
|
1856
|
-
const M = l.description || l.summary || l.title || "";
|
|
1857
|
-
if (M && (u["media:description"] = M), l.title) {
|
|
1858
|
-
const S = [];
|
|
1859
|
-
l.title && S.push(...l.title.toLowerCase().split(/\s+/).filter((A) => A.length > 3)), l.description && S.push(...l.description.toLowerCase().split(/\s+/).filter((A) => A.length > 3)), S.length > 0 && (u["media:keywords"] = [...new Set(S)].slice(0, 10).join(", "));
|
|
1860
|
-
}
|
|
1861
|
-
if (l.authors && Array.isArray(l.authors) && l.authors.length > 0 ? u["media:credit"] = l.authors.map((S) => ({
|
|
1862
|
-
value: S.name || S.displayName || "Unknown",
|
|
1863
|
-
role: "author"
|
|
1864
|
-
})) : E.author && (u["media:credit"] = [{
|
|
1865
|
-
value: E.author.name,
|
|
1866
|
-
role: "author"
|
|
1867
|
-
}]), E.copyright && (u["media:copyright"] = E.copyright), e && (u["media:category"] = [{
|
|
1868
|
-
value: e,
|
|
1869
|
-
scheme: "http://www.schema.org/"
|
|
1870
|
-
}]), u["media:group"] = [{
|
|
1871
|
-
"media:content": [D],
|
|
1872
|
-
"media:thumbnail": [T],
|
|
1873
|
-
"media:title": l.title || "Untitled",
|
|
1874
|
-
"media:description": M
|
|
1875
|
-
}], g.url && l.content && !l.content.includes(g.url)) {
|
|
1876
|
-
const S = `<img src="${g.url}" alt="${l.title || ""}"${g.width ? ` width="${g.width}"` : ""}${g.height ? ` height="${g.height}"` : ""} />`;
|
|
1877
|
-
u["content:encoded"] = `${S}
|
|
1878
|
-
${l.content}`;
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
if (typeof l.content == "string" && l.content.trim() !== "" && u["content:encoded"] === void 0 && (u["content:encoded"] = l.content), !u.enclosures && (l.feature_image || l.featureImage || l.image)) {
|
|
1882
|
-
const g = l.feature_image || l.featureImage || l.image, D = Ot(g);
|
|
1883
|
-
D && (u.enclosures = [{
|
|
1884
|
-
url: D,
|
|
1885
|
-
type: "image/jpeg"
|
|
1886
|
-
}]);
|
|
2016
|
+
u.title && (m.title = u.title), u.link && (m.link = u.link), u.description && (m.description = u.description), (u.date || u.pubDate) && (m.pubDate = u.date || u.pubDate), u.guid ? m.guid = {
|
|
2017
|
+
value: u.guid,
|
|
2018
|
+
isPermaLink: typeof u.guid == "string" && (u.guid.startsWith("http://") || u.guid.startsWith("https://"))
|
|
2019
|
+
} : u.id && (m.guid = {
|
|
2020
|
+
value: u.id,
|
|
2021
|
+
isPermaLink: typeof u.id == "string" && (u.id.startsWith("http://") || u.id.startsWith("https://"))
|
|
2022
|
+
});
|
|
2023
|
+
const C = en(u);
|
|
2024
|
+
if (C && tn(
|
|
2025
|
+
m,
|
|
2026
|
+
u,
|
|
2027
|
+
C,
|
|
2028
|
+
e,
|
|
2029
|
+
T.author,
|
|
2030
|
+
T.copyright
|
|
2031
|
+
), typeof u.content == "string" && u.content.trim() !== "" && m["content:encoded"] === void 0 && (m["content:encoded"] = u.content), m.dc = {}, (u.date || u.pubDate) && (m.dc.date = u.date || u.pubDate), u.timeCreated) {
|
|
2032
|
+
const S = new Date(u.timeCreated * 1e3);
|
|
2033
|
+
m.dc.dates || (m.dc.dates = []), m.dc.dates.push(S);
|
|
1887
2034
|
}
|
|
1888
|
-
|
|
1889
|
-
const g = new Date(l.timeCreated * 1e3);
|
|
1890
|
-
u.dc.dates || (u.dc.dates = []), u.dc.dates.push(g);
|
|
1891
|
-
}
|
|
1892
|
-
return (l.seedUid || l.SeedUid) && (u.dc.identifier || (u.dc.identifier = []), u.dc.identifier.push(l.seedUid || l.SeedUid)), (l.storageTransactionId || l.storage_transaction_id) && (u.dc.identifier || (u.dc.identifier = []), u.dc.identifier.push(l.storageTransactionId || l.storage_transaction_id)), (l.import_url || l.importUrl) && (u.dc.source = l.import_url || l.importUrl), (l.seedUid || l.SeedUid) && (u.seedUid = l.seedUid || l.SeedUid), (l.storageTransactionId || l.storage_transaction_id) && (u.storageTransactionId = l.storageTransactionId || l.storage_transaction_id), l.timeCreated && (u.timeCreated = l.timeCreated), u;
|
|
2035
|
+
return (u.seedUid || u.SeedUid) && (m.dc.identifier || (m.dc.identifier = []), m.dc.identifier.push(u.seedUid || u.SeedUid)), (u.storageTransactionId || u.storage_transaction_id) && (m.dc.identifier || (m.dc.identifier = []), m.dc.identifier.push(u.storageTransactionId || u.storage_transaction_id)), (u.import_url || u.importUrl) && (m.dc.source = u.import_url || u.importUrl), (u.seedUid || u.SeedUid) && (m.seedUid = u.seedUid || u.SeedUid), (u.storageTransactionId || u.storage_transaction_id) && (m.storageTransactionId = u.storageTransactionId || u.storage_transaction_id), u.timeCreated && (m.timeCreated = u.timeCreated), m;
|
|
1893
2036
|
})
|
|
1894
2037
|
};
|
|
1895
|
-
return Promise.resolve(
|
|
2038
|
+
return Promise.resolve(Nt(w));
|
|
1896
2039
|
}
|
|
1897
2040
|
}
|
|
1898
2041
|
};
|
|
1899
|
-
function
|
|
2042
|
+
function Xe(t) {
|
|
1900
2043
|
switch (t) {
|
|
1901
2044
|
case "atom":
|
|
1902
2045
|
return "application/atom+xml; charset=utf-8";
|
|
@@ -1907,16 +2050,16 @@ function je(t) {
|
|
|
1907
2050
|
return "application/rss+xml; charset=utf-8";
|
|
1908
2051
|
}
|
|
1909
2052
|
}
|
|
1910
|
-
function
|
|
2053
|
+
function Je(t) {
|
|
1911
2054
|
const e = t.toLowerCase();
|
|
1912
2055
|
return ["rss", "atom", "json"].includes(e) ? e : null;
|
|
1913
2056
|
}
|
|
1914
|
-
function
|
|
2057
|
+
function sn(t) {
|
|
1915
2058
|
return t.charAt(0).toUpperCase() + t.slice(1);
|
|
1916
2059
|
}
|
|
1917
|
-
async function
|
|
1918
|
-
const
|
|
1919
|
-
if (!
|
|
2060
|
+
async function Sn(t, e, n, s, o) {
|
|
2061
|
+
const i = Je(e);
|
|
2062
|
+
if (!i)
|
|
1920
2063
|
return new Response(
|
|
1921
2064
|
JSON.stringify({ error: `Invalid feed format: ${e}` }),
|
|
1922
2065
|
{
|
|
@@ -1924,123 +2067,123 @@ async function nn(t, e, n, s, r) {
|
|
|
1924
2067
|
headers: { "Content-Type": "application/json" }
|
|
1925
2068
|
}
|
|
1926
2069
|
);
|
|
1927
|
-
const
|
|
1928
|
-
console.log(`Schema name: ${
|
|
1929
|
-
const
|
|
2070
|
+
const r = U.singular(t.toLowerCase()), a = U(r), c = G(), l = Math.max(1, o ?? 1), d = c.pageSize, h = (l - 1) * d, g = l > 1 ? { page: l } : void 0;
|
|
2071
|
+
console.log(`Schema name: ${r}`), console.log(`Collection name: ${a}`);
|
|
2072
|
+
const f = He(), y = fe();
|
|
1930
2073
|
try {
|
|
1931
|
-
if (
|
|
1932
|
-
const
|
|
1933
|
-
if (
|
|
1934
|
-
return n &&
|
|
2074
|
+
if (y.enabled) {
|
|
2075
|
+
const A = await f.getFeedContent(r, i, g);
|
|
2076
|
+
if (A)
|
|
2077
|
+
return n && je(n, A.etag) ? (console.log(`Cache hit with ETag match for ${r}:${i} - returning 304`), new Response(null, {
|
|
1935
2078
|
status: 304,
|
|
1936
2079
|
headers: {
|
|
1937
|
-
ETag:
|
|
1938
|
-
"Last-Modified": new Date(
|
|
2080
|
+
ETag: A.etag,
|
|
2081
|
+
"Last-Modified": new Date(A.lastModified * 1e3).toUTCString(),
|
|
1939
2082
|
"Cache-Control": "public, max-age=3600, s-maxage=3600, must-revalidate"
|
|
1940
2083
|
}
|
|
1941
|
-
})) : (console.log(`Cache hit for ${
|
|
2084
|
+
})) : (console.log(`Cache hit for ${r}:${i}`), new Response(A.content, {
|
|
1942
2085
|
status: 200,
|
|
1943
2086
|
headers: {
|
|
1944
|
-
"Content-Type":
|
|
1945
|
-
ETag:
|
|
1946
|
-
"Last-Modified": new Date(
|
|
2087
|
+
"Content-Type": A.contentType,
|
|
2088
|
+
ETag: A.etag,
|
|
2089
|
+
"Last-Modified": new Date(A.lastModified * 1e3).toUTCString(),
|
|
1947
2090
|
"Cache-Control": "public, max-age=3600, s-maxage=3600, must-revalidate",
|
|
1948
|
-
"X-Feed-Schema":
|
|
1949
|
-
"X-Feed-Format":
|
|
2091
|
+
"X-Feed-Schema": r,
|
|
2092
|
+
"X-Feed-Format": i,
|
|
1950
2093
|
"X-Cache": "HIT"
|
|
1951
2094
|
}
|
|
1952
2095
|
}));
|
|
1953
2096
|
}
|
|
1954
|
-
console.log(`Cache miss for ${
|
|
1955
|
-
const
|
|
1956
|
-
const
|
|
1957
|
-
if (
|
|
1958
|
-
const
|
|
1959
|
-
gateways:
|
|
1960
|
-
timeout:
|
|
2097
|
+
console.log(`Cache miss for ${r}:${i} - fetching items`);
|
|
2098
|
+
const p = async () => {
|
|
2099
|
+
const A = await ne(r, { limit: d, skip: h });
|
|
2100
|
+
if (y.imageMetadata?.enabled) {
|
|
2101
|
+
const _ = new Ae({
|
|
2102
|
+
gateways: y.imageMetadata.gateways,
|
|
2103
|
+
timeout: y.imageMetadata.timeout
|
|
1961
2104
|
});
|
|
1962
|
-
return
|
|
2105
|
+
return Ee(A, _, f);
|
|
1963
2106
|
}
|
|
1964
|
-
return
|
|
1965
|
-
},
|
|
1966
|
-
const
|
|
1967
|
-
let
|
|
1968
|
-
if (
|
|
1969
|
-
console.log(`Incremental fetch: last processed timestamp: ${
|
|
1970
|
-
const v = await
|
|
1971
|
-
|
|
2107
|
+
return A;
|
|
2108
|
+
}, w = y.enabled && l === 1 ? await f.withRefreshLock(r, async () => {
|
|
2109
|
+
const A = await f.getFeedData(r);
|
|
2110
|
+
let _;
|
|
2111
|
+
if (A) {
|
|
2112
|
+
console.log(`Incremental fetch: last processed timestamp: ${A.lastProcessedTimestamp}`);
|
|
2113
|
+
const v = await ne(r, { limit: d, skip: 0 }), z = f.filterNewItems(v, A.lastProcessedTimestamp);
|
|
2114
|
+
z.length > 0 ? (console.log(`Found ${z.length} new items, merging with ${A.items.length} cached items`), _ = f.mergeItems(A.items, z).slice(0, d)) : _ = A.items;
|
|
1972
2115
|
} else {
|
|
1973
2116
|
console.log("Cold cache - fetching page 1");
|
|
1974
|
-
const v = await
|
|
1975
|
-
v && console.log(`Client initialized: ${v.isInitialized()}`),
|
|
2117
|
+
const v = await rn();
|
|
2118
|
+
v && console.log(`Client initialized: ${v.isInitialized()}`), _ = await ne(r, { limit: d, skip: 0 }), console.log(`Found ${_.length} feed items for schema ${r}`);
|
|
1976
2119
|
}
|
|
1977
|
-
if (
|
|
1978
|
-
const v = new
|
|
1979
|
-
gateways:
|
|
1980
|
-
timeout:
|
|
1981
|
-
}),
|
|
1982
|
-
return await
|
|
2120
|
+
if (y.imageMetadata?.enabled) {
|
|
2121
|
+
const v = new Ae({
|
|
2122
|
+
gateways: y.imageMetadata.gateways,
|
|
2123
|
+
timeout: y.imageMetadata.timeout
|
|
2124
|
+
}), z = await Ee(_, v, f);
|
|
2125
|
+
return await f.setFeedData(r, _), z;
|
|
1983
2126
|
}
|
|
1984
|
-
return await
|
|
1985
|
-
}) : await
|
|
1986
|
-
if (
|
|
1987
|
-
const
|
|
1988
|
-
|
|
2127
|
+
return await f.setFeedData(r, _), _;
|
|
2128
|
+
}) : await p(), u = `${T.feedUrl}/${a}/${i}`, m = w.length === d, C = [];
|
|
2129
|
+
if (l === 1) {
|
|
2130
|
+
const A = /* @__PURE__ */ new Date(), _ = new Date(A.getFullYear(), A.getMonth() - 1, 1);
|
|
2131
|
+
C.push({
|
|
1989
2132
|
rel: "prev-archive",
|
|
1990
|
-
href: `${
|
|
2133
|
+
href: `${T.feedUrl}/${a}/archive/${_.getFullYear()}/${_.getMonth() + 1}/${i}`
|
|
1991
2134
|
});
|
|
1992
2135
|
}
|
|
1993
|
-
const
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
2136
|
+
const D = await Ge(
|
|
2137
|
+
w,
|
|
2138
|
+
r,
|
|
2139
|
+
i,
|
|
1997
2140
|
s,
|
|
1998
2141
|
{
|
|
1999
|
-
page:
|
|
2000
|
-
pageSize:
|
|
2001
|
-
hasNext:
|
|
2002
|
-
baseUrl:
|
|
2142
|
+
page: l,
|
|
2143
|
+
pageSize: d,
|
|
2144
|
+
hasNext: m,
|
|
2145
|
+
baseUrl: u
|
|
2003
2146
|
},
|
|
2004
|
-
|
|
2147
|
+
C.length ? C : void 0,
|
|
2005
2148
|
!1
|
|
2006
|
-
),
|
|
2007
|
-
if (
|
|
2008
|
-
await
|
|
2009
|
-
const
|
|
2010
|
-
return new Response(
|
|
2149
|
+
), k = Xe(i);
|
|
2150
|
+
if (y.enabled) {
|
|
2151
|
+
await f.setFeedContent(r, i, D, k, g);
|
|
2152
|
+
const A = await f.getFeedContent(r, i, g), _ = A?.etag || "", v = A?.lastModified || Math.floor(Date.now() / 1e3);
|
|
2153
|
+
return new Response(D, {
|
|
2011
2154
|
status: 200,
|
|
2012
2155
|
headers: {
|
|
2013
|
-
"Content-Type":
|
|
2014
|
-
ETag:
|
|
2156
|
+
"Content-Type": k,
|
|
2157
|
+
ETag: _,
|
|
2015
2158
|
"Last-Modified": new Date(v * 1e3).toUTCString(),
|
|
2016
2159
|
"Cache-Control": "public, max-age=3600, s-maxage=3600, must-revalidate",
|
|
2017
|
-
"X-Feed-Schema":
|
|
2018
|
-
"X-Feed-Format":
|
|
2160
|
+
"X-Feed-Schema": r,
|
|
2161
|
+
"X-Feed-Format": i,
|
|
2019
2162
|
"X-Cache": "MISS"
|
|
2020
2163
|
}
|
|
2021
2164
|
});
|
|
2022
2165
|
}
|
|
2023
|
-
return new Response(
|
|
2166
|
+
return new Response(D, {
|
|
2024
2167
|
status: 200,
|
|
2025
2168
|
headers: {
|
|
2026
|
-
"Content-Type":
|
|
2169
|
+
"Content-Type": k,
|
|
2027
2170
|
"Cache-Control": "public, max-age=3600, s-maxage=3600",
|
|
2028
|
-
"X-Feed-Schema":
|
|
2029
|
-
"X-Feed-Format":
|
|
2171
|
+
"X-Feed-Schema": r,
|
|
2172
|
+
"X-Feed-Format": i
|
|
2030
2173
|
}
|
|
2031
2174
|
});
|
|
2032
|
-
} catch (
|
|
2033
|
-
if (console.error("Feed generation error:",
|
|
2034
|
-
const
|
|
2035
|
-
if (
|
|
2036
|
-
return console.log("Serving stale cache due to error"), new Response(
|
|
2175
|
+
} catch (p) {
|
|
2176
|
+
if (console.error("Feed generation error:", p), y.enabled) {
|
|
2177
|
+
const w = await f.getFeedContent(r, i, g);
|
|
2178
|
+
if (w)
|
|
2179
|
+
return console.log("Serving stale cache due to error"), new Response(w.content, {
|
|
2037
2180
|
status: 200,
|
|
2038
2181
|
headers: {
|
|
2039
|
-
"Content-Type":
|
|
2040
|
-
ETag:
|
|
2182
|
+
"Content-Type": w.contentType,
|
|
2183
|
+
ETag: w.etag,
|
|
2041
2184
|
"Cache-Control": "public, max-age=3600, s-maxage=3600, must-revalidate",
|
|
2042
|
-
"X-Feed-Schema":
|
|
2043
|
-
"X-Feed-Format":
|
|
2185
|
+
"X-Feed-Schema": r,
|
|
2186
|
+
"X-Feed-Format": i,
|
|
2044
2187
|
"X-Cache": "STALE",
|
|
2045
2188
|
Warning: '299 - "Cache is stale"'
|
|
2046
2189
|
}
|
|
@@ -2049,7 +2192,7 @@ async function nn(t, e, n, s, r) {
|
|
|
2049
2192
|
return new Response(
|
|
2050
2193
|
JSON.stringify({
|
|
2051
2194
|
error: "Failed to generate feed",
|
|
2052
|
-
message:
|
|
2195
|
+
message: p instanceof Error ? p.message : "Unknown error"
|
|
2053
2196
|
}),
|
|
2054
2197
|
{
|
|
2055
2198
|
status: 500,
|
|
@@ -2058,7 +2201,7 @@ async function nn(t, e, n, s, r) {
|
|
|
2058
2201
|
);
|
|
2059
2202
|
}
|
|
2060
2203
|
}
|
|
2061
|
-
async function
|
|
2204
|
+
async function Dn(t, e, n, s, o, i) {
|
|
2062
2205
|
if (e < 1970 || e > 2100)
|
|
2063
2206
|
return new Response(
|
|
2064
2207
|
JSON.stringify({ error: `Invalid year: ${e}` }),
|
|
@@ -2069,108 +2212,108 @@ async function rn(t, e, n, s, r, a) {
|
|
|
2069
2212
|
JSON.stringify({ error: `Invalid month: ${n}` }),
|
|
2070
2213
|
{ status: 400, headers: { "Content-Type": "application/json" } }
|
|
2071
2214
|
);
|
|
2072
|
-
const
|
|
2073
|
-
if (!
|
|
2215
|
+
const r = Je(s);
|
|
2216
|
+
if (!r)
|
|
2074
2217
|
return new Response(
|
|
2075
2218
|
JSON.stringify({ error: `Invalid feed format: ${s}` }),
|
|
2076
2219
|
{ status: 400, headers: { "Content-Type": "application/json" } }
|
|
2077
2220
|
);
|
|
2078
|
-
const
|
|
2221
|
+
const a = U.singular(t.toLowerCase()), c = U(a), l = { archive: { year: e, month: n } }, d = He(), h = fe();
|
|
2079
2222
|
try {
|
|
2080
|
-
if (
|
|
2081
|
-
const
|
|
2082
|
-
if (
|
|
2083
|
-
return
|
|
2223
|
+
if (h.enabled) {
|
|
2224
|
+
const D = await d.getFeedContent(a, r, l);
|
|
2225
|
+
if (D)
|
|
2226
|
+
return o && je(o, D.etag) ? new Response(null, {
|
|
2084
2227
|
status: 304,
|
|
2085
2228
|
headers: {
|
|
2086
|
-
ETag:
|
|
2087
|
-
"Last-Modified": new Date(
|
|
2229
|
+
ETag: D.etag,
|
|
2230
|
+
"Last-Modified": new Date(D.lastModified * 1e3).toUTCString(),
|
|
2088
2231
|
"Cache-Control": "public, max-age=86400, s-maxage=86400, must-revalidate"
|
|
2089
2232
|
}
|
|
2090
|
-
}) : new Response(
|
|
2233
|
+
}) : new Response(D.content, {
|
|
2091
2234
|
status: 200,
|
|
2092
2235
|
headers: {
|
|
2093
|
-
"Content-Type":
|
|
2094
|
-
ETag:
|
|
2095
|
-
"Last-Modified": new Date(
|
|
2236
|
+
"Content-Type": D.contentType,
|
|
2237
|
+
ETag: D.etag,
|
|
2238
|
+
"Last-Modified": new Date(D.lastModified * 1e3).toUTCString(),
|
|
2096
2239
|
"Cache-Control": "public, max-age=86400, s-maxage=86400, must-revalidate",
|
|
2097
|
-
"X-Feed-Schema":
|
|
2098
|
-
"X-Feed-Format":
|
|
2240
|
+
"X-Feed-Schema": a,
|
|
2241
|
+
"X-Feed-Format": r,
|
|
2099
2242
|
"X-Cache": "HIT"
|
|
2100
2243
|
}
|
|
2101
2244
|
});
|
|
2102
2245
|
}
|
|
2103
|
-
const
|
|
2104
|
-
{ rel: "prev-archive", href: `${
|
|
2105
|
-
{ rel: "current", href:
|
|
2106
|
-
],
|
|
2107
|
-
(
|
|
2108
|
-
const
|
|
2109
|
-
|
|
2110
|
-
i,
|
|
2111
|
-
o,
|
|
2246
|
+
const g = await Et(a, e, n), f = `${T.feedUrl}/${c}/${r}`, y = `${T.feedUrl}/${c}/archive`, p = [
|
|
2247
|
+
{ rel: "prev-archive", href: `${y}/${n === 1 ? e - 1 : e}/${n === 1 ? 12 : n - 1}/${r}` },
|
|
2248
|
+
{ rel: "current", href: f }
|
|
2249
|
+
], w = n === 12 ? e + 1 : e, u = n === 12 ? 1 : n + 1, m = /* @__PURE__ */ new Date();
|
|
2250
|
+
(w < m.getFullYear() || w === m.getFullYear() && u <= m.getMonth() + 1) && p.push({ rel: "next-archive", href: `${y}/${w}/${u}/${r}` });
|
|
2251
|
+
const C = await Ge(
|
|
2252
|
+
g,
|
|
2112
2253
|
a,
|
|
2254
|
+
r,
|
|
2255
|
+
i,
|
|
2113
2256
|
void 0,
|
|
2114
|
-
|
|
2257
|
+
p,
|
|
2115
2258
|
!0
|
|
2116
|
-
),
|
|
2117
|
-
if (
|
|
2118
|
-
await
|
|
2119
|
-
const
|
|
2120
|
-
return new Response(
|
|
2259
|
+
), S = Xe(r);
|
|
2260
|
+
if (h.enabled) {
|
|
2261
|
+
await d.setFeedContent(a, r, C, S, l);
|
|
2262
|
+
const D = await d.getFeedContent(a, r, l), k = D?.etag || "", A = D?.lastModified || Math.floor(Date.now() / 1e3);
|
|
2263
|
+
return new Response(C, {
|
|
2121
2264
|
status: 200,
|
|
2122
2265
|
headers: {
|
|
2123
|
-
"Content-Type":
|
|
2124
|
-
ETag:
|
|
2125
|
-
"Last-Modified": new Date(
|
|
2266
|
+
"Content-Type": S,
|
|
2267
|
+
ETag: k,
|
|
2268
|
+
"Last-Modified": new Date(A * 1e3).toUTCString(),
|
|
2126
2269
|
"Cache-Control": "public, max-age=86400, s-maxage=86400, must-revalidate",
|
|
2127
|
-
"X-Feed-Schema":
|
|
2128
|
-
"X-Feed-Format":
|
|
2270
|
+
"X-Feed-Schema": a,
|
|
2271
|
+
"X-Feed-Format": r,
|
|
2129
2272
|
"X-Cache": "MISS"
|
|
2130
2273
|
}
|
|
2131
2274
|
});
|
|
2132
2275
|
}
|
|
2133
|
-
return new Response(
|
|
2276
|
+
return new Response(C, {
|
|
2134
2277
|
status: 200,
|
|
2135
2278
|
headers: {
|
|
2136
|
-
"Content-Type":
|
|
2279
|
+
"Content-Type": S,
|
|
2137
2280
|
"Cache-Control": "public, max-age=86400, s-maxage=86400",
|
|
2138
|
-
"X-Feed-Schema":
|
|
2139
|
-
"X-Feed-Format":
|
|
2281
|
+
"X-Feed-Schema": a,
|
|
2282
|
+
"X-Feed-Format": r
|
|
2140
2283
|
}
|
|
2141
2284
|
});
|
|
2142
|
-
} catch (
|
|
2143
|
-
return console.error("Archive feed generation error:",
|
|
2285
|
+
} catch (g) {
|
|
2286
|
+
return console.error("Archive feed generation error:", g), new Response(
|
|
2144
2287
|
JSON.stringify({
|
|
2145
2288
|
error: "Failed to generate archive feed",
|
|
2146
|
-
message:
|
|
2289
|
+
message: g instanceof Error ? g.message : "Unknown error"
|
|
2147
2290
|
}),
|
|
2148
2291
|
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
2149
2292
|
);
|
|
2150
2293
|
}
|
|
2151
2294
|
}
|
|
2152
2295
|
export {
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2296
|
+
dt as FEED_RICH_BODY_STORAGE_SCHEMAS,
|
|
2297
|
+
En as classifyMediaRef,
|
|
2298
|
+
Ge as createFeed,
|
|
2299
|
+
lt as enrichImageSeedCloneForFeed,
|
|
2300
|
+
qt as feedItemRichTextContainsDataUriImage,
|
|
2301
|
+
Zt as filterItemsByRichTextDataUriImagePolicy,
|
|
2302
|
+
rn as getClient,
|
|
2303
|
+
_n as getFeedItemStringField,
|
|
2304
|
+
ne as getFeedItemsBySchemaName,
|
|
2305
|
+
Et as getFeedItemsBySchemaNameForMonth,
|
|
2306
|
+
Dn as handleArchiveFeedRequest,
|
|
2307
|
+
Sn as handleFeedRequest,
|
|
2308
|
+
nn as initializeSeedClient,
|
|
2166
2309
|
B as isFeedRichBodyStorageSchema,
|
|
2167
2310
|
G as loadFeedConfig,
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2311
|
+
In as normalizeFeedItemFields,
|
|
2312
|
+
yn as parseRssString,
|
|
2313
|
+
Kt as pickFeedItemContent,
|
|
2314
|
+
Vt as pickFeedItemDescription,
|
|
2315
|
+
wn as resetCacheManager,
|
|
2316
|
+
$n as resolveMediaRef,
|
|
2317
|
+
Cn as teardownSeedClient
|
|
2175
2318
|
};
|
|
2176
2319
|
//# sourceMappingURL=index.js.map
|