Commit 6839527655b266fe0e7ea9e840a892514428e492
Add repo fork button
Charles Lehner committed on 4/4/2016, 10:43:54 PMParent: ffa2c61fc246f99bb8e6115e732fbce4bfdd80d4
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -509,18 +509,33 @@ | ||
509 | 509 | if (err) return cb(null, serveError(err, 400)) |
510 | 510 | if (!data) return cb(null, serveError(new Error('No data'), 400)) |
511 | 511 | |
512 | 512 | switch (data.action) { |
513 | + case 'repo': | |
514 | + if (data.fork != null) { | |
515 | + var repoId = data.id | |
516 | + if (!repoId) return cb(null, | |
517 | + serveError(new Error('Missing repo id'), 400)) | |
518 | + ssbGit.createRepo(ssb, {upstream: repoId}, | |
519 | + function (err, repo) { | |
520 | + if (err) return cb(null, serveError(err)) | |
521 | + cb(null, serveRedirect(encodeLink(repo.id))) | |
522 | + }) | |
523 | + } else if (data.vote != null) { | |
524 | + // fallthrough | |
525 | + } else { | |
526 | + return cb(null, serveError(new Error('Unknown action'), 400)) | |
527 | + } | |
528 | + | |
513 | 529 | case 'vote': |
514 | - var voteValue = +data.vote || 0 | |
530 | + var voteValue = +data.value || 0 | |
515 | 531 | if (!data.id) |
516 | 532 | return cb(null, serveError(new Error('Missing vote id'), 400)) |
517 | 533 | var msg = schemas.vote(data.id, voteValue) |
518 | 534 | return ssb.publish(msg, function (err) { |
519 | 535 | if (err) return cb(null, serveError(err)) |
520 | 536 | cb(null, serveRedirect(req.url)) |
521 | 537 | }) |
522 | - return | |
523 | 538 | |
524 | 539 | case 'repo-name': |
525 | 540 | if (!data.name) |
526 | 541 | return cb(null, serveError(new Error('Missing name'), 400)) |
@@ -1039,14 +1054,18 @@ | ||
1039 | 1054 | '<button class="btn" ' + |
1040 | 1055 | (isPublic ? 'disabled="disabled"' : ' type="submit"') + '>' + |
1041 | 1056 | '<i>โ</i> ' + (!isPublic && upvoted ? 'Undig' : 'Dig') + |
1042 | 1057 | '</button>' + |
1043 | - (isPublic ? '' : '<input type="hidden" name="vote" value="' + | |
1058 | + (isPublic ? '' : '<input type="hidden" name="value" value="' + | |
1044 | 1059 | (upvoted ? '0' : '1') + '">' + |
1045 | - '<input type="hidden" name="action" value="vote">' + | |
1060 | + '<input type="hidden" name="action" value="repo">' + | |
1046 | 1061 | '<input type="hidden" name="id" value="' + |
1047 | 1062 | escapeHTML(repo.id) + '">') + ' ' + |
1048 | - '<strong>' + link(digsPath, votes.upvotes) + '</strong>' + | |
1063 | + '<strong>' + link(digsPath, votes.upvotes) + '</strong> ' + | |
1064 | + (isPublic ? '' : | |
1065 | + '<button class="btn" type="submit" name="fork">' + | |
1066 | + '<i>โ</i> Fork' + | |
1067 | + '</button>') + | |
1049 | 1068 | '</form>' + |
1050 | 1069 | renderNameForm(!isPublic, repo.id, repoName, 'repo-name', null, |
1051 | 1070 | 'Rename the repo', |
1052 | 1071 | '<h2>' + link([repo.feed], authorName) + ' / ' + |
Built with git-ssb-web