Skip to content

Commit

Permalink
Merge pull request #1 from lelemm/typescript
Browse files Browse the repository at this point in the history
Typescript
  • Loading branch information
lelemm authored Mar 1, 2024
2 parents 1436371 + b3da3f4 commit 685c232
Show file tree
Hide file tree
Showing 24 changed files with 870 additions and 124 deletions.
9 changes: 9 additions & 0 deletions docker-compose.yml
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
7 changes: 7 additions & 0 deletions src/.dockerignore
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
15 changes: 12 additions & 3 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
FROM node:slim

FROM node:slim as builder
WORKDIR /app

COPY package.json ./
COPY tsconfig.json ./
COPY . .
RUN npm install
RUN npm run build

FROM node:slim as final
WORKDIR /app

COPY package.json ./
RUN npm install --only=production
COPY --from=builder /app/build .
COPY --from=builder /app/public ./public/

CMD [ "node", "index.js" ]

Expand Down
29 changes: 29 additions & 0 deletions src/app.ts
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);
}
}
28 changes: 28 additions & 0 deletions src/build/app.js
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;
34 changes: 34 additions & 0 deletions src/build/controllers/ConfirmController.js
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();
51 changes: 51 additions & 0 deletions src/build/controllers/CssController.js
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();
28 changes: 28 additions & 0 deletions src/build/helpers/ConfigReader.js
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();
6 changes: 6 additions & 0 deletions src/build/index.js
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'));
13 changes: 8 additions & 5 deletions src/models/ConfirmModel.js → src/build/models/ConfirmModel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class ConfirmModel {
constructor() {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfirmModel = void 0;
var ConfirmModel = /** @class */ (function () {
function ConfirmModel() {
this.sizeW = '50';
this.sizeH = '100';
this.expandedW = '90';
Expand All @@ -19,6 +22,6 @@ class ConfirmModel {
this.customThemeActiveYes = '';
this.customThemeActiveNo = '';
}
}

module.exports = { ConfirmModel }
return ConfirmModel;
}());
exports.ConfirmModel = ConfirmModel;
89 changes: 89 additions & 0 deletions src/build/public/scripts/actions.js
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);
});
11 changes: 11 additions & 0 deletions src/build/router.js
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);
1 change: 1 addition & 0 deletions src/config.yml
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:
Expand Down
30 changes: 30 additions & 0 deletions src/controllers/ConfirmController.ts
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();
Loading

0 comments on commit 685c232

Please sign in to comment.