From 780d96aa0ccfcb56116e1ee701dda08eee8b1b08 Mon Sep 17 00:00:00 2001
From: Christopher Hase
Date: Thu, 10 Apr 2025 15:16:16 +0200
Subject: [PATCH] add http-server part 6.3.2
---
dist/backend/broker.d.ts | 3 -
dist/backend/broker.d.ts.map | 1 -
dist/backend/broker.js | 131 ------------------------------
dist/backend/broker.test.d.ts | 2 -
dist/backend/broker.test.d.ts.map | 1 -
dist/backend/broker.test.js | 21 -----
dist/backend/server.d.ts | 2 -
dist/backend/server.d.ts.map | 1 -
dist/backend/server.js | 11 ---
9 files changed, 173 deletions(-)
delete mode 100644 dist/backend/broker.d.ts
delete mode 100644 dist/backend/broker.d.ts.map
delete mode 100644 dist/backend/broker.js
delete mode 100644 dist/backend/broker.test.d.ts
delete mode 100644 dist/backend/broker.test.d.ts.map
delete mode 100644 dist/backend/broker.test.js
delete mode 100644 dist/backend/server.d.ts
delete mode 100644 dist/backend/server.d.ts.map
delete mode 100644 dist/backend/server.js
diff --git a/dist/backend/broker.d.ts b/dist/backend/broker.d.ts
deleted file mode 100644
index 61adb3b..0000000
--- a/dist/backend/broker.d.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export declare function executeCommand(): void;
-export declare function html(inputText: string): string;
-//# sourceMappingURL=broker.d.ts.map
\ No newline at end of file
diff --git a/dist/backend/broker.d.ts.map b/dist/backend/broker.d.ts.map
deleted file mode 100644
index c427dc0..0000000
--- a/dist/backend/broker.d.ts.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../backend/broker.ts"],"names":[],"mappings":"AAqBA,wBAAgB,cAAc,IAAI,IAAI,CAwBrC;AAwCD,wBAAgB,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAK9C"}
\ No newline at end of file
diff --git a/dist/backend/broker.js b/dist/backend/broker.js
deleted file mode 100644
index 3c3b807..0000000
--- a/dist/backend/broker.js
+++ /dev/null
@@ -1,131 +0,0 @@
-import { exec } from 'child_process';
-import * as fs from 'fs';
-var config;
-const nodemailer = require('nodemailer');
-export function executeCommand() {
- exec('iching divine', (error, stdout, stderr) => {
- console.log(`Begin`);
- if (error) {
- console.error(`Error: ${error.message}`);
- return;
- }
- if (stderr) {
- console.error(`Stderr: ${stderr}`);
- return;
- }
- //Load config once
- if (config == undefined) {
- config = loadConfig();
- }
- console.log(`Send E-Mail`);
- sendEmail(stdout);
- });
-}
-// Run function once initially, called from Dockerfile
-executeCommand();
-// Load the Configuration
-function loadConfig() {
- console.log(`Load Config`);
- const data = fs.readFileSync('config.json', 'utf-8');
- return JSON.parse(data);
-}
-// Send E-Mail
-async function sendEmail(content) {
- // Create Transporter
- const transporter = nodemailer.createTransport({
- host: config.mailHost,
- port: config.mailPort,
- secure: false
- });
- try {
- const info = await transporter.sendMail({
- from: '"The Oracle" ',
- to: config.emailReceiver,
- subject: "Your Horoscope Is Ready",
- text: content,
- html: html(content)
- });
- console.log("E-Mail sent: ", info.messageId);
- }
- catch (error) {
- console.error("Error Sending E-Mail:", error);
- }
-}
-// Generate 1) Parse Tree and 2) HTML
-export function html(inputText) {
- const parseTree = parse(inputText);
- const htmlOutput = render(parseTree);
- return htmlOutput;
-}
-// Generate the Parse Tree
-function parse(input) {
- console.log("Parse input text");
- const root = { type: "Root" };
- var currentNode = root;
- const lines = input.split("\n");
- for (const line of lines) {
- if (line.startsWith("Hexagram")) {
- const hexagram = { type: "Hexagram" };
- currentNode.child = hexagram;
- currentNode = hexagram;
- currentNode.value = "" + line + "
";
- }
- else if (line.startsWith("Judgement")) {
- const judgement = { type: "Judgement" };
- currentNode.child = judgement;
- currentNode = judgement;
- currentNode.value = "" + line + "
";
- }
- else if (line.startsWith("Images")) {
- const images = { type: "Images" };
- currentNode.child = images;
- currentNode = images;
- currentNode.value = "" + line + "
";
- }
- else if (line.startsWith("~") && currentNode.type != "ChangingLines") {
- const changingLines = { type: "ChangingLines" };
- currentNode.child = changingLines;
- currentNode = changingLines;
- currentNode.value = line; // + "
"; TODO: try without this
- }
- else {
- currentNode.value = currentNode.value + line + "
";
- }
- }
- return root;
-}
-// Generate HTML from Parse Tree
-function render(node) {
- if (node == undefined) {
- console.log("Rendering of nodes finished!");
- return "";
- }
- console.log("Render node" + node.type);
- var outputHTML = "";
- switch (node.type) {
- case "Root":
- return render(node.child);
- case "Hexagram":
- node.value = node.value?.replace("", "");
- node.value = node.value?.replace("
", "
");
- node.value = node.value?.replace("
", " - ");
- outputHTML = "
" + node.value + "
";
- outputHTML = outputHTML + render(node.child);
- return outputHTML;
- case "Images":
- outputHTML = "
" + node.value + "
"; //EXTRA closing div (was opened at beginning of hexagram)
- outputHTML = outputHTML + render(node.child);
- return outputHTML;
- case "ChangingLines":
- const regex = new RegExp("~", "g");
- node.value = node.value?.replace(regex, "");
- //outputHTML = "
" + node.value + "
";
- outputHTML = "
" + node.value + "
";
- outputHTML = outputHTML + render(node.child);
- return outputHTML;
- default:
- outputHTML = "" + node.value + "
";
- outputHTML = outputHTML + render(node.child);
- return outputHTML;
- }
-}
diff --git a/dist/backend/broker.test.d.ts b/dist/backend/broker.test.d.ts
deleted file mode 100644
index 1be33f2..0000000
--- a/dist/backend/broker.test.d.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export {};
-//# sourceMappingURL=broker.test.d.ts.map
\ No newline at end of file
diff --git a/dist/backend/broker.test.d.ts.map b/dist/backend/broker.test.d.ts.map
deleted file mode 100644
index 64ae74c..0000000
--- a/dist/backend/broker.test.d.ts.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"broker.test.d.ts","sourceRoot":"","sources":["../../backend/broker.test.ts"],"names":[],"mappings":""}
\ No newline at end of file
diff --git a/dist/backend/broker.test.js b/dist/backend/broker.test.js
deleted file mode 100644
index e6acab6..0000000
--- a/dist/backend/broker.test.js
+++ /dev/null
@@ -1,21 +0,0 @@
-export {};
-/*import { html } from "./broker";
-import { test, beforeAll, afterAll } from "@jest/globals";
-
-jest.useFakeTimers();
-
-test("Generate HTML for hexagram", () => {
- expect(html("Hexagram No. 45 ䷬\nGathering Together [Massing]\n萃 (cuì)"))
- .toBe("
Hexagram No. 45 ䷬
Gathering Together [Massing] - 萃 (cuì)
");
-});
-
-test("Generate HTML for judgement", () => {
- expect(html("Judgement:\nGathering Together. Success.\nThe king approaches his temple.\nIt furthers one to see the great man.\nThis brings success. Perseverance furthers.\nTo bring great offerings creates good fortune.\nIt furthers one to undertake something."))
- .toBe("
Judgement:
Gathering Together. Success.
The king approaches his temple.
It furthers one to see the great man.
This brings success. Perseverance furthers.
To bring great offerings creates good fortune.
It furthers one to undertake something.
");
-});
-
-test("Generate HTML for images", () => {
- expect(html("Images:\nOver the earth, the lake:\nThe image of Gathering Together.\nThus the superior man renews his weapons\nIn order to meet the unforseen."))
- .toBe("
Images:
Over the earth, the lake:
The image of Gathering Together.
Thus the superior man renews his weapons
In order to meet the unforseen.
");
-});
-*/
diff --git a/dist/backend/server.d.ts b/dist/backend/server.d.ts
deleted file mode 100644
index 21e3405..0000000
--- a/dist/backend/server.d.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export {};
-//# sourceMappingURL=server.d.ts.map
\ No newline at end of file
diff --git a/dist/backend/server.d.ts.map b/dist/backend/server.d.ts.map
deleted file mode 100644
index aaf01ea..0000000
--- a/dist/backend/server.d.ts.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../backend/server.ts"],"names":[],"mappings":""}
\ No newline at end of file
diff --git a/dist/backend/server.js b/dist/backend/server.js
deleted file mode 100644
index b3c2186..0000000
--- a/dist/backend/server.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import express from 'express';
-import { executeCommand } from './broker.mjs';
-const app = express();
-const port = 8080;
-app.post('/api/command', (req, res) => {
- executeCommand();
- res.status(200).send('Command executed');
-});
-app.listen(port, '0.0.0.0', () => {
- console.log(`Server läuft auf http://0.0.0.0:${port}`);
-});