Skip to content

Commit 4e15e33

Browse files
committed
gui and server added
1 parent 4782f02 commit 4e15e33

37 files changed

+1136
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
node_modules
3+
package-lock.json

api/.gitignore

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
saves
10+
package-lock.json
11+
# Diagnostic reports (https://nodejs.org/api/report.html)
12+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
*.lcov
26+
27+
# nyc test coverage
28+
.nyc_output
29+
30+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
31+
.grunt
32+
33+
# Bower dependency directory (https://bower.io/)
34+
bower_components
35+
36+
# node-waf configuration
37+
.lock-wscript
38+
39+
# Compiled binary addons (https://nodejs.org/api/addons.html)
40+
build/Release
41+
42+
# Dependency directories
43+
node_modules/
44+
jspm_packages/
45+
46+
# Snowpack dependency directory (https://snowpack.dev/)
47+
web_modules/
48+
49+
# TypeScript cache
50+
*.tsbuildinfo
51+
52+
# Optional npm cache directory
53+
.npm
54+
55+
# Optional eslint cache
56+
.eslintcache
57+
58+
# Optional stylelint cache
59+
.stylelintcache
60+
61+
# Microbundle cache
62+
.rpt2_cache/
63+
.rts2_cache_cjs/
64+
.rts2_cache_es/
65+
.rts2_cache_umd/
66+
67+
# Optional REPL history
68+
.node_repl_history
69+
70+
# Output of 'npm pack'
71+
*.tgz
72+
73+
# Yarn Integrity file
74+
.yarn-integrity
75+
76+
# dotenv environment variable files
77+
.env
78+
.env.development.local
79+
.env.test.local
80+
.env.production.local
81+
.env.local
82+
83+
# parcel-bundler cache (https://parceljs.org/)
84+
.cache
85+
.parcel-cache
86+
87+
# Next.js build output
88+
.next
89+
out
90+
91+
# Nuxt.js build / generate output
92+
.nuxt
93+
dist
94+
95+
# Gatsby files
96+
.cache/
97+
# Comment in the public line in if your project uses Gatsby and not Next.js
98+
# https://nextjs.org/blog/next-9-1#public-directory-support
99+
# public
100+
101+
# vuepress build output
102+
.vuepress/dist
103+
104+
# vuepress v2.x temp and cache directory
105+
.temp
106+
.cache
107+
108+
# Docusaurus cache and generated files
109+
.docusaurus
110+
111+
# Serverless directories
112+
.serverless/
113+
114+
# FuseBox cache
115+
.fusebox/
116+
117+
# DynamoDB Local files
118+
.dynamodb/
119+
120+
# TernJS port file
121+
.tern-port
122+
123+
# Stores VSCode versions used for testing VSCode extensions
124+
.vscode-test
125+
126+
# yarn v2
127+
.yarn/cache
128+
.yarn/unplugged
129+
.yarn/build-state.yml
130+
.yarn/install-state.gz
131+
.pnp.*

api/nodes.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const express = require('express')
2+
const init = node => {
3+
const getSub = async (req, res) => {
4+
try {
5+
console.log(req.params.id);
6+
console.log(req.body);
7+
req.body.rootKey.publicKey = Buffer.from(Object.values(req.body.rootKey.publicKey));
8+
req.body.rootKey.secretKey = Buffer.from(Object.values(req.body.rootKey.secretKey));
9+
const output = node.getSub(req.body.rootKey, req.params.id);
10+
if (typeof output == "object") res.write(JSON.stringify(output));
11+
else if (typeof output == "string") res.write(output);
12+
res.status(200).end()
13+
} catch (err) {
14+
console.log(err)
15+
res.write(JSON.stringify(err));
16+
res.status(500).end()
17+
}
18+
};
19+
const findNodes = async (req, res) => {
20+
try {
21+
console.log(req.params.id)
22+
console.log(req.body)
23+
req.body.key.publicKey = Buffer.from(Object.values(req.body.key.publicKey.data))
24+
console.log(req.body.key.publicKey.toString('hex'))
25+
const results = await node.lookup(req.body.key.publicKey.toString('hex'))
26+
const output = [];
27+
for (remote of results) {
28+
for (peer of remote.peers) {
29+
const hex = peer.publicKey.toString('hex');
30+
if (!output.includes(hex)) {
31+
output.push(hex)
32+
}
33+
}
34+
}
35+
36+
console.log('output', output)
37+
if (typeof output == "object") res.write(JSON.stringify(output))
38+
else if (typeof output == "string") res.write(output)
39+
res.status(200).end()
40+
} catch (err) {
41+
console.log(err)
42+
res.write(JSON.stringify(err));
43+
res.status(500).end()
44+
}
45+
};
46+
const startNode = (req, res) => {
47+
try {
48+
req.body.hostKey.publicKey = Buffer.from(Object.values(req.body.hostKey.publicKey));
49+
req.body.hostKey.secretKey = Buffer.from(Object.values(req.body.hostKey.secretKey));
50+
const output = node.run(sub, "startNode", {
51+
name: req.params.name
52+
});
53+
54+
if (typeof output == "object") res.write(JSON.stringify(output));
55+
else if (typeof output == "string") res.write(output);
56+
res.status(200).end()
57+
} catch (err) {
58+
console.log(err)
59+
res.write(JSON.stringify(err));
60+
res.status(500).end()
61+
}
62+
};
63+
const router = express.Router();
64+
router.get("/callNode/:name", startNode);
65+
router.post("/findNodes/:name", findNodes);
66+
router.post("/getSub/:id", getSub);
67+
return router
68+
};
69+
module.exports = init;

