@evanp/activitypub-bot 0.28.3 → 0.28.4
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/lib/activitypubclient.js +37 -1
- package/package.json +1 -1
package/lib/activitypubclient.js
CHANGED
|
@@ -105,7 +105,10 @@ export class ActivityPubClient {
|
|
|
105
105
|
}
|
|
106
106
|
const json = await res.json()
|
|
107
107
|
const obj = await as2.import(json)
|
|
108
|
-
|
|
108
|
+
const resolved = (URL.parse(url).hash)
|
|
109
|
+
? this.#resolveObject(obj, url)
|
|
110
|
+
: obj
|
|
111
|
+
return resolved
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
async post (url, obj, username) {
|
|
@@ -220,4 +223,37 @@ export class ActivityPubClient {
|
|
|
220
223
|
json.object.object = 'https://www.w3.org/ns/activitystreams#Public'
|
|
221
224
|
}
|
|
222
225
|
}
|
|
226
|
+
|
|
227
|
+
#resolveObject (obj, url, visited = new Set()) {
|
|
228
|
+
if (obj.id && obj.id === url) {
|
|
229
|
+
return obj
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (obj.id) {
|
|
233
|
+
if (visited.has(obj.id)) {
|
|
234
|
+
return null
|
|
235
|
+
}
|
|
236
|
+
visited.add(obj.id)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
for (const key of obj) {
|
|
240
|
+
if (key === '@type' || key === '@id') continue
|
|
241
|
+
|
|
242
|
+
const val = obj.get(key)
|
|
243
|
+
|
|
244
|
+
if (val == null || typeof val[Symbol.iterator] !== 'function') {
|
|
245
|
+
continue
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
for (const item of val) {
|
|
249
|
+
if (item instanceof as2.models.Base) {
|
|
250
|
+
const found = this.#resolveObject(item, url, visited)
|
|
251
|
+
if (found) {
|
|
252
|
+
return found
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return null
|
|
258
|
+
}
|
|
223
259
|
}
|