Merge pull request #225 from christianbundy/search-refs

Redirect search to SSB references
This commit is contained in:
Jonathan Dahan 2020-02-17 16:56:10 -05:00 committed by GitHub
commit b1b58d8a64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 10 deletions

View File

@ -34,6 +34,7 @@ const ssbMentions = require("ssb-mentions");
const ssbRef = require("ssb-ref");
const isSvg = require("is-svg");
const { themeNames } = require("@fraction/base16-css");
const { isFeed, isMsg, isBlob } = require("ssb-ref");
const ssb = require("./ssb");
@ -170,18 +171,26 @@ router
ctx.body = await author(feed);
})
.get("/search/", async ctx => {
const { query } = ctx.query;
const search = async ({ query }) => {
if (typeof query === "string") {
// https://github.com/ssbc/ssb-search/issues/7
query = query.toLowerCase();
}
let { query } = ctx.query;
const messages = await post.search({ query });
if (isMsg(query)) {
return ctx.redirect(`/thread/${encodeURIComponent(query)}`);
}
if (isFeed(query)) {
return ctx.redirect(`/author/${encodeURIComponent(query)}`);
}
if (isBlob(query)) {
return ctx.redirect(`/blob/${encodeURIComponent(query)}`);
}
return searchView({ messages, query });
};
ctx.body = await search({ query });
if (typeof query === "string") {
// https://github.com/ssbc/ssb-search/issues/7
query = query.toLowerCase();
}
const messages = await post.search({ query });
ctx.body = await searchView({ messages, query });
})
.get("/inbox", async ctx => {
const inbox = async () => {