api/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "svelte-tailwind-gui",
3+
"version": "1.0.0",
4+
"scripts": {},
5+
"dependencies": {
6+
"dotenv": "^16.3.1",
7+
"express": "^4.18.2",
8+
"hyper-ipc-secure": "latest",
9+
"hypercore-crypto": "^3.4.0"
10+
}
11+
}

api/server.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Loads the environment variables and starts the server.
3+
*/
4+
require("dotenv").config();
5+
const express = require("express");
6+
const nodes = require("./nodes.js");
7+
const fs = require("fs");
8+
const node = require("hyper-ipc-secure")();
9+
/**
10+
* Creates a folder if it doesn't exist.
11+
* @param {string} folderPath - The path of the folder.
12+
*/
13+
function createFolderIfNotExists(folderPath) {
14+
if (!fs.existsSync(folderPath)) {
15+
// If the folder doesn't exist, create it
16+
fs.mkdirSync(folderPath);
17+
console.log(`Folder "${folderPath}" created.`)
18+
} else {
19+
console.log(`Folder "${folderPath}" already exists.`)
20+
}
21+
}
22+
createFolderIfNotExists("saves");
23+
const app = express();
24+
const port = process.env.PORT || 3011;
25+
app.use(express.json());
26+
app.use(express.urlencoded({
27+
extended: true
28+
}));
29+
app.use((function(req, res, next) {
30+
res.setHeader("Access-Control-Allow-Origin", "*");
31+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE");
32+
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type");
33+
res.setHeader("Access-Control-Allow-Credentials", true);
34+
next()
35+
}));
36+
const vault = nodes(node);
37+
console.log(vault)
38+
app.use("/vault/", vault);
39+
app.use(express.static('public'));
40+
app.listen(port, (() => {
41+
console.log(`Example app listening on port ${port}`)
42+
}));

api/transformed.out

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#^App.svelte&^<script>
2+
import { onMount } from 'svelte';
3+
import { get } from 'svelte/store';
4+
import { names, selectedName } from './store.js';
5+
6+
onMount(async () => {
7+
const response = await fetch('/api/names');
8+
const data = await response.json();
9+
names.set(data);
10+
});
11+
12+
function selectName(name) {
13+
selectedName.set(name);
14+
}
15+
</script>
16+
17+
<div class="flex">
18+
<div class="w-1/4 bg-gray-200 p-4">
19+
<h2 class="text-lg font-bold mb-4">Names</h2>
20+
{#each $names as name}
21+
<div class="cursor-pointer mb-2" on:click={() => selectName(name)}>
22+
{name}
23+
</div>
24+
{/each}
25+
</div>
26+
<div class="w-3/4 p-4">
27+
{#if $selectedName}
28+
<NameDetails />
29+
{/if}
30+
</div>
31+
</div>
32+
33+
<style>
34+
.flex {
35+
display: flex;
36+
}
37+
.bg-gray-200 {
38+
background-color: #edf2f7;
39+
}
40+
.p-4 {
41+
padding: 1rem;
42+
}
43+
.text-lg {
44+
font-size: 1.125rem;
45+
}
46+
.font-bold {
47+
font-weight: 700;
48+
}
49+
.mb-4 {
50+
margin-bottom: 1rem;
51+
}
52+
.mb-2 {
53+
margin-bottom: 0.5rem;
54+
}
55+
.cursor-pointer {
56+
cursor: pointer;
57+
}
58+
.w-1/4 {
59+
width: 25%;
60+
}
61+
.w-3/4 {
62+
width: 75%;
63+
}
64+
</style>

gui/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
.vercel
10+
.output
11+
vite.config.js.timestamp-*
12+
vite.config.ts.timestamp-*

gui/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

gui/.prettierignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
10+
# Ignore files for PNPM, NPM and YARN
11+
pnpm-lock.yaml
12+
package-lock.json
13+
yarn.lock

gui/.prettierrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"useTabs": true,
3+
"singleQuote": true,
4+
"trailingComma": "none",
5+
"printWidth": 100,
6+
"plugins": ["prettier-plugin-svelte"],
7+
"pluginSearchDirs": ["."],
8+
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
9+
}

0 commit comments

Comments
 (0)