i hate nim
This commit is contained in:
parent
6e222f7529
commit
4f40e59b17
17 changed files with 1439 additions and 31 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
*.db
|
*.db
|
||||||
gw
|
gw
|
||||||
|
gw.exe
|
||||||
|
gw_linkerArgs.txt
|
30
index.html
Normal file
30
index.html
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<script src="/public/standard.js"></script>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="lelelelele">
|
||||||
|
<h1>???</h1>
|
||||||
|
Referral: <input id="referral-other" type="text"></input>
|
||||||
|
<button onclick="entry()">Create entry.</button>
|
||||||
|
<br><br>
|
||||||
|
<b>What is this?</b>
|
||||||
|
<p>At exactly 00:00 CET on 1 Jan, the system will choose a random entry. Their referral key shall be publically
|
||||||
|
displayed on this page. The person associated to this referral key shall contact us with their private key.
|
||||||
|
They shall win a little prize. To have one's entry weigh more than the rest, one shall have to spread their
|
||||||
|
referral key amongst the people. Every referral shall increase their chance of getting selected.</p>
|
||||||
|
<b>How does one enter?</b>
|
||||||
|
<p>One needs a referral key to enter.</p>
|
||||||
|
<p id="referral-key"></p>
|
||||||
|
<p id="private-key"></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background-color: black;
|
||||||
|
color: #4af626;
|
||||||
|
text-align: center;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -1,4 +1,4 @@
|
||||||
import prologue, prologue/middlewares/staticfile, std/json, sysrandom, asyncdispatch, std/strutils, db_connector/db_sqlite, std/asyncnet
|
import prologue, prologue/middlewares/staticfile, prologue/middlewares/cors, std/json, sysrandom, asyncdispatch, std/strutils, db_connector/db_sqlite, std/asyncnet
|
||||||
|
|
||||||
const key_len = 128
|
const key_len = 128
|
||||||
const refer_len = 16
|
const refer_len = 16
|
||||||
|
@ -52,6 +52,8 @@ proc gentry*(ctx: Context) {.async.} =
|
||||||
resp jsonResponse(info)
|
resp jsonResponse(info)
|
||||||
|
|
||||||
var app = newApp()
|
var app = newApp()
|
||||||
|
|
||||||
|
app.use(CorsMiddleware(allowOrigins = @["*"], allowHeaders = @["*"], allowMethods = @["*"]))
|
||||||
app.use(staticFileMiddleware("./public"))
|
app.use(staticFileMiddleware("./public"))
|
||||||
app.addRoute("/", index)
|
app.addRoute("/", index)
|
||||||
app.addRoute("/entry", gentry)
|
app.addRoute("/entry", gentry)
|
||||||
|
|
19
taskfile.yml
Normal file
19
taskfile.yml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
build:
|
||||||
|
cmds:
|
||||||
|
# build backend
|
||||||
|
- rm gw
|
||||||
|
- nimble c -d:usestd src/gw.nim -o:gw
|
||||||
|
# build frontend
|
||||||
|
- cd web
|
||||||
|
- pnpm install
|
||||||
|
- pnpm run build
|
||||||
|
dev-backend:
|
||||||
|
cmds:
|
||||||
|
- nimble c -d:usestd -r src/gw.nim -o:gw
|
||||||
|
dev-frontend:
|
||||||
|
dir: ./web
|
||||||
|
cmds:
|
||||||
|
- pnpm run dev
|
24
web/.gitignore
vendored
Normal file
24
web/.gitignore
vendored
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
15
web/README.md
Normal file
15
web/README.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# `create-preact`
|
||||||
|
|
||||||
|
<h2 align="center">
|
||||||
|
<img height="256" width="256" src="./src/assets/preact.svg">
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<h3 align="center">Get started using Preact and Vite!</h3>
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
- `pnpm dev` - Starts a dev server at http://localhost:5173/
|
||||||
|
|
||||||
|
- `pnpm build` - Builds for production, emitting to `dist/`
|
||||||
|
|
||||||
|
- `pnpm preview` - Starts a server at http://localhost:4173/ to test production build locally
|
|
@ -1,30 +1,14 @@
|
||||||
<script src="/public/standard.js"></script>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html lang="en">
|
||||||
|
<head>
|
||||||
<body>
|
<meta charset="UTF-8" />
|
||||||
<div id="lelelelele">
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<h1>???</h1>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
Referral: <input id="referral-other" type="text"></input>
|
<meta name="color-scheme" content="light dark" />
|
||||||
<button onclick="entry()">Create entry.</button>
|
<title>Vite + Preact</title>
|
||||||
<br><br>
|
</head>
|
||||||
<b>What is this?</b>
|
<body>
|
||||||
<p>At exactly 00:00 CET on 1 Jan, the system will choose a random entry. Their referral key shall be publically
|
<div id="app"></div>
|
||||||
displayed on this page. The person associated to this referral key shall contact us with their private key.
|
<script type="module" src="/src/index.tsx"></script>
|
||||||
They shall win a little prize. To have one's entry weigh more than the rest, one shall have to spread their
|
</body>
|
||||||
referral key amongst the people. Every referral shall increase their chance of getting selected.</p>
|
|
||||||
<b>How does one enter?</b>
|
|
||||||
<p>One needs a referral key to enter.</p>
|
|
||||||
<p id="referral-key"></p>
|
|
||||||
<p id="private-key"></p>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
background-color: black;
|
|
||||||
color: #4af626;
|
|
||||||
text-align: center;
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
18
web/package.json
Normal file
18
web/package.json
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"preact": "^10.25.3",
|
||||||
|
"preact-iso": "^2.8.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@preact/preset-vite": "^2.9.3",
|
||||||
|
"typescript": "^5.7.2",
|
||||||
|
"vite": "^6.0.4"
|
||||||
|
}
|
||||||
|
}
|
1155
web/pnpm-lock.yaml
Normal file
1155
web/pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load diff
15
web/public/vite.svg
Normal file
15
web/public/vite.svg
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257">
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%">
|
||||||
|
<stop offset="0%" stop-color="#41D1FF"></stop>
|
||||||
|
<stop offset="100%" stop-color="#BD34FE"></stop>
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%">
|
||||||
|
<stop offset="0%" stop-color="#FFEA83"></stop>
|
||||||
|
<stop offset="8.333%" stop-color="#FFDD35"></stop>
|
||||||
|
<stop offset="100%" stop-color="#FFA800"></stop>
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path>
|
||||||
|
<path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
6
web/src/assets/preact.svg
Normal file
6
web/src/assets/preact.svg
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="27.68" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 296">
|
||||||
|
<path fill="#673AB8" d="m128 0l128 73.9v147.8l-128 73.9L0 221.7V73.9z"></path>
|
||||||
|
<path fill="#FFF" d="M34.865 220.478c17.016 21.78 71.095 5.185 122.15-34.704c51.055-39.888 80.24-88.345 63.224-110.126c-17.017-21.78-71.095-5.184-122.15 34.704c-51.055 39.89-80.24 88.346-63.224 110.126Zm7.27-5.68c-5.644-7.222-3.178-21.402 7.573-39.253c11.322-18.797 30.541-39.548 54.06-57.923c23.52-18.375 48.303-32.004 69.281-38.442c19.922-6.113 34.277-5.075 39.92 2.148c5.644 7.223 3.178 21.403-7.573 39.254c-11.322 18.797-30.541 39.547-54.06 57.923c-23.52 18.375-48.304 32.004-69.281 38.441c-19.922 6.114-34.277 5.076-39.92-2.147Z"></path>
|
||||||
|
<path fill="#FFF" d="M220.239 220.478c17.017-21.78-12.169-70.237-63.224-110.126C105.96 70.464 51.88 53.868 34.865 75.648c-17.017 21.78 12.169 70.238 63.224 110.126c51.055 39.889 105.133 56.485 122.15 34.704Zm-7.27-5.68c-5.643 7.224-19.998 8.262-39.92 2.148c-20.978-6.437-45.761-20.066-69.28-38.441c-23.52-18.376-42.74-39.126-54.06-57.923c-10.752-17.851-13.218-32.03-7.575-39.254c5.644-7.223 19.999-8.261 39.92-2.148c20.978 6.438 45.762 20.067 69.281 38.442c23.52 18.375 42.739 39.126 54.06 57.923c10.752 17.85 13.218 32.03 7.574 39.254Z"></path>
|
||||||
|
<path fill="#FFF" d="M127.552 167.667c10.827 0 19.603-8.777 19.603-19.604c0-10.826-8.776-19.603-19.603-19.603c-10.827 0-19.604 8.777-19.604 19.603c0 10.827 8.777 19.604 19.604 19.604Z"></path>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
22
web/src/index.tsx
Normal file
22
web/src/index.tsx
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import { render } from 'preact';
|
||||||
|
import { LocationProvider, Route, Router } from 'preact-iso';
|
||||||
|
|
||||||
|
import { NotFound } from './pages/_404.jsx';
|
||||||
|
import { Error } from './pages/Error/index.js';
|
||||||
|
import { Home } from './pages/Home/index.jsx';
|
||||||
|
|
||||||
|
export function App() {
|
||||||
|
return (
|
||||||
|
<LocationProvider>
|
||||||
|
<main>
|
||||||
|
<Router>
|
||||||
|
<Route path="/" component={Home} />
|
||||||
|
<Route default component={NotFound} />
|
||||||
|
<Route path="/error" component={Error} />
|
||||||
|
</Router>
|
||||||
|
</main>
|
||||||
|
</LocationProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
render(<App />, document.getElementById('app'));
|
5
web/src/pages/Error/index.tsx
Normal file
5
web/src/pages/Error/index.tsx
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export const Error = () => {
|
||||||
|
return (
|
||||||
|
<h1 style="font-weight:bold;color:red">Do not mess with me.</h1>
|
||||||
|
)
|
||||||
|
};
|
73
web/src/pages/Home/index.tsx
Normal file
73
web/src/pages/Home/index.tsx
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
|
|
||||||
|
type EntryBody = {
|
||||||
|
err: boolean;
|
||||||
|
referral: string;
|
||||||
|
key: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const Home = () => {
|
||||||
|
const [referral, setReferral] = useState('');
|
||||||
|
const [entryBody, setEntryBody] = useState<EntryBody | null>({
|
||||||
|
err: true,
|
||||||
|
referral: '',
|
||||||
|
key: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log('Referral:', referral);
|
||||||
|
}, [referral]);
|
||||||
|
|
||||||
|
const entry = async () => {
|
||||||
|
let res = await fetch("http://localhost:8080/entry", {
|
||||||
|
method: 'GET',
|
||||||
|
headers: { referral }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
console.error('Error:', res.status);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let body: EntryBody = await res.json();
|
||||||
|
|
||||||
|
if (body.err) {
|
||||||
|
console.error('Error:', body.referral);
|
||||||
|
window.location.href = '/error';
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Entry:', body);
|
||||||
|
|
||||||
|
setEntryBody(body);
|
||||||
|
|
||||||
|
setReferral('');
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1>???</h1>
|
||||||
|
<div>
|
||||||
|
<span>
|
||||||
|
Referral: <input type="text" value={referral} onInput={(e) => setReferral(e.currentTarget.value)} />
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<button onClick={async () => await entry()}>Submit</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{
|
||||||
|
!entryBody.err && (
|
||||||
|
<>
|
||||||
|
<h2>Key: {entryBody?.key}</h2>
|
||||||
|
<h2>Referral: {entryBody?.referral}</h2>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
};
|
8
web/src/pages/_404.tsx
Normal file
8
web/src/pages/_404.tsx
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
export function NotFound() {
|
||||||
|
return (
|
||||||
|
<section>
|
||||||
|
<h1>404: Not Found</h1>
|
||||||
|
<p>It's gone :(</p>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
20
web/tsconfig.json
Normal file
20
web/tsconfig.json
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"noEmit": true,
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
|
||||||
|
/* Preact Config */
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"paths": {
|
||||||
|
"react": ["./node_modules/preact/compat/"],
|
||||||
|
"react-dom": ["./node_modules/preact/compat/"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": ["node_modules/vite/client.d.ts", "**/*"]
|
||||||
|
}
|
10
web/vite.config.ts
Normal file
10
web/vite.config.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import preact from '@preact/preset-vite';
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [preact()],
|
||||||
|
server: {
|
||||||
|
cors: true
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in a new issue