This commit is contained in:
parent
d82e150eaa
commit
c0ed70e3b6
@ -5,7 +5,6 @@ ADD bun.lockb bun.lockb
|
||||
ADD package.json package.json
|
||||
ADD tsconfig.json tsconfig.json
|
||||
|
||||
|
||||
# install all deps
|
||||
RUN bun install
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
lnurl_db:
|
||||
container_name: lnurl-db
|
||||
image: gitea.chromart.dynv6.net/martin/lnurl-db:latest
|
||||
doorman:
|
||||
container_name: doorman
|
||||
image: gitea.chromart.dedyn.io/martin/doorman:latest
|
||||
environment:
|
||||
- CHALLENGE_EXPIRE_MS=105000
|
||||
- BASE_DOMAIN=chromart.dynv6.net
|
||||
- BASE_DOMAIN=gitea.chromart.dedyn.io
|
||||
- REDIS_CONNECT_URL=redis://@redis:6379
|
||||
depends_on:
|
||||
- redis
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "lnurl-db",
|
||||
"name": "doorman",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"workspaces": ["packages/*"],
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "lnurl-db-client",
|
||||
"name": "doorman-client",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "lnurl-db-server",
|
||||
"name": "doorman-server",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
|
||||
@ -79,4 +79,8 @@ export class RedisDbClient<A extends RedisModules, B extends RedisFunctions, C e
|
||||
public async remove(key: string): Promise<string | null> {
|
||||
return this.client.getDel(key);
|
||||
}
|
||||
|
||||
public getClient() {
|
||||
return this.client;
|
||||
}
|
||||
}
|
||||
30
packages/server/src/routers/DoorRouter.ts
Normal file
30
packages/server/src/routers/DoorRouter.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import express from "express";
|
||||
import { getRedisClient } from "../clients/db/RedisDbProvider";
|
||||
import { IDoor } from "../types/IDoor";
|
||||
import { RedisKeys, concatKeys } from "../types/RedisKeys";
|
||||
|
||||
const router = express.Router();
|
||||
const client = await getRedisClient();
|
||||
|
||||
router.post('/:id', async(req, res) => {
|
||||
const door: IDoor = req.body;
|
||||
|
||||
await client.getClient().hSet(concatKeys(RedisKeys.DOORS, req.params.id), {
|
||||
...door
|
||||
});
|
||||
|
||||
res.status(200).json(door);
|
||||
});
|
||||
|
||||
router.get('/:id/status', async(req, res) => {
|
||||
const isOpen = await client.getClient().exists(concatKeys(RedisKeys.DOORS, req.params.id, 'open'));
|
||||
|
||||
if (isOpen) {
|
||||
res.status(200).json({ status: 'open' });
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(401).json({ status: 'closed' });
|
||||
});
|
||||
|
||||
export default router;
|
||||
@ -3,6 +3,7 @@ import fileUpload from "express-fileupload";
|
||||
import { challengeLimiter, uploadDownloadLimiter } from "./util/RateLimits";
|
||||
import LnurlRouter from "./routers/LnurlRouter";
|
||||
import ActionRouter from "./routers/ActionRouter";
|
||||
import DoorRouter from "./routers/DoorRouter";
|
||||
|
||||
const app = express();
|
||||
|
||||
@ -21,6 +22,7 @@ app.use(express.static("dist"));
|
||||
// use routers
|
||||
app.use('/api/lnurl', LnurlRouter);
|
||||
app.use('/api/actions', ActionRouter);
|
||||
app.use('/api/door', DoorRouter);
|
||||
|
||||
app.listen(5000, async () => {
|
||||
console.log("listening on port 5000");
|
||||
|
||||
4
packages/server/src/types/IDoor.ts
Normal file
4
packages/server/src/types/IDoor.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface IDoor {
|
||||
id: string;
|
||||
open?: string;
|
||||
}
|
||||
@ -1,3 +1,8 @@
|
||||
export enum RedisKeys {
|
||||
CHALLENGES = "challenges",
|
||||
DOORS = "doors"
|
||||
}
|
||||
|
||||
export function concatKeys(...keys: String[]) {
|
||||
return keys.join(':');
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user