Forgot to generate id for log events

This commit is contained in:
Martin Kleinschrodt 2022-07-29 17:58:49 +02:00
parent cc092fae03
commit 3736fac4c5
2 changed files with 14 additions and 0 deletions

View File

@ -21,6 +21,18 @@ export async function uuid(): Promise<string> {
].join("-");
}
/**
* Generates a random UUID v4
* NOT CRYPTOGRAPHICALLY SAFE!
*/
export function unsafeUUID(): string {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
/** Caracters, by category */
export const chars = {
numbers: "0123456789",

View File

@ -1,4 +1,5 @@
import { Logger, LogEvent } from "@padloc/core/src/logging";
import { unsafeUUID } from "@padloc/core/src/util";
import { PostgresStorage } from "../storage/postgres";
export class PostgresLogger implements Logger {
@ -6,6 +7,7 @@ export class PostgresLogger implements Logger {
log(type: string, data?: any) {
const event = new LogEvent(type, data);
event.id = unsafeUUID();
(async () => {
try {
this._storage.save(event);