mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
use uuid
This commit is contained in:
parent
b0bed5e73a
commit
c147742d7a
@ -5,7 +5,7 @@ import useFetch from 'hooks/useFetch';
|
||||
import Dot from 'components/common/Dot';
|
||||
import styles from './ActiveUsers.module.css';
|
||||
|
||||
export default function ActiveUsers({ websiteId, className, value, interval = 60000 }) {
|
||||
export default function ActiveUsers({ websiteId, className, value, interval = 600000 }) {
|
||||
const url = websiteId ? `/websites/${websiteId}/active` : null;
|
||||
const { data } = useFetch(url, {
|
||||
interval,
|
||||
|
@ -17,8 +17,8 @@ export default function WebsiteHeader({ websiteId, title, domain, showLink = fal
|
||||
<Favicon domain={domain} />
|
||||
<Link
|
||||
className={styles.titleLink}
|
||||
href="/website/[...id]"
|
||||
as={`/website/${websiteId}/${title}`}
|
||||
href="/websites/[...id]"
|
||||
as={`/websites/${websiteId}/${title}`}
|
||||
>
|
||||
<OverflowText tooltipId={`${websiteId}-title`}>{title}</OverflowText>
|
||||
</Link>
|
||||
@ -41,8 +41,8 @@ export default function WebsiteHeader({ websiteId, title, domain, showLink = fal
|
||||
<RefreshButton websiteId={websiteId} />
|
||||
{showLink && (
|
||||
<Link
|
||||
href="/website/[...id]"
|
||||
as={`/website/${websiteId}/${title}`}
|
||||
href="/websites/[...id]"
|
||||
as={`/websites/${websiteId}/${title}`}
|
||||
className={styles.link}
|
||||
icon={<Arrow />}
|
||||
size="small"
|
||||
|
@ -27,7 +27,7 @@ export default function WebsiteList({ websites, showCharts, limit }) {
|
||||
const ordered = useMemo(
|
||||
() =>
|
||||
websites
|
||||
.map(website => ({ ...website, order: websiteOrder.indexOf(website.id) || 0 }))
|
||||
.map(website => ({ ...website, order: websiteOrder.indexOf(website.websiteUuid) || 0 }))
|
||||
.sort(firstBy('order')),
|
||||
[websites, websiteOrder],
|
||||
);
|
||||
@ -46,11 +46,11 @@ export default function WebsiteList({ websites, showCharts, limit }) {
|
||||
|
||||
return (
|
||||
<div>
|
||||
{ordered.map(({ id, name, domain }, index) =>
|
||||
{ordered.map(({ websiteUuid, name, domain }, index) =>
|
||||
index < limit ? (
|
||||
<div key={id} className={styles.website}>
|
||||
<div key={websiteUuid} className={styles.website}>
|
||||
<WebsiteChart
|
||||
websiteId={id}
|
||||
websiteId={websiteUuid}
|
||||
title={name}
|
||||
domain={domain}
|
||||
showChart={showCharts}
|
||||
|
@ -84,7 +84,7 @@ export default function WebsiteSettings() {
|
||||
);
|
||||
|
||||
const DetailsLink = ({ id, name, domain }) => (
|
||||
<Link className={styles.detailLink} href="/website/[...id]" as={`/website/${id}/${name}`}>
|
||||
<Link className={styles.detailLink} href="/websites/[...id]" as={`/websites/${id}/${name}`}>
|
||||
<Favicon domain={domain} />
|
||||
<OverflowText tooltipId={`${id}-name`}>{name}</OverflowText>
|
||||
</Link>
|
||||
|
@ -11,9 +11,7 @@ export default async (req, res) => {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { id } = req.query;
|
||||
|
||||
const websiteId = +id;
|
||||
const { id: websiteId } = req.query;
|
||||
|
||||
const result = await getActiveVisitors(websiteId);
|
||||
|
||||
|
@ -14,13 +14,11 @@ export default async (req, res) => {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { id, start_at, end_at, unit, tz, url, event_name } = req.query;
|
||||
const { id: websiteId, start_at, end_at, unit, tz, url, event_name } = req.query;
|
||||
|
||||
if (!moment.tz.zone(tz) || !unitTypes.includes(unit)) {
|
||||
return badRequest(res);
|
||||
}
|
||||
|
||||
const websiteId = +id;
|
||||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
|
@ -1,14 +1,10 @@
|
||||
import { methodNotAllowed, ok, unauthorized, getRandomChars } from 'next-basics';
|
||||
import { deleteWebsite, getAccount, getWebsite, updateWebsite } from 'queries';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useAuth, useCors } from 'lib/middleware';
|
||||
import { validate } from 'uuid';
|
||||
import { getRandomChars, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { deleteWebsite, getAccount, getWebsite, getWebsiteByUuid, updateWebsite } from 'queries';
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id } = req.query;
|
||||
|
||||
const websiteId = +id;
|
||||
const where = validate(id) ? { websiteUuid: id } : { id: +id };
|
||||
const { id: websiteId } = req.query;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
await useCors(req, res);
|
||||
@ -17,7 +13,7 @@ export default async (req, res) => {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const website = await getWebsite(where);
|
||||
const website = await getWebsiteByUuid(websiteId);
|
||||
|
||||
return ok(res, website);
|
||||
}
|
||||
@ -33,7 +29,7 @@ export default async (req, res) => {
|
||||
account = await getAccount({ accountUuid });
|
||||
}
|
||||
|
||||
const website = await getWebsite(where);
|
||||
const website = await getWebsite(websiteId);
|
||||
|
||||
const shareId = enable_share_url ? website.shareId || getRandomChars(8) : null;
|
||||
|
||||
@ -48,7 +44,7 @@ export default async (req, res) => {
|
||||
shareId: shareId,
|
||||
userId: account ? account.id : +owner,
|
||||
},
|
||||
where,
|
||||
{ websiteUuid: websiteId },
|
||||
);
|
||||
|
||||
return ok(res);
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { getPageviewMetrics, getSessionMetrics, getWebsiteById } from 'queries';
|
||||
import { ok, methodNotAllowed, unauthorized, badRequest } from 'next-basics';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useCors } from 'lib/middleware';
|
||||
import { FILTER_IGNORED } from 'lib/constants';
|
||||
import { useCors } from 'lib/middleware';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getPageviewMetrics, getSessionMetrics, getWebsiteByUuid } from 'queries';
|
||||
|
||||
const sessionColumns = ['browser', 'os', 'device', 'screen', 'country', 'language'];
|
||||
const pageviewColumns = ['url', 'referrer', 'query'];
|
||||
@ -41,9 +41,19 @@ export default async (req, res) => {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { id, type, start_at, end_at, url, referrer, os, browser, device, country } = req.query;
|
||||
const {
|
||||
id: websiteId,
|
||||
type,
|
||||
start_at,
|
||||
end_at,
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
} = req.query;
|
||||
|
||||
const websiteId = +id;
|
||||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
@ -83,7 +93,7 @@ export default async (req, res) => {
|
||||
let domain;
|
||||
|
||||
if (type === 'referrer') {
|
||||
const website = await getWebsiteById(websiteId);
|
||||
const website = await getWebsiteByUuid(websiteId);
|
||||
|
||||
if (!website) {
|
||||
return badRequest(res);
|
||||
|
@ -14,10 +14,20 @@ export default async (req, res) => {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { id, start_at, end_at, unit, tz, url, referrer, os, browser, device, country } =
|
||||
req.query;
|
||||
const {
|
||||
id: websiteId,
|
||||
start_at,
|
||||
end_at,
|
||||
unit,
|
||||
tz,
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
} = req.query;
|
||||
|
||||
const websiteId = +id;
|
||||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
|
@ -3,8 +3,7 @@ import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id } = req.query;
|
||||
const websiteId = +id;
|
||||
const { id: websiteId } = req.query;
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (!(await allowQuery(req))) {
|
||||
|
@ -11,9 +11,18 @@ export default async (req, res) => {
|
||||
return unauthorized(res);
|
||||
}
|
||||
|
||||
const { website_id, start_at, end_at, url, referrer, os, browser, device, country } = req.query;
|
||||
const {
|
||||
id: websiteId,
|
||||
start_at,
|
||||
end_at,
|
||||
url,
|
||||
referrer,
|
||||
os,
|
||||
browser,
|
||||
device,
|
||||
country,
|
||||
} = req.query;
|
||||
|
||||
const websiteId = +website_id;
|
||||
const startDate = new Date(+start_at);
|
||||
const endDate = new Date(+end_at);
|
||||
|
||||
|
@ -23,11 +23,13 @@ async function relationalQuery(
|
||||
return rawQuery(
|
||||
`select
|
||||
event_name x,
|
||||
${getDateQuery('created_at', unit, timezone)} t,
|
||||
${getDateQuery('event.created_at', unit, timezone)} t,
|
||||
count(*) y
|
||||
from event
|
||||
where website_id=$1
|
||||
and created_at between $2 and $3
|
||||
join website
|
||||
on event.website_id = website.website_id
|
||||
where website_uuid='${websiteId}'
|
||||
and event.created_at between $2 and $3
|
||||
${getFilterQuery('event', filters, params)}
|
||||
group by 1, 2
|
||||
order by 2`,
|
||||
|
@ -22,8 +22,9 @@ async function relationalQuery(websiteId, { startDate, endDate, column, table, f
|
||||
return rawQuery(
|
||||
`select ${column} x, count(*) y
|
||||
from ${table}
|
||||
${` join website on ${table}.website_id = website.website_id`}
|
||||
${joinSession}
|
||||
where ${table}.website_id=$1
|
||||
where website.website_uuid='${websiteId}'
|
||||
and ${table}.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${joinSession && sessionQuery}
|
||||
|
@ -22,8 +22,9 @@ async function relationalQuery(websiteId, start_at, end_at, column, table, filte
|
||||
`select url x,
|
||||
count(*) y
|
||||
from ${table}
|
||||
${` join website on ${table}.website_id = website.website_id`}
|
||||
${joinSession}
|
||||
where ${table}.website_id=$1
|
||||
where website.website_uuid='${websiteId}'
|
||||
and ${table}.created_at between $2 and $3
|
||||
and ${table}.url like '%?%'
|
||||
${pageviewQuery}
|
||||
|
@ -34,8 +34,10 @@ async function relationalQuery(
|
||||
`select ${getDateQuery('pageview.created_at', unit, timezone)} t,
|
||||
count(${count !== '*' ? `${count}${sessionKey}` : count}) y
|
||||
from pageview
|
||||
join website
|
||||
on pageview.website_id = website.website_id
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
where website.website_uuid='${websiteId}'
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
|
@ -20,8 +20,10 @@ async function relationalQuery(websiteId, { startDate, endDate, field, filters =
|
||||
where x.session_id in (
|
||||
select pageview.session_id
|
||||
from pageview
|
||||
join website
|
||||
on pageview.website_id = website.website_id
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
where website.website_uuid='${websiteId}'
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
|
@ -17,8 +17,10 @@ async function relationalQuery(websiteId) {
|
||||
return prisma.rawQuery(
|
||||
`select count(distinct session_id) x
|
||||
from pageview
|
||||
where website_id = $1
|
||||
and created_at >= $2`,
|
||||
join website
|
||||
on pageview.website_id = website.website_id
|
||||
where website.website_uuid = '${websiteId}'
|
||||
and pageview.created_at >= $2`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
@ -30,11 +30,13 @@ async function relationalQuery(websiteId, { start_at, end_at, filters = {} }) {
|
||||
count(*) c,
|
||||
${getTimestampInterval('pageview.created_at')} as "time"
|
||||
from pageview
|
||||
join website
|
||||
on pageview.website_id = website.website_id
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
where website.website_uuid='${websiteId}'
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
group by 1, 2
|
||||
) t`,
|
||||
params,
|
||||
|
Loading…
x
Reference in New Issue
Block a user