Author SHA1 Message Date
Kostas Drakontidis 97712364ca Initial Pi code for public lookup api 2026-05-13 23:27:55 +03:00
15 changed files with 3337 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
node_modules
.git
npm-debug.log
+5
View File
@@ -0,0 +1,5 @@
node_modules
# Keep environment variables out of version control
.env
**/generated/prisma
+19
View File
@@ -0,0 +1,19 @@
FROM node:24-slim
WORKDIR /app
RUN apt-get update -y && apt-get install -y openssl
COPY package*.json ./
RUN npm ci
COPY . .
RUN npx prisma generate
RUN npm run build
EXPOSE 80
CMD ["node", "dist/index.js"]
File diff suppressed because it is too large Load Diff
+28
View File
@@ -0,0 +1,28 @@
{
"name": "officesense",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"main": "index.js",
"type": "module",
"scripts": {
"dev": "tsx src/index.ts",
"build": "tsc",
"start": "node dist/index.js"
},
"devDependencies": {
"@types/better-sqlite3": "^7.6.13",
"@types/express": "^5.0.6",
"@types/node": "^25.7.0",
"prisma": "^7.8.0",
"tsx": "^4.21.0",
"typescript": "^6.0.3"
},
"dependencies": {
"@prisma/adapter-better-sqlite3": "^7.8.0",
"@prisma/client": "^7.8.0",
"dotenv": "^17.4.2",
"express": "^5.2.1"
}
}
+14
View File
@@ -0,0 +1,14 @@
// This file was generated by Prisma, and assumes you have installed the following:
// npm install --save-dev prisma dotenv
import "dotenv/config";
import { defineConfig } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: process.env["DATABASE_URL"],
},
});
@@ -0,0 +1,17 @@
-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL PRIMARY KEY,
"firstName" TEXT NOT NULL,
"lastName" TEXT NOT NULL,
"faceEmbedding" BLOB NOT NULL
);
-- CreateTable
CREATE TABLE "Tag" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
CONSTRAINT "Tag_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateIndex
CREATE UNIQUE INDEX "Tag_userId_key" ON "Tag"("userId");
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "sqlite"
+22
View File
@@ -0,0 +1,22 @@
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}
datasource db {
provider = "sqlite"
}
model User {
id String @id @default(uuid())
firstName String
lastName String
faceEmbedding Bytes?
tag Tag?
}
model Tag {
id String @id @default(uuid())
userId String @unique
user User @relation(fields: [userId], references: [id])
}
@@ -0,0 +1,16 @@
import type { Request, Response } from "express";
import { existsByUUID } from "./lookup.repository.js";
interface Params {
uuid: string;
}
export async function check(req: Request<Params>, res: Response) {
const { uuid } = req.params;
const exists = await existsByUUID(uuid);
if (!exists) return res.sendStatus(404);
return res.sendStatus(200);
}
@@ -0,0 +1,9 @@
import { prisma } from "../../lib/prisma.js";
export async function existsByUUID(uuid: string): Promise<boolean> {
const user = await prisma.user.findUnique({
where: { id: uuid }
});
return !!user;
}
@@ -0,0 +1,8 @@
import express from "express";
import { check } from "./lookup.controller.js";
const router = express.Router();
router.get("/check/:uuid", check);
export default router;
+12
View File
@@ -0,0 +1,12 @@
import express from "express";
import lookupRoutes from "./api/lookup/lookup.routes.js";
const app = express();
const PORT = 80;
const ADDRESS = "0.0.0.0";
app.use("/", lookupRoutes);
app.listen(PORT, ADDRESS, () => {
console.log(`Server listening on ${ADDRESS}:${PORT}`);
});
+10
View File
@@ -0,0 +1,10 @@
import "dotenv/config";
import { PrismaBetterSqlite3 } from "@prisma/adapter-better-sqlite3";
import { PrismaClient } from "../generated/prisma/client.js";
const connectionString = `${process.env.DATABASE_URL}`;
const adapter = new PrismaBetterSqlite3({ url: connectionString });
const prisma = new PrismaClient({ adapter });
export { prisma };
+49
View File
@@ -0,0 +1,49 @@
{
// Visit https://aka.ms/tsconfig to read more about this file
"compilerOptions": {
// File Layout
"rootDir": "./src",
"outDir": "./dist",
// Environment Settings
// See also https://aka.ms/tsconfig/module
"module": "NodeNext",
"target": "ES2022",
"moduleResolution": "NodeNext",
"types": [],
"esModuleInterop": true,
"ignoreDeprecations": "6.0",
// For nodejs:
// "lib": ["esnext"],
// "types": ["node"],
// and npm install -D @types/node
// Other Outputs
"sourceMap": true,
"declaration": true,
"declarationMap": true,
// Stricter Typechecking Options
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
// Style Options
// "noImplicitReturns": true,
// "noImplicitOverride": true,
// "noUnusedLocals": true,
// "noUnusedParameters": true,
// "noFallthroughCasesInSwitch": true,
// "noPropertyAccessFromIndexSignature": true,
// Recommended Options
"strict": true,
"jsx": "react-jsx",
"verbatimModuleSyntax": true,
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true,
},
"include": ["src/**/*"],
"exclude": [
"node_modules",
"generated",
"dist",
"prisma.config.ts"
]
}