Commit afabd2eacb34221e1b60ed77cce59a621e8c8022
Handle channels/hashtags in form
cel committed on 8/22/2018, 9:38:52 PMParent: e3821bb878a58ca1a08b75301065fee04d4108de
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -528,26 +528,35 @@ | ||
528 | 528 | fs.createReadStream(file).pipe(res) |
529 | 529 | }) |
530 | 530 | } |
531 | 531 | |
532 | +function asChannelLink(id) { | |
533 | + var channel = refs.normalizeChannel(id) | |
534 | + if (channel) return '#' + channel | |
535 | +} | |
536 | + | |
532 | 537 | function asLink(id) { |
533 | 538 | if (!id || typeof id !== 'string') return null |
534 | 539 | id = id.trim() |
540 | + if (id[0] === '#') return asChannelLink(id) | |
535 | 541 | if (refs.isLink(id)) return id |
536 | 542 | try { |
537 | 543 | id = decodeURIComponent(id) |
538 | 544 | } catch(e) { |
539 | 545 | return null |
540 | 546 | } |
547 | + if (id[0] === '#') return asChannelLink(id) | |
541 | 548 | if (refs.isLink(id)) return id |
542 | 549 | } |
543 | 550 | |
544 | 551 | function serveHome(req, res, query, conf) { |
545 | 552 | var q = query ? qs.parse(query) : {} |
546 | 553 | var id = asLink(q.id) |
547 | 554 | if (id) { |
548 | 555 | 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) | |
550 | 559 | }) |
551 | 560 | return res.end() |
552 | 561 | } |
553 | 562 | res.writeHead(200, { |
Built with git-ssb-web