@seedprotocol/feed 0.5.1 → 0.5.3
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/README.md +2 -2
- package/dist/cache/CacheManager.d.ts +5 -59
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/FileCache.d.ts +2 -54
- package/dist/cache/FileCache.d.ts.map +1 -1
- package/dist/cache/MemoryCache.d.ts +4 -48
- package/dist/cache/MemoryCache.d.ts.map +1 -1
- package/dist/cache/types.d.ts +3 -11
- package/dist/cache/types.d.ts.map +1 -1
- package/dist/feedFieldStorageModel.d.ts +2 -11
- package/dist/feedFieldStorageModel.d.ts.map +1 -1
- package/dist/getFeedItems.d.ts +10 -0
- package/dist/getFeedItems.d.ts.map +1 -1
- package/dist/hydrateArweaveRichText.d.ts +1 -10
- package/dist/hydrateArweaveRichText.d.ts.map +1 -1
- package/dist/imageRelationEnrichment.d.ts +1 -5
- package/dist/imageRelationEnrichment.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +334 -830
- package/dist/index.js.map +1 -1
- package/dist/listRelationKey.d.ts +1 -12
- package/dist/listRelationKey.d.ts.map +1 -1
- package/dist/parseEasPropertyMetadataForFeed.d.ts +2 -24
- package/dist/parseEasPropertyMetadataForFeed.d.ts.map +1 -1
- package/dist/utils/arweaveUrl.d.ts +1 -6
- package/dist/utils/arweaveUrl.d.ts.map +1 -1
- package/dist/utils/etag.d.ts +0 -4
- package/dist/utils/etag.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,43 +1,37 @@
|
|
|
1
|
-
import { BaseArweaveClient as e, DEFAULT_ARWEAVE_HOST as t, DEFAULT_ARWEAVE_HOST as n,
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import ae from "image-size";
|
|
1
|
+
import { BaseArweaveClient as e, DEFAULT_ARWEAVE_HOST as t, DEFAULT_ARWEAVE_HOST as n, SEED_RSS_IMAGE_RELATION_FIELD_KEYS as r, classifyMediaRef as i, ensureReadGatewaySelected as a, getArweaveReadGatewayHostsForPrimary as o, getDefaultArweaveReadGatewayHostsOrdered as s, getFeedItemStringField as c, getReadGatewayHostsForConfig as l, getResolvedSeedGatewayEndpoints as u, isEasAttestationExplorerUrl as d, normalizeFeedItemFields as f, resolveArweaveHostFromEnv as p, resolveSeedRssImageRelationFromItem as m, resolveSeedRssImageRelationRef as h, resolveSeedRssImageRelationRef as g } from "@seedprotocol/arweave";
|
|
2
|
+
import { FEED_RICH_BODY_STORAGE_SCHEMAS as _, enrichImageSeedCloneForFeed as v, feedRichBodyModelPriority as y, getArweaveUrlForTransaction as b, getFeedFieldStorageModels as x, getFeedListElementStorageModels as ee, isFeedRichBodyStorageSchema as S, queryBySchema as te, queryBySchemaForMonth as ne } from "@seedprotocol/query";
|
|
3
|
+
import re from "rss-parser";
|
|
4
|
+
import C from "pluralize";
|
|
5
|
+
import { generateAtomFeed as ie, generateJsonFeed as ae } from "feedsmith";
|
|
6
|
+
import { create as oe } from "xmlbuilder2";
|
|
7
|
+
import { createHash as se } from "crypto";
|
|
8
|
+
import { promises as w } from "fs";
|
|
9
|
+
import { join as T } from "path";
|
|
10
|
+
import ce from "image-size";
|
|
12
11
|
//#region src/bootstrap.ts
|
|
13
|
-
var
|
|
14
|
-
function
|
|
15
|
-
return e ??
|
|
12
|
+
var E = !1;
|
|
13
|
+
function le(e) {
|
|
14
|
+
return e ?? p() ?? n;
|
|
16
15
|
}
|
|
17
|
-
async function
|
|
18
|
-
if (
|
|
16
|
+
async function D(e) {
|
|
17
|
+
if (E) return;
|
|
19
18
|
let [{ registerNodeEasPlatform: t }, { registerNodeArweavePlatform: n }] = await Promise.all([import("@seedprotocol/eas/node"), import("@seedprotocol/arweave/node")]);
|
|
20
|
-
if (t(), n({ arweaveDomain:
|
|
19
|
+
if (t(), n({ arweaveDomain: le(e?.arweaveDomain) }), e?.arweaveDomain) {
|
|
21
20
|
let { BaseArweaveClient: t } = await import("@seedprotocol/arweave");
|
|
22
21
|
t.setHost(e.arweaveDomain);
|
|
23
22
|
}
|
|
24
|
-
|
|
23
|
+
E = !0;
|
|
25
24
|
}
|
|
26
|
-
var
|
|
27
|
-
async function
|
|
28
|
-
return await
|
|
25
|
+
var ue = D;
|
|
26
|
+
async function de() {
|
|
27
|
+
return await D(), { isInitialized: () => E };
|
|
29
28
|
}
|
|
30
|
-
async function
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/utils/arweaveUrl.ts
|
|
35
|
-
function E(t) {
|
|
36
|
-
return `https://${e.getHost()}/${t}`;
|
|
29
|
+
async function fe() {
|
|
30
|
+
E = !1;
|
|
37
31
|
}
|
|
38
32
|
//#endregion
|
|
39
33
|
//#region src/config.ts
|
|
40
|
-
var
|
|
34
|
+
var O = {
|
|
41
35
|
title: "Seed Protocol",
|
|
42
36
|
description: "Content published via Seed Protocol",
|
|
43
37
|
siteUrl: "https://seedprotocol.io",
|
|
@@ -50,15 +44,15 @@ var D = {
|
|
|
50
44
|
link: "https://seedprotocol.io"
|
|
51
45
|
}
|
|
52
46
|
};
|
|
53
|
-
function
|
|
47
|
+
function k(e) {
|
|
54
48
|
return {
|
|
55
49
|
...e,
|
|
56
50
|
author: e.author ? { ...e.author } : void 0
|
|
57
51
|
};
|
|
58
52
|
}
|
|
59
|
-
var
|
|
60
|
-
function
|
|
61
|
-
if (!e) return
|
|
53
|
+
var A = k(O);
|
|
54
|
+
function j(e, t = A) {
|
|
55
|
+
if (!e) return k(t);
|
|
62
56
|
let n = {
|
|
63
57
|
...t,
|
|
64
58
|
...e,
|
|
@@ -70,16 +64,16 @@ function A(e, t = k) {
|
|
|
70
64
|
name: e.author.name ?? n.author?.name ?? ""
|
|
71
65
|
}), n;
|
|
72
66
|
}
|
|
73
|
-
function
|
|
74
|
-
return
|
|
67
|
+
function pe() {
|
|
68
|
+
return k(A);
|
|
75
69
|
}
|
|
76
|
-
function
|
|
77
|
-
return
|
|
70
|
+
function me(e) {
|
|
71
|
+
return A = j(e, O), pe();
|
|
78
72
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
73
|
+
function he() {
|
|
74
|
+
A = k(O);
|
|
81
75
|
}
|
|
82
|
-
function
|
|
76
|
+
function M() {
|
|
83
77
|
return {
|
|
84
78
|
itemUrlBase: process.env.FEED_ITEM_URL_BASE?.trim() || "https://optimism-sepolia.easscan.org",
|
|
85
79
|
itemUrlPath: process.env.FEED_ITEM_URL_PATH?.trim() || "attestation/view",
|
|
@@ -90,192 +84,8 @@ function j() {
|
|
|
90
84
|
};
|
|
91
85
|
}
|
|
92
86
|
//#endregion
|
|
93
|
-
//#region src/listRelationKey.ts
|
|
94
|
-
var pe = /^(.+?)([A-Z][a-zA-Z]+)Ids$/;
|
|
95
|
-
function M(e) {
|
|
96
|
-
let t = pe.exec(e);
|
|
97
|
-
if (t) {
|
|
98
|
-
let e = t[1];
|
|
99
|
-
if (e) return x(e);
|
|
100
|
-
}
|
|
101
|
-
if (e.endsWith("_ids")) {
|
|
102
|
-
let t = e.slice(0, -4), n = t.split("_").filter(Boolean);
|
|
103
|
-
if (n.length >= 2) {
|
|
104
|
-
let e = n[0];
|
|
105
|
-
return e.endsWith("s") ? e : x(e);
|
|
106
|
-
}
|
|
107
|
-
return x(t);
|
|
108
|
-
}
|
|
109
|
-
return e;
|
|
110
|
-
}
|
|
111
|
-
function me(e, t) {
|
|
112
|
-
for (let n of Object.keys(e)) n !== t && M(n) === t && delete e[n];
|
|
113
|
-
}
|
|
114
|
-
function he(e) {
|
|
115
|
-
if (Array.isArray(e) || typeof e != "string") return e;
|
|
116
|
-
let t = e.trim();
|
|
117
|
-
if (!t.startsWith("[")) return e;
|
|
118
|
-
try {
|
|
119
|
-
let e = JSON.parse(t);
|
|
120
|
-
if (Array.isArray(e)) return e;
|
|
121
|
-
} catch {}
|
|
122
|
-
return e;
|
|
123
|
-
}
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/imageRelationEnrichment.ts
|
|
126
|
-
function ge(e) {
|
|
127
|
-
let t = e.storageTransactionId ?? e.storage_transaction_id;
|
|
128
|
-
if (t && typeof t == "string" && t.trim()) try {
|
|
129
|
-
e.arweaveUrl = E(t.trim());
|
|
130
|
-
} catch {}
|
|
131
|
-
}
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/feedFieldStorageModel.ts
|
|
134
|
-
var _e = new Set([
|
|
135
|
-
"html",
|
|
136
|
-
"file",
|
|
137
|
-
"json"
|
|
138
|
-
]), ve = "_feedFieldStorageModels", ye = "_feedListElementStorageModels";
|
|
139
|
-
function N(e) {
|
|
140
|
-
return e.trim().toLowerCase();
|
|
141
|
-
}
|
|
142
|
-
function P(e) {
|
|
143
|
-
return _e.has(N(e));
|
|
144
|
-
}
|
|
145
|
-
function be(e) {
|
|
146
|
-
let t = N(e);
|
|
147
|
-
return t === "html" ? 0 : t === "file" ? 1 : t === "json" ? 2 : 99;
|
|
148
|
-
}
|
|
149
|
-
function F(e) {
|
|
150
|
-
let t = e[ve];
|
|
151
|
-
if (typeof t == "object" && t && !Array.isArray(t)) return t;
|
|
152
|
-
}
|
|
153
|
-
function I(e) {
|
|
154
|
-
let t = e[ye];
|
|
155
|
-
if (typeof t == "object" && t && !Array.isArray(t)) return t;
|
|
156
|
-
}
|
|
157
|
-
function xe(e, t, n) {
|
|
158
|
-
let r = N(n), i = F(e);
|
|
159
|
-
i || (i = {}, e[ve] = i), i[t] = r;
|
|
160
|
-
}
|
|
161
|
-
function Se(e, t, n) {
|
|
162
|
-
let r = I(e);
|
|
163
|
-
r || (r = {}, e[ye] = r), r[t] = n.map(N);
|
|
164
|
-
}
|
|
165
|
-
//#endregion
|
|
166
|
-
//#region src/hydrateArweaveRichText.ts
|
|
167
|
-
var Ce = [
|
|
168
|
-
"html",
|
|
169
|
-
"Html",
|
|
170
|
-
"body",
|
|
171
|
-
"Body",
|
|
172
|
-
"content",
|
|
173
|
-
"Content"
|
|
174
|
-
], we = 8e6;
|
|
175
|
-
function Te(t) {
|
|
176
|
-
let n = t.trim();
|
|
177
|
-
if (!n.startsWith("http://") && !n.startsWith("https://")) return !1;
|
|
178
|
-
try {
|
|
179
|
-
let t = new URL(n), r = t.hostname.toLowerCase();
|
|
180
|
-
if (r !== e.getHost().toLowerCase() && !u(r)) return !1;
|
|
181
|
-
let i = t.pathname.replace(/^\//, "").split("/").filter(Boolean);
|
|
182
|
-
if (i.length !== 1) return !1;
|
|
183
|
-
let a = i[0];
|
|
184
|
-
return /^[A-Za-z0-9_-]{43}$/.test(a);
|
|
185
|
-
} catch {
|
|
186
|
-
return !1;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
async function Ee(e) {
|
|
190
|
-
try {
|
|
191
|
-
let t = await fetch(e, {
|
|
192
|
-
headers: { Accept: "text/html, text/plain, text/markdown, application/json, */*" },
|
|
193
|
-
signal: AbortSignal.timeout(15e3)
|
|
194
|
-
});
|
|
195
|
-
if (!t.ok) return null;
|
|
196
|
-
let n = t.headers.get("content-type") ?? "";
|
|
197
|
-
if (/^(image|video|audio)\//i.test(n)) return null;
|
|
198
|
-
let r = await t.arrayBuffer();
|
|
199
|
-
if (r.byteLength > we) return null;
|
|
200
|
-
let i = new TextDecoder("utf-8", { fatal: !1 }).decode(r);
|
|
201
|
-
return i.length === 0 || i.includes("\0") ? null : i;
|
|
202
|
-
} catch {
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
async function De(e, t) {
|
|
207
|
-
let n = e[t];
|
|
208
|
-
if (typeof n != "string" || n.trim() === "" || !Te(n)) return;
|
|
209
|
-
let r = await Ee(n);
|
|
210
|
-
r !== null && (e[t] = r);
|
|
211
|
-
}
|
|
212
|
-
async function Oe(e) {
|
|
213
|
-
for (let t of e) {
|
|
214
|
-
let e = new Set([...Ce]), n = F(t);
|
|
215
|
-
if (n) for (let [t, r] of Object.entries(n)) P(r) && e.add(t);
|
|
216
|
-
for (let n of e) await De(t, n);
|
|
217
|
-
let r = I(t);
|
|
218
|
-
if (r) for (let [e, n] of Object.entries(r)) {
|
|
219
|
-
let r = t[e];
|
|
220
|
-
if (!Array.isArray(r)) continue;
|
|
221
|
-
let i = Math.min(n.length, r.length);
|
|
222
|
-
for (let e = 0; e < i; e++) {
|
|
223
|
-
if (!P(n[e])) continue;
|
|
224
|
-
let t = r[e];
|
|
225
|
-
if (typeof t != "string" || !Te(t)) continue;
|
|
226
|
-
let i = await Ee(t);
|
|
227
|
-
i !== null && (r[e] = i);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
//#endregion
|
|
233
|
-
//#region src/parseEasPropertyMetadataForFeed.ts
|
|
234
|
-
function ke(e) {
|
|
235
|
-
let t = typeof e == "string" ? e.trim() : "";
|
|
236
|
-
if (!t) return {
|
|
237
|
-
ok: !1,
|
|
238
|
-
reason: "empty"
|
|
239
|
-
};
|
|
240
|
-
let n;
|
|
241
|
-
try {
|
|
242
|
-
n = JSON.parse(t);
|
|
243
|
-
} catch (e) {
|
|
244
|
-
return {
|
|
245
|
-
ok: !1,
|
|
246
|
-
reason: "parse",
|
|
247
|
-
error: e
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
return !Array.isArray(n) || n.length === 0 || !n[0]?.value ? {
|
|
251
|
-
ok: !1,
|
|
252
|
-
reason: "shape"
|
|
253
|
-
} : {
|
|
254
|
-
ok: !0,
|
|
255
|
-
metadata: n[0].value
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
//#endregion
|
|
259
87
|
//#region src/getFeedItems.ts
|
|
260
|
-
var
|
|
261
|
-
query GetSeeds($where: AttestationWhereInput!, $take: Int, $skip: Int) {
|
|
262
|
-
itemSeeds: attestations(where: $where, orderBy: [{ timeCreated: desc }], take: $take, skip: $skip) {
|
|
263
|
-
id
|
|
264
|
-
decodedDataJson
|
|
265
|
-
attester
|
|
266
|
-
schema {
|
|
267
|
-
schemaNames {
|
|
268
|
-
name
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
refUID
|
|
272
|
-
revoked
|
|
273
|
-
schemaId
|
|
274
|
-
timeCreated
|
|
275
|
-
isOffchain
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
`, z = (e) => e.replace(/_([a-z])/g, (e, t) => t.toUpperCase()), je = (e) => {
|
|
88
|
+
var ge = (e) => {
|
|
279
89
|
let t = /* @__PURE__ */ new Date(e * 1e3), n = [
|
|
280
90
|
"Sun",
|
|
281
91
|
"Mon",
|
|
@@ -299,21 +109,12 @@ var L = "image", R = ["0x0000000000000000000000000000000000000000000000000000000
|
|
|
299
109
|
"Dec"
|
|
300
110
|
], i = n[t.getUTCDay()], a = r[t.getUTCMonth()], o = t.getUTCFullYear();
|
|
301
111
|
return `${i}, ${t.getUTCDate().toString().padStart(2, "0")} ${a} ${o} ${t.getUTCHours().toString().padStart(2, "0")}:${t.getUTCMinutes().toString().padStart(2, "0")}:${t.getUTCSeconds().toString().padStart(2, "0")} GMT`;
|
|
302
|
-
},
|
|
303
|
-
let [t, n, r] = e.split("_");
|
|
304
|
-
if (!t || !n) return null;
|
|
305
|
-
let i = r === "ids";
|
|
306
|
-
return {
|
|
307
|
-
propertyName: t.endsWith("s") ? t : t + "s",
|
|
308
|
-
modelName: n,
|
|
309
|
-
isList: i
|
|
310
|
-
};
|
|
311
|
-
}, B = (e, t, n, r) => {
|
|
112
|
+
}, _e = (e) => e === "image" ? "images" : e === "post" ? "posts" : e.toLowerCase() + "s", N = (e, t, n, r) => {
|
|
312
113
|
let { itemUrlBase: i, itemUrlPath: a, siteUrl: o } = r;
|
|
313
114
|
!e.title && !e.Title ? (e.title = t, e.Title = t) : e.title && !e.Title ? e.Title = e.title : e.Title && !e.title && (e.title = e.Title);
|
|
314
|
-
let s = e.storage_transaction_id && typeof e.storage_transaction_id == "string" && e.storage_transaction_id.trim() !== "" && e.storage_transaction_id !== "undefined" && e.storage_transaction_id !== t ? e.storage_transaction_id.trim() : null, c = e.storageTransactionId && typeof e.storageTransactionId == "string" && e.storageTransactionId.trim() !== "" && e.storageTransactionId !== "undefined" && e.storageTransactionId !== t ? e.storageTransactionId.trim() : null, l = s || c, u =
|
|
115
|
+
let s = e.storage_transaction_id && typeof e.storage_transaction_id == "string" && e.storage_transaction_id.trim() !== "" && e.storage_transaction_id !== "undefined" && e.storage_transaction_id !== t ? e.storage_transaction_id.trim() : null, c = e.storageTransactionId && typeof e.storageTransactionId == "string" && e.storageTransactionId.trim() !== "" && e.storageTransactionId !== "undefined" && e.storageTransactionId !== t ? e.storageTransactionId.trim() : null, l = s || c, u = _e(n), d = t && typeof t == "string" && t.trim() !== "" ? t : "unknown", f;
|
|
315
116
|
if (l && l !== t && l.length > 0) try {
|
|
316
|
-
f =
|
|
117
|
+
f = b(l);
|
|
317
118
|
} catch (e) {
|
|
318
119
|
console.error("[feed] [setFeedItemDefaults] Error generating Arweave URL:", e), f = i == null ? `${o.replace(/\/$/, "")}/${u}/${d}` : `${i.replace(/\/$/, "")}/${(a ?? "attestation/view").replace(/^\//, "")}/${d}`;
|
|
319
120
|
}
|
|
@@ -322,248 +123,102 @@ var L = "image", R = ["0x0000000000000000000000000000000000000000000000000000000
|
|
|
322
123
|
!p || p === "undefined" || typeof p == "string" && p.trim() === "" ? (e.link = f, e.Link = f) : ((!e.link || e.link === "undefined") && (e.link = p), (!e.Link || e.Link === "undefined") && (e.Link = p));
|
|
323
124
|
let m = e.guid || e.Guid;
|
|
324
125
|
if (!m || m === "undefined" || typeof m == "string" && m.trim() === "" ? (e.guid = e.link || f, e.Guid = e.guid) : ((!e.guid || e.guid === "undefined") && (e.guid = m), (!e.Guid || e.Guid === "undefined") && (e.Guid = m)), e.timeCreated && !e.pubDate && !e.PubDate) {
|
|
325
|
-
let t =
|
|
126
|
+
let t = ge(e.timeCreated);
|
|
326
127
|
e.pubDate = t, e.PubDate = t;
|
|
327
128
|
} else e.pubDate && !e.PubDate ? e.PubDate = e.pubDate : e.PubDate && !e.pubDate && (e.pubDate = e.PubDate);
|
|
328
129
|
!e.seedUid && !e.SeedUid ? (e.seedUid = t, e.SeedUid = t) : e.seedUid && !e.SeedUid ? e.SeedUid = e.seedUid : e.SeedUid && !e.seedUid && (e.seedUid = e.SeedUid), e.attester && !e.Attester ? e.Attester = e.attester : e.Attester && !e.attester && (e.attester = e.Attester);
|
|
329
|
-
},
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
});
|
|
356
|
-
} else R.includes(r.value) || H.add(r.value);
|
|
357
|
-
let d = r.value;
|
|
358
|
-
o && s && Array.isArray(d) ? d = d.map((e) => String(e)) : typeof d != "string" && (d = JSON.stringify(d)), o && !s && t.find((e) => e.id === r.value)?.schema?.schemaNames, o && s && t.filter((e) => Array.isArray(r.value) && r.value.includes(e.id)).length;
|
|
359
|
-
let f = Pe.get(e.refUID);
|
|
360
|
-
if (!f) return;
|
|
361
|
-
let p = U.get(f) || {};
|
|
362
|
-
p[i] = d;
|
|
363
|
-
let m = z(i);
|
|
364
|
-
m !== i && (p[m] = d), U.set(f, p);
|
|
365
|
-
}, Re = async (e) => {
|
|
366
|
-
let t = e.map((e) => e.id);
|
|
367
|
-
for (let n = 0; n < e.length; n++) {
|
|
368
|
-
let r = e[n];
|
|
369
|
-
if (!r) continue;
|
|
370
|
-
t.push(r.id);
|
|
371
|
-
let i = r.schema?.schemaNames?.[0]?.name ?? "unknown";
|
|
372
|
-
V.set(r.id, i), U.has(r.id) || U.set(r.id, {
|
|
373
|
-
seedUid: r.id,
|
|
374
|
-
timeCreated: r.timeCreated,
|
|
375
|
-
attester: r.attester
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
let n = await h({ seedUids: t });
|
|
379
|
-
for (let e = 0; e < n.length; e++) {
|
|
380
|
-
let t = n[e], r = t.refUID;
|
|
381
|
-
Pe.set(t.id, r);
|
|
382
|
-
let i = W.get(r) || [];
|
|
383
|
-
W.set(r, [...i, t]);
|
|
384
|
-
}
|
|
385
|
-
let r = [];
|
|
386
|
-
for (let [e, t] of W.entries()) {
|
|
387
|
-
let n = [...t].sort((e, t) => t.timeCreated - e.timeCreated)[0];
|
|
388
|
-
n && (r.push(n.id), Fe.set(e, n.id));
|
|
389
|
-
}
|
|
390
|
-
let i = _(await m({ versionUids: r }));
|
|
391
|
-
for (let t = 0; t < i.length; t++) await Le(i[t], e);
|
|
392
|
-
}, ze = new Set([
|
|
393
|
-
"seedUid",
|
|
394
|
-
"SeedUid",
|
|
395
|
-
"timeCreated",
|
|
396
|
-
"attester",
|
|
397
|
-
"Attester",
|
|
398
|
-
"storage_transaction_id",
|
|
399
|
-
"storage_provider_transaction_id",
|
|
400
|
-
"storageTransactionId",
|
|
401
|
-
"storageProviderTransactionId"
|
|
402
|
-
]);
|
|
403
|
-
function Be(e) {
|
|
404
|
-
let t = Array.from(U.entries()).filter(([t]) => V.get(t) === e);
|
|
405
|
-
for (let [, e] of t) {
|
|
406
|
-
let t = Object.keys(e).filter((e) => !e.startsWith("_") && !ze.has(e));
|
|
407
|
-
for (let n of t) {
|
|
408
|
-
let t = e[n], r = he(t);
|
|
409
|
-
if (r !== t && Array.isArray(r) && (e[n] = r, t = r), Array.isArray(t)) {
|
|
410
|
-
let r = t;
|
|
411
|
-
if (!r.some((e) => typeof e == "string" && !R.includes(e) && U.has(e))) continue;
|
|
412
|
-
let i = [], a = [], o = !1;
|
|
413
|
-
for (let e of r) {
|
|
414
|
-
if (typeof e != "string" || R.includes(e)) {
|
|
415
|
-
i.push(String(e)), a.push("unknown");
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
let t = V.get(e) ?? "unknown";
|
|
419
|
-
if (t === L) {
|
|
420
|
-
i.push(e), a.push(L);
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
let n = U.get(e), r = n?.storageTransactionId ?? n?.storage_transaction_id;
|
|
424
|
-
if (r && typeof r == "string" && r.trim()) try {
|
|
425
|
-
i.push(E(r)), a.push(t), o = !0;
|
|
426
|
-
} catch {
|
|
427
|
-
i.push(e), a.push(t);
|
|
428
|
-
}
|
|
429
|
-
else i.push(e), a.push(t);
|
|
430
|
-
}
|
|
431
|
-
if (o) {
|
|
432
|
-
let t = M(n);
|
|
433
|
-
if (e[t] = i, Se(e, t, a), me(e, t), t !== n) {
|
|
434
|
-
delete e[n];
|
|
435
|
-
let t = z(n);
|
|
436
|
-
t !== n && delete e[t];
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
} else if (typeof t == "string") {
|
|
440
|
-
if (R.includes(t) || !U.has(t)) continue;
|
|
441
|
-
let r = U.get(t);
|
|
442
|
-
if (V.get(t) === L) continue;
|
|
443
|
-
let i = r?.storageTransactionId ?? r?.storage_transaction_id;
|
|
444
|
-
if (i && typeof i == "string" && i.trim()) try {
|
|
445
|
-
let r = n.endsWith("_id") ? n.replace(/_id$/, "") : n;
|
|
446
|
-
e[r] = E(i);
|
|
447
|
-
let a = V.get(t) ?? "unknown";
|
|
448
|
-
xe(e, r, a);
|
|
449
|
-
let o = z(r);
|
|
450
|
-
if (o !== r && xe(e, o, a), r !== n) {
|
|
451
|
-
delete e[n];
|
|
452
|
-
let t = z(n);
|
|
453
|
-
t !== n && delete e[t];
|
|
454
|
-
}
|
|
455
|
-
} catch {}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
function Ve(e, t, n) {
|
|
461
|
-
if (!n) return;
|
|
462
|
-
let r = Array.from(U.entries()).filter(([t]) => V.get(t) === e);
|
|
463
|
-
for (let [, e] of r) {
|
|
464
|
-
let n = Object.keys(e).filter((e) => !e.startsWith("_") && !ze.has(e));
|
|
465
|
-
for (let r of n) {
|
|
466
|
-
let n = e[r], i = he(n);
|
|
467
|
-
i !== n && Array.isArray(i) && (e[r] = i, n = i);
|
|
468
|
-
let a = Array.isArray(n), o = a ? n : [n], s = [], c = !1;
|
|
469
|
-
for (let e of o) {
|
|
470
|
-
if (typeof e != "string" || R.includes(e)) {
|
|
471
|
-
s.push(e);
|
|
472
|
-
continue;
|
|
473
|
-
}
|
|
474
|
-
let n = U.get(e);
|
|
475
|
-
if (!n) {
|
|
476
|
-
s.push(e);
|
|
477
|
-
continue;
|
|
478
|
-
}
|
|
479
|
-
let r = n?.storageTransactionId ?? n?.storage_transaction_id;
|
|
480
|
-
if (V.get(e) === L) {
|
|
481
|
-
let r = V.get(e) ?? "unknown", i = { ...n };
|
|
482
|
-
B(i, e, r, t), ge(i), s.push(i), c = !0;
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
if (r && typeof r == "string" && r.trim()) {
|
|
486
|
-
s.push(e);
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
let i = V.get(e) ?? "unknown", a = { ...n };
|
|
490
|
-
B(a, e, i, t), s.push(a), c = !0;
|
|
491
|
-
}
|
|
492
|
-
if (c) {
|
|
493
|
-
let t = a ? M(r) : r.endsWith("_id") ? r.replace(/_id$/, "") : r;
|
|
494
|
-
if (e[t] = a ? s : s[0], me(e, t), t !== r) {
|
|
495
|
-
delete e[r];
|
|
496
|
-
let t = z(r);
|
|
497
|
-
t !== r && delete e[t];
|
|
498
|
-
}
|
|
130
|
+
}, P = (e, t) => {
|
|
131
|
+
if (!e.title && !e.Title ? (e.title = t, e.Title = t) : e.title && !e.Title ? e.Title = e.title : e.Title && !e.title && (e.title = e.Title), e.timeCreated && !e.pubDate && !e.PubDate) {
|
|
132
|
+
let t = ge(e.timeCreated);
|
|
133
|
+
e.pubDate = t, e.PubDate = t;
|
|
134
|
+
} else e.pubDate && !e.PubDate ? e.PubDate = e.pubDate : e.PubDate && !e.pubDate && (e.pubDate = e.PubDate);
|
|
135
|
+
!e.seedUid && !e.SeedUid ? (e.seedUid = t, e.SeedUid = t) : e.seedUid && !e.SeedUid ? e.SeedUid = e.seedUid : e.SeedUid && !e.seedUid && (e.seedUid = e.SeedUid), e.attester && !e.Attester ? e.Attester = e.attester : e.Attester && !e.attester && (e.attester = e.Attester);
|
|
136
|
+
let n = e.storage_transaction_id && typeof e.storage_transaction_id == "string" && e.storage_transaction_id.trim() !== "" && e.storage_transaction_id !== "undefined" && e.storage_transaction_id !== t ? e.storage_transaction_id.trim() : null, r = e.storageTransactionId && typeof e.storageTransactionId == "string" && e.storageTransactionId.trim() !== "" && e.storageTransactionId !== "undefined" && e.storageTransactionId !== t ? e.storageTransactionId.trim() : null, i = n || r;
|
|
137
|
+
if (delete e.link, delete e.Link, delete e.guid, delete e.Guid, i && i.length > 0) try {
|
|
138
|
+
let t = b(i);
|
|
139
|
+
e.link = t, e.Link = t;
|
|
140
|
+
} catch {}
|
|
141
|
+
};
|
|
142
|
+
function F(e) {
|
|
143
|
+
if (!e || typeof e != "object" || Array.isArray(e)) return !1;
|
|
144
|
+
let t = e;
|
|
145
|
+
return typeof t.seedUid == "string" || typeof t.SeedUid == "string";
|
|
146
|
+
}
|
|
147
|
+
function ve(e, t, n) {
|
|
148
|
+
N(e, e.seedUid || e.SeedUid || "", t, n);
|
|
149
|
+
for (let r of Object.keys(e)) {
|
|
150
|
+
if (r.startsWith("_")) continue;
|
|
151
|
+
let i = e[r];
|
|
152
|
+
if (Array.isArray(i)) {
|
|
153
|
+
for (let e of i) if (F(e)) {
|
|
154
|
+
let r = e.seedUid || e.SeedUid || "", i = typeof e.schemaName == "string" ? e.schemaName : t;
|
|
155
|
+
i === "image" ? P(e, r) : N(e, r, i, n);
|
|
499
156
|
}
|
|
157
|
+
} else if (F(i)) {
|
|
158
|
+
let e = i.seedUid || i.SeedUid || "", r = typeof i.schemaName == "string" ? i.schemaName : t;
|
|
159
|
+
r === "image" ? P(i, e) : N(i, e, r, n);
|
|
500
160
|
}
|
|
501
161
|
}
|
|
502
162
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
skip: 0
|
|
509
|
-
});
|
|
510
|
-
await Re(a ?? []), Be(e);
|
|
511
|
-
let o = j(), s = {
|
|
512
|
-
itemUrlBase: o.itemUrlBase,
|
|
513
|
-
itemUrlPath: o.itemUrlPath,
|
|
514
|
-
siteUrl: o.siteUrl
|
|
163
|
+
function I(e, t) {
|
|
164
|
+
let n = M(), r = {
|
|
165
|
+
itemUrlBase: n.itemUrlBase,
|
|
166
|
+
itemUrlPath: n.itemUrlPath,
|
|
167
|
+
siteUrl: n.siteUrl
|
|
515
168
|
};
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
169
|
+
return t.map((t) => {
|
|
170
|
+
let n = t.data;
|
|
171
|
+
return ve(n, e, r), n;
|
|
172
|
+
});
|
|
519
173
|
}
|
|
520
|
-
var
|
|
521
|
-
await
|
|
522
|
-
let n =
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
gte: o,
|
|
528
|
-
lt: s
|
|
529
|
-
} }] }), { itemSeeds: l } = await p.getEasClient().request(Ae, {
|
|
530
|
-
where: c,
|
|
531
|
-
take: 1e3,
|
|
532
|
-
skip: 0
|
|
174
|
+
var ye = async (e, t) => {
|
|
175
|
+
await D();
|
|
176
|
+
let n = M(), r = t?.limit ?? 100, i = t?.skip ?? 0, { items: a } = await te(e, {
|
|
177
|
+
limit: r,
|
|
178
|
+
skip: i,
|
|
179
|
+
expandRelations: n.expandRelations !== !1,
|
|
180
|
+
hydrateStorage: !0
|
|
533
181
|
});
|
|
534
|
-
return
|
|
182
|
+
return I(e, a);
|
|
183
|
+
}, be = async (e, t, n) => {
|
|
184
|
+
await D();
|
|
185
|
+
let r = M();
|
|
186
|
+
return I(e, await ne(e, t, n, {
|
|
187
|
+
expandRelations: r.expandRelations !== !1,
|
|
188
|
+
hydrateStorage: !0
|
|
189
|
+
}));
|
|
535
190
|
};
|
|
536
191
|
//#endregion
|
|
537
192
|
//#region src/consume/parseRss.ts
|
|
538
|
-
function
|
|
193
|
+
function xe(e) {
|
|
539
194
|
try {
|
|
540
195
|
return JSON.parse(JSON.stringify(e));
|
|
541
196
|
} catch {
|
|
542
197
|
return { ...e };
|
|
543
198
|
}
|
|
544
199
|
}
|
|
545
|
-
var
|
|
200
|
+
var Se = new re({ customFields: { item: [
|
|
546
201
|
"featureImage",
|
|
547
202
|
"feature_image",
|
|
548
203
|
"content:encoded",
|
|
549
204
|
"seedUid",
|
|
550
205
|
"SeedUid"
|
|
551
206
|
] } });
|
|
552
|
-
async function
|
|
553
|
-
let t = await
|
|
207
|
+
async function Ce(e) {
|
|
208
|
+
let t = await Se.parseString(e);
|
|
554
209
|
return {
|
|
555
210
|
title: t.title,
|
|
556
211
|
link: t.link,
|
|
557
212
|
description: t.description,
|
|
558
|
-
items: (t.items ?? []).map(
|
|
213
|
+
items: (t.items ?? []).map(xe)
|
|
559
214
|
};
|
|
560
215
|
}
|
|
561
216
|
//#endregion
|
|
562
217
|
//#region src/rss/generateRssXml.ts
|
|
563
|
-
var
|
|
218
|
+
var L = "http://purl.org/dc/elements/1.1/", R = "http://purl.org/rss/1.0/modules/content/", z = "http://search.yahoo.com/mrss/", we = { publication: {
|
|
564
219
|
prefix: "publication",
|
|
565
220
|
uri: "https://seedprotocol.io/ns/publication/1.0"
|
|
566
|
-
} },
|
|
221
|
+
} }, Te = "https://seedprotocol.io/ns/relations", Ee = /* @__PURE__ */ new Set([
|
|
567
222
|
"xml",
|
|
568
223
|
"xmlns",
|
|
569
224
|
"dc",
|
|
@@ -571,17 +226,17 @@ var K = "http://purl.org/dc/elements/1.1/", q = "http://purl.org/rss/1.0/modules
|
|
|
571
226
|
"content",
|
|
572
227
|
"atom",
|
|
573
228
|
"fh"
|
|
574
|
-
]),
|
|
229
|
+
]), De = /* @__PURE__ */ new Set([
|
|
575
230
|
"Title",
|
|
576
231
|
"Link",
|
|
577
232
|
"Guid",
|
|
578
233
|
"PubDate",
|
|
579
234
|
"SeedUid"
|
|
580
235
|
]);
|
|
581
|
-
function
|
|
582
|
-
return
|
|
236
|
+
function Oe(e, t) {
|
|
237
|
+
return De.has(e) ? e.charAt(0).toLowerCase() + e.slice(1) in t : !1;
|
|
583
238
|
}
|
|
584
|
-
var
|
|
239
|
+
var B = [
|
|
585
240
|
"title",
|
|
586
241
|
"link",
|
|
587
242
|
"description",
|
|
@@ -605,7 +260,7 @@ var Qe = [
|
|
|
605
260
|
"media:category",
|
|
606
261
|
"media:group"
|
|
607
262
|
];
|
|
608
|
-
function
|
|
263
|
+
function V(e) {
|
|
609
264
|
if (e instanceof Date) return e.toUTCString();
|
|
610
265
|
if (typeof e == "string") {
|
|
611
266
|
let t = new Date(e);
|
|
@@ -613,22 +268,25 @@ function $e(e) {
|
|
|
613
268
|
}
|
|
614
269
|
return String(e);
|
|
615
270
|
}
|
|
616
|
-
function
|
|
271
|
+
function ke(e) {
|
|
617
272
|
return /[<>&]|]]>/.test(e);
|
|
618
273
|
}
|
|
619
|
-
function
|
|
274
|
+
function H(e, t) {
|
|
620
275
|
let n = String(t);
|
|
621
|
-
if (n !== "")
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
276
|
+
if (n !== "") {
|
|
277
|
+
if (ke(n)) {
|
|
278
|
+
if (n.includes("]]>")) {
|
|
279
|
+
let t = n.split("]]>");
|
|
280
|
+
for (let n = 0; n < t.length; n++) e.dat(t[n]), n < t.length - 1 && e.txt("]]>");
|
|
281
|
+
} else e.dat(n);
|
|
282
|
+
} else e.txt(n);
|
|
283
|
+
}
|
|
626
284
|
}
|
|
627
|
-
function
|
|
285
|
+
function U(e) {
|
|
628
286
|
return typeof e == "object" && !!e && !Array.isArray(e) && !(e instanceof Date);
|
|
629
287
|
}
|
|
630
|
-
var
|
|
631
|
-
...
|
|
288
|
+
var Ae = 4, je = /* @__PURE__ */ new Set([
|
|
289
|
+
...B,
|
|
632
290
|
"guid",
|
|
633
291
|
"source",
|
|
634
292
|
"dc",
|
|
@@ -636,79 +294,79 @@ var tt = 4, nt = new Set([
|
|
|
636
294
|
"content:encoded",
|
|
637
295
|
"items"
|
|
638
296
|
]);
|
|
639
|
-
function
|
|
297
|
+
function Me(e) {
|
|
640
298
|
return e.endsWith("s") && e.length > 1 ? e.slice(0, -1) : e;
|
|
641
299
|
}
|
|
642
|
-
function
|
|
300
|
+
function Ne(e) {
|
|
643
301
|
return e.trim().replace(/[^A-Za-z0-9_.-]+/g, "_").replace(/^[^A-Za-z_]+/, "").replace(/^$/, "rel").toLowerCase();
|
|
644
302
|
}
|
|
645
|
-
function
|
|
646
|
-
if (!t.has(e) && !
|
|
303
|
+
function Pe(e, t) {
|
|
304
|
+
if (!t.has(e) && !Ee.has(e)) return t.add(e), e;
|
|
647
305
|
let n = 2;
|
|
648
306
|
for (;;) {
|
|
649
307
|
let r = `${e}${n}`;
|
|
650
|
-
if (!t.has(r) && !
|
|
308
|
+
if (!t.has(r) && !Ee.has(r)) return t.add(r), r;
|
|
651
309
|
n += 1;
|
|
652
310
|
}
|
|
653
311
|
}
|
|
654
|
-
function
|
|
655
|
-
return Array.isArray(e) && e.length > 0 && e.every((e) =>
|
|
312
|
+
function Fe(e) {
|
|
313
|
+
return Array.isArray(e) && e.length > 0 && e.every((e) => U(e));
|
|
656
314
|
}
|
|
657
|
-
function
|
|
658
|
-
let t = { ...
|
|
315
|
+
function Ie(e) {
|
|
316
|
+
let t = { ...we }, n = new Set(Object.values(t).map((e) => e.prefix)), r = /* @__PURE__ */ new Set();
|
|
659
317
|
for (let t of e) for (let [e, n] of Object.entries(t)) {
|
|
660
|
-
let t = e === "author" &&
|
|
661
|
-
e.startsWith("_") ||
|
|
318
|
+
let t = e === "author" && U(n) || e === "authors" && Fe(n);
|
|
319
|
+
e.startsWith("_") || (!je.has(e) || t) && (U(n) || Fe(n)) && r.add(Me(e));
|
|
662
320
|
}
|
|
663
321
|
let i = [...r].sort();
|
|
664
322
|
for (let e of i) t[e] || (t[e] = {
|
|
665
|
-
prefix:
|
|
666
|
-
uri: `${
|
|
323
|
+
prefix: Pe(Ne(e), n),
|
|
324
|
+
uri: `${Te}/${e}/1.0`
|
|
667
325
|
});
|
|
668
326
|
return t;
|
|
669
327
|
}
|
|
670
|
-
function
|
|
328
|
+
function W(e, t) {
|
|
671
329
|
if (e in t) return t[e];
|
|
672
330
|
if (e.endsWith("s") && e.length > 1) {
|
|
673
331
|
let n = e.slice(0, -1);
|
|
674
332
|
if (n in t) return t[n];
|
|
675
333
|
}
|
|
676
334
|
}
|
|
677
|
-
function
|
|
335
|
+
function Le(e, t) {
|
|
678
336
|
return t ? `${t.prefix}:${e}` : e;
|
|
679
337
|
}
|
|
680
|
-
function
|
|
338
|
+
function G(e, t, n, r, i = 0, a) {
|
|
681
339
|
let o = e.ele(n);
|
|
682
340
|
for (let [e, n] of Object.entries(t)) {
|
|
683
341
|
if (n == null || e.startsWith("_") || e === "items") continue;
|
|
684
|
-
let t =
|
|
685
|
-
if (i >=
|
|
686
|
-
|
|
342
|
+
let t = Le(e, a);
|
|
343
|
+
if (i >= Ae) {
|
|
344
|
+
H(o.ele(t), typeof n == "object" ? JSON.stringify(n) : String(n));
|
|
687
345
|
continue;
|
|
688
346
|
}
|
|
689
347
|
if (Array.isArray(n)) {
|
|
690
|
-
let t =
|
|
691
|
-
for (let e of n) e != null && (
|
|
348
|
+
let t = Le(e.endsWith("s") && e.length > 1 ? e.slice(0, -1) : e, a);
|
|
349
|
+
for (let e of n) e != null && (U(e) ? G(o, e, t, !1, i + 1, a) : H(o.ele(t), String(e)));
|
|
692
350
|
continue;
|
|
693
351
|
}
|
|
694
|
-
if (
|
|
695
|
-
|
|
352
|
+
if (U(n)) {
|
|
353
|
+
G(o, n, t, !1, i + 1, a);
|
|
696
354
|
continue;
|
|
697
355
|
}
|
|
698
|
-
|
|
356
|
+
H(o.ele(t), String(n));
|
|
699
357
|
}
|
|
700
358
|
if (r) {
|
|
701
359
|
let n = t.name ?? t.seedUid;
|
|
702
|
-
n && e.ele(
|
|
360
|
+
n && e.ele(L, "creator").txt(String(n));
|
|
703
361
|
}
|
|
704
362
|
}
|
|
705
|
-
function
|
|
363
|
+
function Re(e, t, n, r, i) {
|
|
706
364
|
if (!(n == null || t.startsWith("_")) && t !== "items") {
|
|
707
365
|
if (t === "guid") {
|
|
708
366
|
let t = n, r = t?.value ?? String(n);
|
|
709
367
|
if (!r) return;
|
|
710
368
|
let i = {};
|
|
711
|
-
typeof t?.isPermaLink == "boolean" && (i.isPermaLink = t.isPermaLink ? "true" : "false"),
|
|
369
|
+
typeof t?.isPermaLink == "boolean" && (i.isPermaLink = t.isPermaLink ? "true" : "false"), H(e.ele("guid", i), r);
|
|
712
370
|
return;
|
|
713
371
|
}
|
|
714
372
|
if (t === "source" && typeof n == "object" && n) {
|
|
@@ -730,37 +388,39 @@ function lt(e, t, n, r, i) {
|
|
|
730
388
|
}
|
|
731
389
|
if (t === "dc" && typeof n == "object" && n) {
|
|
732
390
|
let t = n;
|
|
733
|
-
for (let [n, r] of Object.entries(t)) if (r != null)
|
|
734
|
-
|
|
735
|
-
let r
|
|
736
|
-
|
|
391
|
+
for (let [n, r] of Object.entries(t)) if (r != null) {
|
|
392
|
+
if (Array.isArray(r)) {
|
|
393
|
+
for (let t of r) if (t != null) {
|
|
394
|
+
let r = e.ele(L, n);
|
|
395
|
+
t instanceof Date ? r.txt(t.toISOString()) : H(r, String(t));
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
let t = e.ele(L, n);
|
|
399
|
+
r instanceof Date ? t.txt(r.toISOString()) : H(t, String(r));
|
|
737
400
|
}
|
|
738
|
-
} else {
|
|
739
|
-
let t = e.ele(K, n);
|
|
740
|
-
r instanceof Date ? t.txt(r.toISOString()) : Y(t, String(r));
|
|
741
401
|
}
|
|
742
402
|
return;
|
|
743
403
|
}
|
|
744
404
|
if (t === "content:encoded") {
|
|
745
|
-
|
|
405
|
+
H(e.ele(R, "encoded"), String(n));
|
|
746
406
|
return;
|
|
747
407
|
}
|
|
748
408
|
if (t === "content" && typeof n == "string" && !("content:encoded" in r)) {
|
|
749
|
-
|
|
409
|
+
H(e.ele(R, "encoded"), String(n));
|
|
750
410
|
return;
|
|
751
411
|
}
|
|
752
412
|
if (t !== "content") {
|
|
753
413
|
if (t === "media:group" && Array.isArray(n)) {
|
|
754
414
|
for (let t of n) if (t && typeof t == "object") {
|
|
755
|
-
let n = e.ele(
|
|
415
|
+
let n = e.ele(z, "group");
|
|
756
416
|
for (let [e, r] of Object.entries(t)) if (r != null && e.startsWith("media:")) {
|
|
757
417
|
let t = e.slice(6);
|
|
758
418
|
if (Array.isArray(r)) {
|
|
759
419
|
for (let e of r) if (e && typeof e == "object") {
|
|
760
|
-
let r = n.ele(
|
|
761
|
-
for (let [t, n] of Object.entries(e)) n != null && (t === "url" || t === "value" ?
|
|
420
|
+
let r = n.ele(z, t);
|
|
421
|
+
for (let [t, n] of Object.entries(e)) n != null && (t === "url" || t === "value" ? H(r, String(n)) : r.att(t, String(n)));
|
|
762
422
|
}
|
|
763
|
-
} else typeof r == "string" &&
|
|
423
|
+
} else typeof r == "string" && H(n.ele(z, t), r);
|
|
764
424
|
}
|
|
765
425
|
}
|
|
766
426
|
return;
|
|
@@ -771,27 +431,27 @@ function lt(e, t, n, r, i) {
|
|
|
771
431
|
if (typeof t != "object" || !t) continue;
|
|
772
432
|
let n = {}, i = null;
|
|
773
433
|
for (let [e, r] of Object.entries(t)) r != null && (e === "value" ? i = String(r) : n[e] = String(r));
|
|
774
|
-
let a = e.ele(
|
|
775
|
-
i !== null &&
|
|
434
|
+
let a = e.ele(z, r, n);
|
|
435
|
+
i !== null && H(a, i);
|
|
776
436
|
}
|
|
777
437
|
return;
|
|
778
438
|
}
|
|
779
439
|
if (t.startsWith("media:") && typeof n == "string") {
|
|
780
440
|
let r = t.slice(6);
|
|
781
|
-
|
|
441
|
+
H(e.ele(z, r), n);
|
|
782
442
|
return;
|
|
783
443
|
}
|
|
784
444
|
if (n instanceof Date) {
|
|
785
|
-
e.ele(t).txt(
|
|
445
|
+
e.ele(t).txt(V(n));
|
|
786
446
|
return;
|
|
787
447
|
}
|
|
788
|
-
if (t === "author" &&
|
|
789
|
-
|
|
448
|
+
if (t === "author" && U(n)) {
|
|
449
|
+
G(e, n, "author", !0, 0, W(t, i));
|
|
790
450
|
return;
|
|
791
451
|
}
|
|
792
452
|
if (t === "authors" && Array.isArray(n)) {
|
|
793
|
-
let r =
|
|
794
|
-
for (let t of n) if (t &&
|
|
453
|
+
let r = W(t, i);
|
|
454
|
+
for (let t of n) if (t && U(t)) G(e, t, "author", !0, 0, r);
|
|
795
455
|
else {
|
|
796
456
|
let n = typeof t == "string" ? t : t && typeof t == "object" && "name" in t ? `${t.email ?? ""} (${t.name ?? ""})`.trim() || t.name : String(t);
|
|
797
457
|
n && e.ele("author").txt(n);
|
|
@@ -808,137 +468,109 @@ function lt(e, t, n, r, i) {
|
|
|
808
468
|
}
|
|
809
469
|
return;
|
|
810
470
|
}
|
|
811
|
-
if (Array.isArray(n) && n.length > 0 && n.every((e) =>
|
|
812
|
-
let r = t.endsWith("s") ? t.slice(0, -1) : t, a =
|
|
813
|
-
for (let t of n) t &&
|
|
471
|
+
if (Array.isArray(n) && n.length > 0 && n.every((e) => U(e))) {
|
|
472
|
+
let r = t.endsWith("s") ? t.slice(0, -1) : t, a = W(t, i);
|
|
473
|
+
for (let t of n) t && G(e, t, r, !1, 0, a);
|
|
814
474
|
return;
|
|
815
475
|
}
|
|
816
476
|
if (Array.isArray(n) && n.every((e) => typeof e == "string")) {
|
|
817
477
|
let r = t.endsWith("s") ? t.slice(0, -1) : t;
|
|
818
|
-
for (let t of n) t &&
|
|
478
|
+
for (let t of n) t && H(e.ele(r), t);
|
|
819
479
|
return;
|
|
820
480
|
}
|
|
821
|
-
if (
|
|
822
|
-
|
|
481
|
+
if (U(n)) {
|
|
482
|
+
G(e, n, t, !1, 0, W(t, i));
|
|
823
483
|
return;
|
|
824
484
|
}
|
|
825
|
-
|
|
485
|
+
H(e.ele(t), String(n));
|
|
826
486
|
}
|
|
827
487
|
}
|
|
828
488
|
}
|
|
829
|
-
var
|
|
830
|
-
function
|
|
831
|
-
let t =
|
|
489
|
+
var ze = "http://www.w3.org/2005/Atom", Be = "http://purl.org/syndication/history/1.0";
|
|
490
|
+
function Ve(e) {
|
|
491
|
+
let t = oe({
|
|
832
492
|
version: "1.0",
|
|
833
493
|
encoding: "UTF-8"
|
|
834
|
-
}), n =
|
|
835
|
-
"xmlns:dc":
|
|
836
|
-
"xmlns:content":
|
|
837
|
-
"xmlns:media":
|
|
838
|
-
"xmlns:atom":
|
|
494
|
+
}), n = Ie(e.items), r = {
|
|
495
|
+
"xmlns:dc": L,
|
|
496
|
+
"xmlns:content": R,
|
|
497
|
+
"xmlns:media": z,
|
|
498
|
+
"xmlns:atom": ze,
|
|
839
499
|
...Object.values(n).reduce((e, t) => (e[`xmlns:${t.prefix}`] = t.uri, e), {})
|
|
840
500
|
};
|
|
841
|
-
e.isArchive && (r["xmlns:fh"] =
|
|
501
|
+
e.isArchive && (r["xmlns:fh"] = Be);
|
|
842
502
|
let i = t.ele("rss", {
|
|
843
503
|
version: "2.0",
|
|
844
504
|
...r
|
|
845
505
|
}).ele("channel", {
|
|
846
|
-
"xmlns:dc":
|
|
847
|
-
"xmlns:content":
|
|
848
|
-
"xmlns:media":
|
|
506
|
+
"xmlns:dc": L,
|
|
507
|
+
"xmlns:content": R,
|
|
508
|
+
"xmlns:media": z
|
|
849
509
|
});
|
|
850
|
-
if (i.ele("title").txt(e.title), e.link && i.ele("link").txt(e.link), i.ele("description").txt(e.description), e.language && i.ele("language").txt(e.language), e.copyright && i.ele("copyright").txt(e.copyright), e.webMaster && i.ele("webMaster").txt(e.webMaster), e.pubDate && i.ele("pubDate").txt(
|
|
510
|
+
if (i.ele("title").txt(e.title), e.link && i.ele("link").txt(e.link), i.ele("description").txt(e.description), e.language && i.ele("language").txt(e.language), e.copyright && i.ele("copyright").txt(e.copyright), e.webMaster && i.ele("webMaster").txt(e.webMaster), e.pubDate && i.ele("pubDate").txt(V(e.pubDate)), e.lastBuildDate && i.ele("lastBuildDate").txt(V(e.lastBuildDate)), e.links?.length) for (let t of e.links) {
|
|
851
511
|
let e = {
|
|
852
512
|
rel: t.rel,
|
|
853
513
|
href: t.href
|
|
854
514
|
};
|
|
855
|
-
t.type && (e.type = t.type), i.ele(
|
|
515
|
+
t.type && (e.type = t.type), i.ele(ze, "link", e);
|
|
856
516
|
}
|
|
857
|
-
e.isArchive && i.ele(
|
|
858
|
-
let a = new Set(
|
|
517
|
+
e.isArchive && i.ele(Be, "archive");
|
|
518
|
+
let a = new Set(B);
|
|
859
519
|
for (let t of e.items) {
|
|
860
520
|
let e = i.ele("item"), r = /* @__PURE__ */ new Set();
|
|
861
|
-
for (let i of
|
|
862
|
-
let o = Object.keys(t).filter((e) => !r.has(e) && !a.has(e) && !e.startsWith("_") && !
|
|
863
|
-
for (let r of o)
|
|
521
|
+
for (let i of B) i in t && (Re(e, i, t[i], t, n), r.add(i));
|
|
522
|
+
let o = Object.keys(t).filter((e) => !r.has(e) && !a.has(e) && !e.startsWith("_") && !Oe(e, t)).sort();
|
|
523
|
+
for (let r of o) Re(e, r, t[r], t, n);
|
|
864
524
|
}
|
|
865
525
|
return t.end({ prettyPrint: !0 });
|
|
866
526
|
}
|
|
867
527
|
//#endregion
|
|
868
528
|
//#region src/cache/types.ts
|
|
869
|
-
function
|
|
529
|
+
function K(e, t, n) {
|
|
870
530
|
return n?.archive ? `${e}:${t}:archive-${n.archive.year}-${n.archive.month}` : n?.page != null && n.page > 1 ? `${e}:${t}:page-${n.page}` : `${e}:${t}`;
|
|
871
531
|
}
|
|
872
532
|
//#endregion
|
|
873
533
|
//#region src/utils/etag.ts
|
|
874
|
-
function
|
|
875
|
-
return `"${
|
|
534
|
+
function He(e) {
|
|
535
|
+
return `"${se("md5").update(e).digest("hex").substring(0, 16)}"`;
|
|
876
536
|
}
|
|
877
|
-
function
|
|
878
|
-
return
|
|
537
|
+
function Ue(e, t, n, r) {
|
|
538
|
+
return He(`${e}-${t}-${n}-${r}`);
|
|
879
539
|
}
|
|
880
|
-
function
|
|
881
|
-
return mt(`${e}-${t}-${n}-${r}`);
|
|
882
|
-
}
|
|
883
|
-
function _t(e, t) {
|
|
540
|
+
function We(e, t) {
|
|
884
541
|
let n = (e) => e.replace(/^"|"$/g, "");
|
|
885
542
|
return n(e) === n(t);
|
|
886
543
|
}
|
|
887
|
-
function
|
|
544
|
+
function Ge(e) {
|
|
888
545
|
return e ? e.split(",").map((e) => e.trim()).filter((e) => e.length > 0) : [];
|
|
889
546
|
}
|
|
890
|
-
function
|
|
891
|
-
let n =
|
|
892
|
-
return n.length === 0 ? !1 : n.includes("*") ? !0 : n.some((e) =>
|
|
547
|
+
function Ke(e, t) {
|
|
548
|
+
let n = Ge(e);
|
|
549
|
+
return n.length === 0 ? !1 : n.includes("*") ? !0 : n.some((e) => We(e, t));
|
|
893
550
|
}
|
|
894
551
|
//#endregion
|
|
895
552
|
//#region src/cache/MemoryCache.ts
|
|
896
|
-
var
|
|
897
|
-
feedDataCache = /* @__PURE__ */ new Map();
|
|
553
|
+
var qe = class {
|
|
898
554
|
feedContentCache = /* @__PURE__ */ new Map();
|
|
899
555
|
imageMetadataCache = /* @__PURE__ */ new Map();
|
|
900
556
|
config;
|
|
901
|
-
refreshLocks = /* @__PURE__ */ new Map();
|
|
902
557
|
constructor(e) {
|
|
903
558
|
this.config = e;
|
|
904
559
|
}
|
|
905
|
-
getFeedData(e) {
|
|
906
|
-
let t = this.feedDataCache.get(e);
|
|
907
|
-
return t ? Math.floor(Date.now() / 1e3) - t.lastUpdated > this.config.ttl ? (this.feedDataCache.delete(e), this.clearContentCache(e), null) : t : null;
|
|
908
|
-
}
|
|
909
|
-
setFeedData(e, t) {
|
|
910
|
-
let n = Math.floor(Date.now() / 1e3), r = 0, i = "";
|
|
911
|
-
for (let e of t) {
|
|
912
|
-
let t = e.timeCreated;
|
|
913
|
-
t && t > r && (r = t, i = e.id || e.seedUid || e.SeedUid || "");
|
|
914
|
-
}
|
|
915
|
-
r === 0 && (r = n);
|
|
916
|
-
let a = ht(e, "data", r, t.length), o = {
|
|
917
|
-
items: [...t],
|
|
918
|
-
lastProcessedTimestamp: r,
|
|
919
|
-
lastProcessedItemId: i,
|
|
920
|
-
lastUpdated: n,
|
|
921
|
-
etag: a
|
|
922
|
-
};
|
|
923
|
-
this.feedDataCache.set(e, o);
|
|
924
|
-
}
|
|
925
560
|
getFeedContent(e, t, n) {
|
|
926
|
-
let r =
|
|
561
|
+
let r = K(e, t, n), i = this.feedContentCache.get(r);
|
|
927
562
|
return i ? Math.floor(Date.now() / 1e3) > i.expiresAt ? (this.feedContentCache.delete(r), null) : i : null;
|
|
928
563
|
}
|
|
929
564
|
setFeedContent(e, t, n, r, i, a) {
|
|
930
|
-
let o =
|
|
565
|
+
let o = K(e, t, i), s = Math.floor(Date.now() / 1e3), c = s + (a ?? this.config.ttl), l = {
|
|
931
566
|
content: n,
|
|
932
567
|
contentType: r,
|
|
933
|
-
etag:
|
|
568
|
+
etag: Ue(e, t, s, n.length),
|
|
934
569
|
lastModified: s,
|
|
935
570
|
expiresAt: c
|
|
936
571
|
};
|
|
937
572
|
this.feedContentCache.set(o, l);
|
|
938
573
|
}
|
|
939
|
-
clearFeedData(e) {
|
|
940
|
-
this.feedDataCache.delete(e);
|
|
941
|
-
}
|
|
942
574
|
clearContentCache(e) {
|
|
943
575
|
let t = [];
|
|
944
576
|
for (let n of this.feedContentCache.keys()) n.startsWith(`${e}:`) && t.push(n);
|
|
@@ -957,19 +589,7 @@ var bt = class {
|
|
|
957
589
|
this.imageMetadataCache.set(e, r);
|
|
958
590
|
}
|
|
959
591
|
clearAll() {
|
|
960
|
-
this.
|
|
961
|
-
}
|
|
962
|
-
async withRefreshLock(e, t) {
|
|
963
|
-
let n = this.refreshLocks.get(e);
|
|
964
|
-
n && (await n, this.getFeedData(e));
|
|
965
|
-
let r = (async () => {
|
|
966
|
-
try {
|
|
967
|
-
return await t();
|
|
968
|
-
} finally {
|
|
969
|
-
this.refreshLocks.delete(e);
|
|
970
|
-
}
|
|
971
|
-
})();
|
|
972
|
-
return this.refreshLocks.set(e, r), r;
|
|
592
|
+
this.feedContentCache.clear(), this.imageMetadataCache.clear();
|
|
973
593
|
}
|
|
974
594
|
updateConfig(e) {
|
|
975
595
|
this.config = {
|
|
@@ -979,13 +599,11 @@ var bt = class {
|
|
|
979
599
|
}
|
|
980
600
|
getStats() {
|
|
981
601
|
return {
|
|
982
|
-
feedDataCount: this.feedDataCache.size,
|
|
983
602
|
feedContentCount: this.feedContentCache.size,
|
|
984
|
-
imageMetadataCount: this.imageMetadataCache.size
|
|
985
|
-
activeLocks: this.refreshLocks.size
|
|
603
|
+
imageMetadataCount: this.imageMetadataCache.size
|
|
986
604
|
};
|
|
987
605
|
}
|
|
988
|
-
},
|
|
606
|
+
}, Je = class {
|
|
989
607
|
cacheDir;
|
|
990
608
|
config;
|
|
991
609
|
constructor(e) {
|
|
@@ -995,49 +613,30 @@ var bt = class {
|
|
|
995
613
|
}
|
|
996
614
|
async ensureCacheDir() {
|
|
997
615
|
try {
|
|
998
|
-
await
|
|
616
|
+
await w.mkdir(this.cacheDir, { recursive: !0 });
|
|
999
617
|
} catch (e) {
|
|
1000
618
|
if (e.code !== "EEXIST") throw e;
|
|
1001
619
|
}
|
|
1002
620
|
}
|
|
1003
|
-
getFeedDataPath(e) {
|
|
1004
|
-
return C(this.cacheDir, `${e}.json`);
|
|
1005
|
-
}
|
|
1006
621
|
getFeedContentPath(e, t, n) {
|
|
1007
|
-
let r =
|
|
1008
|
-
return
|
|
622
|
+
let r = K(e, t, n).replace(/:/g, "-");
|
|
623
|
+
return T(this.cacheDir, `${r}.json`);
|
|
1009
624
|
}
|
|
1010
625
|
getImageMetadataPath(e) {
|
|
1011
|
-
|
|
626
|
+
let t = T(this.cacheDir, "image-metadata");
|
|
627
|
+
return T(t, `${e}.json`);
|
|
1012
628
|
}
|
|
1013
629
|
async ensureImageMetadataDir() {
|
|
1014
630
|
try {
|
|
1015
|
-
let e =
|
|
1016
|
-
await
|
|
631
|
+
let e = T(this.cacheDir, "image-metadata");
|
|
632
|
+
await w.mkdir(e, { recursive: !0 });
|
|
1017
633
|
} catch (e) {
|
|
1018
634
|
if (e.code !== "EEXIST") throw e;
|
|
1019
635
|
}
|
|
1020
636
|
}
|
|
1021
|
-
async getFeedData(e) {
|
|
1022
|
-
try {
|
|
1023
|
-
let t = this.getFeedDataPath(e), n = await S.readFile(t, "utf-8"), r = JSON.parse(n);
|
|
1024
|
-
return Math.floor(Date.now() / 1e3) - r.lastUpdated > this.config.ttl ? (await this.clearFeedData(e), null) : r;
|
|
1025
|
-
} catch (t) {
|
|
1026
|
-
return t.code === "ENOENT" || console.error(`Error reading feed data cache for ${e}:`, t), null;
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
async setFeedData(e, t) {
|
|
1030
|
-
try {
|
|
1031
|
-
await this.ensureCacheDir();
|
|
1032
|
-
let n = this.getFeedDataPath(e);
|
|
1033
|
-
await S.writeFile(n, JSON.stringify(t, null, 2), "utf-8");
|
|
1034
|
-
} catch (t) {
|
|
1035
|
-
console.error(`Error writing feed data cache for ${e}:`, t);
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
637
|
async getFeedContent(e, t, n) {
|
|
1039
638
|
try {
|
|
1040
|
-
let r = this.getFeedContentPath(e, t, n), i = await
|
|
639
|
+
let r = this.getFeedContentPath(e, t, n), i = await w.readFile(r, "utf-8"), a = JSON.parse(i);
|
|
1041
640
|
return Math.floor(Date.now() / 1e3) > a.expiresAt ? (await this.clearFeedContent(e, t, n), null) : a;
|
|
1042
641
|
} catch (n) {
|
|
1043
642
|
return n.code === "ENOENT" || console.error(`Error reading feed content cache for ${e}:${t}:`, n), null;
|
|
@@ -1047,38 +646,30 @@ var bt = class {
|
|
|
1047
646
|
try {
|
|
1048
647
|
await this.ensureCacheDir();
|
|
1049
648
|
let i = this.getFeedContentPath(e, t, r);
|
|
1050
|
-
await
|
|
649
|
+
await w.writeFile(i, JSON.stringify(n, null, 2), "utf-8");
|
|
1051
650
|
} catch (n) {
|
|
1052
651
|
console.error(`Error writing feed content cache for ${e}:${t}:`, n);
|
|
1053
652
|
}
|
|
1054
653
|
}
|
|
1055
|
-
async clearFeedData(e) {
|
|
1056
|
-
try {
|
|
1057
|
-
let t = this.getFeedDataPath(e);
|
|
1058
|
-
await S.unlink(t);
|
|
1059
|
-
} catch (t) {
|
|
1060
|
-
t.code !== "ENOENT" && console.error(`Error clearing feed data cache for ${e}:`, t);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
654
|
async clearFeedContent(e, t, n) {
|
|
1064
655
|
try {
|
|
1065
656
|
let r = this.getFeedContentPath(e, t, n);
|
|
1066
|
-
await
|
|
657
|
+
await w.unlink(r);
|
|
1067
658
|
} catch (n) {
|
|
1068
659
|
n.code !== "ENOENT" && console.error(`Error clearing feed content cache for ${e}:${t}:`, n);
|
|
1069
660
|
}
|
|
1070
661
|
}
|
|
1071
662
|
async clearAllContentCache(e) {
|
|
1072
663
|
try {
|
|
1073
|
-
let t = await
|
|
1074
|
-
for (let r of t) r.startsWith(n) && r.endsWith(".json") && r !== `${e}.json` && await
|
|
664
|
+
let t = await w.readdir(this.cacheDir), n = `${e}-`;
|
|
665
|
+
for (let r of t) r.startsWith(n) && r.endsWith(".json") && r !== `${e}.json` && await w.unlink(T(this.cacheDir, r));
|
|
1075
666
|
} catch (t) {
|
|
1076
667
|
console.error(`Error clearing all content cache for ${e}:`, t);
|
|
1077
668
|
}
|
|
1078
669
|
}
|
|
1079
670
|
async getImageMetadata(e) {
|
|
1080
671
|
try {
|
|
1081
|
-
let t = this.getImageMetadataPath(e), n = await
|
|
672
|
+
let t = this.getImageMetadataPath(e), n = await w.readFile(t, "utf-8"), r = JSON.parse(n);
|
|
1082
673
|
return Math.floor(Date.now() / 1e3) > r.expiresAt ? (await this.clearImageMetadata(e), null) : r.metadata;
|
|
1083
674
|
} catch (t) {
|
|
1084
675
|
return t.code === "ENOENT" || console.error(`Error reading image metadata cache for ${e}:`, t), null;
|
|
@@ -1092,7 +683,7 @@ var bt = class {
|
|
|
1092
683
|
cachedAt: r,
|
|
1093
684
|
expiresAt: r + (this.config.imageMetadata?.ttl || 604800)
|
|
1094
685
|
};
|
|
1095
|
-
await
|
|
686
|
+
await w.writeFile(n, JSON.stringify(i, null, 2), "utf-8");
|
|
1096
687
|
} catch (t) {
|
|
1097
688
|
console.error(`Error writing image metadata cache for ${e}:`, t);
|
|
1098
689
|
}
|
|
@@ -1100,25 +691,25 @@ var bt = class {
|
|
|
1100
691
|
async clearImageMetadata(e) {
|
|
1101
692
|
try {
|
|
1102
693
|
let t = this.getImageMetadataPath(e);
|
|
1103
|
-
await
|
|
694
|
+
await w.unlink(t);
|
|
1104
695
|
} catch (t) {
|
|
1105
696
|
t.code !== "ENOENT" && console.error(`Error clearing image metadata cache for ${e}:`, t);
|
|
1106
697
|
}
|
|
1107
698
|
}
|
|
1108
699
|
async clearAll() {
|
|
1109
700
|
try {
|
|
1110
|
-
let e = await
|
|
1111
|
-
for (let t of e) t.endsWith(".json") && await
|
|
1112
|
-
let t =
|
|
701
|
+
let e = await w.readdir(this.cacheDir);
|
|
702
|
+
for (let t of e) t.endsWith(".json") && t.includes("-") && await w.unlink(T(this.cacheDir, t));
|
|
703
|
+
let t = T(this.cacheDir, "image-metadata");
|
|
1113
704
|
try {
|
|
1114
|
-
let e = await
|
|
1115
|
-
for (let n of e) n.endsWith(".json") && await
|
|
705
|
+
let e = await w.readdir(t);
|
|
706
|
+
for (let n of e) n.endsWith(".json") && await w.unlink(T(t, n));
|
|
1116
707
|
} catch {}
|
|
1117
708
|
} catch (e) {
|
|
1118
709
|
console.error("Error clearing all caches:", e);
|
|
1119
710
|
}
|
|
1120
711
|
}
|
|
1121
|
-
},
|
|
712
|
+
}, Ye = class {
|
|
1122
713
|
memoryCache;
|
|
1123
714
|
fileCache;
|
|
1124
715
|
config;
|
|
@@ -1129,25 +720,7 @@ var bt = class {
|
|
|
1129
720
|
errors: 0
|
|
1130
721
|
};
|
|
1131
722
|
constructor(e) {
|
|
1132
|
-
this.config = e, this.memoryCache = new
|
|
1133
|
-
}
|
|
1134
|
-
async getFeedData(e) {
|
|
1135
|
-
if (!this.config.enabled) return null;
|
|
1136
|
-
try {
|
|
1137
|
-
let t = this.memoryCache.getFeedData(e);
|
|
1138
|
-
return t ? (this.stats.hits++, t) : (t = await this.fileCache.getFeedData(e), t ? (this.memoryCache.setFeedData(e, t.items), this.stats.hits++, t) : (this.stats.misses++, null));
|
|
1139
|
-
} catch (t) {
|
|
1140
|
-
return console.error(`Error getting feed data cache for ${e}:`, t), this.stats.errors++, null;
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
async setFeedData(e, t) {
|
|
1144
|
-
if (this.config.enabled) try {
|
|
1145
|
-
this.memoryCache.setFeedData(e, t);
|
|
1146
|
-
let n = this.memoryCache.getFeedData(e);
|
|
1147
|
-
n && await this.fileCache.setFeedData(e, n);
|
|
1148
|
-
} catch (t) {
|
|
1149
|
-
console.error(`Error setting feed data cache for ${e}:`, t), this.stats.errors++;
|
|
1150
|
-
}
|
|
723
|
+
this.config = e, this.memoryCache = new qe(e), this.fileCache = new Je(e);
|
|
1151
724
|
}
|
|
1152
725
|
async getFeedContent(e, t, n) {
|
|
1153
726
|
if (!this.config.enabled) return null;
|
|
@@ -1168,37 +741,12 @@ var bt = class {
|
|
|
1168
741
|
console.error(`Error setting feed content cache for ${e}:${t}:`, n), this.stats.errors++;
|
|
1169
742
|
}
|
|
1170
743
|
}
|
|
1171
|
-
async
|
|
1172
|
-
this.memoryCache.
|
|
744
|
+
async clearContent(e) {
|
|
745
|
+
this.memoryCache.clearContentCache(e), await this.fileCache.clearAllContentCache(e);
|
|
1173
746
|
}
|
|
1174
747
|
async clearAll() {
|
|
1175
748
|
this.memoryCache.clearAll(), await this.fileCache.clearAll();
|
|
1176
749
|
}
|
|
1177
|
-
async withRefreshLock(e, t) {
|
|
1178
|
-
return this.memoryCache.withRefreshLock(e, t);
|
|
1179
|
-
}
|
|
1180
|
-
mergeItems(e, t) {
|
|
1181
|
-
let n = /* @__PURE__ */ new Map();
|
|
1182
|
-
for (let t of e) {
|
|
1183
|
-
let e = t.id || t.seedUid || t.SeedUid || "";
|
|
1184
|
-
e && n.set(e, t);
|
|
1185
|
-
}
|
|
1186
|
-
for (let e of t) {
|
|
1187
|
-
let t = e.id || e.seedUid || e.SeedUid || "";
|
|
1188
|
-
t ? n.set(t, e) : n.set(`temp-${Date.now()}-${Math.random()}`, e);
|
|
1189
|
-
}
|
|
1190
|
-
let r = Array.from(n.values());
|
|
1191
|
-
return r.sort((e, t) => {
|
|
1192
|
-
let n = e.timeCreated || 0;
|
|
1193
|
-
return (t.timeCreated || 0) - n;
|
|
1194
|
-
}), r;
|
|
1195
|
-
}
|
|
1196
|
-
filterNewItems(e, t) {
|
|
1197
|
-
return e.filter((e) => {
|
|
1198
|
-
let n = e.timeCreated;
|
|
1199
|
-
return n && n > t;
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
750
|
updateConfig(e) {
|
|
1203
751
|
this.config = {
|
|
1204
752
|
...this.config,
|
|
@@ -1221,7 +769,7 @@ var bt = class {
|
|
|
1221
769
|
}
|
|
1222
770
|
}
|
|
1223
771
|
async setImageMetadata(e, t) {
|
|
1224
|
-
if (
|
|
772
|
+
if (this.config.enabled && this.config.imageMetadata?.enabled) try {
|
|
1225
773
|
this.memoryCache.setImageMetadata(e, t), await this.fileCache.setImageMetadata(e, t);
|
|
1226
774
|
} catch (t) {
|
|
1227
775
|
console.error(`Error setting image metadata cache for ${e}:`, t), this.stats.errors++;
|
|
@@ -1238,17 +786,17 @@ var bt = class {
|
|
|
1238
786
|
};
|
|
1239
787
|
//#endregion
|
|
1240
788
|
//#region src/cache/config.ts
|
|
1241
|
-
function
|
|
1242
|
-
let t = parseInt(process.env.CACHE_TTL || "3600", 10), n = process.env.CACHE_DIR || "./cache", r = process.env.CACHE_ENABLED === "false" || process.env.CACHE_ENABLED === "0" || process.env.CACHE_ENABLED === "no" || process.env.CACHE_ENABLED === "off", i = process.env.CACHE_ENABLED === "true" || process.env.CACHE_ENABLED === "1" || process.env.CACHE_ENABLED === "yes",
|
|
1243
|
-
s = r ? !1 : i ? !0 : !
|
|
789
|
+
function q() {
|
|
790
|
+
let t = parseInt(process.env.CACHE_TTL || "3600", 10), n = process.env.CACHE_DIR || "./cache", r = process.env.CACHE_ENABLED === "false" || process.env.CACHE_ENABLED === "0" || process.env.CACHE_ENABLED === "no" || process.env.CACHE_ENABLED === "off", i = process.env.CACHE_ENABLED === "true" || process.env.CACHE_ENABLED === "1" || process.env.CACHE_ENABLED === "yes", a = process.env.NODE_ENV === "development", s;
|
|
791
|
+
s = r ? !1 : i ? !0 : !a;
|
|
1244
792
|
let c = process.env.CACHE_BACKGROUND_REFRESH === "true", l = parseInt(process.env.CACHE_REFRESH_INTERVAL || "300", 10);
|
|
1245
|
-
s || console.log(`⚠️ Cache is DISABLED (${r ? "CACHE_ENABLED=false" :
|
|
793
|
+
s || console.log(`⚠️ Cache is DISABLED (${r ? "CACHE_ENABLED=false" : a ? "NODE_ENV=development" : "CACHE_ENABLED=false"})`);
|
|
1246
794
|
let u = {
|
|
1247
795
|
enabled: process.env.IMAGE_METADATA_ENABLED !== "false",
|
|
1248
796
|
ttl: parseInt(process.env.IMAGE_METADATA_TTL || "604800", 10),
|
|
1249
|
-
gateways: process.env.IMAGE_METADATA_GATEWAYS ? process.env.IMAGE_METADATA_GATEWAYS.split(",").map((e) => e.trim()) :
|
|
797
|
+
gateways: process.env.IMAGE_METADATA_GATEWAYS ? process.env.IMAGE_METADATA_GATEWAYS.split(",").map((e) => e.trim()) : o(p() ?? e.getHost()),
|
|
1250
798
|
timeout: parseInt(process.env.IMAGE_METADATA_TIMEOUT || "5000", 10)
|
|
1251
|
-
}, d = parseInt(process.env.CACHE_PAGE_TTL || "300", 10),
|
|
799
|
+
}, d = parseInt(process.env.CACHE_PAGE_TTL || "300", 10), f = parseInt(process.env.CACHE_ARCHIVE_TTL || "86400", 10);
|
|
1252
800
|
return {
|
|
1253
801
|
ttl: t,
|
|
1254
802
|
cacheDir: n,
|
|
@@ -1257,22 +805,22 @@ function Ct() {
|
|
|
1257
805
|
refreshInterval: l,
|
|
1258
806
|
imageMetadata: u,
|
|
1259
807
|
pageTtl: d,
|
|
1260
|
-
archiveTtl:
|
|
808
|
+
archiveTtl: f
|
|
1261
809
|
};
|
|
1262
810
|
}
|
|
1263
811
|
//#endregion
|
|
1264
812
|
//#region src/services/arweaveImageService.ts
|
|
1265
|
-
var
|
|
813
|
+
var Xe = class {
|
|
1266
814
|
config;
|
|
1267
815
|
constructor(e) {
|
|
1268
816
|
this.config = e;
|
|
1269
817
|
}
|
|
1270
818
|
async detectImage(t) {
|
|
1271
|
-
let n =
|
|
1272
|
-
(!n || n.activePath !== "hyper-sidecar") && await
|
|
1273
|
-
let r = n ?
|
|
819
|
+
let n = u();
|
|
820
|
+
(!n || n.activePath !== "hyper-sidecar" && n.activePath !== "http-proxy") && await a().catch(() => {});
|
|
821
|
+
let r = n ? l(n, s()) : this.config.gateways?.length ? this.config.gateways : o(e.getHost()), i = n?.arweaveProtocol ?? "https";
|
|
1274
822
|
for (let e of r) try {
|
|
1275
|
-
let n = `${
|
|
823
|
+
let n = `${i}://${e.trim().replace(/\/$/, "")}/${t}`, r = await this.getImageMetadata(n);
|
|
1276
824
|
if (r.isImage) return r;
|
|
1277
825
|
} catch (n) {
|
|
1278
826
|
console.warn(`Failed to fetch from gateway ${e} for transaction ${t}:`, n);
|
|
@@ -1280,7 +828,7 @@ var wt = class {
|
|
|
1280
828
|
}
|
|
1281
829
|
return {
|
|
1282
830
|
isImage: !1,
|
|
1283
|
-
url: `${
|
|
831
|
+
url: `${i}://${r[0]?.trim() || e.getHost()}/${t}`
|
|
1284
832
|
};
|
|
1285
833
|
}
|
|
1286
834
|
async getImageMetadata(e) {
|
|
@@ -1345,7 +893,7 @@ var wt = class {
|
|
|
1345
893
|
}
|
|
1346
894
|
extractImageDimensions(e, t) {
|
|
1347
895
|
try {
|
|
1348
|
-
let t =
|
|
896
|
+
let t = ce(e);
|
|
1349
897
|
if (t.width && t.height) return {
|
|
1350
898
|
width: t.width,
|
|
1351
899
|
height: t.height
|
|
@@ -1367,7 +915,7 @@ var wt = class {
|
|
|
1367
915
|
}
|
|
1368
916
|
}
|
|
1369
917
|
try {
|
|
1370
|
-
let e =
|
|
918
|
+
let e = ce(t);
|
|
1371
919
|
if (e.type) return e.type.toLowerCase();
|
|
1372
920
|
} catch {}
|
|
1373
921
|
}
|
|
@@ -1386,28 +934,28 @@ var wt = class {
|
|
|
1386
934
|
};
|
|
1387
935
|
//#endregion
|
|
1388
936
|
//#region src/pickFeedItemRichText.ts
|
|
1389
|
-
function
|
|
937
|
+
function J(e, t) {
|
|
1390
938
|
for (let n of t) {
|
|
1391
939
|
let t = e[n];
|
|
1392
940
|
if (typeof t == "string" && t.trim() !== "") return t;
|
|
1393
941
|
}
|
|
1394
942
|
return "";
|
|
1395
943
|
}
|
|
1396
|
-
var
|
|
944
|
+
var Ze = [
|
|
1397
945
|
"summary",
|
|
1398
946
|
"Summary",
|
|
1399
947
|
"description",
|
|
1400
948
|
"Description",
|
|
1401
949
|
"text",
|
|
1402
950
|
"Text"
|
|
1403
|
-
],
|
|
951
|
+
], Qe = [
|
|
1404
952
|
"html",
|
|
1405
953
|
"Html",
|
|
1406
954
|
"body",
|
|
1407
955
|
"Body",
|
|
1408
956
|
"content",
|
|
1409
957
|
"Content"
|
|
1410
|
-
],
|
|
958
|
+
], $e = [
|
|
1411
959
|
"summary",
|
|
1412
960
|
"Summary",
|
|
1413
961
|
"description",
|
|
@@ -1415,16 +963,16 @@ var Et = [
|
|
|
1415
963
|
"text",
|
|
1416
964
|
"Text"
|
|
1417
965
|
];
|
|
1418
|
-
function
|
|
1419
|
-
let n =
|
|
966
|
+
function et(e, t) {
|
|
967
|
+
let n = y(e.model) - y(t.model);
|
|
1420
968
|
if (n !== 0) return n;
|
|
1421
969
|
let r = e.key.localeCompare(t.key);
|
|
1422
970
|
return r === 0 ? e.index - t.index : r;
|
|
1423
971
|
}
|
|
1424
|
-
function
|
|
1425
|
-
let t =
|
|
972
|
+
function tt(e) {
|
|
973
|
+
let t = x(e), n = ee(e), r = null;
|
|
1426
974
|
if (t) for (let [n, i] of Object.entries(t)) {
|
|
1427
|
-
if (!
|
|
975
|
+
if (!S(i)) continue;
|
|
1428
976
|
let t = e[n];
|
|
1429
977
|
if (typeof t != "string" || t.trim() === "") continue;
|
|
1430
978
|
let a = {
|
|
@@ -1433,7 +981,7 @@ function At(e) {
|
|
|
1433
981
|
index: 0,
|
|
1434
982
|
value: t
|
|
1435
983
|
};
|
|
1436
|
-
(!r ||
|
|
984
|
+
(!r || et(a, r) < 0) && (r = a);
|
|
1437
985
|
}
|
|
1438
986
|
if (n) for (let [t, i] of Object.entries(n)) {
|
|
1439
987
|
let n = e[t];
|
|
@@ -1441,7 +989,7 @@ function At(e) {
|
|
|
1441
989
|
let a = Math.min(i.length, n.length);
|
|
1442
990
|
for (let e = 0; e < a; e++) {
|
|
1443
991
|
let a = i[e];
|
|
1444
|
-
if (!
|
|
992
|
+
if (!S(a)) continue;
|
|
1445
993
|
let o = n[e];
|
|
1446
994
|
if (typeof o != "string" || o.trim() === "") continue;
|
|
1447
995
|
let s = {
|
|
@@ -1450,102 +998,83 @@ function At(e) {
|
|
|
1450
998
|
index: e,
|
|
1451
999
|
value: o
|
|
1452
1000
|
};
|
|
1453
|
-
(!r ||
|
|
1001
|
+
(!r || et(s, r) < 0) && (r = s);
|
|
1454
1002
|
}
|
|
1455
1003
|
}
|
|
1456
1004
|
return r?.value ?? "";
|
|
1457
1005
|
}
|
|
1458
|
-
function
|
|
1459
|
-
return
|
|
1006
|
+
function nt(e) {
|
|
1007
|
+
return J(e, Ze);
|
|
1460
1008
|
}
|
|
1461
|
-
function
|
|
1462
|
-
let t =
|
|
1009
|
+
function rt(e) {
|
|
1010
|
+
let t = tt(e);
|
|
1463
1011
|
if (t !== "") return t;
|
|
1464
|
-
let n =
|
|
1465
|
-
return n === "" ?
|
|
1012
|
+
let n = J(e, Qe);
|
|
1013
|
+
return n === "" ? J(e, $e) : n;
|
|
1466
1014
|
}
|
|
1467
|
-
function
|
|
1468
|
-
return typeof e == "string"
|
|
1015
|
+
function Y(e) {
|
|
1016
|
+
return typeof e == "string" && e.includes("data:image/") && e.includes(";base64,");
|
|
1469
1017
|
}
|
|
1470
|
-
function
|
|
1471
|
-
let t =
|
|
1018
|
+
function it(e) {
|
|
1019
|
+
let t = x(e);
|
|
1472
1020
|
if (t) {
|
|
1473
|
-
for (let [n, r] of Object.entries(t)) if (
|
|
1021
|
+
for (let [n, r] of Object.entries(t)) if (S(r) && Y(e[n])) return !0;
|
|
1474
1022
|
}
|
|
1475
|
-
let n =
|
|
1023
|
+
let n = ee(e);
|
|
1476
1024
|
if (n) for (let [t, r] of Object.entries(n)) {
|
|
1477
1025
|
let n = e[t];
|
|
1478
1026
|
if (!Array.isArray(n)) continue;
|
|
1479
1027
|
let i = Math.min(r.length, n.length);
|
|
1480
|
-
for (let e = 0; e < i; e++) if (
|
|
1028
|
+
for (let e = 0; e < i; e++) if (S(r[e]) && Y(n[e])) return !0;
|
|
1481
1029
|
}
|
|
1482
1030
|
return !1;
|
|
1483
1031
|
}
|
|
1484
|
-
function
|
|
1485
|
-
if (
|
|
1486
|
-
for (let t of
|
|
1487
|
-
for (let t of
|
|
1032
|
+
function X(e) {
|
|
1033
|
+
if (it(e)) return !0;
|
|
1034
|
+
for (let t of Qe) if (Y(e[t])) return !0;
|
|
1035
|
+
for (let t of Ze) if (Y(e[t])) return !0;
|
|
1488
1036
|
return !1;
|
|
1489
1037
|
}
|
|
1490
|
-
function
|
|
1491
|
-
return t === "include_items" ? [...e] : e.filter((e) => !
|
|
1038
|
+
function at(e, t = "omit_items") {
|
|
1039
|
+
return t === "include_items" ? [...e] : e.filter((e) => !X(e));
|
|
1492
1040
|
}
|
|
1493
1041
|
//#endregion
|
|
1494
1042
|
//#region src/index.ts
|
|
1495
|
-
function
|
|
1496
|
-
|
|
1497
|
-
if (typeof e == "string") {
|
|
1498
|
-
if (e.startsWith("http://") || e.startsWith("https://")) return e;
|
|
1499
|
-
try {
|
|
1500
|
-
return E(e);
|
|
1501
|
-
} catch {
|
|
1502
|
-
return;
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
if (typeof e == "object" && !Array.isArray(e)) {
|
|
1506
|
-
let t = e, n = t.arweaveUrl;
|
|
1507
|
-
if (typeof n == "string" && n.trim()) return n.trim();
|
|
1508
|
-
let r = t.storageTransactionId ?? t.storage_transaction_id;
|
|
1509
|
-
if (r && typeof r == "string" && r.trim()) try {
|
|
1510
|
-
return E(r.trim());
|
|
1511
|
-
} catch {
|
|
1512
|
-
return;
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1043
|
+
function ot(e) {
|
|
1044
|
+
return g(e)?.mediaUrl;
|
|
1516
1045
|
}
|
|
1517
|
-
function
|
|
1046
|
+
function Z(e) {
|
|
1518
1047
|
if (typeof e == "number" && Number.isFinite(e) && e > 0) return e;
|
|
1519
1048
|
if (typeof e == "string") {
|
|
1520
1049
|
let t = Number(e);
|
|
1521
1050
|
if (Number.isFinite(t) && t > 0) return t;
|
|
1522
1051
|
}
|
|
1523
1052
|
}
|
|
1524
|
-
function
|
|
1053
|
+
function st(e) {
|
|
1525
1054
|
if (Array.isArray(e)) {
|
|
1526
1055
|
for (let t of e) {
|
|
1527
|
-
let e =
|
|
1056
|
+
let e = st(t);
|
|
1528
1057
|
if (e) return e;
|
|
1529
1058
|
}
|
|
1530
1059
|
return;
|
|
1531
1060
|
}
|
|
1532
|
-
let t =
|
|
1061
|
+
let t = ot(e);
|
|
1533
1062
|
if (t) {
|
|
1534
1063
|
if (e && typeof e == "object" && !Array.isArray(e)) {
|
|
1535
1064
|
let n = e;
|
|
1536
1065
|
return {
|
|
1537
1066
|
url: t,
|
|
1538
1067
|
mimeType: typeof n.mimeType == "string" && n.mimeType || typeof n.type == "string" && n.type || typeof n.contentType == "string" && n.contentType || void 0,
|
|
1539
|
-
width:
|
|
1540
|
-
height:
|
|
1541
|
-
size:
|
|
1068
|
+
width: Z(n.width),
|
|
1069
|
+
height: Z(n.height),
|
|
1070
|
+
size: Z(n.size ?? n.fileSize),
|
|
1542
1071
|
format: typeof n.format == "string" ? n.format : void 0
|
|
1543
1072
|
};
|
|
1544
1073
|
}
|
|
1545
1074
|
return { url: t };
|
|
1546
1075
|
}
|
|
1547
1076
|
}
|
|
1548
|
-
function
|
|
1077
|
+
function ct(e) {
|
|
1549
1078
|
if (e._hasImage && e._imageMetadata && typeof e._imageMetadata == "object") {
|
|
1550
1079
|
let t = e._imageMetadata;
|
|
1551
1080
|
if (t.url) return {
|
|
@@ -1569,11 +1098,11 @@ function zt(e) {
|
|
|
1569
1098
|
"thumbnailImage"
|
|
1570
1099
|
]) {
|
|
1571
1100
|
if (!(t in e)) continue;
|
|
1572
|
-
let n =
|
|
1101
|
+
let n = st(e[t]);
|
|
1573
1102
|
if (n) return n;
|
|
1574
1103
|
}
|
|
1575
1104
|
}
|
|
1576
|
-
function
|
|
1105
|
+
function lt(e, t, n, r, i, a) {
|
|
1577
1106
|
let o = n.mimeType || "image/jpeg";
|
|
1578
1107
|
e.enclosures = [{
|
|
1579
1108
|
url: n.url,
|
|
@@ -1609,14 +1138,14 @@ function Bt(e, t, n, r, i, a) {
|
|
|
1609
1138
|
"media:description": l
|
|
1610
1139
|
}], n.url && typeof t.content == "string" && t.content.trim() !== "" && !t.content.includes(n.url) && (e["content:encoded"] = `${`<img src="${n.url}" alt="${t.title || ""}"${n.width ? ` width="${n.width}"` : ""}${n.height ? ` height="${n.height}"` : ""} />`}\n${t.content}`);
|
|
1611
1140
|
}
|
|
1612
|
-
var
|
|
1613
|
-
function
|
|
1614
|
-
return
|
|
1141
|
+
var Q = null;
|
|
1142
|
+
function ut() {
|
|
1143
|
+
return Q ||= new Ye(q()), Q;
|
|
1615
1144
|
}
|
|
1616
|
-
function
|
|
1617
|
-
|
|
1145
|
+
function dt() {
|
|
1146
|
+
Q = null;
|
|
1618
1147
|
}
|
|
1619
|
-
async function
|
|
1148
|
+
async function ft(e, t, n) {
|
|
1620
1149
|
let r = e.filter((e) => e.storageTransactionId || e.storage_transaction_id);
|
|
1621
1150
|
if (r.length === 0) return e;
|
|
1622
1151
|
console.log(`Enriching ${r.length} items with image metadata`);
|
|
@@ -1638,10 +1167,10 @@ async function Wt(e, t, n) {
|
|
|
1638
1167
|
return o.get(t) || e;
|
|
1639
1168
|
});
|
|
1640
1169
|
}
|
|
1641
|
-
function
|
|
1170
|
+
function pt(e, t) {
|
|
1642
1171
|
let { schemaName: n, siteUrl: r, itemUrlBase: i, itemUrlPath: a, richTextDataUriImages: o = "omit_items" } = t;
|
|
1643
|
-
return
|
|
1644
|
-
let t = e.id || e.seedUid || e.SeedUid || e.storageTransactionId || e.storage_transaction_id, o = i == null ? `${r}/${
|
|
1172
|
+
return at(e, o).map((e) => {
|
|
1173
|
+
let t = e.id || e.seedUid || e.SeedUid || e.storageTransactionId || e.storage_transaction_id, o = i == null ? `${r}/${C(n)}/${t}` : `${i.replace(/\/$/, "")}/${(a ?? "attestation/view").replace(/^\//, "")}/${t}`, s = e.link || e.Link || e.import_url || e.importUrl || o, c;
|
|
1645
1174
|
if (e.pubDate || e.PubDate) {
|
|
1646
1175
|
let t = e.pubDate || e.PubDate;
|
|
1647
1176
|
c = new Date(t);
|
|
@@ -1650,7 +1179,7 @@ function Gt(e, t) {
|
|
|
1650
1179
|
let t = e.publishedAt || e.createdAt || e.updatedAt;
|
|
1651
1180
|
c = t && typeof t == "object" && t.constructor === Date ? t : new Date(t);
|
|
1652
1181
|
} else c = /* @__PURE__ */ new Date();
|
|
1653
|
-
let l =
|
|
1182
|
+
let l = nt(e), u = rt(e), d = {
|
|
1654
1183
|
...e,
|
|
1655
1184
|
id: t,
|
|
1656
1185
|
title: e.title || e.Title || "Untitled",
|
|
@@ -1670,8 +1199,8 @@ function Gt(e, t) {
|
|
|
1670
1199
|
}), d;
|
|
1671
1200
|
});
|
|
1672
1201
|
}
|
|
1673
|
-
var
|
|
1674
|
-
let l =
|
|
1202
|
+
var $ = (e, t, n, r, i, a, o, s, c) => {
|
|
1203
|
+
let l = j(c), u = C(t), d = `${l.feedUrl}/${u}/${n}`, f = r ? `${d}?v=${r}` : d, p = `${l.title} - ${gt(u)}`, m = /* @__PURE__ */ new Date(), h = M(), g = [];
|
|
1675
1204
|
if (i) {
|
|
1676
1205
|
let e = i.baseUrl.replace(/\?.*$/, ""), t = e.includes("?") ? "&" : "?";
|
|
1677
1206
|
i.hasNext && g.push({
|
|
@@ -1689,7 +1218,7 @@ var Kt = (e, t, n, r, i, a, o, s, c) => {
|
|
|
1689
1218
|
rel: e.rel,
|
|
1690
1219
|
href: e.href
|
|
1691
1220
|
});
|
|
1692
|
-
let _ =
|
|
1221
|
+
let _ = pt(e, {
|
|
1693
1222
|
schemaName: t,
|
|
1694
1223
|
siteUrl: l.siteUrl,
|
|
1695
1224
|
itemUrlBase: h.itemUrlBase,
|
|
@@ -1745,10 +1274,10 @@ var Kt = (e, t, n, r, i, a, o, s, c) => {
|
|
|
1745
1274
|
return t;
|
|
1746
1275
|
})
|
|
1747
1276
|
};
|
|
1748
|
-
return Promise.resolve(
|
|
1277
|
+
return Promise.resolve(ie(t));
|
|
1749
1278
|
}
|
|
1750
1279
|
case "json": {
|
|
1751
|
-
let e = i?.hasNext ? `${i.baseUrl.replace(/\?.*$/, "")}?page=${i.page + 1}` : void 0, t =
|
|
1280
|
+
let e = i?.hasNext ? `${i.baseUrl.replace(/\?.*$/, "")}?page=${i.page + 1}` : void 0, t = {
|
|
1752
1281
|
title: p,
|
|
1753
1282
|
home_page_url: l.siteUrl,
|
|
1754
1283
|
feed_url: f,
|
|
@@ -1774,8 +1303,8 @@ var Kt = (e, t, n, r, i, a, o, s, c) => {
|
|
|
1774
1303
|
}
|
|
1775
1304
|
return t;
|
|
1776
1305
|
})
|
|
1777
|
-
});
|
|
1778
|
-
return Promise.resolve(typeof
|
|
1306
|
+
}, n = ae(t);
|
|
1307
|
+
return Promise.resolve(typeof n == "string" ? n : JSON.stringify(n));
|
|
1779
1308
|
}
|
|
1780
1309
|
default: {
|
|
1781
1310
|
let e = {
|
|
@@ -1802,26 +1331,26 @@ var Kt = (e, t, n, r, i, a, o, s, c) => {
|
|
|
1802
1331
|
value: e.id,
|
|
1803
1332
|
isPermaLink: typeof e.id == "string" && (e.id.startsWith("http://") || e.id.startsWith("https://"))
|
|
1804
1333
|
});
|
|
1805
|
-
let r =
|
|
1806
|
-
if (r &&
|
|
1334
|
+
let r = ct(e);
|
|
1335
|
+
if (r && lt(n, e, r, t, l.author, l.copyright), typeof e.content == "string" && e.content.trim() !== "" && n["content:encoded"] === void 0 && (n["content:encoded"] = e.content), n.dc = {}, (e.date || e.pubDate) && (n.dc.date = e.date || e.pubDate), e.timeCreated) {
|
|
1807
1336
|
let t = /* @__PURE__ */ new Date(e.timeCreated * 1e3);
|
|
1808
1337
|
n.dc.dates || (n.dc.dates = []), n.dc.dates.push(t);
|
|
1809
1338
|
}
|
|
1810
1339
|
return (e.seedUid || e.SeedUid) && (n.dc.identifier || (n.dc.identifier = []), n.dc.identifier.push(e.seedUid || e.SeedUid)), (e.storageTransactionId || e.storage_transaction_id) && (n.dc.identifier || (n.dc.identifier = []), n.dc.identifier.push(e.storageTransactionId || e.storage_transaction_id)), (e.import_url || e.importUrl) && (n.dc.source = e.import_url || e.importUrl), (e.seedUid || e.SeedUid) && (n.seedUid = e.seedUid || e.SeedUid), (e.storageTransactionId || e.storage_transaction_id) && (n.storageTransactionId = e.storageTransactionId || e.storage_transaction_id), e.timeCreated && (n.timeCreated = e.timeCreated), n;
|
|
1811
1340
|
})
|
|
1812
1341
|
};
|
|
1813
|
-
return Promise.resolve(
|
|
1342
|
+
return Promise.resolve(Ve(e));
|
|
1814
1343
|
}
|
|
1815
1344
|
}
|
|
1816
1345
|
};
|
|
1817
|
-
function
|
|
1346
|
+
function mt(e) {
|
|
1818
1347
|
switch (e) {
|
|
1819
1348
|
case "atom": return "application/atom+xml; charset=utf-8";
|
|
1820
1349
|
case "json": return "application/feed+json; charset=utf-8";
|
|
1821
1350
|
default: return "application/rss+xml; charset=utf-8";
|
|
1822
1351
|
}
|
|
1823
1352
|
}
|
|
1824
|
-
function
|
|
1353
|
+
function ht(e) {
|
|
1825
1354
|
let t = e.toLowerCase();
|
|
1826
1355
|
return [
|
|
1827
1356
|
"rss",
|
|
@@ -1829,22 +1358,22 @@ function Jt(e) {
|
|
|
1829
1358
|
"json"
|
|
1830
1359
|
].includes(t) ? t : null;
|
|
1831
1360
|
}
|
|
1832
|
-
function
|
|
1361
|
+
function gt(e) {
|
|
1833
1362
|
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
1834
1363
|
}
|
|
1835
|
-
async function
|
|
1836
|
-
let o =
|
|
1364
|
+
async function _t(e, t, n, r, i, a) {
|
|
1365
|
+
let o = ht(t);
|
|
1837
1366
|
if (!o) return new Response(JSON.stringify({ error: `Invalid feed format: ${t}` }), {
|
|
1838
1367
|
status: 400,
|
|
1839
1368
|
headers: { "Content-Type": "application/json" }
|
|
1840
1369
|
});
|
|
1841
|
-
let s =
|
|
1370
|
+
let s = C.singular(e.toLowerCase()), c = C(s), l = j(a), u = M(), d = Math.max(1, i ?? 1), f = u.pageSize, p = (d - 1) * f, m = d > 1 ? { page: d } : void 0;
|
|
1842
1371
|
console.log(`Schema name: ${s}`), console.log(`Collection name: ${c}`);
|
|
1843
|
-
let h =
|
|
1372
|
+
let h = ut(), g = q();
|
|
1844
1373
|
try {
|
|
1845
1374
|
if (g.enabled) {
|
|
1846
1375
|
let e = await h.getFeedContent(s, o, m);
|
|
1847
|
-
if (e) return n &&
|
|
1376
|
+
if (e) return n && Ke(n, e.etag) ? (console.log(`Cache hit with ETag match for ${s}:${o} - returning 304`), new Response(null, {
|
|
1848
1377
|
status: 304,
|
|
1849
1378
|
headers: {
|
|
1850
1379
|
ETag: e.etag,
|
|
@@ -1865,37 +1394,12 @@ async function Xt(e, t, n, r, i, a) {
|
|
|
1865
1394
|
}));
|
|
1866
1395
|
}
|
|
1867
1396
|
console.log(`Cache miss for ${s}:${o} - fetching items`);
|
|
1868
|
-
let e =
|
|
1869
|
-
let e = await
|
|
1870
|
-
if (e) {
|
|
1871
|
-
console.log(`Incremental fetch: last processed timestamp: ${e.lastProcessedTimestamp}`);
|
|
1872
|
-
let n = await G(s, {
|
|
1873
|
-
limit: f,
|
|
1874
|
-
skip: 0
|
|
1875
|
-
}), r = h.filterNewItems(n, e.lastProcessedTimestamp);
|
|
1876
|
-
r.length > 0 ? (console.log(`Found ${r.length} new items, merging with ${e.items.length} cached items`), t = h.mergeItems(e.items, r).slice(0, f)) : t = e.items;
|
|
1877
|
-
} else {
|
|
1878
|
-
console.log("Cold cache - fetching page 1");
|
|
1879
|
-
let e = await ce();
|
|
1880
|
-
e && console.log(`Client initialized: ${e.isInitialized()}`), t = await G(s, {
|
|
1881
|
-
limit: f,
|
|
1882
|
-
skip: 0
|
|
1883
|
-
}), console.log(`Found ${t.length} feed items for schema ${s}`);
|
|
1884
|
-
}
|
|
1885
|
-
if (g.imageMetadata?.enabled) {
|
|
1886
|
-
let e = new wt({
|
|
1887
|
-
gateways: g.imageMetadata.gateways,
|
|
1888
|
-
timeout: g.imageMetadata.timeout
|
|
1889
|
-
}), n = await Wt(t, e, h);
|
|
1890
|
-
return await h.setFeedData(s, t), n;
|
|
1891
|
-
}
|
|
1892
|
-
return await h.setFeedData(s, t), t;
|
|
1893
|
-
}) : await (async () => {
|
|
1894
|
-
let e = await G(s, {
|
|
1397
|
+
let e = await (async () => {
|
|
1398
|
+
let e = await ye(s, {
|
|
1895
1399
|
limit: f,
|
|
1896
1400
|
skip: p
|
|
1897
1401
|
});
|
|
1898
|
-
return g.imageMetadata?.enabled ?
|
|
1402
|
+
return console.log(`Found ${e.length} feed items for schema ${s}`), g.imageMetadata?.enabled ? ft(e, new Xe({
|
|
1899
1403
|
gateways: g.imageMetadata.gateways,
|
|
1900
1404
|
timeout: g.imageMetadata.timeout
|
|
1901
1405
|
}), h) : e;
|
|
@@ -1907,12 +1411,12 @@ async function Xt(e, t, n, r, i, a) {
|
|
|
1907
1411
|
href: `${l.feedUrl}/${c}/archive/${t.getFullYear()}/${t.getMonth() + 1}/${o}`
|
|
1908
1412
|
});
|
|
1909
1413
|
}
|
|
1910
|
-
let _ = await
|
|
1414
|
+
let _ = await $(e, s, o, r, {
|
|
1911
1415
|
page: d,
|
|
1912
1416
|
pageSize: f,
|
|
1913
1417
|
hasNext: i,
|
|
1914
1418
|
baseUrl: t
|
|
1915
|
-
}, u.length ? u : void 0, !1, void 0, a), v =
|
|
1419
|
+
}, u.length ? u : void 0, !1, void 0, a), v = mt(o);
|
|
1916
1420
|
if (g.enabled) {
|
|
1917
1421
|
await h.setFeedContent(s, o, _, v, m);
|
|
1918
1422
|
let e = await h.getFeedContent(s, o, m), t = e?.etag || "", n = e?.lastModified || Math.floor(Date.now() / 1e3);
|
|
@@ -1963,7 +1467,7 @@ async function Xt(e, t, n, r, i, a) {
|
|
|
1963
1467
|
});
|
|
1964
1468
|
}
|
|
1965
1469
|
}
|
|
1966
|
-
async function
|
|
1470
|
+
async function vt(e, t, n, r, i, a, o) {
|
|
1967
1471
|
if (t < 1970 || t > 2100) return new Response(JSON.stringify({ error: `Invalid year: ${t}` }), {
|
|
1968
1472
|
status: 400,
|
|
1969
1473
|
headers: { "Content-Type": "application/json" }
|
|
@@ -1972,19 +1476,19 @@ async function Zt(e, t, n, r, i, a, o) {
|
|
|
1972
1476
|
status: 400,
|
|
1973
1477
|
headers: { "Content-Type": "application/json" }
|
|
1974
1478
|
});
|
|
1975
|
-
let s =
|
|
1479
|
+
let s = ht(r);
|
|
1976
1480
|
if (!s) return new Response(JSON.stringify({ error: `Invalid feed format: ${r}` }), {
|
|
1977
1481
|
status: 400,
|
|
1978
1482
|
headers: { "Content-Type": "application/json" }
|
|
1979
1483
|
});
|
|
1980
|
-
let c =
|
|
1484
|
+
let c = C.singular(e.toLowerCase()), l = C(c), u = j(o), d = { archive: {
|
|
1981
1485
|
year: t,
|
|
1982
1486
|
month: n
|
|
1983
|
-
} }, f =
|
|
1487
|
+
} }, f = ut(), p = q();
|
|
1984
1488
|
try {
|
|
1985
1489
|
if (p.enabled) {
|
|
1986
1490
|
let e = await f.getFeedContent(c, s, d);
|
|
1987
|
-
if (e) return i &&
|
|
1491
|
+
if (e) return i && Ke(i, e.etag) ? new Response(null, {
|
|
1988
1492
|
status: 304,
|
|
1989
1493
|
headers: {
|
|
1990
1494
|
ETag: e.etag,
|
|
@@ -2004,7 +1508,7 @@ async function Zt(e, t, n, r, i, a, o) {
|
|
|
2004
1508
|
}
|
|
2005
1509
|
});
|
|
2006
1510
|
}
|
|
2007
|
-
let e = await
|
|
1511
|
+
let e = await be(c, t, n), r = `${u.feedUrl}/${l}/${s}`, m = `${u.feedUrl}/${l}/archive`, h = [{
|
|
2008
1512
|
rel: "prev-archive",
|
|
2009
1513
|
href: `${m}/${n === 1 ? t - 1 : t}/${n === 1 ? 12 : n - 1}/${s}`
|
|
2010
1514
|
}, {
|
|
@@ -2015,7 +1519,7 @@ async function Zt(e, t, n, r, i, a, o) {
|
|
|
2015
1519
|
rel: "next-archive",
|
|
2016
1520
|
href: `${m}/${g}/${_}/${s}`
|
|
2017
1521
|
});
|
|
2018
|
-
let y = await
|
|
1522
|
+
let y = await $(e, c, s, a, void 0, h, !0, void 0, o), b = mt(s);
|
|
2019
1523
|
if (p.enabled) {
|
|
2020
1524
|
await f.setFeedContent(c, s, y, b, d);
|
|
2021
1525
|
let e = await f.getFeedContent(c, s, d), t = e?.etag || "", n = e?.lastModified || Math.floor(Date.now() / 1e3);
|
|
@@ -2052,6 +1556,6 @@ async function Zt(e, t, n, r, i, a, o) {
|
|
|
2052
1556
|
}
|
|
2053
1557
|
}
|
|
2054
1558
|
//#endregion
|
|
2055
|
-
export { t as DEFAULT_ARWEAVE_HOST,
|
|
1559
|
+
export { t as DEFAULT_ARWEAVE_HOST, O as DEFAULT_SITE_CONFIG, _ as FEED_RICH_BODY_STORAGE_SCHEMAS, r as SEED_RSS_IMAGE_RELATION_FIELD_KEYS, i as classifyMediaRef, $ as createFeed, v as enrichImageSeedCloneForFeed, X as feedItemRichTextContainsDataUriImage, at as filterItemsByRichTextDataUriImagePolicy, de as getClient, c as getFeedItemStringField, ye as getFeedItemsBySchemaName, be as getFeedItemsBySchemaNameForMonth, pe as getSiteConfig, vt as handleArchiveFeedRequest, _t as handleFeedRequest, D as initializeFeedPlatform, ue as initializeSeedClient, d as isEasAttestationExplorerUrl, S as isFeedRichBodyStorageSchema, M as loadFeedConfig, f as normalizeFeedItemFields, Ce as parseRssString, rt as pickFeedItemContent, nt as pickFeedItemDescription, dt as resetCacheManager, he as resetSiteConfig, m as resolveSeedRssImageRelationFromItem, h as resolveSeedRssImageRelationRef, j as resolveSiteConfig, me as setSiteConfig, fe as teardownSeedClient };
|
|
2056
1560
|
|
|
2057
1561
|
//# sourceMappingURL=index.js.map
|