index.jsView |
---|
133 | 133 | return str |
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | | -function getRepoName(repoId, cb) { |
138 | | - |
139 | | - cb(null, repoId.substr(0, 20) + '…') |
| 137 | +function getRepoName(about, ownerId, repoId, cb) { |
| 138 | + about.getName({ |
| 139 | + owner: ownerId, |
| 140 | + target: repoId, |
| 141 | + toString: function () { |
| 142 | + |
| 143 | + return ownerId + '/' + repoId |
| 144 | + } |
| 145 | + }, cb) |
140 | 146 | } |
141 | 147 | |
142 | 148 | var hasOwnProp = Object.prototype.hasOwnProperty |
143 | 149 | |
347 | 353 | pull.once('<hr/></article></body></html>') |
348 | 354 | ]) |
349 | 355 | } |
350 | 356 | |
351 | | - function serveError(err) { |
| 357 | + function serveError(err, status) { |
352 | 358 | if (err.message == 'stream is closed') |
353 | 359 | reconnect() |
354 | 360 | return pull( |
355 | 361 | pull.once( |
356 | 362 | '<h2>' + err.name + '</h3>' + |
357 | 363 | '<pre>' + escapeHTML(err.stack) + '</pre>'), |
358 | | - serveTemplate(err.name, 500) |
| 364 | + serveTemplate(err.name, status || 500) |
359 | 365 | ) |
360 | 366 | } |
361 | 367 | |
362 | 368 | |
387 | 393 | |
388 | 394 | function renderRepoCreated(msg, authorName, cb) { |
389 | 395 | var msgLink = link([msg.key], |
390 | 396 | new Date(msg.value.timestamp).toLocaleString()) |
391 | | - var repoLink = link([msg.key]) |
392 | 397 | var authorLink = link([msg.value.author], authorName) |
393 | | - cb(null, '<section class="collapse">' + msgLink + '<br>' + |
394 | | - authorLink + ' created repo ' + repoLink + '</section>') |
| 398 | + var author = msg.value.author |
| 399 | + getRepoName(about, author, msg.key, function (err, repoName) { |
| 400 | + if (err) return cb(err) |
| 401 | + var repoLink = link([msg.key], repoName) |
| 402 | + cb(null, '<section class="collapse">' + msgLink + '<br>' + |
| 403 | + authorLink + ' created repo ' + repoLink + '</section>') |
| 404 | + }) |
395 | 405 | } |
396 | 406 | |
397 | 407 | function renderUpdate(msg, authorName, cb) { |
398 | 408 | var msgLink = link([msg.key], |
399 | 409 | new Date(msg.value.timestamp).toLocaleString()) |
400 | | - var repoLink = link([msg.value.content.repo]) |
401 | 410 | var authorLink = link([msg.value.author], authorName) |
402 | | - cb(null, '<section class="collapse">' + msgLink + '<br>' + |
403 | | - authorLink + ' pushed to ' + repoLink + '</section>') |
| 411 | + var repoId = msg.value.content.repo |
| 412 | + var author = msg.value.author |
| 413 | + getRepoName(about, author, repoId, function (err, repoName) { |
| 414 | + if (err) return cb(err) |
| 415 | + var repoLink = link([msg.value.content.repo], repoName) |
| 416 | + cb(null, '<section class="collapse">' + msgLink + '<br>' + |
| 417 | + authorLink + ' pushed to ' + repoLink + '</section>') |
| 418 | + }) |
404 | 419 | } |
405 | 420 | |
406 | 421 | |
407 | 422 | |
466 | 481 | |
467 | 482 | if (req.method == 'POST') { |
468 | 483 | return readNext(function (cb) { |
469 | 484 | readReqJSON(req, function (err, data) { |
470 | | - if (data && data.vote != null) { |
| 485 | + if (err) return cb(null, serveError(err, 400)) |
| 486 | + if (!data) return cb(null, serveError(new Error('No data'), 400)) |
| 487 | + if (data.vote != null) { |
471 | 488 | var voteValue = +data.vote || 0 |
472 | 489 | ssb.publish(schemas.vote(repo.id, voteValue), function (err) { |
473 | 490 | if (err) return cb(null, serveError(err)) |
474 | 491 | cb(null, serveRedirect(req.url)) |
475 | 492 | }) |
| 493 | + } else if ('repo-name' in data) { |
| 494 | + var name = data['repo-name'] |
| 495 | + if (!name) return cb(null, serveRedirect(req.url)) |
| 496 | + var msg = schemas.name(repo.id, name) |
| 497 | + ssb.publish(msg, function (err) { |
| 498 | + if (err) return cb(null, serveError(err)) |
| 499 | + cb(null, serveRedirect(req.url)) |
| 500 | + }) |
476 | 501 | } else { |
477 | 502 | cb(null, servePlainError(400, 'What are you trying to do?')) |
478 | 503 | } |
479 | 504 | }) |
519 | 544 | 'onclick="this.select()"/>' |
520 | 545 | var digsPath = [repo.id, 'digs'] |
521 | 546 | |
522 | 547 | var done = multicb({ pluck: 1, spread: true }) |
523 | | - getRepoName(repo.id, done()) |
| 548 | + about.getName(repo.id, done()) |
524 | 549 | about.getName(repo.feed, done()) |
525 | 550 | getVotes(repo.id, done()) |
526 | 551 | |
527 | 552 | return readNext(function (cb) { |
540 | 565 | (upvoted ? 'Undig' : 'Dig') + |
541 | 566 | '</button>') + ' ' + |
542 | 567 | '<strong>' + link(digsPath, votes.upvotes) + '</strong>' + |
543 | 568 | '</form>' + |
544 | | - '<h2>' + link([repo.feed], authorName) + ' / ' + |
| 569 | + '<form class="petname" action="" method="post">' + |
| 570 | + '<input name="repo-name" id="repo-name" value="' + |
| 571 | + escapeHTML(repoName) + '" />' + |
| 572 | + '<label class="repo-name-toggle" for="repo-name" ' + |
| 573 | + 'title="Rename the repo"><i>✍</i></label>' + |
| 574 | + '<input class="repo-name-btn" type="submit" value="Rename">' + |
| 575 | + '<h2 class="left">' + link([repo.feed], authorName) + ' / ' + |
545 | 576 | link([repo.id], repoName) + '</h2>' + |
| 577 | + '</form>' + |
| 578 | + '<br clear="all" \>' + |
546 | 579 | '</div><div class="repo-nav">' + link([repo.id], 'Code') + |
547 | 580 | link([repo.id, 'activity'], 'Activity') + |
548 | 581 | link([repo.id, 'commits', branch || ''], 'Commits') + |
549 | 582 | gitLink + |