git ssb

0+

Daan Patchwork / ssb-viewer



forked from cel / ssb-viewer

Commit afabd2eacb34221e1b60ed77cce59a621e8c8022

Handle channels/hashtags in form

cel committed on 8/22/2018, 9:38:52 PM
Parent: e3821bb878a58ca1a08b75301065fee04d4108de

Files changed

index.jschanged
index.jsView
@@ -528,26 +528,35 @@
528528 fs.createReadStream(file).pipe(res)
529529 })
530530 }
531531
532+function asChannelLink(id) {
533+ var channel = refs.normalizeChannel(id)
534+ if (channel) return '#' + channel
535+}
536+
532537 function asLink(id) {
533538 if (!id || typeof id !== 'string') return null
534539 id = id.trim()
540+ if (id[0] === '#') return asChannelLink(id)
535541 if (refs.isLink(id)) return id
536542 try {
537543 id = decodeURIComponent(id)
538544 } catch(e) {
539545 return null
540546 }
547+ if (id[0] === '#') return asChannelLink(id)
541548 if (refs.isLink(id)) return id
542549 }
543550
544551 function serveHome(req, res, query, conf) {
545552 var q = query ? qs.parse(query) : {}
546553 var id = asLink(q.id)
547554 if (id) {
548555 res.writeHead(303, {
549- Location: '/' + (refs.isMsgId(id) ? encodeURIComponent(id) : id)
556+ Location: '/' + (
557+ id[0] === '#' ? 'channel/' + id.substr(1) :
558+ refs.isMsgId(id) ? encodeURIComponent(id) : id)
550559 })
551560 return res.end()
552561 }
553562 res.writeHead(200, {

Built with git-ssb-web