-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lelemm/typescript
Typescript
- Loading branch information
Showing
24 changed files
with
870 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
services: | ||
confirm: | ||
build: ./src/. | ||
ports: | ||
- 8446:8000 | ||
restart: unless-stopped | ||
volumes: | ||
- ./src/config.yml:/app/config.yml | ||
- ./src/views:/app/views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dist | ||
node_modules | ||
README.md | ||
docker-compose.yml | ||
config.yml | ||
views/**/ | ||
views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import express from "express"; | ||
import { router } from "./router"; | ||
import mustacheExpress from "mustache-express"; | ||
import favicon from 'serve-favicon'; | ||
|
||
export class App{ | ||
public server: express.Application; | ||
|
||
constructor(){ | ||
this.server = express(); | ||
this.middleware(); | ||
this.mustache(); | ||
this.router(); | ||
this.server.use(express.static('public')) | ||
this.server.use(favicon(__dirname + '/public/images/favicon.ico')); | ||
} | ||
|
||
private middleware(){ | ||
this.server.use(express.json()); | ||
} | ||
|
||
private mustache() { | ||
this.server.engine("mustache", mustacheExpress()); | ||
} | ||
|
||
private router(){ | ||
this.server.use(router); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.App = void 0; | ||
var express_1 = __importDefault(require("express")); | ||
var router_1 = require("./router"); | ||
var mustache_express_1 = __importDefault(require("mustache-express")); | ||
var App = /** @class */ (function () { | ||
function App() { | ||
this.server = (0, express_1.default)(); | ||
this.middleware(); | ||
this.mustache(); | ||
this.router(); | ||
} | ||
App.prototype.middleware = function () { | ||
this.server.use(express_1.default.json()); | ||
}; | ||
App.prototype.mustache = function () { | ||
this.server.engine("mustache", (0, mustache_express_1.default)()); | ||
}; | ||
App.prototype.router = function () { | ||
this.server.use(router_1.router); | ||
}; | ||
return App; | ||
}()); | ||
exports.App = App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.confirmController = void 0; | ||
var ConfigReader_1 = require("../helpers/ConfigReader"); | ||
var url_1 = __importDefault(require("url")); | ||
var mustache_1 = __importDefault(require("mustache")); | ||
var ConfirmController = /** @class */ (function () { | ||
function ConfirmController() { | ||
} | ||
ConfirmController.prototype.alias = function (req, res) { | ||
var doc = ConfigReader_1.configReader.getDoc(); | ||
var alias = doc.pages[req.params.alias]; | ||
if (alias == undefined) { | ||
res.status(404); | ||
res.send('404 - Not found'); | ||
return; | ||
} | ||
var url_parts = url_1.default.parse(req.url, false); | ||
return res.render('confirm.mustache', { | ||
link: alias, | ||
query: url_parts.query, | ||
yes: doc.strings.yes, | ||
no: doc.strings.no, | ||
title: mustache_1.default.render(doc.strings.window_title, { link: alias }), | ||
open_link: mustache_1.default.render(doc.strings.open_link, { link: alias }), | ||
theme: doc.config.theme | ||
}); | ||
}; | ||
return ConfirmController; | ||
}()); | ||
exports.confirmController = new ConfirmController(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.cssController = void 0; | ||
var ConfigReader_1 = require("../helpers/ConfigReader"); | ||
var ConfirmModel_1 = require("../models/ConfirmModel"); | ||
var CssController = /** @class */ (function () { | ||
function CssController() { | ||
} | ||
CssController.prototype.variables = function (req, res) { | ||
var doc = ConfigReader_1.configReader.getDoc(); | ||
var confirmModel = new ConfirmModel_1.ConfirmModel(); | ||
confirmModel.direction = doc.config.direction; | ||
confirmModel.directionMobile = confirmModel.direction; | ||
if (doc.config.theme != 'default') { | ||
confirmModel.customThemeNo = doc.themes[doc.config.theme].default.no; | ||
confirmModel.customThemeYes = doc.themes[doc.config.theme].default.yes; | ||
confirmModel.customThemeActiveNo = doc.themes[doc.config.theme].active.no; | ||
confirmModel.customThemeActiveYes = doc.themes[doc.config.theme].active.yes; | ||
} | ||
if (doc.config.direction == 'column') { | ||
confirmModel.sizeW = '100'; | ||
confirmModel.sizeH = '50'; | ||
confirmModel.expandedH = '90'; | ||
confirmModel.expandedW = '100'; | ||
confirmModel.contractedH = '10'; | ||
confirmModel.contractedW = '100'; | ||
confirmModel.sizeWMobile = '100'; | ||
confirmModel.sizeHMobile = '50'; | ||
confirmModel.expandedHMobile = '90'; | ||
confirmModel.expandedWMobile = '100'; | ||
confirmModel.contractedHMobile = '10'; | ||
confirmModel.contractedWMobile = '100'; | ||
} | ||
else if (doc.config.direction == 'dynamic') { | ||
confirmModel.directionMobile = 'column'; | ||
confirmModel.direction = 'row'; | ||
confirmModel.sizeWMobile = '100'; | ||
confirmModel.sizeHMobile = '50'; | ||
confirmModel.expandedHMobile = '90'; | ||
confirmModel.expandedWMobile = '100'; | ||
confirmModel.contractedHMobile = '10'; | ||
confirmModel.contractedWMobile = '100'; | ||
} | ||
return res.render('variables.mustache', { | ||
doc: doc, | ||
confirmModel: confirmModel | ||
}); | ||
}; | ||
return CssController; | ||
}()); | ||
exports.cssController = new CssController(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.configReader = void 0; | ||
var yaml = require('js-yaml'); | ||
var fs = require('fs'); | ||
var ConfigReader = /** @class */ (function () { | ||
function ConfigReader() { | ||
this.lastReadTime = 0; | ||
} | ||
ConfigReader.prototype.readYmlFile = function () { | ||
if (this.doc == null || this.lastReadTime == 0 || (new Date().getTime() - this.lastReadTime) > 1000) { | ||
try { | ||
this.doc = yaml.load(fs.readFileSync('./config.yml', 'utf8')); | ||
return this.doc; | ||
} | ||
catch (e) { | ||
console.log(e); | ||
} | ||
return {}; | ||
} | ||
}; | ||
ConfigReader.prototype.getDoc = function () { | ||
this.readYmlFile(); | ||
return this.doc; | ||
}; | ||
return ConfigReader; | ||
}()); | ||
exports.configReader = new ConfigReader(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
var App = require("./app").App; | ||
new App().server.listen(3000); | ||
// const favicon = require('serve-favicon'); | ||
// app.use(express.static('public')) | ||
// app.use(favicon(__dirname + '/public/images/favicon.ico')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"use strict"; | ||
function clicked(url) { | ||
window.location = url; | ||
} | ||
function noClicked() { | ||
if (document.body.classList.contains('dark')) { | ||
window.location = 'https://blackscreen.app/'; | ||
} | ||
else { | ||
window.location = 'about:blank'; | ||
} | ||
} | ||
var yesDiv = document.getElementById('yesdiv'); | ||
var noDiv = document.getElementById('nodiv'); | ||
var lightToogle = document.getElementById('light-toogle'); | ||
lightToogle.addEventListener("click", function () { | ||
if (document.body.classList.contains('dark')) { | ||
document.body.classList.remove('dark'); | ||
document.body.classList.add('light'); | ||
} | ||
else if (document.body.classList.contains('light')) { | ||
document.body.classList.remove('light'); | ||
document.body.classList.add('dark'); | ||
} | ||
if (!document.body.classList.contains('forced')) { | ||
document.body.classList.add('forced'); | ||
} | ||
}); | ||
function registerEffect(ele, other, f) { | ||
var mc = new Hammer(ele); | ||
mc.on("hammer.input", function (ev) { | ||
if (ev.eventType == 1) { | ||
ele.classList.add('expanded'); | ||
other.classList.add('contracted'); | ||
} | ||
else if (ev.deltaTime > 2000 && ev.eventType == 2) { | ||
if (ev.pointers[0].clientX >= ele.getBoundingClientRect().left && ev.pointers[0].clientX <= ele.getBoundingClientRect().right && | ||
ev.pointers[0].clientY >= ele.getBoundingClientRect().top && ev.pointers[0].clientY <= ele.getBoundingClientRect().bottom) { | ||
mc.off("hammer.input"); | ||
f(ele.getAttribute('data-url')); | ||
} | ||
} | ||
else if (ev.eventType == 4) { | ||
ele.classList.remove('expanded'); | ||
other.classList.remove('contracted'); | ||
if (ev.deltaTime > 2000 && | ||
ev.pointers[0].clientX >= ele.getBoundingClientRect().left && ev.pointers[0].clientX <= ele.getBoundingClientRect().right && | ||
ev.pointers[0].clientY >= ele.getBoundingClientRect().top && ev.pointers[0].clientY <= ele.getBoundingClientRect().bottom) { | ||
f(ele.getAttribute('data-url')); | ||
} | ||
} | ||
}); | ||
mc.on("press", function (ev) { | ||
}); | ||
} | ||
registerEffect(yesDiv, noDiv, clicked); | ||
registerEffect(noDiv, yesDiv, noClicked); | ||
if (window.screen.height > window.screen.width) { | ||
document.body.classList.add('mobile'); | ||
} | ||
window.addEventListener('resize', function (event) { | ||
if (document.body.scrollHeight < document.body.scrollWidth) { | ||
document.body.classList.remove('mobile'); | ||
} | ||
else if (!document.body.classList.contains('mobile')) { | ||
document.body.classList.add('mobile'); | ||
} | ||
}, true); | ||
if (document.body.classList.contains('default')) { | ||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
document.body.classList.add('dark'); | ||
} | ||
else { | ||
document.body.classList.add('light'); | ||
} | ||
} | ||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function (event) { | ||
if (document.body.classList.contains('forced') || !document.body.classList.contains('default')) { | ||
return; | ||
} | ||
var newColorScheme = event.matches ? "dark" : "light"; | ||
if (!document.body.classList.contains('dark')) { | ||
document.body.classList.add('dark'); | ||
} | ||
if (!document.body.classList.contains('light')) { | ||
document.body.classList.add('light'); | ||
} | ||
document.body.classList.add(newColorScheme); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.router = void 0; | ||
var express_1 = require("express"); | ||
var CssController_1 = require("./controllers/CssController"); | ||
var ConfirmController_1 = require("./controllers/ConfirmController"); | ||
var router = (0, express_1.Router)(); | ||
exports.router = router; | ||
//Routes | ||
router.get("/css/variables.css", CssController_1.cssController.variables); | ||
router.get("/:alias", ConfirmController_1.confirmController.alias); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pages: | ||
google: http://www.google.com.br | ||
mode: auth # | ||
themes: | ||
light: | ||
default: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Request, Response } from "express"; | ||
import { configReader } from "../helpers/ConfigReader"; | ||
import url from 'url'; | ||
import Mustache from 'mustache'; | ||
|
||
class ConfirmController { | ||
|
||
public alias(req:Request, res:Response) { | ||
let doc = configReader.getDoc(); | ||
|
||
var alias = doc.pages[req.params.alias]; | ||
if(alias == undefined) { | ||
res.status(404); | ||
res.send('404 - Not found'); | ||
return; | ||
} | ||
var url_parts = url.parse(req.url, false); | ||
return res.render('confirm.mustache', { | ||
link: alias, | ||
query: url_parts.query, | ||
yes: doc.strings.yes, | ||
no: doc.strings.no, | ||
title: Mustache.render(doc.strings.window_title, {link: alias}), | ||
open_link: Mustache.render(doc.strings.open_link, {link: alias}), | ||
theme: doc.config.theme | ||
}) | ||
} | ||
} | ||
|
||
export const confirmController = new ConfirmController(); |
Oops, something went wrong.