mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
Merge branch 'dev' into dependabot/npm_and_yarn/terser-5.14.2
This commit is contained in:
commit
59d5a4fc32
@ -16,7 +16,8 @@
|
||||
"react/display-name": "off",
|
||||
"react/react-in-jsx-scope": "off",
|
||||
"react/prop-types": "off",
|
||||
"import/no-anonymous-default-export": "off"
|
||||
"import/no-anonymous-default-export": "off",
|
||||
"@next/next/no-img-element": "off"
|
||||
},
|
||||
"globals": {
|
||||
"React": "writable"
|
||||
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -15,10 +15,6 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- node-version: 12.x
|
||||
db-type: postgresql
|
||||
- node-version: 12.x
|
||||
db-type: mysql
|
||||
- node-version: 14.x
|
||||
db-type: postgresql
|
||||
- node-version: 14.x
|
||||
|
@ -3,12 +3,12 @@ import { FormattedMessage } from 'react-intl';
|
||||
import ButtonLayout from 'components/layout/ButtonLayout';
|
||||
import useStore, { checkVersion } from 'store/version';
|
||||
import { setItem } from 'lib/web';
|
||||
import { VERSION_CHECK, VERSION_URL } from 'lib/constants';
|
||||
import { REPO_URL, VERSION_CHECK } from 'lib/constants';
|
||||
import Button from './Button';
|
||||
import styles from './UpdateNotice.module.css';
|
||||
|
||||
export default function UpdateNotice() {
|
||||
const { latest, checked, hasUpdate } = useStore();
|
||||
const { latest, checked, hasUpdate, releaseUrl } = useStore();
|
||||
const [dismissed, setDismissed] = useState(false);
|
||||
|
||||
const updateCheck = useCallback(() => {
|
||||
@ -18,7 +18,7 @@ export default function UpdateNotice() {
|
||||
function handleViewClick() {
|
||||
updateCheck();
|
||||
setDismissed(true);
|
||||
location.href = VERSION_URL;
|
||||
location.href = releaseUrl || REPO_URL;
|
||||
}
|
||||
|
||||
function handleDismissClick() {
|
||||
|
@ -4,7 +4,7 @@ import { FormattedMessage } from 'react-intl';
|
||||
import Link from 'components/common/Link';
|
||||
import styles from './Footer.module.css';
|
||||
import useStore from 'store/version';
|
||||
import { HOMEPAGE_URL, VERSION_URL } from 'lib/constants';
|
||||
import { HOMEPAGE_URL, REPO_URL } from 'lib/constants';
|
||||
|
||||
export default function Footer() {
|
||||
const { current } = useStore();
|
||||
@ -26,8 +26,11 @@ export default function Footer() {
|
||||
/>
|
||||
</div>
|
||||
<div className={classNames(styles.version, 'col-12 col-md-4')}>
|
||||
<Link href={VERSION_URL}>{`v${current}`}</Link>
|
||||
<Link href={REPO_URL}>{`v${current}`}</Link>
|
||||
</div>
|
||||
{!process.env.telemetryDisabled && (
|
||||
<img src={`https://i.umami.is/a.png?v=${current}`} alt="" />
|
||||
)}
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
|
15
components/metrics/ScreenTable.js
Normal file
15
components/metrics/ScreenTable.js
Normal file
@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import MetricsTable from './MetricsTable';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
|
||||
export default function ScreenTable({ websiteId, ...props }) {
|
||||
return (
|
||||
<MetricsTable
|
||||
{...props}
|
||||
title={<FormattedMessage id="metrics.screens" defaultMessage="Screen" />}
|
||||
type="screen"
|
||||
metric={<FormattedMessage id="metrics.visitors" defaultMessage="Visitors" />}
|
||||
websiteId={websiteId}
|
||||
/>
|
||||
);
|
||||
}
|
@ -22,6 +22,7 @@ import useFetch from 'hooks/useFetch';
|
||||
import usePageQuery from 'hooks/usePageQuery';
|
||||
import { DEFAULT_ANIMATION_DURATION } from 'lib/constants';
|
||||
import styles from './WebsiteDetails.module.css';
|
||||
import ScreenTable from 'components/metrics/ScreenTable';
|
||||
|
||||
const views = {
|
||||
url: PagesTable,
|
||||
@ -29,6 +30,7 @@ const views = {
|
||||
browser: BrowsersTable,
|
||||
os: OSTable,
|
||||
device: DevicesTable,
|
||||
screen: ScreenTable,
|
||||
country: CountriesTable,
|
||||
language: LanguagesTable,
|
||||
event: EventsTable,
|
||||
@ -64,6 +66,10 @@ export default function WebsiteDetails({ websiteId }) {
|
||||
label: <FormattedMessage id="metrics.referrers" defaultMessage="Referrers" />,
|
||||
value: resolve({ view: 'referrer' }),
|
||||
},
|
||||
{
|
||||
label: <FormattedMessage id="metrics.screens" defaultMessage="Screens" />,
|
||||
value: resolve({ view: 'screen' }),
|
||||
},
|
||||
{
|
||||
label: <FormattedMessage id="metrics.browsers" defaultMessage="Browsers" />,
|
||||
value: resolve({ view: 'browser' }),
|
||||
|
@ -9,7 +9,7 @@ CREATE TABLE `account` (
|
||||
|
||||
UNIQUE INDEX `username`(`username`),
|
||||
PRIMARY KEY (`user_id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `event` (
|
||||
@ -25,7 +25,7 @@ CREATE TABLE `event` (
|
||||
INDEX `event_session_id_idx`(`session_id`),
|
||||
INDEX `event_website_id_idx`(`website_id`),
|
||||
PRIMARY KEY (`event_id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `pageview` (
|
||||
@ -42,7 +42,7 @@ CREATE TABLE `pageview` (
|
||||
INDEX `pageview_website_id_idx`(`website_id`),
|
||||
INDEX `pageview_website_id_session_id_created_at_idx`(`website_id`, `session_id`, `created_at`),
|
||||
PRIMARY KEY (`view_id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `session` (
|
||||
@ -62,7 +62,7 @@ CREATE TABLE `session` (
|
||||
INDEX `session_created_at_idx`(`created_at`),
|
||||
INDEX `session_website_id_idx`(`website_id`),
|
||||
PRIMARY KEY (`session_id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `website` (
|
||||
@ -78,7 +78,7 @@ CREATE TABLE `website` (
|
||||
UNIQUE INDEX `share_id`(`share_id`),
|
||||
INDEX `website_user_id_idx`(`user_id`),
|
||||
PRIMARY KEY (`website_id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `event` ADD CONSTRAINT `event_ibfk_2` FOREIGN KEY (`session_id`) REFERENCES `session`(`session_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
|
||||
|
@ -9,7 +9,7 @@ datasource db {
|
||||
|
||||
model account {
|
||||
user_id Int @id @default(autoincrement())
|
||||
username String @unique(map: "account.username_unique") @db.VarChar(255)
|
||||
username String @unique @db.VarChar(255)
|
||||
password String @db.VarChar(60)
|
||||
is_admin Boolean @default(false)
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
@ -25,8 +25,8 @@ model event {
|
||||
url String @db.VarChar(500)
|
||||
event_type String @db.VarChar(50)
|
||||
event_value String @db.VarChar(50)
|
||||
session session @relation(fields: [session_id], references: [session_id], onDelete: Cascade)
|
||||
website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade)
|
||||
session session @relation(fields: [session_id], references: [session_id], onDelete: Cascade, onUpdate: NoAction)
|
||||
website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade, onUpdate: NoAction)
|
||||
|
||||
@@index([created_at])
|
||||
@@index([session_id])
|
||||
@ -40,8 +40,8 @@ model pageview {
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
url String @db.VarChar(500)
|
||||
referrer String? @db.VarChar(500)
|
||||
session session @relation(fields: [session_id], references: [session_id], onDelete: Cascade)
|
||||
website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade)
|
||||
session session @relation(fields: [session_id], references: [session_id], onDelete: Cascade, onUpdate: NoAction)
|
||||
website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade, onUpdate: NoAction)
|
||||
|
||||
@@index([created_at])
|
||||
@@index([session_id])
|
||||
@ -52,17 +52,17 @@ model pageview {
|
||||
|
||||
model session {
|
||||
session_id Int @id @default(autoincrement())
|
||||
session_uuid String @unique(map: "session.session_uuid_unique") @db.Uuid
|
||||
session_uuid String @unique @db.Uuid
|
||||
website_id Int
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
hostname String? @db.VarChar(100)
|
||||
browser String? @db.VarChar(20)
|
||||
os String? @db.VarChar(20)
|
||||
device String? @db.VarChar(20)
|
||||
screen String? @db.VarChar(11)
|
||||
language String? @db.VarChar(35)
|
||||
country String? @db.Char(2)
|
||||
website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade)
|
||||
device String? @db.VarChar(20)
|
||||
website website @relation(fields: [website_id], references: [website_id], onDelete: Cascade, onUpdate: NoAction)
|
||||
event event[]
|
||||
pageview pageview[]
|
||||
|
||||
@ -72,16 +72,16 @@ model session {
|
||||
|
||||
model website {
|
||||
website_id Int @id @default(autoincrement())
|
||||
website_uuid String @unique(map: "website.website_uuid_unique") @db.Uuid
|
||||
user_id Int
|
||||
website_uuid String @unique @db.Uuid
|
||||
name String @db.VarChar(100)
|
||||
domain String? @db.VarChar(500)
|
||||
share_id String? @unique(map: "website.share_id_unique") @db.VarChar(64)
|
||||
created_at DateTime? @default(now()) @db.Timestamptz(6)
|
||||
account account @relation(fields: [user_id], references: [user_id], onDelete: Cascade)
|
||||
user_id Int
|
||||
domain String? @db.VarChar(500)
|
||||
share_id String? @unique(map: "website_share_id_idx") @db.VarChar(64)
|
||||
account account @relation(fields: [user_id], references: [user_id], onDelete: NoAction, onUpdate: NoAction)
|
||||
event event[]
|
||||
pageview pageview[]
|
||||
session session[]
|
||||
|
||||
@@index([user_id])
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
"label.add-website": "Tilføj hjemmeside",
|
||||
"label.administrator": "Administrator",
|
||||
"label.all": "Alle",
|
||||
"label.all-events": "All events",
|
||||
"label.all-time": "All time",
|
||||
"label.all-websites": "Alle websites",
|
||||
"label.all-events": "Alle hændelser",
|
||||
"label.all-time": "Altid",
|
||||
"label.all-websites": "Alle hjemmesider",
|
||||
"label.back": "Tilbage",
|
||||
"label.cancel": "Afvis",
|
||||
"label.change-password": "Skift adgangskode",
|
||||
@ -28,30 +28,30 @@
|
||||
"label.enable-share-url": "Aktivér delings-URL",
|
||||
"label.invalid": "Ugyldig",
|
||||
"label.invalid-domain": "Ugyldigt domæne",
|
||||
"label.language": "Language",
|
||||
"label.language": "Sprog",
|
||||
"label.last-days": "Sidste {x} dage",
|
||||
"label.last-hours": "Sidste {x} timer",
|
||||
"label.logged-in-as": "Loggede ind som {username}",
|
||||
"label.logged-in-as": "Logget ind som {username}",
|
||||
"label.login": "Log ind",
|
||||
"label.logout": "Log ud",
|
||||
"label.more": "Mere",
|
||||
"label.name": "Navn",
|
||||
"label.new-password": "Ny adgangskode",
|
||||
"label.owner": "Owner",
|
||||
"label.owner": "Ejer",
|
||||
"label.password": "Adgangskode",
|
||||
"label.passwords-dont-match": "Adgangskoder matcher ikke",
|
||||
"label.passwords-dont-match": "Adgangskoderne matcher ikke",
|
||||
"label.profile": "Profil",
|
||||
"label.realtime": "Realtid",
|
||||
"label.realtime-logs": "Realtid logs",
|
||||
"label.refresh": "Opdater",
|
||||
"label.required": "Påkrævet",
|
||||
"label.reset": "Reset",
|
||||
"label.reset-website": "Reset statistics",
|
||||
"label.reset": "Nulstil",
|
||||
"label.reset-website": "Nulstil statistikker",
|
||||
"label.save": "Gem",
|
||||
"label.settings": "Indstillinger",
|
||||
"label.share-url": "Del URL",
|
||||
"label.single-day": "Enkelt dag",
|
||||
"label.theme": "Theme",
|
||||
"label.theme": "Tema",
|
||||
"label.this-month": "Denne måned",
|
||||
"label.this-week": "Denne uge",
|
||||
"label.this-year": "Dette år",
|
||||
@ -64,7 +64,7 @@
|
||||
"label.websites": "Hjemmesider",
|
||||
"message.active-users": "{x} nuværende {x, plural, one {bruger} other {brugere}}",
|
||||
"message.confirm-delete": "Er du sikker på at du vil slette {target}?",
|
||||
"message.confirm-reset": "Are your sure you want to reset {target}'s statistics?",
|
||||
"message.confirm-reset": "Er du sikker på at du ville nulstille {target}'s statistikker?",
|
||||
"message.copied": "Kopieret!",
|
||||
"message.delete-warning": "Alle tilknyttede data slettes også.",
|
||||
"message.failure": "Noget gik galt.",
|
||||
@ -75,14 +75,14 @@
|
||||
"message.log.visitor": "Besøgende fra {country} bruger {browser} på {os} {device}",
|
||||
"message.new-version-available": "Ny udgave af Umami {version} er tilgængelig!",
|
||||
"message.no-data-available": "Ingen data tilgængelig.",
|
||||
"message.no-websites-configured": "Du har ikke konfigureret nogen websteder.",
|
||||
"message.no-websites-configured": "Du har ikke konfigureret nogen hjemmesider.",
|
||||
"message.page-not-found": "Side ikke fundet.",
|
||||
"message.powered-by": "Drevet af {name}",
|
||||
"message.reset-warning": "All statistics for this website will be deleted, but your tracking code will remain intact.",
|
||||
"message.reset-warning": "Alle statistikker for denne hjemmeside ville blive slettet, men sporingskode ville forblive intakt.",
|
||||
"message.save-success": "Gemt!",
|
||||
"message.share-url": "Dette er den offentligt delings-URL til {target}.",
|
||||
"message.toggle-charts": "Toggle charts",
|
||||
"message.track-stats": "For at spore statistik for {target} skal du placere følgende kode i {head} sektionen på dit websted.",
|
||||
"message.share-url": "Dette er den offentlige delings-URL til {target}.",
|
||||
"message.toggle-charts": "Ændre graf",
|
||||
"message.track-stats": "For at spore statistik for {target} skal du placere følgende kode i {head} sektionen på din hjemmeside.",
|
||||
"message.type-delete": "Skriv {delete} i boksen nedenfor, for at bekræfte.",
|
||||
"message.type-reset": "Skriv {reset} i boksen nedenfor, for at bekræfte.",
|
||||
"metrics.actions": "Handlinger",
|
||||
@ -99,7 +99,7 @@
|
||||
"metrics.filter.combined": "Kombineret",
|
||||
"metrics.filter.domain-only": "Kun domæne",
|
||||
"metrics.filter.raw": "Rå",
|
||||
"metrics.languages": "Languages",
|
||||
"metrics.languages": "Sprog",
|
||||
"metrics.operating-systems": "Operativsystemer",
|
||||
"metrics.page-views": "Sidevisninger",
|
||||
"metrics.pages": "Sider",
|
||||
|
@ -106,5 +106,6 @@
|
||||
"metrics.referrers": "Referrer",
|
||||
"metrics.unique-visitors": "Eindeutige Besucher",
|
||||
"metrics.views": "Aufrufe",
|
||||
"metrics.visitors": "Besucher"
|
||||
"metrics.visitors": "Besucher",
|
||||
"metrics.screens": "Bildschirmauflösungen"
|
||||
}
|
||||
|
@ -106,5 +106,6 @@
|
||||
"metrics.referrers": "Referrers",
|
||||
"metrics.unique-visitors": "Unique visitors",
|
||||
"metrics.views": "Views",
|
||||
"metrics.visitors": "Visitors"
|
||||
"metrics.visitors": "Visitors",
|
||||
"metrics.screens": "Screens"
|
||||
}
|
||||
|
@ -106,5 +106,6 @@
|
||||
"metrics.referrers": "Referrers",
|
||||
"metrics.unique-visitors": "Unique visitors",
|
||||
"metrics.views": "Views",
|
||||
"metrics.visitors": "Visitors"
|
||||
"metrics.visitors": "Visitors",
|
||||
"metrics.screens": "Screens"
|
||||
}
|
||||
|
@ -4,8 +4,8 @@
|
||||
"label.add-website": "Legg til nettsted",
|
||||
"label.administrator": "Administrator",
|
||||
"label.all": "Alle",
|
||||
"label.all-events": "All events",
|
||||
"label.all-time": "All time",
|
||||
"label.all-events": "Alle hendelser",
|
||||
"label.all-time": "Noensinne",
|
||||
"label.all-websites": "Alle nettsteder",
|
||||
"label.back": "Tilbake",
|
||||
"label.cancel": "Avvis",
|
||||
@ -14,7 +14,7 @@
|
||||
"label.copy-to-clipboard": "Kopier til utklippstavle",
|
||||
"label.current-password": "Nåværende passord",
|
||||
"label.custom-range": "Egendefinert utvalg",
|
||||
"label.dashboard": "Dashboard",
|
||||
"label.dashboard": "Dashbord",
|
||||
"label.date-range": "Datointervall",
|
||||
"label.default-date-range": "Standard datoperiode",
|
||||
"label.delete": "Slett",
|
||||
@ -28,16 +28,16 @@
|
||||
"label.enable-share-url": "Aktiver delings-URL",
|
||||
"label.invalid": "Ugyldig",
|
||||
"label.invalid-domain": "Ugyldig domene",
|
||||
"label.language": "Language",
|
||||
"label.language": "Språk",
|
||||
"label.last-days": "Siste {x} dager",
|
||||
"label.last-hours": "Siste {x} timer",
|
||||
"label.logged-in-as": "Logget på som {brukernavn}",
|
||||
"label.logged-in-as": "Logget på som {username}",
|
||||
"label.login": "Logg inn",
|
||||
"label.logout": "Logg ut",
|
||||
"label.more": "Mer",
|
||||
"label.name": "Navn",
|
||||
"label.new-password": "Nytt passord",
|
||||
"label.owner": "Owner",
|
||||
"label.owner": "Eier",
|
||||
"label.password": "Passord",
|
||||
"label.passwords-dont-match": "Passordene er ikke like",
|
||||
"label.profile": "Profil",
|
||||
@ -46,7 +46,7 @@
|
||||
"label.refresh": "Oppdater",
|
||||
"label.required": "Påkrevd",
|
||||
"label.reset": "Nullstill",
|
||||
"label.reset-website": "Reset statistics",
|
||||
"label.reset-website": "Nullstill statistikk",
|
||||
"label.save": "Lagre",
|
||||
"label.settings": "Innstillinger",
|
||||
"label.share-url": "Del URL",
|
||||
@ -64,7 +64,7 @@
|
||||
"label.websites": "Nettsteder",
|
||||
"message.active-users": "{x} {x, plural, one {besøkende} other {besøkende}} nå",
|
||||
"message.confirm-delete": "Er du sikker på at du vil slette {target}?",
|
||||
"message.confirm-reset": "Are your sure you want to reset {target}'s statistics?",
|
||||
"message.confirm-reset": "Er du sikker på at du vil nullstille {target}'s statistikk?",
|
||||
"message.copied": "Kopiert!",
|
||||
"message.delete-warning": "Alle tilknyttede data slettes også.",
|
||||
"message.failure": "Noe gikk galt.",
|
||||
@ -78,15 +78,15 @@
|
||||
"message.no-websites-configured": "Du har ikke satt opp noen nettsteder.",
|
||||
"message.page-not-found": "Side ikke funnet.",
|
||||
"message.powered-by": "Drevet av {name}",
|
||||
"message.reset-warning": "All statistics for this website will be deleted, but your tracking code will remain intact.",
|
||||
"message.reset-warning": "All statistikk for denne nettsiden vil bli slettet, men sporingskoden din vil forbli uberørt.",
|
||||
"message.save-success": "Lagret!",
|
||||
"message.share-url": "Dette er den offentlige delings-URL-en for {target}.",
|
||||
"message.toggle-charts": "Toggle charts",
|
||||
"message.toggle-charts": "Veksle grafer",
|
||||
"message.track-stats": "For å spore statistikk for {target}, plasser følgende kode i {head}-delen av nettstedet ditt.",
|
||||
"message.type-delete": "Skriv inn {delete} i boksen nedenfor for å bekrefte.",
|
||||
"message.type-reset": "Skriv inn {reset} i boksen nedenfor for å bekrefte.",
|
||||
"metrics.actions": "Handlinger",
|
||||
"metrics.average-visit-time": "Gjennomsnittlig besøkelsestid",
|
||||
"metrics.average-visit-time": "Gjennomsnittlig besøkstid",
|
||||
"metrics.bounce-rate": "Avvisningsfrekvens",
|
||||
"metrics.browsers": "Nettlesere",
|
||||
"metrics.countries": "Land",
|
||||
@ -99,7 +99,7 @@
|
||||
"metrics.filter.combined": "Kombinert",
|
||||
"metrics.filter.domain-only": "Bare domene",
|
||||
"metrics.filter.raw": "Rå",
|
||||
"metrics.languages": "Languages",
|
||||
"metrics.languages": "Språk",
|
||||
"metrics.operating-systems": "Operativsystemer",
|
||||
"metrics.page-views": "Sidevisninger",
|
||||
"metrics.pages": "Sider",
|
||||
@ -107,4 +107,4 @@
|
||||
"metrics.unique-visitors": "Unike besøkende",
|
||||
"metrics.views": "Visninger",
|
||||
"metrics.visitors": "Besøkende"
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
"label.administrator": "Administrator",
|
||||
"label.all": "Alles",
|
||||
"label.all-events": "Alle gebeurtenissen",
|
||||
"label.all-time": "All time",
|
||||
"label.all-time": "Onbeperkt",
|
||||
"label.all-websites": "Alle websites",
|
||||
"label.back": "Terug",
|
||||
"label.cancel": "Annuleren",
|
||||
@ -28,7 +28,7 @@
|
||||
"label.enable-share-url": "Sta delen via openbare URL toe",
|
||||
"label.invalid": "Ongeldig",
|
||||
"label.invalid-domain": "Ongeldig domein",
|
||||
"label.language": "Language",
|
||||
"label.language": "Taal",
|
||||
"label.last-days": "Laatste {x} dagen",
|
||||
"label.last-hours": "Laatste {x} uur",
|
||||
"label.logged-in-as": "Ingelogd als {username}",
|
||||
@ -37,7 +37,7 @@
|
||||
"label.more": "Toon meer",
|
||||
"label.name": "Naam",
|
||||
"label.new-password": "Nieuw wachtwoord",
|
||||
"label.owner": "Owner",
|
||||
"label.owner": "Eigenaar",
|
||||
"label.password": "Wachtwoord",
|
||||
"label.passwords-dont-match": "Wachtwoorden komen niet overeen",
|
||||
"label.profile": "Profiel",
|
||||
@ -46,12 +46,12 @@
|
||||
"label.refresh": "Vernieuwen",
|
||||
"label.required": "Verplicht",
|
||||
"label.reset": "Resetten",
|
||||
"label.reset-website": "Reset statistics",
|
||||
"label.reset-website": "Statistieken opnieuw instellen",
|
||||
"label.save": "Opslaan",
|
||||
"label.settings": "Instellingen",
|
||||
"label.share-url": "URL delen",
|
||||
"label.single-day": "Enkele dag",
|
||||
"label.theme": "Theme",
|
||||
"label.theme": "Thema",
|
||||
"label.this-month": "Deze maand",
|
||||
"label.this-week": "Deze week",
|
||||
"label.this-year": "Dit jaar",
|
||||
@ -64,7 +64,7 @@
|
||||
"label.websites": "Websites",
|
||||
"message.active-users": "{x} actieve {x, plural, one {bezoeker} other {bezoekers}}",
|
||||
"message.confirm-delete": "Weet je zeker dat je {target} wilt verwijderen?",
|
||||
"message.confirm-reset": "Are your sure you want to reset {target}'s statistics?",
|
||||
"message.confirm-reset": "Weet je zeker dat je de statistieken van {target} opnieuw wilt instellen?",
|
||||
"message.copied": "Gekopiëerd!",
|
||||
"message.delete-warning": "Alle verwante gegezens zullen ook verwijderd worden.",
|
||||
"message.failure": "Er is iets misgegaan.",
|
||||
@ -81,7 +81,7 @@
|
||||
"message.reset-warning": "All statistics for this website will be deleted, but your tracking code will remain intact.",
|
||||
"message.save-success": "Opslaan succesvol.",
|
||||
"message.share-url": "Met deze URL kan {target} openbaar gedeeld worden.",
|
||||
"message.toggle-charts": "Toggle charts",
|
||||
"message.toggle-charts": "Grafieken tonen/verbergen",
|
||||
"message.track-stats": "Om statistieken voor {target} bij te houden, plaats je de volgende code in het {head} gedeelte van je website.",
|
||||
"message.type-delete": "Type {delete} in onderstaande veld om dit te bevestigen.",
|
||||
"message.type-reset": "Type {reset} in onderstaande veld om dit te bevestigen.",
|
||||
@ -100,7 +100,7 @@
|
||||
"metrics.filter.domain-only": "Alleen domein",
|
||||
"metrics.filter.raw": "Ruw",
|
||||
"metrics.languages": "Languages",
|
||||
"metrics.operating-systems": "Besturingssysteem",
|
||||
"metrics.operating-systems": "Besturingssystemen",
|
||||
"metrics.page-views": "Paginaweergaven",
|
||||
"metrics.pages": "Pagina's",
|
||||
"metrics.referrers": "Verwijzers",
|
||||
|
@ -106,5 +106,6 @@
|
||||
"metrics.referrers": "Yönlendirenler",
|
||||
"metrics.unique-visitors": "Tekil kullanıcı",
|
||||
"metrics.views": "Görüntüleme",
|
||||
"metrics.visitors": "Ziyaretçi"
|
||||
"metrics.visitors": "Ziyaretçi",
|
||||
"metrics.screens": "Ekranlar"
|
||||
}
|
||||
|
@ -99,7 +99,7 @@
|
||||
"metrics.filter.combined": "总和",
|
||||
"metrics.filter.domain-only": "只看域名",
|
||||
"metrics.filter.raw": "原始",
|
||||
"metrics.languages": "Languages",
|
||||
"metrics.languages": "语言",
|
||||
"metrics.operating-systems": "操作系统",
|
||||
"metrics.page-views": "页面浏览量",
|
||||
"metrics.pages": "网页",
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { parseSecureToken, parseToken } from './crypto';
|
||||
import { SHARE_TOKEN_HEADER } from './constants';
|
||||
import { getWebsiteById } from './queries';
|
||||
import { getWebsiteById } from 'queries';
|
||||
|
||||
export async function getAuthToken(req) {
|
||||
try {
|
||||
|
@ -7,7 +7,8 @@ export const DASHBOARD_CONFIG = 'umami.dashboard';
|
||||
export const VERSION_CHECK = 'umami.version-check';
|
||||
export const SHARE_TOKEN_HEADER = 'x-umami-share-token';
|
||||
export const HOMEPAGE_URL = 'https://umami.is';
|
||||
export const VERSION_URL = 'https://github.com/mikecao/umami/releases';
|
||||
export const REPO_URL = 'https://github.com/umami-software/umami';
|
||||
export const UPDATES_URL = 'https://api.umami.is/v1/updates';
|
||||
|
||||
export const DEFAULT_LOCALE = 'en-US';
|
||||
export const DEFAULT_THEME = 'light';
|
||||
|
22
lib/db.js
22
lib/db.js
@ -1,6 +1,10 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import chalk from 'chalk';
|
||||
|
||||
BigInt.prototype.toJSON = function () {
|
||||
return Number(this);
|
||||
};
|
||||
|
||||
const options = {
|
||||
log: [
|
||||
{
|
||||
@ -14,20 +18,20 @@ function logQuery(e) {
|
||||
console.log(chalk.yellow(e.params), '->', e.query, chalk.greenBright(`${e.duration}ms`));
|
||||
}
|
||||
|
||||
let prisma;
|
||||
function getClient(options) {
|
||||
const prisma = new PrismaClient(options);
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
prisma = new PrismaClient(options);
|
||||
} else {
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient(options);
|
||||
if (process.env.LOG_QUERY) {
|
||||
prisma.$on('query', logQuery);
|
||||
}
|
||||
|
||||
prisma = global.prisma;
|
||||
return prisma;
|
||||
}
|
||||
|
||||
if (process.env.LOG_QUERY) {
|
||||
prisma.$on('query', logQuery);
|
||||
const prisma = global.prisma || getClient(options);
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
global.prisma = prisma;
|
||||
}
|
||||
|
||||
export default prisma;
|
||||
|
@ -50,13 +50,15 @@ export const refFilter = (data, { domain, domainOnly, raw }) => {
|
||||
const links = {};
|
||||
|
||||
const isValidRef = referrer => {
|
||||
return (
|
||||
referrer !== '' && referrer !== null && !referrer.startsWith('/') && !referrer.startsWith('#')
|
||||
);
|
||||
return referrer !== null && !referrer.startsWith('/') && !referrer.startsWith('#');
|
||||
};
|
||||
|
||||
const cleanUrl = url => {
|
||||
try {
|
||||
if (url === '') {
|
||||
return 'Direct / None';
|
||||
}
|
||||
|
||||
const { hostname, origin, pathname, searchParams, protocol } = new URL(url);
|
||||
|
||||
if (regex.test(url)) {
|
||||
|
483
lib/queries.js
483
lib/queries.js
@ -1,13 +1,6 @@
|
||||
import moment from 'moment-timezone';
|
||||
import { MYSQL, MYSQL_DATE_FORMATS, POSTGRESQL, POSTGRESQL_DATE_FORMATS } from 'lib/constants';
|
||||
import prisma from 'lib/db';
|
||||
import { subMinutes } from 'date-fns';
|
||||
import {
|
||||
MYSQL,
|
||||
POSTGRESQL,
|
||||
MYSQL_DATE_FORMATS,
|
||||
POSTGRESQL_DATE_FORMATS,
|
||||
URL_LENGTH,
|
||||
} from 'lib/constants';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
export function getDatabase() {
|
||||
const type =
|
||||
@ -21,24 +14,36 @@ export function getDatabase() {
|
||||
return type;
|
||||
}
|
||||
|
||||
export function getDateStringQuery(data, unit) {
|
||||
const db = getDatabase();
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return `to_char(${data}, '${POSTGRESQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return `DATE_FORMAT(${data}, '${MYSQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
}
|
||||
|
||||
export function getDateQuery(field, unit, timezone) {
|
||||
const db = getDatabase();
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
if (timezone) {
|
||||
return `to_char(date_trunc('${unit}', ${field} at time zone '${timezone}'), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
|
||||
return `date_trunc('${unit}', ${field} at time zone '${timezone}')`;
|
||||
}
|
||||
return `to_char(date_trunc('${unit}', ${field}), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
|
||||
return `date_trunc('${unit}', ${field})`;
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
if (timezone) {
|
||||
const tz = moment.tz(timezone).format('Z');
|
||||
|
||||
return `DATE_FORMAT(convert_tz(${field},'+00:00','${tz}'), '${MYSQL_DATE_FORMATS[unit]}')`;
|
||||
return `convert_tz(${field},'+00:00','${tz}')`;
|
||||
}
|
||||
|
||||
return `DATE_FORMAT(${field}, '${MYSQL_DATE_FORMATS[unit]}')`;
|
||||
return `${field}`;
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,455 +153,3 @@ export async function rawQuery(query, params = []) {
|
||||
|
||||
return runQuery(prisma.$queryRawUnsafe.apply(prisma, [sql, ...params]));
|
||||
}
|
||||
|
||||
export async function getWebsiteById(website_id) {
|
||||
return runQuery(
|
||||
prisma.website.findUnique({
|
||||
where: {
|
||||
website_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getWebsiteByUuid(website_uuid) {
|
||||
return runQuery(
|
||||
prisma.website.findUnique({
|
||||
where: {
|
||||
website_uuid,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getWebsiteByShareId(share_id) {
|
||||
return runQuery(
|
||||
prisma.website.findUnique({
|
||||
where: {
|
||||
share_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getUserWebsites(user_id) {
|
||||
return runQuery(
|
||||
prisma.website.findMany({
|
||||
where: {
|
||||
user_id,
|
||||
},
|
||||
orderBy: {
|
||||
name: 'asc',
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getAllWebsites() {
|
||||
let data = await runQuery(
|
||||
prisma.website.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
user_id: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'asc',
|
||||
},
|
||||
],
|
||||
include: {
|
||||
account: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
return data.map(i => ({ ...i, account: i.account.username }));
|
||||
}
|
||||
|
||||
export async function createWebsite(user_id, data) {
|
||||
return runQuery(
|
||||
prisma.website.create({
|
||||
data: {
|
||||
account: {
|
||||
connect: {
|
||||
user_id,
|
||||
},
|
||||
},
|
||||
...data,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateWebsite(website_id, data) {
|
||||
return runQuery(
|
||||
prisma.website.update({
|
||||
where: {
|
||||
website_id,
|
||||
},
|
||||
data,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function resetWebsite(website_id) {
|
||||
return runQuery(prisma.$queryRaw`delete from session where website_id=${website_id}`);
|
||||
}
|
||||
|
||||
export async function deleteWebsite(website_id) {
|
||||
return runQuery(
|
||||
prisma.website.delete({
|
||||
where: {
|
||||
website_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function createSession(website_id, data) {
|
||||
return runQuery(
|
||||
prisma.session.create({
|
||||
data: {
|
||||
website_id,
|
||||
...data,
|
||||
},
|
||||
select: {
|
||||
session_id: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getSessionByUuid(session_uuid) {
|
||||
return runQuery(
|
||||
prisma.session.findUnique({
|
||||
where: {
|
||||
session_uuid,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function savePageView(website_id, session_id, url, referrer) {
|
||||
return runQuery(
|
||||
prisma.pageview.create({
|
||||
data: {
|
||||
website_id,
|
||||
session_id,
|
||||
url: url?.substr(0, URL_LENGTH),
|
||||
referrer: referrer?.substr(0, URL_LENGTH),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function saveEvent(website_id, session_id, url, event_type, event_value) {
|
||||
return runQuery(
|
||||
prisma.event.create({
|
||||
data: {
|
||||
website_id,
|
||||
session_id,
|
||||
url: url?.substr(0, URL_LENGTH),
|
||||
event_type: event_type?.substr(0, 50),
|
||||
event_value: event_value?.substr(0, 50),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getAccounts() {
|
||||
return runQuery(
|
||||
prisma.account.findMany({
|
||||
orderBy: [
|
||||
{ is_admin: 'desc' },
|
||||
{
|
||||
username: 'asc',
|
||||
},
|
||||
],
|
||||
select: {
|
||||
user_id: true,
|
||||
username: true,
|
||||
is_admin: true,
|
||||
created_at: true,
|
||||
updated_at: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getAccountById(user_id) {
|
||||
return runQuery(
|
||||
prisma.account.findUnique({
|
||||
where: {
|
||||
user_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getAccountByUsername(username) {
|
||||
return runQuery(
|
||||
prisma.account.findUnique({
|
||||
where: {
|
||||
username,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateAccount(user_id, data) {
|
||||
return runQuery(
|
||||
prisma.account.update({
|
||||
where: {
|
||||
user_id,
|
||||
},
|
||||
data,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteAccount(user_id) {
|
||||
return runQuery(
|
||||
prisma.account.delete({
|
||||
where: {
|
||||
user_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function createAccount(data) {
|
||||
return runQuery(
|
||||
prisma.account.create({
|
||||
data,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getSessions(websites, start_at) {
|
||||
return runQuery(
|
||||
prisma.session.findMany({
|
||||
where: {
|
||||
website: {
|
||||
website_id: {
|
||||
in: websites,
|
||||
},
|
||||
},
|
||||
created_at: {
|
||||
gte: start_at,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getPageviews(websites, start_at) {
|
||||
return runQuery(
|
||||
prisma.pageview.findMany({
|
||||
where: {
|
||||
website: {
|
||||
website_id: {
|
||||
in: websites,
|
||||
},
|
||||
},
|
||||
created_at: {
|
||||
gte: start_at,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function getEvents(websites, start_at) {
|
||||
return runQuery(
|
||||
prisma.event.findMany({
|
||||
where: {
|
||||
website: {
|
||||
website_id: {
|
||||
in: websites,
|
||||
},
|
||||
},
|
||||
created_at: {
|
||||
gte: start_at,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function getWebsiteStats(website_id, start_at, end_at, filters = {}) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters('pageview', filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select sum(t.c) as "pageviews",
|
||||
count(distinct t.session_id) as "uniques",
|
||||
sum(case when t.c = 1 then 1 else 0 end) as "bounces",
|
||||
sum(t.time) as "totaltime"
|
||||
from (
|
||||
select pageview.session_id,
|
||||
${getDateQuery('pageview.created_at', 'hour')},
|
||||
count(*) c,
|
||||
${getTimestampInterval('pageview.created_at')} as "time"
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
group by 1, 2
|
||||
) t
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export function getPageviewStats(
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
timezone = 'utc',
|
||||
unit = 'day',
|
||||
count = '*',
|
||||
filters = {},
|
||||
) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters('pageview', filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select ${getDateQuery('pageview.created_at', unit, timezone)} t,
|
||||
count(${count}) y
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
group by 1
|
||||
order by 1
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export function getSessionMetrics(website_id, start_at, end_at, field, filters = {}) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters('pageview', filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select ${field} x, count(*) y
|
||||
from session as x
|
||||
where x.session_id in (
|
||||
select pageview.session_id
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
)
|
||||
group by 1
|
||||
order by 2 desc
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export function getPageviewMetrics(website_id, start_at, end_at, field, table, filters = {}) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
|
||||
table,
|
||||
filters,
|
||||
params,
|
||||
);
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select ${field} x, count(*) y
|
||||
from ${table}
|
||||
${joinSession}
|
||||
where ${table}.website_id=$1
|
||||
and ${table}.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${joinSession && sessionQuery}
|
||||
${eventQuery}
|
||||
group by 1
|
||||
order by 2 desc
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export function getActiveVisitors(website_id) {
|
||||
const date = subMinutes(new Date(), 5);
|
||||
const params = [website_id, date];
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select count(distinct session_id) x
|
||||
from pageview
|
||||
where website_id=$1
|
||||
and created_at >= $2
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export function getEventMetrics(
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
timezone = 'utc',
|
||||
unit = 'day',
|
||||
filters = {},
|
||||
) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
event_value x,
|
||||
${getDateQuery('created_at', unit, timezone)} t,
|
||||
count(*) y
|
||||
from event
|
||||
where website_id=$1
|
||||
and created_at between $2 and $3
|
||||
${getFilterQuery('event', filters, params)}
|
||||
group by 1, 2
|
||||
order by 2
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getRealtimeData(websites, time) {
|
||||
const [pageviews, sessions, events] = await Promise.all([
|
||||
getPageviews(websites, time),
|
||||
getSessions(websites, time),
|
||||
getEvents(websites, time),
|
||||
]);
|
||||
|
||||
return {
|
||||
pageviews: pageviews.map(({ view_id, ...props }) => ({
|
||||
__id: `p${view_id}`,
|
||||
view_id,
|
||||
...props,
|
||||
})),
|
||||
sessions: sessions.map(({ session_id, ...props }) => ({
|
||||
__id: `s${session_id}`,
|
||||
session_id,
|
||||
...props,
|
||||
})),
|
||||
events: events.map(({ event_id, ...props }) => ({
|
||||
__id: `e${event_id}`,
|
||||
event_id,
|
||||
...props,
|
||||
})),
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'lib/queries';
|
||||
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'queries';
|
||||
import { getJsonBody, getClientInfo } from 'lib/request';
|
||||
import { uuid, isValidUuid, parseToken } from 'lib/crypto';
|
||||
|
||||
|
@ -1,5 +1,23 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export const config = {
|
||||
matcher: '/:path*',
|
||||
};
|
||||
|
||||
function customCollectEndpoint(req) {
|
||||
const collectEndpoint = process.env.COLLECT_API_ENDPOINT;
|
||||
|
||||
if (collectEndpoint) {
|
||||
const url = req.nextUrl.clone();
|
||||
const { pathname } = url;
|
||||
|
||||
if (pathname.endsWith(collectEndpoint)) {
|
||||
url.pathname = '/api/collect';
|
||||
return NextResponse.rewrite(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function customScriptName(req) {
|
||||
const scriptName = process.env.TRACKER_SCRIPT_NAME;
|
||||
|
||||
@ -23,8 +41,8 @@ function forceSSL(req, res) {
|
||||
return res;
|
||||
}
|
||||
|
||||
export function middleware(req) {
|
||||
const fns = [customScriptName];
|
||||
export default function middleware(req) {
|
||||
const fns = [customCollectEndpoint, customScriptName];
|
||||
|
||||
for (const fn of fns) {
|
||||
const res = fn(req);
|
@ -6,11 +6,10 @@ module.exports = {
|
||||
currentVersion: pkg.version,
|
||||
loginDisabled: process.env.DISABLE_LOGIN,
|
||||
updatesDisabled: process.env.DISABLE_UPDATES,
|
||||
telemetryDisabled: process.env.DISABLE_TELEMETRY,
|
||||
},
|
||||
basePath: process.env.BASE_PATH,
|
||||
experimental: {
|
||||
outputStandalone: true,
|
||||
},
|
||||
output: 'standalone',
|
||||
eslint: {
|
||||
ignoreDuringBuilds: true,
|
||||
},
|
||||
|
15
package.json
15
package.json
@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "umami",
|
||||
"version": "1.33.1",
|
||||
"version": "1.34.0",
|
||||
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
|
||||
"author": "Mike Cao <mike@mikecao.com>",
|
||||
"license": "MIT",
|
||||
"homepage": "https://umami.is",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mikecao/umami.git"
|
||||
"url": "https://github.com/umami-software/umami.git"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
@ -55,7 +55,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource/inter": "4.5.7",
|
||||
"@prisma/client": "3.15.2",
|
||||
"@prisma/client": "4.0.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"chalk": "^4.1.1",
|
||||
"chart.js": "^2.9.4",
|
||||
@ -79,8 +79,8 @@
|
||||
"jose": "2.0.5",
|
||||
"maxmind": "^4.3.6",
|
||||
"moment-timezone": "^0.5.33",
|
||||
"next": "12.1.0",
|
||||
"node-fetch": "^3.2.3",
|
||||
"next": "^12.2.0",
|
||||
"node-fetch": "^3.2.8",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prop-types": "^15.7.2",
|
||||
"react": "^17.0.0",
|
||||
@ -101,10 +101,11 @@
|
||||
"devDependencies": {
|
||||
"@formatjs/cli": "^4.2.29",
|
||||
"@rollup/plugin-buble": "^0.21.3",
|
||||
"@rollup/plugin-replace": "^4.0.0",
|
||||
"@svgr/webpack": "^6.2.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-next": "^12.0.1",
|
||||
"eslint-config-next": "^12.2.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"extract-react-intl-messages": "^4.1.1",
|
||||
@ -116,7 +117,7 @@
|
||||
"postcss-preset-env": "7.4.3",
|
||||
"postcss-rtlcss": "^3.6.1",
|
||||
"prettier": "^2.6.2",
|
||||
"prisma": "3.15.2",
|
||||
"prisma": "4.0.0",
|
||||
"prompts": "2.4.2",
|
||||
"rollup": "^2.70.1",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getAccountById, deleteAccount } from 'lib/queries';
|
||||
import { getAccountById, deleteAccount } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getAccountById, getAccountByUsername, updateAccount, createAccount } from 'lib/queries';
|
||||
import { getAccountById, getAccountByUsername, updateAccount, createAccount } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { hashPassword } from 'lib/crypto';
|
||||
import { ok, unauthorized, methodNotAllowed, badRequest } from 'lib/response';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getAccountById, updateAccount } from 'lib/queries';
|
||||
import { getAccountById, updateAccount } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'lib/response';
|
||||
import { checkPassword, hashPassword } from 'lib/crypto';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getAccounts } from 'lib/queries';
|
||||
import { getAccounts } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, unauthorized, methodNotAllowed } from 'lib/response';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { checkPassword, createSecureToken } from 'lib/crypto';
|
||||
import { getAccountByUsername } from 'lib/queries';
|
||||
import { getAccountByUsername } from 'queries/admin/account/getAccountByUsername';
|
||||
import { ok, unauthorized, badRequest } from 'lib/response';
|
||||
|
||||
export default async (req, res) => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
const { Resolver } = require('dns').promises;
|
||||
import isbot from 'isbot';
|
||||
import ipaddr from 'ipaddr.js';
|
||||
import { savePageView, saveEvent } from 'lib/queries';
|
||||
import { savePageView, saveEvent } from 'queries';
|
||||
import { useCors, useSession } from 'lib/middleware';
|
||||
import { getJsonBody, getIpAddress } from 'lib/request';
|
||||
import { ok, send, badRequest, forbidden } from 'lib/response';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { subMinutes } from 'date-fns';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, methodNotAllowed } from 'lib/response';
|
||||
import { getUserWebsites, getRealtimeData } from 'lib/queries';
|
||||
import { getUserWebsites, getRealtimeData } from 'queries';
|
||||
import { createToken } from 'lib/crypto';
|
||||
|
||||
export default async (req, res) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, methodNotAllowed, badRequest } from 'lib/response';
|
||||
import { getRealtimeData } from 'lib/queries';
|
||||
import { getRealtimeData } from 'queries';
|
||||
import { parseToken } from 'lib/crypto';
|
||||
import { SHARE_TOKEN_HEADER } from 'lib/constants';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getWebsiteByShareId } from 'lib/queries';
|
||||
import { getWebsiteByShareId } from 'queries';
|
||||
import { ok, notFound, methodNotAllowed } from 'lib/response';
|
||||
import { createToken } from 'lib/crypto';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { getActiveVisitors } from 'lib/queries';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useCors } from 'lib/middleware';
|
||||
import { getActiveVisitors } from 'queries';
|
||||
|
||||
export default async (req, res) => {
|
||||
if (req.method === 'GET') {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import moment from 'moment-timezone';
|
||||
import { getEventMetrics } from 'lib/queries';
|
||||
import { getEventMetrics } from 'queries';
|
||||
import { ok, badRequest, methodNotAllowed, unauthorized } from 'lib/response';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useCors } from 'lib/middleware';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { deleteWebsite, getWebsiteById } from 'lib/queries';
|
||||
import { deleteWebsite, getWebsiteById } from 'queries';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useCors } from 'lib/middleware';
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { getPageviewMetrics, getSessionMetrics, getWebsiteById } from 'lib/queries';
|
||||
import { getPageviewMetrics, getSessionMetrics, getWebsiteById } from 'queries';
|
||||
import { ok, methodNotAllowed, unauthorized, badRequest } from 'lib/response';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useCors } from 'lib/middleware';
|
||||
|
||||
const sessionColumns = ['browser', 'os', 'device', 'country', 'language'];
|
||||
const sessionColumns = ['browser', 'os', 'device', 'screen', 'country', 'language'];
|
||||
const pageviewColumns = ['url', 'referrer'];
|
||||
|
||||
function getTable(type) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import moment from 'moment-timezone';
|
||||
import { getPageviewStats } from 'lib/queries';
|
||||
import { getPageviewStats } from 'queries';
|
||||
import { ok, badRequest, methodNotAllowed, unauthorized } from 'lib/response';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useCors } from 'lib/middleware';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { resetWebsite } from 'lib/queries';
|
||||
import { resetWebsite } from 'queries';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getWebsiteStats } from 'lib/queries';
|
||||
import { getWebsiteStats } from 'queries';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
|
||||
import { allowQuery } from 'lib/auth';
|
||||
import { useCors } from 'lib/middleware';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { updateWebsite, createWebsite, getWebsiteById } from 'lib/queries';
|
||||
import { updateWebsite, createWebsite, getWebsiteById } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { uuid, getRandomChars } from 'lib/crypto';
|
||||
import { ok, unauthorized, methodNotAllowed } from 'lib/response';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getAllWebsites, getUserWebsites } from 'lib/queries';
|
||||
import { getAllWebsites, getUserWebsites } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, methodNotAllowed, unauthorized } from 'lib/response';
|
||||
|
||||
|
@ -32,19 +32,19 @@
|
||||
"label.all-events": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "All events"
|
||||
"value": "Alle hændelser"
|
||||
}
|
||||
],
|
||||
"label.all-time": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "All time"
|
||||
"value": "Altid"
|
||||
}
|
||||
],
|
||||
"label.all-websites": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Alle websites"
|
||||
"value": "Alle hjemmesider"
|
||||
}
|
||||
],
|
||||
"label.back": [
|
||||
@ -176,7 +176,7 @@
|
||||
"label.language": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Language"
|
||||
"value": "Sprog"
|
||||
}
|
||||
],
|
||||
"label.last-days": [
|
||||
@ -210,7 +210,7 @@
|
||||
"label.logged-in-as": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Loggede ind som "
|
||||
"value": "Logget ind som "
|
||||
},
|
||||
{
|
||||
"type": 1,
|
||||
@ -250,7 +250,7 @@
|
||||
"label.owner": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Owner"
|
||||
"value": "Ejer"
|
||||
}
|
||||
],
|
||||
"label.password": [
|
||||
@ -262,7 +262,7 @@
|
||||
"label.passwords-dont-match": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Adgangskoder matcher ikke"
|
||||
"value": "Adgangskoderne matcher ikke"
|
||||
}
|
||||
],
|
||||
"label.profile": [
|
||||
@ -298,13 +298,13 @@
|
||||
"label.reset": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Reset"
|
||||
"value": "Nulstil"
|
||||
}
|
||||
],
|
||||
"label.reset-website": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Reset statistics"
|
||||
"value": "Nulstil statistikker"
|
||||
}
|
||||
],
|
||||
"label.save": [
|
||||
@ -334,7 +334,7 @@
|
||||
"label.theme": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Theme"
|
||||
"value": "Tema"
|
||||
}
|
||||
],
|
||||
"label.this-month": [
|
||||
@ -448,7 +448,7 @@
|
||||
"message.confirm-reset": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Are your sure you want to reset "
|
||||
"value": "Er du sikker på at du ville nulstille "
|
||||
},
|
||||
{
|
||||
"type": 1,
|
||||
@ -456,7 +456,7 @@
|
||||
},
|
||||
{
|
||||
"type": 0,
|
||||
"value": "'s statistics?"
|
||||
"value": "'s statistikker?"
|
||||
}
|
||||
],
|
||||
"message.copied": [
|
||||
@ -558,7 +558,7 @@
|
||||
"message.no-websites-configured": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Du har ikke konfigureret nogen websteder."
|
||||
"value": "Du har ikke konfigureret nogen hjemmesider."
|
||||
}
|
||||
],
|
||||
"message.page-not-found": [
|
||||
@ -580,7 +580,7 @@
|
||||
"message.reset-warning": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "All statistics for this website will be deleted, but your tracking code will remain intact."
|
||||
"value": "Alle statistikker for denne hjemmeside ville blive slettet, men sporingskode ville forblive intakt."
|
||||
}
|
||||
],
|
||||
"message.save-success": [
|
||||
@ -592,7 +592,7 @@
|
||||
"message.share-url": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Dette er den offentligt delings-URL til "
|
||||
"value": "Dette er den offentlige delings-URL til "
|
||||
},
|
||||
{
|
||||
"type": 1,
|
||||
@ -606,7 +606,7 @@
|
||||
"message.toggle-charts": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Toggle charts"
|
||||
"value": "Ændre graf"
|
||||
}
|
||||
],
|
||||
"message.track-stats": [
|
||||
@ -628,7 +628,7 @@
|
||||
},
|
||||
{
|
||||
"type": 0,
|
||||
"value": " sektionen på dit websted."
|
||||
"value": " sektionen på din hjemmeside."
|
||||
}
|
||||
],
|
||||
"message.type-delete": [
|
||||
@ -746,7 +746,7 @@
|
||||
"metrics.languages": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Languages"
|
||||
"value": "Sprog"
|
||||
}
|
||||
],
|
||||
"metrics.operating-systems": [
|
||||
|
@ -773,6 +773,12 @@
|
||||
"value": "Referrer"
|
||||
}
|
||||
],
|
||||
"metrics.screens": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Bildschirmauflösungen"
|
||||
}
|
||||
],
|
||||
"metrics.unique-visitors": [
|
||||
{
|
||||
"type": 0,
|
||||
|
@ -773,6 +773,12 @@
|
||||
"value": "Referrers"
|
||||
}
|
||||
],
|
||||
"metrics.screens": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Screens"
|
||||
}
|
||||
],
|
||||
"metrics.unique-visitors": [
|
||||
{
|
||||
"type": 0,
|
||||
|
@ -773,6 +773,12 @@
|
||||
"value": "Referrers"
|
||||
}
|
||||
],
|
||||
"metrics.screens": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Screens"
|
||||
}
|
||||
],
|
||||
"metrics.unique-visitors": [
|
||||
{
|
||||
"type": 0,
|
||||
|
@ -38,7 +38,7 @@
|
||||
"label.all-time": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "All time"
|
||||
"value": "Onbeperkt"
|
||||
}
|
||||
],
|
||||
"label.all-websites": [
|
||||
@ -176,7 +176,7 @@
|
||||
"label.language": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Language"
|
||||
"value": "Taal"
|
||||
}
|
||||
],
|
||||
"label.last-days": [
|
||||
@ -250,7 +250,7 @@
|
||||
"label.owner": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Owner"
|
||||
"value": "Eigenaar"
|
||||
}
|
||||
],
|
||||
"label.password": [
|
||||
@ -304,7 +304,7 @@
|
||||
"label.reset-website": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Reset statistics"
|
||||
"value": "Statistieken opnieuw instellen"
|
||||
}
|
||||
],
|
||||
"label.save": [
|
||||
@ -334,7 +334,7 @@
|
||||
"label.theme": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Theme"
|
||||
"value": "Thema"
|
||||
}
|
||||
],
|
||||
"label.this-month": [
|
||||
@ -448,7 +448,7 @@
|
||||
"message.confirm-reset": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Are your sure you want to reset "
|
||||
"value": "Weet je zeker dat je de statistieken van "
|
||||
},
|
||||
{
|
||||
"type": 1,
|
||||
@ -456,7 +456,7 @@
|
||||
},
|
||||
{
|
||||
"type": 0,
|
||||
"value": "'s statistics?"
|
||||
"value": " opnieuw wilt instellen?"
|
||||
}
|
||||
],
|
||||
"message.copied": [
|
||||
@ -606,7 +606,7 @@
|
||||
"message.toggle-charts": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Toggle charts"
|
||||
"value": "Grafieken tonen/verbergen"
|
||||
}
|
||||
],
|
||||
"message.track-stats": [
|
||||
@ -752,7 +752,7 @@
|
||||
"metrics.operating-systems": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Besturingssysteem"
|
||||
"value": "Besturingssystemen"
|
||||
}
|
||||
],
|
||||
"metrics.page-views": [
|
||||
|
@ -737,6 +737,12 @@
|
||||
"value": "Yönlendirenler"
|
||||
}
|
||||
],
|
||||
"metrics.screens": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Ekranlar"
|
||||
}
|
||||
],
|
||||
"metrics.unique-visitors": [
|
||||
{
|
||||
"type": 0,
|
||||
|
@ -734,7 +734,7 @@
|
||||
"metrics.languages": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Languages"
|
||||
"value": "语言"
|
||||
}
|
||||
],
|
||||
"metrics.operating-systems": [
|
||||
|
10
queries/admin/account/createAccount.js
Normal file
10
queries/admin/account/createAccount.js
Normal file
@ -0,0 +1,10 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function createAccount(data) {
|
||||
return runQuery(
|
||||
prisma.account.create({
|
||||
data,
|
||||
}),
|
||||
);
|
||||
}
|
12
queries/admin/account/deleteAccount.js
Normal file
12
queries/admin/account/deleteAccount.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function deleteAccount(user_id) {
|
||||
return runQuery(
|
||||
prisma.account.delete({
|
||||
where: {
|
||||
user_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
12
queries/admin/account/getAccountById.js
Normal file
12
queries/admin/account/getAccountById.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getAccountById(user_id) {
|
||||
return runQuery(
|
||||
prisma.account.findUnique({
|
||||
where: {
|
||||
user_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
12
queries/admin/account/getAccountByUsername.js
Normal file
12
queries/admin/account/getAccountByUsername.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getAccountByUsername(username) {
|
||||
return runQuery(
|
||||
prisma.account.findUnique({
|
||||
where: {
|
||||
username,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
22
queries/admin/account/getAccounts.js
Normal file
22
queries/admin/account/getAccounts.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getAccounts() {
|
||||
return runQuery(
|
||||
prisma.account.findMany({
|
||||
orderBy: [
|
||||
{ is_admin: 'desc' },
|
||||
{
|
||||
username: 'asc',
|
||||
},
|
||||
],
|
||||
select: {
|
||||
user_id: true,
|
||||
username: true,
|
||||
is_admin: true,
|
||||
created_at: true,
|
||||
updated_at: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
13
queries/admin/account/updateAccount.js
Normal file
13
queries/admin/account/updateAccount.js
Normal file
@ -0,0 +1,13 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function updateAccount(user_id, data) {
|
||||
return runQuery(
|
||||
prisma.account.update({
|
||||
where: {
|
||||
user_id,
|
||||
},
|
||||
data,
|
||||
}),
|
||||
);
|
||||
}
|
17
queries/admin/website/createWebsite.js
Normal file
17
queries/admin/website/createWebsite.js
Normal file
@ -0,0 +1,17 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function createWebsite(user_id, data) {
|
||||
return runQuery(
|
||||
prisma.website.create({
|
||||
data: {
|
||||
account: {
|
||||
connect: {
|
||||
user_id,
|
||||
},
|
||||
},
|
||||
...data,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
12
queries/admin/website/deleteWebsite.js
Normal file
12
queries/admin/website/deleteWebsite.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function deleteWebsite(website_id) {
|
||||
return runQuery(
|
||||
prisma.website.delete({
|
||||
where: {
|
||||
website_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
25
queries/admin/website/getAllWebsites.js
Normal file
25
queries/admin/website/getAllWebsites.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getAllWebsites() {
|
||||
let data = await runQuery(
|
||||
prisma.website.findMany({
|
||||
orderBy: [
|
||||
{
|
||||
user_id: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'asc',
|
||||
},
|
||||
],
|
||||
include: {
|
||||
account: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
return data.map(i => ({ ...i, account: i.account.username }));
|
||||
}
|
15
queries/admin/website/getUserWebsites.js
Normal file
15
queries/admin/website/getUserWebsites.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getUserWebsites(user_id) {
|
||||
return runQuery(
|
||||
prisma.website.findMany({
|
||||
where: {
|
||||
user_id,
|
||||
},
|
||||
orderBy: {
|
||||
name: 'asc',
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
12
queries/admin/website/getWebsiteById.js
Normal file
12
queries/admin/website/getWebsiteById.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getWebsiteById(website_id) {
|
||||
return runQuery(
|
||||
prisma.website.findUnique({
|
||||
where: {
|
||||
website_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
12
queries/admin/website/getWebsiteByShareId.js
Normal file
12
queries/admin/website/getWebsiteByShareId.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getWebsiteByShareId(share_id) {
|
||||
return runQuery(
|
||||
prisma.website.findUnique({
|
||||
where: {
|
||||
share_id,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
12
queries/admin/website/getWebsiteByUuid.js
Normal file
12
queries/admin/website/getWebsiteByUuid.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getWebsiteByUuid(website_uuid) {
|
||||
return runQuery(
|
||||
prisma.website.findUnique({
|
||||
where: {
|
||||
website_uuid,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
6
queries/admin/website/resetWebsite.js
Normal file
6
queries/admin/website/resetWebsite.js
Normal file
@ -0,0 +1,6 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function resetWebsite(website_id) {
|
||||
return runQuery(prisma.$queryRaw`delete from session where website_id=${website_id}`);
|
||||
}
|
13
queries/admin/website/updateWebsite.js
Normal file
13
queries/admin/website/updateWebsite.js
Normal file
@ -0,0 +1,13 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function updateWebsite(website_id, data) {
|
||||
return runQuery(
|
||||
prisma.website.update({
|
||||
where: {
|
||||
website_id,
|
||||
},
|
||||
data,
|
||||
}),
|
||||
);
|
||||
}
|
28
queries/analytics/event/getEventMetrics.js
Normal file
28
queries/analytics/event/getEventMetrics.js
Normal file
@ -0,0 +1,28 @@
|
||||
import { getDateQuery, getDateStringQuery, getFilterQuery, rawQuery } from 'lib/queries';
|
||||
|
||||
export function getEventMetrics(
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
timezone = 'utc',
|
||||
unit = 'day',
|
||||
filters = {},
|
||||
) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
event_value x,
|
||||
${getDateStringQuery(getDateQuery('created_at', unit, timezone), unit)} t,
|
||||
count(*) y
|
||||
from event
|
||||
where website_id=$1
|
||||
and created_at between $2 and $3
|
||||
${getFilterQuery('event', filters, params)}
|
||||
group by 1, 2
|
||||
order by 2
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
19
queries/analytics/event/getEvents.js
Normal file
19
queries/analytics/event/getEvents.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getEvents(websites, start_at) {
|
||||
return runQuery(
|
||||
prisma.event.findMany({
|
||||
where: {
|
||||
website: {
|
||||
website_id: {
|
||||
in: websites,
|
||||
},
|
||||
},
|
||||
created_at: {
|
||||
gte: start_at,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
17
queries/analytics/event/saveEvent.js
Normal file
17
queries/analytics/event/saveEvent.js
Normal file
@ -0,0 +1,17 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
import { URL_LENGTH } from 'lib/constants';
|
||||
|
||||
export async function saveEvent(website_id, session_id, url, event_type, event_value) {
|
||||
return runQuery(
|
||||
prisma.event.create({
|
||||
data: {
|
||||
website_id,
|
||||
session_id,
|
||||
url: url?.substr(0, URL_LENGTH),
|
||||
event_type: event_type?.substr(0, 50),
|
||||
event_value: event_value?.substr(0, 50),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
26
queries/analytics/pageview/getPageviewMetrics.js
Normal file
26
queries/analytics/pageview/getPageviewMetrics.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { parseFilters, rawQuery } from 'lib/queries';
|
||||
|
||||
export function getPageviewMetrics(website_id, start_at, end_at, field, table, filters = {}) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters(
|
||||
table,
|
||||
filters,
|
||||
params,
|
||||
);
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select ${field} x, count(*) y
|
||||
from ${table}
|
||||
${joinSession}
|
||||
where ${table}.website_id=$1
|
||||
and ${table}.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${joinSession && sessionQuery}
|
||||
${eventQuery}
|
||||
group by 1
|
||||
order by 2 desc
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
34
queries/analytics/pageview/getPageviewStats.js
Normal file
34
queries/analytics/pageview/getPageviewStats.js
Normal file
@ -0,0 +1,34 @@
|
||||
import { parseFilters, rawQuery, getDateQuery, getDateStringQuery } from 'lib/queries';
|
||||
|
||||
export function getPageviewStats(
|
||||
website_id,
|
||||
start_at,
|
||||
end_at,
|
||||
timezone = 'utc',
|
||||
unit = 'day',
|
||||
count = '*',
|
||||
filters = {},
|
||||
) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters('pageview', filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
${getDateStringQuery('g.t', unit)} as t,
|
||||
g.y as y
|
||||
from
|
||||
(select ${getDateQuery('pageview.created_at', unit, timezone)} t,
|
||||
count(${count}) y
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
group by 1) g
|
||||
order by 1
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
19
queries/analytics/pageview/getPageviews.js
Normal file
19
queries/analytics/pageview/getPageviews.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getPageviews(websites, start_at) {
|
||||
return runQuery(
|
||||
prisma.pageview.findMany({
|
||||
where: {
|
||||
website: {
|
||||
website_id: {
|
||||
in: websites,
|
||||
},
|
||||
},
|
||||
created_at: {
|
||||
gte: start_at,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
16
queries/analytics/pageview/savePageView.js
Normal file
16
queries/analytics/pageview/savePageView.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
import { URL_LENGTH } from 'lib/constants';
|
||||
|
||||
export async function savePageView(website_id, session_id, url, referrer) {
|
||||
return runQuery(
|
||||
prisma.pageview.create({
|
||||
data: {
|
||||
website_id,
|
||||
session_id,
|
||||
url: url?.substr(0, URL_LENGTH),
|
||||
referrer: referrer?.substr(0, URL_LENGTH),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
16
queries/analytics/session/createSession.js
Normal file
16
queries/analytics/session/createSession.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function createSession(website_id, data) {
|
||||
return runQuery(
|
||||
prisma.session.create({
|
||||
data: {
|
||||
website_id,
|
||||
...data,
|
||||
},
|
||||
select: {
|
||||
session_id: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
12
queries/analytics/session/getSessionByUuid.js
Normal file
12
queries/analytics/session/getSessionByUuid.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getSessionByUuid(session_uuid) {
|
||||
return runQuery(
|
||||
prisma.session.findUnique({
|
||||
where: {
|
||||
session_uuid,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
25
queries/analytics/session/getSessionMetrics.js
Normal file
25
queries/analytics/session/getSessionMetrics.js
Normal file
@ -0,0 +1,25 @@
|
||||
import { parseFilters, rawQuery } from 'lib/queries';
|
||||
|
||||
export function getSessionMetrics(website_id, start_at, end_at, field, filters = {}) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters('pageview', filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select ${field} x, count(*) y
|
||||
from session as x
|
||||
where x.session_id in (
|
||||
select pageview.session_id
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
)
|
||||
group by 1
|
||||
order by 2 desc
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
19
queries/analytics/session/getSessions.js
Normal file
19
queries/analytics/session/getSessions.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { runQuery } from 'lib/queries';
|
||||
import prisma from 'lib/db';
|
||||
|
||||
export async function getSessions(websites, start_at) {
|
||||
return runQuery(
|
||||
prisma.session.findMany({
|
||||
where: {
|
||||
website: {
|
||||
website_id: {
|
||||
in: websites,
|
||||
},
|
||||
},
|
||||
created_at: {
|
||||
gte: start_at,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
17
queries/analytics/stats/getActiveVisitors.js
Normal file
17
queries/analytics/stats/getActiveVisitors.js
Normal file
@ -0,0 +1,17 @@
|
||||
import { rawQuery } from 'lib/queries';
|
||||
import { subMinutes } from 'date-fns';
|
||||
|
||||
export function getActiveVisitors(website_id) {
|
||||
const date = subMinutes(new Date(), 5);
|
||||
const params = [website_id, date];
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select count(distinct session_id) x
|
||||
from pageview
|
||||
where website_id=$1
|
||||
and created_at >= $2
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
30
queries/analytics/stats/getRealtimeData.js
Normal file
30
queries/analytics/stats/getRealtimeData.js
Normal file
@ -0,0 +1,30 @@
|
||||
import { getPageviews } from '../pageview/getPageviews';
|
||||
import { getSessions } from '../session/getSessions';
|
||||
import { getEvents } from '../event/getEvents';
|
||||
|
||||
export async function getRealtimeData(websites, time) {
|
||||
const [pageviews, sessions, events] = await Promise.all([
|
||||
getPageviews(websites, time),
|
||||
getSessions(websites, time),
|
||||
getEvents(websites, time),
|
||||
]);
|
||||
|
||||
return {
|
||||
pageviews: pageviews.map(({ view_id, ...props }) => ({
|
||||
__id: `p${view_id}`,
|
||||
view_id,
|
||||
...props,
|
||||
})),
|
||||
sessions: sessions.map(({ session_id, ...props }) => ({
|
||||
__id: `s${session_id}`,
|
||||
session_id,
|
||||
...props,
|
||||
})),
|
||||
events: events.map(({ event_id, ...props }) => ({
|
||||
__id: `e${event_id}`,
|
||||
event_id,
|
||||
...props,
|
||||
})),
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}
|
29
queries/analytics/stats/getWebsiteStats.js
Normal file
29
queries/analytics/stats/getWebsiteStats.js
Normal file
@ -0,0 +1,29 @@
|
||||
import { parseFilters, rawQuery, getDateQuery, getTimestampInterval } from 'lib/queries';
|
||||
|
||||
export function getWebsiteStats(website_id, start_at, end_at, filters = {}) {
|
||||
const params = [website_id, start_at, end_at];
|
||||
const { pageviewQuery, sessionQuery, joinSession } = parseFilters('pageview', filters, params);
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select sum(t.c) as "pageviews",
|
||||
count(distinct t.session_id) as "uniques",
|
||||
sum(case when t.c = 1 then 1 else 0 end) as "bounces",
|
||||
sum(t.time) as "totaltime"
|
||||
from (
|
||||
select pageview.session_id,
|
||||
${getDateQuery('pageview.created_at', 'hour')},
|
||||
count(*) c,
|
||||
${getTimestampInterval('pageview.created_at')} as "time"
|
||||
from pageview
|
||||
${joinSession}
|
||||
where pageview.website_id=$1
|
||||
and pageview.created_at between $2 and $3
|
||||
${pageviewQuery}
|
||||
${sessionQuery}
|
||||
group by 1, 2
|
||||
) t
|
||||
`,
|
||||
params,
|
||||
);
|
||||
}
|
61
queries/index.js
Normal file
61
queries/index.js
Normal file
@ -0,0 +1,61 @@
|
||||
import { createAccount } from './admin/account/createAccount';
|
||||
import { deleteAccount } from './admin/account/deleteAccount';
|
||||
import { getAccountById } from './admin/account/getAccountById';
|
||||
import { getAccountByUsername } from './admin/account/getAccountByUsername';
|
||||
import { getAccounts } from './admin/account/getAccounts';
|
||||
import { updateAccount } from './admin/account/updateAccount';
|
||||
import { createWebsite } from './admin/website/createWebsite';
|
||||
import { deleteWebsite } from './admin/website/deleteWebsite';
|
||||
import { getAllWebsites } from './admin/website/getAllWebsites';
|
||||
import { getUserWebsites } from './admin/website/getUserWebsites';
|
||||
import { getWebsiteById } from './admin/website/getWebsiteById';
|
||||
import { getWebsiteByShareId } from './admin/website/getWebsiteByShareId';
|
||||
import { getWebsiteByUuid } from './admin/website/getWebsiteByUuid';
|
||||
import { resetWebsite } from './admin/website/resetWebsite';
|
||||
import { updateWebsite } from './admin/website/updateWebsite';
|
||||
import { getEventMetrics } from './analytics/event/getEventMetrics';
|
||||
import { getEvents } from './analytics/event/getEvents';
|
||||
import { saveEvent } from './analytics/event/saveEvent';
|
||||
import { getPageviewMetrics } from './analytics/pageview/getPageviewMetrics';
|
||||
import { getPageviews } from './analytics/pageview/getPageviews';
|
||||
import { getPageviewStats } from './analytics/pageview/getPageviewStats';
|
||||
import { savePageView } from './analytics/pageview/savePageView';
|
||||
import { createSession } from './analytics/session/createSession';
|
||||
import { getSessionByUuid } from './analytics/session/getSessionByUuid';
|
||||
import { getSessionMetrics } from './analytics/session/getSessionMetrics';
|
||||
import { getSessions } from './analytics/session/getSessions';
|
||||
import { getActiveVisitors } from './analytics/stats/getActiveVisitors';
|
||||
import { getRealtimeData } from './analytics/stats/getRealtimeData';
|
||||
import { getWebsiteStats } from './analytics/stats/getWebsiteStats';
|
||||
|
||||
export {
|
||||
createWebsite,
|
||||
deleteWebsite,
|
||||
getAllWebsites,
|
||||
getUserWebsites,
|
||||
getWebsiteById,
|
||||
getWebsiteByShareId,
|
||||
getWebsiteByUuid,
|
||||
resetWebsite,
|
||||
updateWebsite,
|
||||
createAccount,
|
||||
deleteAccount,
|
||||
getAccountById,
|
||||
getAccountByUsername,
|
||||
getAccounts,
|
||||
updateAccount,
|
||||
getEventMetrics,
|
||||
getEvents,
|
||||
saveEvent,
|
||||
getPageviewMetrics,
|
||||
getPageviews,
|
||||
getPageviewStats,
|
||||
savePageView,
|
||||
createSession,
|
||||
getSessionByUuid,
|
||||
getSessionMetrics,
|
||||
getSessions,
|
||||
getActiveVisitors,
|
||||
getRealtimeData,
|
||||
getWebsiteStats,
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
import buble from '@rollup/plugin-buble';
|
||||
import replace from '@rollup/plugin-replace';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
|
||||
export default {
|
||||
@ -7,5 +8,12 @@ export default {
|
||||
file: 'public/umami.js',
|
||||
format: 'iife',
|
||||
},
|
||||
plugins: [buble({ objectAssign: true }), terser({ compress: { evaluate: false } })],
|
||||
plugins: [
|
||||
replace({
|
||||
'/api/collect': process.env.COLLECT_API_ENDPOINT || '/api/collect',
|
||||
delimiters: ['', ''],
|
||||
}),
|
||||
buble({ objectAssign: true }),
|
||||
terser({ compress: { evaluate: false } }),
|
||||
],
|
||||
};
|
||||
|
@ -1,11 +1,10 @@
|
||||
require('dotenv').config();
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const prisma = new PrismaClient();
|
||||
const chalk = require('chalk');
|
||||
const spawn = require('cross-spawn');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
let message = '';
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
function success(msg) {
|
||||
console.log(chalk.greenBright(`✓ ${msg}`));
|
||||
@ -59,7 +58,7 @@ async function run(cmd, args) {
|
||||
async function checkMigrations() {
|
||||
const output = await run('prisma', ['migrate', 'status']);
|
||||
|
||||
const missingMigrations = output.includes('Following migration have not yet been applied');
|
||||
const missingMigrations = output.includes('have not yet been applied');
|
||||
const notManaged = output.includes('The current database is not managed');
|
||||
|
||||
if (notManaged || missingMigrations) {
|
||||
@ -82,7 +81,6 @@ async function checkMigrations() {
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
if (err) {
|
||||
console.log(message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -1,80 +1,102 @@
|
||||
drop table if exists event;
|
||||
drop table if exists pageview;
|
||||
drop table if exists session;
|
||||
drop table if exists website;
|
||||
drop table if exists account;
|
||||
-- CreateTable
|
||||
CREATE TABLE `account` (
|
||||
`user_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`username` VARCHAR(255) NOT NULL,
|
||||
`password` VARCHAR(60) NOT NULL,
|
||||
`is_admin` BOOLEAN NOT NULL DEFAULT false,
|
||||
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
|
||||
create table account (
|
||||
user_id int unsigned not null auto_increment primary key,
|
||||
username varchar(255) unique not null,
|
||||
password varchar(60) not null,
|
||||
is_admin bool not null default false,
|
||||
created_at timestamp default current_timestamp,
|
||||
updated_at timestamp default current_timestamp
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
UNIQUE INDEX `username`(`username`),
|
||||
PRIMARY KEY (`user_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
create table website (
|
||||
website_id int unsigned not null auto_increment primary key,
|
||||
website_uuid varchar(36) unique not null,
|
||||
user_id int unsigned not null,
|
||||
name varchar(100) not null,
|
||||
domain varchar(500),
|
||||
share_id varchar(64) unique,
|
||||
created_at timestamp default current_timestamp,
|
||||
foreign key (user_id) references account(user_id) on delete cascade
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
-- CreateTable
|
||||
CREATE TABLE `event` (
|
||||
`event_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`website_id` INTEGER UNSIGNED NOT NULL,
|
||||
`session_id` INTEGER UNSIGNED NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`url` VARCHAR(500) NOT NULL,
|
||||
`event_type` VARCHAR(50) NOT NULL,
|
||||
`event_value` VARCHAR(50) NOT NULL,
|
||||
|
||||
create table session (
|
||||
session_id int unsigned not null auto_increment primary key,
|
||||
session_uuid varchar(36) unique not null,
|
||||
website_id int unsigned not null references website(website_id) on delete cascade,
|
||||
created_at timestamp default current_timestamp,
|
||||
hostname varchar(100),
|
||||
browser varchar(20),
|
||||
os varchar(20),
|
||||
device varchar(20),
|
||||
screen varchar(11),
|
||||
language varchar(35),
|
||||
country char(2),
|
||||
foreign key (website_id) references website(website_id) on delete cascade
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
INDEX `event_created_at_idx`(`created_at`),
|
||||
INDEX `event_session_id_idx`(`session_id`),
|
||||
INDEX `event_website_id_idx`(`website_id`),
|
||||
PRIMARY KEY (`event_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
create table pageview (
|
||||
view_id int unsigned not null auto_increment primary key,
|
||||
website_id int unsigned not null,
|
||||
session_id int unsigned not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
url varchar(500) not null,
|
||||
referrer varchar(500),
|
||||
foreign key (website_id) references website(website_id) on delete cascade,
|
||||
foreign key (session_id) references session(session_id) on delete cascade
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
-- CreateTable
|
||||
CREATE TABLE `pageview` (
|
||||
`view_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`website_id` INTEGER UNSIGNED NOT NULL,
|
||||
`session_id` INTEGER UNSIGNED NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`url` VARCHAR(500) NOT NULL,
|
||||
`referrer` VARCHAR(500) NULL,
|
||||
|
||||
create table event (
|
||||
event_id int unsigned not null auto_increment primary key,
|
||||
website_id int unsigned not null,
|
||||
session_id int unsigned not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
url varchar(500) not null,
|
||||
event_type varchar(50) not null,
|
||||
event_value varchar(50) not null,
|
||||
foreign key (website_id) references website(website_id) on delete cascade,
|
||||
foreign key (session_id) references session(session_id) on delete cascade
|
||||
) ENGINE=InnoDB COLLATE=utf8_general_ci;
|
||||
INDEX `pageview_created_at_idx`(`created_at`),
|
||||
INDEX `pageview_session_id_idx`(`session_id`),
|
||||
INDEX `pageview_website_id_created_at_idx`(`website_id`, `created_at`),
|
||||
INDEX `pageview_website_id_idx`(`website_id`),
|
||||
INDEX `pageview_website_id_session_id_created_at_idx`(`website_id`, `session_id`, `created_at`),
|
||||
PRIMARY KEY (`view_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
create index website_user_id_idx on website(user_id);
|
||||
-- CreateTable
|
||||
CREATE TABLE `session` (
|
||||
`session_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`session_uuid` VARCHAR(36) NOT NULL,
|
||||
`website_id` INTEGER UNSIGNED NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`hostname` VARCHAR(100) NULL,
|
||||
`browser` VARCHAR(20) NULL,
|
||||
`os` VARCHAR(20) NULL,
|
||||
`device` VARCHAR(20) NULL,
|
||||
`screen` VARCHAR(11) NULL,
|
||||
`language` VARCHAR(35) NULL,
|
||||
`country` CHAR(2) NULL,
|
||||
|
||||
create index session_created_at_idx on session(created_at);
|
||||
create index session_website_id_idx on session(website_id);
|
||||
UNIQUE INDEX `session_uuid`(`session_uuid`),
|
||||
INDEX `session_created_at_idx`(`created_at`),
|
||||
INDEX `session_website_id_idx`(`website_id`),
|
||||
PRIMARY KEY (`session_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
create index pageview_created_at_idx on pageview(created_at);
|
||||
create index pageview_website_id_idx on pageview(website_id);
|
||||
create index pageview_session_id_idx on pageview(session_id);
|
||||
create index pageview_website_id_created_at_idx on pageview(website_id, created_at);
|
||||
create index pageview_website_id_session_id_created_at_idx on pageview(website_id, session_id, created_at);
|
||||
-- CreateTable
|
||||
CREATE TABLE `website` (
|
||||
`website_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`website_uuid` VARCHAR(36) NOT NULL,
|
||||
`user_id` INTEGER UNSIGNED NOT NULL,
|
||||
`name` VARCHAR(100) NOT NULL,
|
||||
`domain` VARCHAR(500) NULL,
|
||||
`share_id` VARCHAR(64) NULL,
|
||||
`created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
|
||||
create index event_created_at_idx on event(created_at);
|
||||
create index event_website_id_idx on event(website_id);
|
||||
create index event_session_id_idx on event(session_id);
|
||||
UNIQUE INDEX `website_uuid`(`website_uuid`),
|
||||
UNIQUE INDEX `share_id`(`share_id`),
|
||||
INDEX `website_user_id_idx`(`user_id`),
|
||||
PRIMARY KEY (`website_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
insert into account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `event` ADD CONSTRAINT `event_ibfk_2` FOREIGN KEY (`session_id`) REFERENCES `session`(`session_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `event` ADD CONSTRAINT `event_ibfk_1` FOREIGN KEY (`website_id`) REFERENCES `website`(`website_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `pageview` ADD CONSTRAINT `pageview_ibfk_2` FOREIGN KEY (`session_id`) REFERENCES `session`(`session_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `pageview` ADD CONSTRAINT `pageview_ibfk_1` FOREIGN KEY (`website_id`) REFERENCES `website`(`website_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `session` ADD CONSTRAINT `session_ibfk_1` FOREIGN KEY (`website_id`) REFERENCES `website`(`website_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `website` ADD CONSTRAINT `website_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`(`user_id`) ON DELETE CASCADE ON UPDATE NO ACTION;
|
||||
|
||||
-- CreateAdminUser
|
||||
INSERT INTO account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);
|
||||
|
@ -1,74 +1,132 @@
|
||||
drop table if exists event;
|
||||
drop table if exists pageview;
|
||||
drop table if exists session;
|
||||
drop table if exists website;
|
||||
drop table if exists account;
|
||||
-- CreateTable
|
||||
CREATE TABLE "account" (
|
||||
"user_id" SERIAL NOT NULL,
|
||||
"username" VARCHAR(255) NOT NULL,
|
||||
"password" VARCHAR(60) NOT NULL,
|
||||
"is_admin" BOOLEAN NOT NULL DEFAULT false,
|
||||
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
create table account (
|
||||
user_id serial primary key,
|
||||
username varchar(255) unique not null,
|
||||
password varchar(60) not null,
|
||||
is_admin bool not null default false,
|
||||
created_at timestamp with time zone default current_timestamp,
|
||||
updated_at timestamp with time zone default current_timestamp
|
||||
PRIMARY KEY ("user_id")
|
||||
);
|
||||
|
||||
create table website (
|
||||
website_id serial primary key,
|
||||
website_uuid uuid unique not null,
|
||||
user_id int not null references account(user_id) on delete cascade,
|
||||
name varchar(100) not null,
|
||||
domain varchar(500),
|
||||
share_id varchar(64) unique,
|
||||
created_at timestamp with time zone default current_timestamp
|
||||
-- CreateTable
|
||||
CREATE TABLE "event" (
|
||||
"event_id" SERIAL NOT NULL,
|
||||
"website_id" INTEGER NOT NULL,
|
||||
"session_id" INTEGER NOT NULL,
|
||||
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||
"url" VARCHAR(500) NOT NULL,
|
||||
"event_type" VARCHAR(50) NOT NULL,
|
||||
"event_value" VARCHAR(50) NOT NULL,
|
||||
|
||||
PRIMARY KEY ("event_id")
|
||||
);
|
||||
|
||||
create table session (
|
||||
session_id serial primary key,
|
||||
session_uuid uuid unique not null,
|
||||
website_id int not null references website(website_id) on delete cascade,
|
||||
created_at timestamp with time zone default current_timestamp,
|
||||
hostname varchar(100),
|
||||
browser varchar(20),
|
||||
os varchar(20),
|
||||
device varchar(20),
|
||||
screen varchar(11),
|
||||
language varchar(35),
|
||||
country char(2)
|
||||
-- CreateTable
|
||||
CREATE TABLE "pageview" (
|
||||
"view_id" SERIAL NOT NULL,
|
||||
"website_id" INTEGER NOT NULL,
|
||||
"session_id" INTEGER NOT NULL,
|
||||
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||
"url" VARCHAR(500) NOT NULL,
|
||||
"referrer" VARCHAR(500),
|
||||
|
||||
PRIMARY KEY ("view_id")
|
||||
);
|
||||
|
||||
create table pageview (
|
||||
view_id serial primary key,
|
||||
website_id int not null references website(website_id) on delete cascade,
|
||||
session_id int not null references session(session_id) on delete cascade,
|
||||
created_at timestamp with time zone default current_timestamp,
|
||||
url varchar(500) not null,
|
||||
referrer varchar(500)
|
||||
-- CreateTable
|
||||
CREATE TABLE "session" (
|
||||
"session_id" SERIAL NOT NULL,
|
||||
"session_uuid" UUID NOT NULL,
|
||||
"website_id" INTEGER NOT NULL,
|
||||
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||
"hostname" VARCHAR(100),
|
||||
"browser" VARCHAR(20),
|
||||
"os" VARCHAR(20),
|
||||
"device" VARCHAR(20),
|
||||
"screen" VARCHAR(11),
|
||||
"language" VARCHAR(35),
|
||||
"country" CHAR(2),
|
||||
|
||||
PRIMARY KEY ("session_id")
|
||||
);
|
||||
|
||||
create table event (
|
||||
event_id serial primary key,
|
||||
website_id int not null references website(website_id) on delete cascade,
|
||||
session_id int not null references session(session_id) on delete cascade,
|
||||
created_at timestamp with time zone default current_timestamp,
|
||||
url varchar(500) not null,
|
||||
event_type varchar(50) not null,
|
||||
event_value varchar(50) not null
|
||||
-- CreateTable
|
||||
CREATE TABLE "website" (
|
||||
"website_id" SERIAL NOT NULL,
|
||||
"website_uuid" UUID NOT NULL,
|
||||
"user_id" INTEGER NOT NULL,
|
||||
"name" VARCHAR(100) NOT NULL,
|
||||
"domain" VARCHAR(500),
|
||||
"share_id" VARCHAR(64),
|
||||
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY ("website_id")
|
||||
);
|
||||
|
||||
create index website_user_id_idx on website(user_id);
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "account.username_unique" ON "account"("username");
|
||||
|
||||
create index session_created_at_idx on session(created_at);
|
||||
create index session_website_id_idx on session(website_id);
|
||||
-- CreateIndex
|
||||
CREATE INDEX "event_created_at_idx" ON "event"("created_at");
|
||||
|
||||
create index pageview_created_at_idx on pageview(created_at);
|
||||
create index pageview_website_id_idx on pageview(website_id);
|
||||
create index pageview_session_id_idx on pageview(session_id);
|
||||
create index pageview_website_id_created_at_idx on pageview(website_id, created_at);
|
||||
create index pageview_website_id_session_id_created_at_idx on pageview(website_id, session_id, created_at);
|
||||
-- CreateIndex
|
||||
CREATE INDEX "event_session_id_idx" ON "event"("session_id");
|
||||
|
||||
create index event_created_at_idx on event(created_at);
|
||||
create index event_website_id_idx on event(website_id);
|
||||
create index event_session_id_idx on event(session_id);
|
||||
-- CreateIndex
|
||||
CREATE INDEX "event_website_id_idx" ON "event"("website_id");
|
||||
|
||||
insert into account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_created_at_idx" ON "pageview"("created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_session_id_idx" ON "pageview"("session_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_website_id_created_at_idx" ON "pageview"("website_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_website_id_idx" ON "pageview"("website_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "pageview_website_id_session_id_created_at_idx" ON "pageview"("website_id", "session_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "session.session_uuid_unique" ON "session"("session_uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "session_created_at_idx" ON "session"("created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "session_website_id_idx" ON "session"("website_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "website.website_uuid_unique" ON "website"("website_uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "website.share_id_unique" ON "website"("share_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "website_user_id_idx" ON "website"("user_id");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "event" ADD FOREIGN KEY ("session_id") REFERENCES "session"("session_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "event" ADD FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "pageview" ADD FOREIGN KEY ("session_id") REFERENCES "session"("session_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "pageview" ADD FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "session" ADD FOREIGN KEY ("website_id") REFERENCES "website"("website_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "website" ADD FOREIGN KEY ("user_id") REFERENCES "account"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- CreateAdminUser
|
||||
INSERT INTO account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);
|
||||
|
@ -1,16 +1,15 @@
|
||||
import create from 'zustand';
|
||||
import produce from 'immer';
|
||||
import semver from 'semver';
|
||||
import { VERSION_CHECK } from 'lib/constants';
|
||||
import { VERSION_CHECK, UPDATES_URL } from 'lib/constants';
|
||||
import { getItem } from 'lib/web';
|
||||
|
||||
const UPDATES_URL = 'https://api.umami.is/v1/updates';
|
||||
|
||||
const initialState = {
|
||||
current: process.env.currentVersion,
|
||||
latest: null,
|
||||
hasUpdate: false,
|
||||
checked: false,
|
||||
releaseUrl: null,
|
||||
};
|
||||
|
||||
const store = create(() => ({ ...initialState }));
|
||||
@ -37,7 +36,7 @@ export async function checkVersion() {
|
||||
|
||||
store.setState(
|
||||
produce(state => {
|
||||
const { latest } = data;
|
||||
const { latest, url } = data;
|
||||
const lastCheck = getItem(VERSION_CHECK);
|
||||
|
||||
const hasUpdate = !!(latest && lastCheck?.version !== latest && semver.gt(latest, current));
|
||||
@ -46,6 +45,7 @@ export async function checkVersion() {
|
||||
state.latest = latest;
|
||||
state.hasUpdate = hasUpdate;
|
||||
state.checked = true;
|
||||
state.releaseUrl = url;
|
||||
|
||||
return state;
|
||||
}),
|
||||
|
Loading…
Reference in New Issue
Block a user