mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 07:37:11 +01:00
Updated components build.
This commit is contained in:
parent
5f27ba149b
commit
56af91950a
53 changed files with 942 additions and 333 deletions
|
|
@ -2,7 +2,8 @@ import bcrypt from 'bcryptjs';
|
|||
import redis from '@/lib/redis';
|
||||
import debug from 'debug';
|
||||
import { ROLE_PERMISSIONS, ROLES, SHARE_TOKEN_HEADER } from '@/lib/constants';
|
||||
import { secret, getRandomChars } from '@/lib/crypto';
|
||||
import { secret } from '@/lib/crypto';
|
||||
import { getRandomChars } from '@/lib/generate';
|
||||
import { createSecureToken, parseSecureToken, parseToken } from '@/lib/jwt';
|
||||
import { ensureArray } from '@/lib/utils';
|
||||
import { getUser } from '@/queries';
|
||||
|
|
@ -36,12 +37,10 @@ export async function checkAuth(request: Request) {
|
|||
}
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
log('checkAuth:', { token, shareToken, payload, user, grant });
|
||||
}
|
||||
log({ token, shareToken, payload, user, grant });
|
||||
|
||||
if (!user?.id && !shareToken) {
|
||||
log('checkAuth: User not authorized');
|
||||
log('User not authorized');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import crypto from 'crypto';
|
||||
import prand from 'pure-rand';
|
||||
import { v4, v5 } from 'uuid';
|
||||
|
||||
const ALGORITHM = 'aes-256-gcm';
|
||||
|
|
@ -12,25 +11,6 @@ const ENC_POSITION = TAG_POSITION + TAG_LENGTH;
|
|||
const HASH_ALGO = 'sha512';
|
||||
const HASH_ENCODING = 'hex';
|
||||
|
||||
const seed = Date.now() ^ (Math.random() * 0x100000000);
|
||||
const rng = prand.xoroshiro128plus(seed);
|
||||
|
||||
export function random(min: number, max: number) {
|
||||
return prand.unsafeUniformIntDistribution(min, max, rng);
|
||||
}
|
||||
|
||||
export function getRandomChars(
|
||||
n: number,
|
||||
chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
) {
|
||||
const arr = chars.split('');
|
||||
let s = '';
|
||||
for (let i = 0; i < n; i++) {
|
||||
s += arr[random(0, arr.length - 1)];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
const getKey = (password: string, salt: Buffer) =>
|
||||
crypto.pbkdf2Sync(password, salt, 10000, 32, 'sha512');
|
||||
|
||||
|
|
|
|||
|
|
@ -1,51 +1,3 @@
|
|||
export const urlFilter = (data: any[]) => {
|
||||
const map = data.reduce((obj, { x, y }) => {
|
||||
if (x) {
|
||||
if (!obj[x]) {
|
||||
obj[x] = y;
|
||||
} else {
|
||||
obj[x] += y;
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
return Object.keys(map).map(key => ({ x: key, y: map[key] }));
|
||||
};
|
||||
|
||||
export const refFilter = (data: any[]) => {
|
||||
const links = {};
|
||||
|
||||
const map = data.reduce((obj, { x, y }) => {
|
||||
let id;
|
||||
|
||||
try {
|
||||
const url = new URL(x);
|
||||
|
||||
id = url.hostname.replace(/www\./, '') || url.href;
|
||||
} catch {
|
||||
id = '';
|
||||
}
|
||||
|
||||
links[id] = x;
|
||||
|
||||
if (!obj[id]) {
|
||||
obj[id] = y;
|
||||
} else {
|
||||
obj[id] += y;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
return Object.keys(map).map(key => ({ x: key, y: map[key], w: links[key] }));
|
||||
};
|
||||
|
||||
export const emptyFilter = (data: any[]) => {
|
||||
return data.map(item => (item.x ? item : null)).filter(n => n);
|
||||
};
|
||||
|
||||
export const percentFilter = (data: any[]) => {
|
||||
if (!data) return [];
|
||||
const total = data.reduce((n, { y }) => n + y, 0);
|
||||
|
|
|
|||
20
src/lib/generate.ts
Normal file
20
src/lib/generate.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import prand from 'pure-rand';
|
||||
|
||||
const seed = Date.now() ^ (Math.random() * 0x100000000);
|
||||
const rng = prand.xoroshiro128plus(seed);
|
||||
|
||||
export function random(min: number, max: number) {
|
||||
return prand.unsafeUniformIntDistribution(min, max, rng);
|
||||
}
|
||||
|
||||
export function getRandomChars(
|
||||
n: number,
|
||||
chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
) {
|
||||
const arr = chars.split('');
|
||||
let s = '';
|
||||
for (let i = 0; i < n; i++) {
|
||||
s += arr[random(0, arr.length - 1)];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue