Merge pull request #2362 from umami-software/dev

Hotfix
This commit is contained in:
Mike Cao 2023-10-20 10:55:56 -10:00 committed by GitHub
commit 91b6dc5908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 2114 additions and 2213 deletions

View File

@ -35,7 +35,7 @@ ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN yarn add npm-run-all dotenv prisma
RUN yarn add npm-run-all dotenv prisma semver
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js .

View File

@ -67,7 +67,7 @@
"@react-spring/web": "^9.7.3",
"@tanstack/react-query": "^4.33.0",
"@umami/prisma-client": "^0.3.0",
"@umami/redis-client": "^0.15.0",
"@umami/redis-client": "^0.16.0",
"chalk": "^4.1.1",
"chart.js": "^4.2.1",
"chartjs-adapter-date-fns": "^3.0.0",
@ -93,9 +93,10 @@
"maxmind": "^4.3.6",
"moment-timezone": "^0.5.35",
"next": "13.5.3",
"next-basics": "^0.36.0",
"next-basics": "^0.37.0",
"node-fetch": "^3.2.8",
"npm-run-all": "^4.1.5",
"prisma": "5.3.1",
"react": "^18.2.0",
"react-basics": "^0.105.0",
"react-beautiful-dnd": "^13.1.0",
@ -106,7 +107,7 @@
"react-use-measure": "^2.0.4",
"react-window": "^1.8.6",
"request-ip": "^3.3.0",
"semver": "^7.5.2",
"semver": "^7.5.4",
"thenby": "^1.3.4",
"timezone-support": "^2.0.2",
"uuid": "^9.0.0",
@ -146,7 +147,6 @@
"postcss-preset-env": "7.8.3",
"postcss-rtlcss": "^4.0.1",
"prettier": "^2.6.2",
"prisma": "5.3.1",
"prompts": "2.4.2",
"rollup": "^3.28.0",
"rollup-plugin-copy": "^3.4.0",

View File

@ -7,19 +7,15 @@ import WebsiteChart from '../../(main)/websites/[id]/WebsiteChart';
import useApi from 'components/hooks/useApi';
import Head from 'next/head';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import useNavigation from 'components/hooks/useNavigation';
import Script from 'next/script';
import { Button } from 'react-basics';
import styles from './TestConsole.module.css';
export function TestConsole() {
export function TestConsole({ websiteId }) {
const { get, useQuery } = useApi();
const { data, isLoading, error } = useQuery(['websites:me'], () => get('/me/websites'));
const router = useRouter();
const {
basePath,
query: { id },
} = router;
const { router } = useNavigation();
function handleChange(value) {
router.push(`/console/${value}`);
@ -72,7 +68,6 @@ export function TestConsole() {
return null;
}
const [websiteId] = id || [];
const website = data?.data.find(({ id }) => websiteId === id);
return (
@ -87,8 +82,8 @@ export function TestConsole() {
<>
<Script
async
data-website-id={website.id}
src={`${basePath}/script.js`}
data-website-id={websiteId}
src={`${process.env.basePath}/script.js`}
data-cache="true"
/>
<div className={styles.test}>

View File

@ -5,14 +5,14 @@ async function getEnabled() {
return !!process.env.ENABLE_TEST_CONSOLE;
}
export default async function ConsolePage() {
export default async function ({ params: { id } }) {
const enabled = await getEnabled();
if (!enabled) {
return null;
}
return <TestConsole />;
return <TestConsole websiteId={id?.[0]} />;
}
export const metadata: Metadata = {

View File

@ -3,57 +3,57 @@ import redis from '@umami/redis-client';
import { getSession, getUserById, getWebsiteById } from '../queries';
async function fetchWebsite(id): Promise<Website> {
return redis.fetchObject(`website:${id}`, () => getWebsiteById(id), 86400);
return redis.getCache(`website:${id}`, () => getWebsiteById(id), 86400);
}
async function storeWebsite(data) {
const { id } = data;
const key = `website:${id}`;
const obj = await redis.storeObject(key, data);
const obj = await redis.setCache(key, data);
await redis.expire(key, 86400);
return obj;
}
async function deleteWebsite(id) {
return redis.deleteObject(`website:${id}`);
return redis.deleteCache(`website:${id}`);
}
async function fetchUser(id): Promise<User> {
return redis.fetchObject(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
return redis.getCache(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
}
async function storeUser(data) {
const { id } = data;
const key = `user:${id}`;
const obj = await redis.storeObject(key, data);
const obj = await redis.setCache(key, data);
await redis.expire(key, 86400);
return obj;
}
async function deleteUser(id) {
return redis.deleteObject(`user:${id}`);
return redis.deleteCache(`user:${id}`);
}
async function fetchSession(id) {
return redis.fetchObject(`session:${id}`, () => getSession(id), 86400);
return redis.getCache(`session:${id}`, () => getSession(id), 86400);
}
async function storeSession(data) {
const { id } = data;
const key = `session:${id}`;
const obj = await redis.storeObject(key, data);
const obj = await redis.setCache(key, data);
await redis.expire(key, 86400);
return obj;
}
async function deleteSession(id) {
return redis.deleteObject(`session:${id}`);
return redis.deleteCache(`session:${id}`);
}
async function fetchUserBlock(userId: string) {

View File

@ -15,7 +15,7 @@ export function salt() {
export function uuid(...args) {
if (!args.length) return v4();
return v5(hash(...args), v5.DNS);
return v5(hash(...args, salt()), v5.DNS);
}
export function isUuid(value) {

View File

@ -8,7 +8,11 @@ export function getEventDataUsage(...args: [websiteIds: string[], startDate: Dat
});
}
function clickhouseQuery(websiteIds: string[], startDate: Date, endDate: Date) {
function clickhouseQuery(
websiteIds: string[],
startDate: Date,
endDate: Date,
): Promise<{ websiteId: string; count: number }[]> {
const { rawQuery } = clickhouse;
return rawQuery(
@ -26,5 +30,9 @@ function clickhouseQuery(websiteIds: string[], startDate: Date, endDate: Date) {
startDate,
endDate,
},
);
).then(a => {
return Object.values(a).map(a => {
return { websiteId: a.websiteId, count: Number(a.count) };
});
});
}

4266
yarn.lock

File diff suppressed because it is too large Load Diff