Highlight und neue ID
This commit is contained in:
@@ -5,4 +5,4 @@ export enum TokenType {
|
||||
Verify
|
||||
}
|
||||
|
||||
export type TokenData = { uid: string, typ: TokenType, exp: number }
|
||||
export type TokenData = { id: string, typ: TokenType, exp: number }
|
||||
@@ -6,22 +6,23 @@ export const API_REFRESH_TOKEN_COOKIE_NAME = "refreshToken";
|
||||
export const API_UID_COOKIE_NAME = "uid";
|
||||
|
||||
export enum VALID_UUID_PREFIXES {
|
||||
"auf" = "Aufnahme",
|
||||
"obj" = "Objekt",
|
||||
"vaw" = "Verbrauchsausweis Wohnen",
|
||||
"vag" = "Verbrauchsausweis Gewerbe",
|
||||
"baw" = "Bedarfsausweis Wohnen",
|
||||
"bag" = "Bedarfsausweis Gewerbe",
|
||||
"usr" = "User",
|
||||
"ant" = "Anteilshaber",
|
||||
"evt" = "Event",
|
||||
"img" = "Bild",
|
||||
"inv" = "Rechnung",
|
||||
"tkt" = "Ticket",
|
||||
"pln" = "Gebäude Plan",
|
||||
"gnw" = "GEG Nachweis Wohnen",
|
||||
"gng" = "GEG Nachweis Gewerbe",
|
||||
"gge" = "GEG Einpreisung",
|
||||
Aufnahme = "AU",
|
||||
Objekt = "OB",
|
||||
VerbrauchsausweisWohnen = "VW",
|
||||
VerbrauchsausweisGewerbe = "VG",
|
||||
BedarfsausweisWohnen = "BW",
|
||||
BedarfsausweisGewerbe = "BG",
|
||||
User = "US",
|
||||
Anteilshaber = "AN",
|
||||
Event = "EV",
|
||||
Bild = "BI",
|
||||
Rechnung = "RE",
|
||||
Ticket = "TK",
|
||||
GebaeudePlan = "PN",
|
||||
GEGNachweisWohnen = "GW",
|
||||
GEGNachweisGewerbe = "GG",
|
||||
GEGEinpreisung = "GE",
|
||||
Unterlage = "UN"
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
37
src/lib/db.ts
Normal file
37
src/lib/db.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import * as crypto from "crypto";
|
||||
|
||||
/**
|
||||
* Generiert eine ID bestimmter Länge für die Datenbank, Implementierung kopiert von https://www.npmjs.com/package/crypto-random-string
|
||||
* @param length Die Länge der generierten ID
|
||||
* @param prefix Ein Optionales Präfix, welches vor die ID geschrieben wird, damit diese identifizierbar bleibt.
|
||||
* @returns Die generierte ID
|
||||
*/
|
||||
export function generatePrefixedId(length: number, prefix: string = ""): string {
|
||||
// Generating entropy is faster than complex math operations, so we use the simplest way
|
||||
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
|
||||
const characterCount = characters.length;
|
||||
const maxValidSelector = (Math.floor(0x1_00_00 / characterCount) * characterCount) - 1; // Using values above this will ruin distribution when using modular division
|
||||
const entropyLength = 2 * Math.ceil(1.1 * length); // Generating a bit more than required so chances we need more than one pass will be really low
|
||||
let string = '';
|
||||
let stringLength = 0;
|
||||
|
||||
while (stringLength < length) { // In case we had many bad values, which may happen for character sets of size above 0x8000 but close to it
|
||||
const entropy = crypto.randomBytes(entropyLength);
|
||||
let entropyPosition = 0;
|
||||
|
||||
while (entropyPosition < entropyLength && stringLength < length) {
|
||||
const entropyValue = readUInt16LE(entropy, entropyPosition);
|
||||
entropyPosition += 2;
|
||||
if (entropyValue > maxValidSelector) { // Skip values which will ruin distribution when using modular division
|
||||
continue;
|
||||
}
|
||||
|
||||
string += characters[entropyValue % characterCount];
|
||||
stringLength++;
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + string;
|
||||
}
|
||||
|
||||
const readUInt16LE = (uInt8Array: Buffer<ArrayBufferLike>, offset: number) => uInt8Array[offset] + (uInt8Array[offset + 1] << 8);
|
||||
@@ -67,7 +67,7 @@ export async function checkAuthorizationHeader(authorization: string) {
|
||||
|
||||
const user = await prisma.benutzer.findUnique({
|
||||
where: {
|
||||
uid: payload.uid
|
||||
id: payload.id
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
|
||||
/**
|
||||
* Gibt den richtigen Prisma Adapter für die Ausweisart basierend auf der UID zurück, oder null bei einer falschen UID.
|
||||
* @param uid Die Ausweis UID
|
||||
* @param id Die Ausweis UID
|
||||
*/
|
||||
export function getPrismaAusweisAdapter(uid: string) {
|
||||
const ausweisart = getAusweisartFromUUID(uid);
|
||||
export function getPrismaAusweisAdapter(id: string) {
|
||||
const ausweisart = getAusweisartFromUUID(id);
|
||||
|
||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
return prisma.verbrauchsausweisWohnen
|
||||
|
||||
Reference in New Issue
Block a user