mirror of
https://github.com/linuxserver/core.git
synced 2026-02-20 05:07:19 +08:00
cleanup
This commit is contained in:
parent
0b7712da1f
commit
fa2d0286d4
@ -78,11 +78,6 @@
|
||||
if (idx == messages.length) idx = messages.length - 1;
|
||||
var msg = messages[idx];
|
||||
|
||||
if (~location.hash.indexOf("create")) {
|
||||
msg = "Creating Your New Workspace";
|
||||
location.hash = location.hash.replace(/&?create/, "");
|
||||
}
|
||||
|
||||
document.querySelector("#loadingide .cool-message").innerHTML = msg;
|
||||
|
||||
setTimeout(function(){
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="./plugins/c9.ide.layout.classic/loading-flat.css" />
|
||||
<div id="loadingcontainer" class="">
|
||||
<div id="loadingide">
|
||||
<div class="cool-message"></div>
|
||||
<div class="cool-message">Loading offline ide example</div>
|
||||
<div class="status" style="display:none"><div class="spinner"></div></div>
|
||||
|
||||
<div id="content" class="loading-progress">
|
||||
@ -26,25 +26,6 @@
|
||||
var loadingIde = document.querySelector("#loadingide");
|
||||
document.body.className = "loading " + loadingIde.className;
|
||||
|
||||
var messages = [
|
||||
"Loading offline ide example"
|
||||
];
|
||||
|
||||
var mac_keybindings = [];
|
||||
|
||||
var win_keybindings = [];
|
||||
|
||||
var idx = Math.floor(Math.random() * messages.length);
|
||||
if (idx == messages.length) idx = messages.length - 1;
|
||||
var msg = messages[idx];
|
||||
|
||||
if (~location.hash.indexOf("create")) {
|
||||
msg = "Creating Your New Workspace";
|
||||
location.hash = location.hash.replace(/&?create/, "");
|
||||
}
|
||||
|
||||
document.querySelector("#loadingide .cool-message").innerHTML = msg;
|
||||
|
||||
setTimeout(function(){
|
||||
var s = document.querySelector("#loadingide .status");
|
||||
if (s) s.style.display = "block";
|
||||
@ -60,31 +41,293 @@
|
||||
<script src="/static/mini_require.js"></script>
|
||||
<script src="/configs/require_config.js"></script>
|
||||
<script>
|
||||
var start = Date.now();
|
||||
var vfsPlugin = {
|
||||
consumes: [],
|
||||
provides: ["vfs", "vfs.ping", "vfs.log", "vfs.endpoint"],
|
||||
setup: function(options, imports, register) {
|
||||
var Stream = require("stream").Stream;
|
||||
var noop = function() { debugger; };
|
||||
var silent = function() {};
|
||||
var connection = {};
|
||||
// initialize mock fsData
|
||||
var fsData = {};
|
||||
findNode("/hello", true, "world");
|
||||
findNode("~", true);
|
||||
// Try loading data from localStorage
|
||||
try {
|
||||
fsData = JSON.parse(localStorage.fsData);
|
||||
} catch (e) {}
|
||||
window.addEventListener("beforeunload", function(e) {
|
||||
localStorage.fsData = JSON.stringify(fsData);
|
||||
});
|
||||
|
||||
var vfsApi = {
|
||||
on: function() {},
|
||||
once: function() {},
|
||||
connected: true,
|
||||
|
||||
get connection() { return connection; },
|
||||
get connecting() { return false; },
|
||||
get connected() { return true },
|
||||
|
||||
get previewUrl() { throw new Error("gone"); },
|
||||
get serviceUrl() { return serviceUrl; },
|
||||
get id() { return id; },
|
||||
get baseUrl() { return vfsBaseUrl; },
|
||||
get region() { return ""; },
|
||||
|
||||
rest: noop,
|
||||
download: noop,
|
||||
url: noop,
|
||||
reconnect: noop,
|
||||
|
||||
vfsUrl: noop,
|
||||
|
||||
var plugins;
|
||||
require(["lib/architect/architect", "configs/ide/default"], function (architect, defaultConfig) {
|
||||
var plugins = defaultConfig({
|
||||
staticPrefix: "/static",
|
||||
workspaceDir: "/",
|
||||
workspaceId: "/",
|
||||
workspaceName: "/",
|
||||
home: "/",
|
||||
platform: "linux",
|
||||
installPath: "/",
|
||||
manifest: {},
|
||||
project: {},
|
||||
user: {},
|
||||
standalone: true,
|
||||
previewUrl: "",
|
||||
dashboardUrl: "",
|
||||
themePrefix: "/static/standalone/skin/default",
|
||||
});
|
||||
// File management
|
||||
resolve: noop,
|
||||
stat: function(path, options, cb) {
|
||||
var data = findNode(path);
|
||||
var name = path.split("/").pop();
|
||||
setTimeout(function() {
|
||||
if (data == null)
|
||||
return cb(ENOENT());
|
||||
var isFile = typeof data == "string";
|
||||
var stat = {
|
||||
name: name.substr(1),
|
||||
size: isFile ? data.length : 1,
|
||||
mtime: 0,
|
||||
ctime: 0,
|
||||
mime: isFile ? "" : "folder"
|
||||
};
|
||||
cb(null, stat);
|
||||
}, 20);
|
||||
},
|
||||
readfile: function(path, options, cb) {
|
||||
var data = findNode(path);
|
||||
setTimeout(function() {
|
||||
if (typeof data != "string")
|
||||
return cb(ENOENT());
|
||||
sendStream(data, cb);
|
||||
}, 20);
|
||||
},
|
||||
readdir: function(path, options, cb) {
|
||||
var data = findNode(path);
|
||||
setTimeout(function() {
|
||||
if (!data || typeof data == "string")
|
||||
return cb(ENOENT());
|
||||
var stats = Object.keys(data).map(function(n) {
|
||||
var isFile = typeof data[n] == "string";
|
||||
return {
|
||||
name: n.substr(1),
|
||||
size: isFile ? data[n].length : 1,
|
||||
mtime: 0,
|
||||
ctime: 0,
|
||||
mime: isFile ? "" : "folder"
|
||||
};
|
||||
});
|
||||
sendStream(stats, cb);
|
||||
});
|
||||
},
|
||||
mkfile: function(path, options, cb) {
|
||||
var parts = path.split("/")
|
||||
var name = "!" + parts.pop();
|
||||
var parent = findNode(parts.join("/"), true);
|
||||
var val = "";
|
||||
options.stream.on("data", function(e) {
|
||||
if (e) val += e;
|
||||
});
|
||||
options.stream.on("end", function(e) {
|
||||
if (e) val += e;
|
||||
setTimeout(function() {
|
||||
if (!parent || typeof parent[name] == "object")
|
||||
return cb(ENOENT());
|
||||
parent[name] = val;
|
||||
cb(null);
|
||||
});
|
||||
});
|
||||
},
|
||||
mkdir: function(path, options, cb) {
|
||||
var data = findNode(path, true);
|
||||
setTimeout(function() {
|
||||
if (!data)
|
||||
return cb(ENOENT());
|
||||
cb();
|
||||
});
|
||||
},
|
||||
mkdirP: function(path, options, cb) {
|
||||
var data = findNode(path, true);
|
||||
setTimeout(function() {
|
||||
if (!data)
|
||||
return cb(ENOENT());
|
||||
cb();
|
||||
});
|
||||
},
|
||||
appendfile: noop,
|
||||
rmfile: function(path, options, cb) {
|
||||
var parts = path.split("/")
|
||||
var name = "!" + parts.pop();
|
||||
setTimeout(function() {
|
||||
var parent = findNode(parts.join("/"));
|
||||
if (!parent || !parent[name])
|
||||
return cb(ENOENT());
|
||||
if (typeof parent[name] != "string")
|
||||
return cb(new Error("EISDIR"))
|
||||
delete parent[name];
|
||||
cb();
|
||||
});
|
||||
},
|
||||
rmdir: function(path, options, cb) {
|
||||
var parts = path.split("/")
|
||||
var name = "!" + parts.pop();
|
||||
setTimeout(function() {
|
||||
var parent = findNode(parts.join("/"));
|
||||
if (!parent || !parent[name])
|
||||
return cb(ENOENT());
|
||||
if (typeof parent[name] == "string")
|
||||
return cb(new Error("EISFILE"))
|
||||
delete parent[name];
|
||||
cb();
|
||||
});
|
||||
},
|
||||
rename: function(to, options, cb) {
|
||||
setTimeout(function() {
|
||||
var from = options.from;
|
||||
var overwrite = options.overwrite;
|
||||
|
||||
var parts = to.split("/")
|
||||
var toName = "!" + parts.pop();
|
||||
var toParent = findNode(parts.join("/"));
|
||||
|
||||
parts = from.split("/")
|
||||
var fromName = "!" + parts.pop();
|
||||
var fromParent = findNode(parts.join("/"));
|
||||
if (toParent[toName] != null && !overwrite)
|
||||
return cb(ENOENT());
|
||||
|
||||
toParent[toName] = fromParent[fromName];
|
||||
delete fromParent[fromName];
|
||||
cb(null);
|
||||
})
|
||||
},
|
||||
copy: function(from, options, cb) {
|
||||
setTimeout(function() {
|
||||
var to = options.to;
|
||||
var overwrite = options.overwrite;
|
||||
|
||||
var toParts = to.split("/")
|
||||
var toName = "!" + toParts.pop();
|
||||
var toParent = findNode(toParts.join("/"));
|
||||
|
||||
var parts = from.split("/")
|
||||
var fromName = "!" + parts.pop();
|
||||
var fromParent = findNode(parts.join("/"));
|
||||
var counter = 0;
|
||||
var name = toName;
|
||||
while (toParent[toName] != null && !options.overwrite)
|
||||
toName = name + "." + (++counter);
|
||||
|
||||
toParent[toName] = fromParent[fromName];
|
||||
toParts.push(toName.substr(1))
|
||||
cb(null, {to: toParts.join("/")});
|
||||
})
|
||||
},
|
||||
chmod: noop,
|
||||
symlink: noop,
|
||||
|
||||
// Save and retrieve Metadata
|
||||
metadata: function(path, value, sync, cb) {
|
||||
setTimeout(function() {
|
||||
cb()
|
||||
});
|
||||
},
|
||||
readFileWithMetadata: function(path, options, cb) {
|
||||
var data = findNode(path);
|
||||
setTimeout(function() {
|
||||
if (typeof data != "string")
|
||||
return cb(ENOENT());
|
||||
// TODO metadata
|
||||
cb(null, data)
|
||||
});
|
||||
return { abort: function() {} };
|
||||
},
|
||||
|
||||
// Wrapper around fs.watch or fs.watchFile
|
||||
watch: silent,
|
||||
|
||||
// Network connection
|
||||
connect: noop,
|
||||
|
||||
// Process Management
|
||||
spawn: silent,
|
||||
pty: silent,
|
||||
tmux: silent,
|
||||
execFile: silent,
|
||||
killtree: silent,
|
||||
|
||||
// Extending the API
|
||||
use: silent,
|
||||
extend: silent,
|
||||
unextend: silent,
|
||||
|
||||
isIdle: function() { return true },
|
||||
}
|
||||
|
||||
function findNode(path, create, val) {
|
||||
if (!path) path = "/";
|
||||
var parts = path.split("/");
|
||||
if (!parts[parts.length - 1])
|
||||
parts.pop();
|
||||
var data = fsData;
|
||||
var prev = null;
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
prev = data;
|
||||
data = data["!" + parts[i]];
|
||||
if (data == null) {
|
||||
if (create && typeof prev != "string")
|
||||
data = prev["!" + parts[i]] = {};
|
||||
else
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (val)
|
||||
data = prev["!" + parts[parts.length - 1]] = val;
|
||||
return data;
|
||||
}
|
||||
function ENOENT() {
|
||||
var err = new Error("ENOENT");
|
||||
err.code = "ENOENT";
|
||||
return err;
|
||||
}
|
||||
function sendStream(data, cb) {
|
||||
var stream = new Stream();
|
||||
stream.readable = true;
|
||||
cb(null, { stream: stream });
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach(function(x) {
|
||||
stream.emit("data", x);
|
||||
});
|
||||
} else {
|
||||
stream.emit("data", data);
|
||||
}
|
||||
stream.emit("end");
|
||||
}
|
||||
register(null, {
|
||||
"vfs": vfsApi,
|
||||
"vfs.ping": {},
|
||||
"vfs.log": {
|
||||
log: function() {}
|
||||
},
|
||||
"vfs.endpoint": {
|
||||
clearCache: function() {}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
function offlineConfig(plugins) {
|
||||
var excludes = [
|
||||
"plugins/c9.ide.immediate/evaluators/debugnode",
|
||||
"plugins/c9.ide.test.mocha/mocha",
|
||||
"plugins/c9.ide.find/find.nak",
|
||||
// "plugins/c9.ide.language.jsonalyzer/jsonalyzer",
|
||||
"plugins/c9.ide.terminal/terminal",
|
||||
"plugins/c9.ide.test/all",
|
||||
"plugins/c9.ide.find/find",
|
||||
@ -129,270 +372,34 @@
|
||||
|
||||
return true;
|
||||
});
|
||||
plugins.push({
|
||||
consumes: [],
|
||||
provides: ["vfs", "vfs.ping", "vfs.log", "vfs.endpoint"],
|
||||
setup: function(options, imports, register) {
|
||||
var Stream = require("stream").Stream;
|
||||
var noop = function() { debugger; };
|
||||
var silent = function() {};
|
||||
var connection = {};
|
||||
var fsData = {};
|
||||
findNode("/hello", true, "world");
|
||||
findNode("~", true);
|
||||
try {
|
||||
fsData = JSON.parse(localStorage.fsData);
|
||||
} catch (e) {}
|
||||
window.addEventListener("beforeunload", function(e) {
|
||||
localStorage.fsData = JSON.stringify(fsData);
|
||||
});
|
||||
|
||||
function findNode(path, create, val) {
|
||||
if (!path) path = "/";
|
||||
var parts = path.split("/");
|
||||
if (!parts[parts.length - 1])
|
||||
parts.pop();
|
||||
var data = fsData;
|
||||
var prev = null;
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
prev = data;
|
||||
data = data["!" + parts[i]];
|
||||
if (data == null) {
|
||||
if (create && typeof prev != "string")
|
||||
data = prev["!" + parts[i]] = {};
|
||||
else
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (val)
|
||||
data = prev["!" + parts[parts.length - 1]] = val;
|
||||
return data;
|
||||
}
|
||||
function ENOENT() {
|
||||
var err = new Error("ENOENT");
|
||||
err.code = "ENOENT";
|
||||
return err;
|
||||
}
|
||||
function sendStream(data, cb) {
|
||||
var stream = new Stream();
|
||||
stream.readable = true;
|
||||
cb(null, { stream: stream });
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach(function(x) {
|
||||
stream.emit("data", x);
|
||||
});
|
||||
} else {
|
||||
stream.emit("data", data);
|
||||
}
|
||||
stream.emit("end");
|
||||
}
|
||||
register(null, {
|
||||
"vfs": {
|
||||
on: function() {
|
||||
|
||||
},
|
||||
once: function() {
|
||||
|
||||
},
|
||||
connected: true,
|
||||
|
||||
get connection() { return connection; },
|
||||
get connecting() { return false; },
|
||||
get connected() { return true },
|
||||
|
||||
get previewUrl() { throw new Error("gone"); },
|
||||
get serviceUrl() { return serviceUrl; },
|
||||
get id() { return id; },
|
||||
get baseUrl() { return vfsBaseUrl; },
|
||||
get region() { return ""; },
|
||||
|
||||
rest: noop,
|
||||
download: noop,
|
||||
url: noop,
|
||||
reconnect: noop,
|
||||
|
||||
vfsUrl: noop,
|
||||
|
||||
// File management
|
||||
resolve: noop,
|
||||
stat: function(path, options, cb) {
|
||||
var data = findNode(path);
|
||||
var name = path.split("/").pop();
|
||||
setTimeout(function() {
|
||||
if (data == null)
|
||||
return cb(ENOENT());
|
||||
var isFile = typeof data == "string";
|
||||
var stat = {
|
||||
name: name.substr(1),
|
||||
size: isFile ? data.length : 1,
|
||||
mtime: 0,
|
||||
ctime: 0,
|
||||
mime: isFile ? "" : "folder"
|
||||
};
|
||||
cb(null, stat);
|
||||
}, 20);
|
||||
},
|
||||
readfile: function(path, options, cb) {
|
||||
var data = findNode(path);
|
||||
setTimeout(function() {
|
||||
if (typeof data != "string")
|
||||
return cb(ENOENT());
|
||||
sendStream(data, cb);
|
||||
}, 20);
|
||||
},
|
||||
readdir: function(path, options, cb) {
|
||||
var data = findNode(path);
|
||||
setTimeout(function() {
|
||||
if (!data || typeof data == "string")
|
||||
return cb(ENOENT());
|
||||
var stats = Object.keys(data).map(function(n) {
|
||||
var isFile = typeof data[n] == "string";
|
||||
return {
|
||||
name: n.substr(1),
|
||||
size: isFile ? data[n].length : 1,
|
||||
mtime: 0,
|
||||
ctime: 0,
|
||||
mime: isFile ? "" : "folder"
|
||||
};
|
||||
});
|
||||
sendStream(stats, cb);
|
||||
});
|
||||
},
|
||||
mkfile: function(path, options, cb) {
|
||||
var parts = path.split("/")
|
||||
var name = "!" + parts.pop();
|
||||
var parent = findNode(parts.join("/"), true);
|
||||
var val = "";
|
||||
options.stream.on("data", function(e) {
|
||||
if (e) val += e;
|
||||
});
|
||||
options.stream.on("end", function(e) {
|
||||
if (e) val += e;
|
||||
setTimeout(function() {
|
||||
if (!parent || typeof parent[name] == "object")
|
||||
return cb(ENOENT());
|
||||
parent[name] = val;
|
||||
cb(null);
|
||||
});
|
||||
});
|
||||
},
|
||||
mkdir: function(path, options, cb) {
|
||||
var data = findNode(path, true);
|
||||
setTimeout(function() {
|
||||
if (!data)
|
||||
return cb(ENOENT());
|
||||
cb();
|
||||
});
|
||||
},
|
||||
mkdirP: function(path, options, cb) {
|
||||
var data = findNode(path, true);
|
||||
setTimeout(function() {
|
||||
if (!data)
|
||||
return cb(ENOENT());
|
||||
cb();
|
||||
});
|
||||
},
|
||||
appendfile: noop,
|
||||
rmfile: function(path, options, cb) {
|
||||
var parts = path.split("/")
|
||||
var name = "!" + parts.pop();
|
||||
setTimeout(function() {
|
||||
var parent = findNode(parts.join("/"));
|
||||
if (!parent || !parent[name])
|
||||
return cb(ENOENT());
|
||||
if (typeof parent[name] != "string")
|
||||
return cb(new Error("EISDIR"))
|
||||
delete parent[name];
|
||||
cb();
|
||||
});
|
||||
},
|
||||
rmdir: function(path, options, cb) {
|
||||
var parts = path.split("/")
|
||||
var name = "!" + parts.pop();
|
||||
setTimeout(function() {
|
||||
var parent = findNode(parts.join("/"));
|
||||
if (!parent || !parent[name])
|
||||
return cb(ENOENT());
|
||||
if (typeof parent[name] == "string")
|
||||
return cb(new Error("EISFILE"))
|
||||
delete parent[name];
|
||||
cb();
|
||||
});
|
||||
},
|
||||
rename: function(to, options, cb) {
|
||||
setTimeout(function() {
|
||||
var from = options.from;
|
||||
var overwrite = options.overwrite;
|
||||
|
||||
var parts = to.split("/")
|
||||
var toName = "!" + parts.pop();
|
||||
var toParent = findNode(parts.join("/"));
|
||||
|
||||
parts = from.split("/")
|
||||
var fromName = "!" + parts.pop();
|
||||
var fromParent = findNode(parts.join("/"));
|
||||
if (toParent[toName] != null && !overwrite)
|
||||
return cb(ENOENT());
|
||||
|
||||
toParent[toName] = fromParent[fromName];
|
||||
delete fromParent[fromName];
|
||||
cb(null);
|
||||
})
|
||||
},
|
||||
copy: noop,
|
||||
chmod: noop,
|
||||
symlink: noop,
|
||||
|
||||
// Save and retrieve Metadata
|
||||
metadata: function(path, value, sync, cb) {
|
||||
setTimeout(function() {
|
||||
cb()
|
||||
});
|
||||
},
|
||||
readFileWithMetadata: function(path, options, cb) {
|
||||
var data = findNode(path);
|
||||
setTimeout(function() {
|
||||
if (typeof data != "string")
|
||||
return cb(ENOENT());
|
||||
// TODO metadata
|
||||
cb(null, data)
|
||||
});
|
||||
return { abort: function() {} };
|
||||
},
|
||||
|
||||
// Wrapper around fs.watch or fs.watchFile
|
||||
watch: silent,
|
||||
|
||||
// Network connection
|
||||
connect: noop,
|
||||
|
||||
// Process Management
|
||||
spawn: silent,
|
||||
pty: silent,
|
||||
tmux: silent,
|
||||
execFile: silent,
|
||||
killtree: silent,
|
||||
|
||||
// Extending the API
|
||||
use: silent,
|
||||
extend: silent,
|
||||
unextend: silent,
|
||||
|
||||
isIdle: function() { return true },
|
||||
|
||||
},
|
||||
"vfs.ping": {
|
||||
|
||||
},
|
||||
"vfs.log": {
|
||||
log: function() {}
|
||||
},
|
||||
"vfs.endpoint": {
|
||||
clearCache: function() {}
|
||||
}
|
||||
});
|
||||
}
|
||||
plugins.push(vfsPlugin);
|
||||
return plugins;
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
|
||||
var start = Date.now();
|
||||
|
||||
var plugins;
|
||||
require(["lib/architect/architect", "configs/ide/default"], function (architect, defaultConfig) {
|
||||
var plugins = defaultConfig({
|
||||
staticPrefix: "/static",
|
||||
workspaceDir: "/",
|
||||
workspaceId: "/",
|
||||
workspaceName: "/",
|
||||
home: "/",
|
||||
platform: "linux",
|
||||
installPath: "/",
|
||||
manifest: {},
|
||||
project: {},
|
||||
user: {},
|
||||
standalone: true,
|
||||
previewUrl: "",
|
||||
dashboardUrl: "",
|
||||
themePrefix: "/static/standalone/skin/default",
|
||||
});
|
||||
plugins = offlineConfig(plugins);
|
||||
|
||||
plugins.push({
|
||||
consumes: [],
|
||||
provides: ["auth.bootstrap"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user