forked from umami-software/umami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored realtime API. Add dot component and colored dots in log.
- Loading branch information
Showing
12 changed files
with
153 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import styles from './Dot.module.css'; | ||
|
||
export default function Dot({ color, size, className }) { | ||
return ( | ||
<div | ||
style={{ background: color }} | ||
className={classNames(styles.dot, className, { | ||
[styles.small]: size === 'small', | ||
[styles.large]: size === 'large', | ||
})} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.dot { | ||
background: var(--green400); | ||
width: 10px; | ||
height: 10px; | ||
border-radius: 100%; | ||
margin-right: 10px; | ||
} | ||
|
||
.dot.small { | ||
width: 8px; | ||
height: 8px; | ||
} | ||
|
||
.dot.large { | ||
width: 16px; | ||
height: 16px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { subMinutes } from 'date-fns'; | ||
import { useAuth } from 'lib/middleware'; | ||
import { ok, methodNotAllowed } from 'lib/response'; | ||
import { getUserWebsites, getRealtimeData } from 'lib/queries'; | ||
import { createToken } from 'lib/crypto'; | ||
|
||
export default async (req, res) => { | ||
await useAuth(req, res); | ||
|
||
if (req.method === 'GET') { | ||
const { user_id } = req.auth; | ||
|
||
const websites = await getUserWebsites(user_id); | ||
const ids = websites.map(({ website_id }) => website_id); | ||
const token = await createToken({ websites: ids }); | ||
const data = await getRealtimeData(ids, subMinutes(new Date(), 30)); | ||
|
||
return ok(res, { | ||
websites, | ||
token, | ||
data, | ||
}); | ||
} | ||
|
||
return methodNotAllowed(res); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useAuth } from 'lib/middleware'; | ||
import { ok, methodNotAllowed, badRequest } from 'lib/response'; | ||
import { getRealtimeData } from 'lib/queries'; | ||
import { parseToken } from 'lib/crypto'; | ||
|
||
export default async (req, res) => { | ||
await useAuth(req, res); | ||
|
||
if (req.method === 'GET') { | ||
const { start_at } = req.query; | ||
|
||
const token = req.headers['x-umami-token']; | ||
|
||
if (!token) { | ||
return badRequest(res); | ||
} | ||
|
||
const { websites } = await parseToken(token); | ||
|
||
const data = await getRealtimeData(websites, new Date(+start_at)); | ||
|
||
return ok(res, data); | ||
} | ||
|
||
return methodNotAllowed(res); | ||
}; |