mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Details page.
This commit is contained in:
parent
5b45301178
commit
ac2612924e
12 changed files with 312 additions and 10 deletions
15
pages/[id].js
Normal file
15
pages/[id].js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import React from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import Layout from 'components/Layout';
|
||||
import WebsiteDetails from '../components/WebsiteDetails';
|
||||
|
||||
export default function DetailsPage() {
|
||||
const router = useRouter();
|
||||
const { id } = router.query;
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<WebsiteDetails websiteId={id} />
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
12
pages/api/website/[id]/index.js
Normal file
12
pages/api/website/[id]/index.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { getWebsite } from 'lib/db';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { id } = req.query;
|
||||
|
||||
const website = await getWebsite(id);
|
||||
|
||||
return res.status(200).json(website);
|
||||
};
|
||||
|
|
@ -2,12 +2,14 @@ import moment from 'moment-timezone';
|
|||
import { getPageviewData } from 'lib/db';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
|
||||
const unitTypes = ['month', 'hour', 'day'];
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { id, start_at, end_at, unit, tz } = req.query;
|
||||
|
||||
if (!moment.tz.zone(tz) || !['month', 'hour', 'day'].includes(unit)) {
|
||||
if (!moment.tz.zone(tz) || !unitTypes.includes(unit)) {
|
||||
return res.status(400).end();
|
||||
}
|
||||
|
||||
|
|
|
|||
21
pages/api/website/[id]/rankings.js
Normal file
21
pages/api/website/[id]/rankings.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { getRankings } from 'lib/db';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
|
||||
const sessionColumns = ['browser', 'os', 'screen'];
|
||||
const pageviewColumns = ['url', 'referrer'];
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { id, type, start_at, end_at } = req.query;
|
||||
|
||||
if (!sessionColumns.includes(type) && !pageviewColumns.includes(type)) {
|
||||
return res.status(400).end();
|
||||
}
|
||||
|
||||
const table = sessionColumns.includes(type) ? 'session' : 'pageview';
|
||||
|
||||
const rankings = await getRankings(+id, new Date(+start_at), new Date(+end_at), type, table);
|
||||
|
||||
return res.status(200).json(rankings);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue