aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519>2020-05-14 20:34:31 -0400
committercel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519>2020-05-15 18:34:01 -0400
commitd19e131248105a3639e7a03f41d023c38b77ec30 (patch)
treef3d3c681fbf3eb7ce72d5da323c9e6f92f169954
parent25a7ff7a983188489590c05b7621393b68e8b002 (diff)
downloadpatchfoo-d19e131248105a3639e7a03f41d023c38b77ec30.tar.gz
patchfoo-d19e131248105a3639e7a03f41d023c38b77ec30.zip
Prefer backlinks.read for /links
-rw-r--r--lib/serve.js29
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 46b78e7..749e075 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -1834,15 +1834,30 @@ Serve.prototype.type = function (path) {
Serve.prototype.links = function (path) {
var q = this.query
var dest = path.substr(1)
- var opts = {
- dest: dest,
- reverse: true,
- values: true,
- }
- if (q.rel) opts.rel = q.rel
+ var sbot = this.app.sbot
pull(
- this.app.sbot.links(opts),
+ q.rel || q.author || !sbot.backlinks ? (q.type ?
+ pull.error(new Error('Unable to satisfy query')) :
+ sbot.links({
+ source: q.author || undefined,
+ dest: dest,
+ reverse: true,
+ values: true,
+ rel: q.rel
+ })) : sbot.backlinks.read({
+ reverse: true,
+ query: [
+ {$filter: {
+ dest: dest,
+ value: q.type ? {
+ content: {
+ type: q.type
+ }
+ } : {}
+ }}
+ ]
+ }),
this.renderThread(),
this.wrapMessages(),
this.wrapLinks(dest),