Make it possible to create a new script again.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3382 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
e8b9bab468
commit
494a1a8776
@ -126,7 +126,7 @@ function edit() {
|
|||||||
function load() {
|
function load() {
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.addEventListener("loadend", function() {
|
request.addEventListener("loadend", function() {
|
||||||
if (request.status == 200) {
|
if (request.status == 200 || request.status == 404) {
|
||||||
document.getElementById("editPane").style.display = 'flex';
|
document.getElementById("editPane").style.display = 'flex';
|
||||||
if (!gEditor) {
|
if (!gEditor) {
|
||||||
gEditor = CodeMirror.fromTextArea(document.getElementById("editor"), {
|
gEditor = CodeMirror.fromTextArea(document.getElementById("editor"), {
|
||||||
@ -138,9 +138,15 @@ function load() {
|
|||||||
'showTrailingSpace': true,
|
'showTrailingSpace': true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
gEditor.setValue(request.responseText);
|
var text;
|
||||||
|
if (request.status == 200) {
|
||||||
|
text = request.responseText;
|
||||||
|
} else {
|
||||||
|
text = '// New script\nterminal.print("Hello, world!");\n';
|
||||||
|
}
|
||||||
|
gEditor.setValue(text);
|
||||||
gEditor.focus();
|
gEditor.focus();
|
||||||
gBackup = request.responseText;
|
gBackup = text;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
request.addEventListener("error", function() {
|
request.addEventListener("error", function() {
|
||||||
|
@ -258,8 +258,13 @@ async function handler(request, response, packageOwner, packageName, uri) {
|
|||||||
var process;
|
var process;
|
||||||
if (uri === "/view") {
|
if (uri === "/view") {
|
||||||
var data = File.readFile("packages/" + packageOwner + "/" + packageName + "/" + packageName + ".js");
|
var data = File.readFile("packages/" + packageOwner + "/" + packageName + "/" + packageName + ".js");
|
||||||
|
if (data) {
|
||||||
response.writeHead(200, {"Content-Type": "text/javascript; charset=utf-8", "Content-Length": data.length});
|
response.writeHead(200, {"Content-Type": "text/javascript; charset=utf-8", "Content-Length": data.length});
|
||||||
response.end(data);
|
response.end(data);
|
||||||
|
} else {
|
||||||
|
response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Content-Length": "File not found".length});
|
||||||
|
response.end("File not found");
|
||||||
|
}
|
||||||
} else if (uri == "/save") {
|
} else if (uri == "/save") {
|
||||||
var credentials = auth.query(request.headers);
|
var credentials = auth.query(request.headers);
|
||||||
var userName = credentials && credentials.session && credentials.session.name ? credentials.session.name : "guest";
|
var userName = credentials && credentials.session && credentials.session.name ? credentials.session.name : "guest";
|
||||||
|
Loading…
Reference in New Issue
Block a user