mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 12:29:35 +01:00
Update redis package.
This commit is contained in:
parent
6291654748
commit
7f1f3b685a
@ -65,7 +65,7 @@
|
||||
"@prisma/client": "5.3.1",
|
||||
"@tanstack/react-query": "^4.33.0",
|
||||
"@umami/prisma-client": "^0.2.0",
|
||||
"@umami/redis-client": "^0.5.0",
|
||||
"@umami/redis-client": "^0.15.0",
|
||||
"chalk": "^4.1.1",
|
||||
"chart.js": "^4.2.1",
|
||||
"chartjs-adapter-date-fns": "^3.0.0",
|
||||
|
@ -3,7 +3,7 @@ import useMessages from 'components/hooks/useMessages';
|
||||
import useConfig from 'components/hooks/useConfig';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export function TrackingCode({ websiteId, analyticsUrl }) {
|
||||
export function TrackingCode({ websiteId, baseUrl }) {
|
||||
const { formatMessage, messages } = useMessages();
|
||||
const { basePath } = useRouter();
|
||||
const config = useConfig();
|
||||
@ -13,9 +13,7 @@ export function TrackingCode({ websiteId, analyticsUrl }) {
|
||||
|
||||
const url = trackerScriptName?.startsWith('http')
|
||||
? trackerScriptName
|
||||
: `${
|
||||
analyticsUrl || process.env.analyticsUrl || location.origin
|
||||
}${basePath}/${trackerScriptName}`;
|
||||
: `${baseUrl || location.origin}${basePath}/${trackerScriptName}`;
|
||||
|
||||
const code = `<script async src="${url}" data-website-id="${websiteId}"></script>`;
|
||||
|
||||
|
@ -2,60 +2,58 @@ import { User, Website } from '@prisma/client';
|
||||
import redis from '@umami/redis-client';
|
||||
import { getSession, getUserById, getWebsiteById } from '../queries';
|
||||
|
||||
const { fetchObject, storeObject, deleteObject, expire } = redis;
|
||||
|
||||
async function fetchWebsite(id): Promise<Website> {
|
||||
return fetchObject(`website:${id}`, () => getWebsiteById(id), 86400);
|
||||
return redis.fetchObject(`website:${id}`, () => getWebsiteById(id), 86400);
|
||||
}
|
||||
|
||||
async function storeWebsite(data) {
|
||||
const { id } = data;
|
||||
const key = `website:${id}`;
|
||||
|
||||
const obj = await storeObject(key, data);
|
||||
await expire(key, 86400);
|
||||
const obj = await redis.storeObject(key, data);
|
||||
await redis.expire(key, 86400);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
async function deleteWebsite(id) {
|
||||
return deleteObject(`website:${id}`);
|
||||
return redis.deleteObject(`website:${id}`);
|
||||
}
|
||||
|
||||
async function fetchUser(id): Promise<User> {
|
||||
return fetchObject(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
|
||||
return redis.fetchObject(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
|
||||
}
|
||||
|
||||
async function storeUser(data) {
|
||||
const { id } = data;
|
||||
const key = `user:${id}`;
|
||||
|
||||
const obj = await storeObject(key, data);
|
||||
await expire(key, 86400);
|
||||
const obj = await redis.storeObject(key, data);
|
||||
await redis.expire(key, 86400);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
async function deleteUser(id) {
|
||||
return deleteObject(`user:${id}`);
|
||||
return redis.deleteObject(`user:${id}`);
|
||||
}
|
||||
|
||||
async function fetchSession(id) {
|
||||
return fetchObject(`session:${id}`, () => getSession(id), 86400);
|
||||
return redis.fetchObject(`session:${id}`, () => getSession(id), 86400);
|
||||
}
|
||||
|
||||
async function storeSession(data) {
|
||||
const { id } = data;
|
||||
const key = `session:${id}`;
|
||||
|
||||
const obj = await storeObject(key, data);
|
||||
await expire(key, 86400);
|
||||
const obj = await redis.storeObject(key, data);
|
||||
await redis.expire(key, 86400);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
async function deleteSession(id) {
|
||||
return deleteObject(`session:${id}`);
|
||||
return redis.deleteObject(`session:${id}`);
|
||||
}
|
||||
|
||||
async function fetchUserBlock(userId: string) {
|
||||
@ -80,5 +78,5 @@ export default {
|
||||
deleteSession,
|
||||
fetchUserBlock,
|
||||
incrementUserBlock,
|
||||
enabled: redis.enabled,
|
||||
enabled: !!redis,
|
||||
};
|
||||
|
@ -55,7 +55,7 @@ export const useAuth = createMiddleware(async (req, res, next) => {
|
||||
|
||||
if (isUuid(userId)) {
|
||||
user = await getUserById(userId);
|
||||
} else if (redis.enabled && authKey) {
|
||||
} else if (redis && authKey) {
|
||||
user = await redis.get(authKey);
|
||||
}
|
||||
|
||||
|
@ -52,17 +52,18 @@ export default async (
|
||||
const user = await getUserByUsername(username, { includePassword: true });
|
||||
|
||||
if (user && checkPassword(password, user.password)) {
|
||||
if (redis.enabled) {
|
||||
if (redis) {
|
||||
const token = await setAuthKey(user);
|
||||
|
||||
return ok(res, { token, user });
|
||||
}
|
||||
|
||||
const token = createSecureToken({ userId: user.id }, secret());
|
||||
const { id, username, role, createdAt } = user;
|
||||
|
||||
return ok(res, {
|
||||
token,
|
||||
user: { id: user.id, username: user.username, role: user.role, createdAt: user.createdAt },
|
||||
user: { id, username, role, createdAt },
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (redis.enabled) {
|
||||
if (redis) {
|
||||
await redis.del(getAuthToken(req));
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import { setAuthKey } from 'lib/auth';
|
||||
export default async (req: NextApiRequestAuth, res: NextApiResponse) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
if (redis.enabled && req.auth.user) {
|
||||
if (redis && req.auth.user) {
|
||||
const token = await setAuthKey(req.auth.user, 86400);
|
||||
|
||||
return ok(res, { user: req.auth.user, token });
|
||||
|
@ -2766,10 +2766,10 @@
|
||||
dependencies:
|
||||
debug "^4.3.4"
|
||||
|
||||
"@umami/redis-client@^0.5.0":
|
||||
version "0.5.0"
|
||||
resolved "https://registry.npmjs.org/@umami/redis-client/-/redis-client-0.5.0.tgz"
|
||||
integrity sha512-x7wx/pMjyg3AAYzgjGOw031bNhyZ81h6tRMAl60RQQI9xlJaJEA1r0TEUrWfFi21gHAvdBLJGYCsvHzpix4LKQ==
|
||||
"@umami/redis-client@^0.15.0":
|
||||
version "0.15.0"
|
||||
resolved "https://registry.yarnpkg.com/@umami/redis-client/-/redis-client-0.15.0.tgz#55e9c4ede28fdd3b6a169378d391a5d2cc039e51"
|
||||
integrity sha512-+Ei6i4qx9Md4o92Mlzvh9rTgkfllgmSwFu1687DEqFnNrHd+KNVxgNNDiyyCwzfC0t/DAaq7PoOFw4NjJYo9wQ==
|
||||
dependencies:
|
||||
debug "^4.3.4"
|
||||
redis "^4.5.1"
|
||||
|
Loading…
Reference in New Issue
Block a user