Skip to content

Commit

Permalink
Init release.
Browse files Browse the repository at this point in the history
  • Loading branch information
csskevin committed Mar 15, 2020
0 parents commit 29847d3
Show file tree
Hide file tree
Showing 11 changed files with 3,880 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Core WebGlasses Services

This project adds basic core functions to the WebGlasses project.
3 changes: 3 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Core from "wg-core";
declare const _default: Core.Service[];
export default _default;
8 changes: 8 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var apphandler_1 = __importDefault(require("./src/apphandler"));
var services = [];
exports.default = services.concat(apphandler_1.default);
3 changes: 3 additions & 0 deletions dist/src/apphandler.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Core from "wg-core";
declare const _default: Core.Service[];
export default _default;
118 changes: 118 additions & 0 deletions dist/src/apphandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var wg_core_1 = __importDefault(require("wg-core"));
var body_parser = require("body-parser");
wg_core_1.default.Driver.register({
method: "get",
path: "/",
handler: function (req, res) {
var app = wg_core_1.default.Verification.getAppBySubdomain(req);
if (app.id === false) {
res.send("Could not find app!");
return;
}
var file_entry = app.entry || "index.html";
res.redirect("/" + file_entry);
}
});
wg_core_1.default.Driver.register({
method: "get",
path: "/*",
handler: function (req, res) {
var app = wg_core_1.default.Verification.getAppBySubdomain(req);
if (app.id === false) {
res.send("Could not find app!");
return;
}
var filepath = req.params[0] || "index.html";
var app_fullpath = wg_core_1.default.Workfolder.app_path + "/" + app.package_name + "/" + app.entry + "/" + filepath;
if (fs.existsSync(app_fullpath)) {
var realpath_app_fullpath = fs.realpathSync(app_fullpath);
res.sendFile(realpath_app_fullpath);
}
else {
res.send("Could not find file!");
}
}
});
wg_core_1.default.Driver.register({
method: "post",
path: "/api/install_app",
parser: body_parser.json,
handler: function (req, res) {
var app = wg_core_1.default.Verification.getAppBySubdomain(req);
if (app.id === false) {
res.send("Could not find app!");
return;
}
if (wg_core_1.default.Permission.hasSpecificPermission(app.id, "apps_control")) {
var request_body = req.body;
if (typeof request_body === 'object') {
var path = request_body === null || request_body === void 0 ? void 0 : request_body.path;
if (path) {
wg_core_1.default.Apps.installApp(path).then(function () {
res.json({ error: 0, message: "App installed." });
}).catch(function (err) {
res.json({ error: 1, message: err });
});
}
else {
res.json({ error: 1, message: "Invalid filepath." });
}
}
else {
res.json({ error: 1, message: "Invalid body." });
}
}
else {
res.json({ error: 1, message: "No permissions." });
}
}
});
wg_core_1.default.Driver.register({
method: "post",
path: "/api/uninstall_app",
parser: body_parser.json,
handler: function (req, res) {
var app = wg_core_1.default.Verification.getAppBySubdomain(req);
if (app.id === false) {
res.send("Could not find app!");
return;
}
if (wg_core_1.default.Permission.hasSpecificPermission(app.id, "apps_control")) {
var request_body = req.body;
if (typeof request_body === 'object') {
var app_name = request_body === null || request_body === void 0 ? void 0 : request_body.app_name;
if (app_name) {
if (wg_core_1.default.Apps.uninstallApp(app_name)) {
res.json({ error: 0, message: "App uninstalled." });
}
else {
res.json({ error: 1, message: "App could not be uninstalled." });
}
}
else {
res.json({ error: 1, message: "Invalid filepath." });
}
}
else {
res.json({ error: 1, message: "Invalid body." });
}
}
else {
res.json({ error: 1, message: "No permissions." });
}
}
});
exports.default = wg_core_1.default.Driver.export();
5 changes: 5 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Core from "wg-core";
import AppHandler from "./src/apphandler";
const services: Array<Core.Service> = [];

export default services.concat(AppHandler);
Loading

0 comments on commit 29847d3

Please sign in to comment.