mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 02:06:19 +01:00
20 lines
599 B
JavaScript
20 lines
599 B
JavaScript
import { getRankings } from 'lib/queries';
|
|
import { ok, badRequest } from 'lib/response';
|
|
|
|
const sessionColumns = ['browser', 'os', 'device', 'country'];
|
|
const pageviewColumns = ['url', 'referrer'];
|
|
|
|
export default async (req, res) => {
|
|
const { id, type, start_at, end_at } = req.query;
|
|
|
|
if (!sessionColumns.includes(type) && !pageviewColumns.includes(type)) {
|
|
return badRequest(res);
|
|
}
|
|
|
|
const table = sessionColumns.includes(type) ? 'session' : 'pageview';
|
|
|
|
const rankings = await getRankings(+id, new Date(+start_at), new Date(+end_at), type, table);
|
|
|
|
return ok(res, rankings);
|
|
};
|