Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statusCodePage enhance further #1289

Merged
merged 1 commit into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,9 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;
var githubUserId = null;
var githubRepoName = null;
var githubDefaultBranch = null;
var githubPathName = null;
var githubPathExt = null;
var githubBlobPath = null;

// Session
Expand All @@ -1218,6 +1221,9 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
options.isOwnRepo = authedUser.ghUsername && authedUser.ghUsername === options.githubUserId;

options.githubRepoName = githubRepoName = aReq.body.repo || aReq.query.repo;
options.githubDefaultBranch = githubDefaultBranch = aReq.body.default_branch || aReq.query.default_branch;
options.githubPathName = githubPathName = aReq.body.pathname || aReq.query.pathname;
options.githubPathExt = githubPathExt = aReq.body.pathext || aReq.query.pathext;
options.githubBlobPath = githubBlobPath = aReq.body.path || aReq.query.path;

if (!(githubUserId && githubRepoName && githubBlobPath)) {
Expand Down Expand Up @@ -1284,7 +1290,17 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
if (aErr) {
statusCodePage(aReq, aRes, aNext, {
statusCode: aErr.status.code,
statusMessage: aErr.status.message
statusMessage: aErr.status.message,
isCustomView: true,
statusData: {
isGHImport: true,
utf_pathname: githubPathName,
utf_pathext: githubPathExt,
user: encodeURIComponent(githubUserId),
repo: encodeURIComponent(githubRepoName),
default_branch: encodeURIComponent(githubDefaultBranch),
path: encodeURIComponent(githubBlobPath)
}
});
return;
}
Expand Down Expand Up @@ -1329,7 +1345,21 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
}
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
} else {
aCallback('Specified file does not contain the proper metadata blocks.');
statusCodePage(aReq, aRes, aNext, {
statusCode: 400,
statusMessage: 'Specified file does not contain the proper metadata blocks.',
isCustomView: true,
statusData: {
isGHImport: true,
utf_pathname: githubPathName,
utf_pathext: githubPathExt,
user: encodeURIComponent(githubUserId),
repo: encodeURIComponent(githubRepoName),
default_branch: encodeURIComponent(githubDefaultBranch),
path: encodeURIComponent(githubBlobPath)
}
});
return;
}

} else if (options.javascriptBlob.isJSLibrary) {
Expand Down Expand Up @@ -1360,11 +1390,23 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
}
scriptStorage.storeScript(authedUser, blocks, aBlobUtf8, false, onScriptStored);
} else {
aCallback('Specified file does not contain the proper metadata blocks.');
statusCodePage(aReq, aRes, aNext, {
statusCode: 400,
statusMessage: 'Specified file does not contain the proper metadata blocks.',
isCustomView: true,
statusData: {
isGHImport: true,
utf_pathname: githubPathName,
utf_pathext: githubPathExt,
user: encodeURIComponent(githubUserId),
repo: encodeURIComponent(githubRepoName),
default_branch: encodeURIComponent(githubDefaultBranch),
path: encodeURIComponent(githubBlobPath)
}
});
return;
}



} else {
aCallback('Invalid filetype.');
}
Expand All @@ -1373,8 +1415,11 @@ exports.userGitHubImportScriptPage = function (aReq, aRes, aNext) {
var script = null;

if (aErr) {
console.error(aErr);
console.error(githubUserId, githubRepoName, githubBlobPath);
console.error([
aErr,
authedUser.name + ' ' + githubUserId + ' ' + githubRepoName + ' ' + githubBlobPath

].join('\n'));
statusCodePage(aReq, aRes, aNext, {
statusCode: 400,
statusMessage: aErr
Expand Down
9 changes: 8 additions & 1 deletion views/pages/statusCodePage.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ <h1 class="status-code text-center">{{statusCode}}</h1>
{{#isAdminSessionLengthView}}
Session Length: <strong>{{length}}</strong>
{{/isAdminSessionLengthView}}
{{#isGHImport}}
{{{statusMessage}}}<br /><a href="https://github.com/{{user}}/{{repo}}/tree/{{default_branch}}/{{path}}"><b>{{utf_pathname}}</b>{{utf_pathext}}</a>
{{/isGHImport}}
{{/statusData}}
{{/isCustomView}}
{{^isCustomView}}
{{{statusMessage}}}
{{/isCustomView}}
</p>
<p class="text-center"> <a id="action" href="#"></a></p>
<div class="text-center">
<ul class="nav navpills">
<li><a id="action" href="#"></a></li>
</ul>
</div>
</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion views/pages/userGitHubRepoPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ <h2><a href="{{{userGitHubRepoListPageUrl}}}" class="script-author">{{repo.owner
<form action="{{{authedUser.userGitHubImportPageUrl}}}" method="post"{{#openImportInNewTab}} target="_blank"{{/openImportInNewTab}}>
<input type="hidden" name="user" value="{{repo.owner.login}}">
<input type="hidden" name="repo" value="{{repo.name}}">
<input type="hidden" name="default_branch" value="{{repo.default_branch}}">
<input type="hidden" name="path" value="{{path.full}}">
<input type="hidden" name="pathname" value="{{path.name}}">
<input type="hidden" name="pathext" value="{{path.ext}}">
<button type="submit" class="btn btn-sm btn-{{^isOwnRepo}}warning{{/isOwnRepo}}{{#isOwnRepo}}success{{/isOwnRepo}} pull-right {{^canUpload}}disabled{{/canUpload}}"><i class="octicon octicon-fw octicon-repo-clone"></i> Import</a>
</form>
</div>

<p>
<a href="https://github.com/{{repo.owner.login}}/{{repo.name}}/tree/{{repoAsEncoded.default_branch}}/{{pathAsEncoded.full}}" target="_blank">{{path.dir}}<b>{{path.name}}</b>{{path.ext}}</a>
<span class="label label-default">{{size}} bytes</span>
Expand Down