Skip to content

Commit

Permalink
Just trying it out
Browse files Browse the repository at this point in the history
  • Loading branch information
strawmelonjuice committed Aug 7, 2024
1 parent 9888a04 commit 8f65788
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
9 changes: 8 additions & 1 deletion source/Plugin-runners/node-plugin-api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,14 @@ export class CynthiaWebResponderApi {
}
}

export const CynthiaPassed = {};
export const CynthiaPassed = {
/*
* This is a simplefied version of the Cynthia and CynthiaWebResponderApi classes.
* It is used to pass the Cynthia object to the modifyOutputHTML and modifyBodyHTML
* (the string_passing_) functions.
* Currently, it's quite empty, but it will be expanded in the future.
*/
};

export namespace Incoming {
export interface WebRequest {
Expand Down
50 changes: 45 additions & 5 deletions source/Plugin-runners/node-plugin-runner/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import * as CynthiaPluginAPI from "cynthia-plugin-api/main";
import { Cynthia } from "cynthia-plugin-api/main";
import * as process from "node:process";

import { terminalOut as console } from "../../node-plugin-api/main";
import {
terminalOut as console,
CynthiaPassed,
} from "../../node-plugin-api/main";
import * as handlebars from "handlebars";
import * as fs from "node:fs";
import path from "node:path";

console.info("Node plugin server starting in " + process.argv0);
const cynthiabase = {
Expand All @@ -22,8 +26,10 @@ const cynthiabase = {
],
modifyBodyHTML: [
(htmlin: string, Cynthia: typeof CynthiaPluginAPI.CynthiaPassed) => {
// Make no changes. Return unchanged.
return htmlin;
// Return with a little comment.
return (
htmlin + "\n<!-- test... Body modifier Node plugins enabled! -->\n"
);
},
],
requestOptions: [
Expand All @@ -36,6 +42,40 @@ const cynthiabase = {
},
],
};

fs.readdirSync("./plugins", { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name)
.forEach((pluginfolder: string) => {
if (pluginfolder.endsWith("-disabled")) return;
function linklog(displaylinked) {}
const plugin_package_json = require(
path.join(__dirname, "/../", "plugins/", pluginfolder, "/package.json"),
);

const plugin = require(
path.join(
__dirname,
"/../",
"plugins/",
pluginfolder,
plugin_package_json.main,
),
);
// if (plugin.CyntiaPluginCompat !== CynthiaPluginLoaderVersion) {
// return;
// }
if (typeof plugin.modifyOutputHTML === "function") {
cynthiabase.modifyOutputHTML.push(plugin.modifyOutputHTML);
}
if (typeof plugin.requestOptions === "function") {
cynthiabase.requestOptions.push(plugin.expressActions);
}
if (typeof plugin.modifyBodyHTML === "function") {
cynthiabase.modifyBodyHTML.push(plugin.modifyBodyHTML);
}
});

process.stdin.resume();
process.stdin.on("data", handle);

Expand Down Expand Up @@ -70,11 +110,11 @@ async function handle(buffer: Buffer) {
const html = compiled(request.body.template_data);
let page = html;
cynthiabase.modifyBodyHTML.forEach((modifier) => {
page = modifier(page /*, Cynthia*/);
page = modifier(page, CynthiaPassed);
});
const response = new CynthiaPluginAPI.OkStringResponse(
request.id,
html,
page,
);
return Cynthia.send(response);
} catch (e) {
Expand Down

0 comments on commit 8f65788

Please sign in to comment.