feat(session): create website on session request

pull/381/head
SinaniG 2020-11-05 10:33:12 +03:00
parent c881751e4f
commit 66f2075f37
6 changed files with 17137 additions and 8 deletions

View File

@ -8,11 +8,13 @@ services:
environment:
DATABASE_URL: postgresql://umami:umami@db:5432/umami
DATABASE_TYPE: postgresql
HASH_SALT: replace-me-with-a-random-string
HASH_SALT: cMP9En7jrhD6uKKAMpuADybe32Ww7Cfu
depends_on:
- db
db:
image: postgres:12-alpine
ports:
- "127.0.0.1:5432:5432"
environment:
POSTGRES_DB: umami
POSTGRES_USER: umami
@ -21,4 +23,4 @@ services:
- ./sql/schema.postgresql.sql:/docker-entrypoint-initdb.d/schema.postgresql.sql:ro
- umami-db-data:/var/lib/postgresql/data
volumes:
umami-db-data:
umami-db-data:

View File

@ -28,7 +28,15 @@ export function uuid(...args) {
}
export function isValidUuid(s) {
return validate(s);
const isValid = validate(s);
if (isValid) return true;
try {
s.toString();
return true;
} catch (error) {
return false;
}
}
export function getRandomChars(n) {

View File

@ -1,4 +1,4 @@
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'lib/queries';
import { getWebsiteByUuid, getSessionByUuid, createSession, createWebsite } from 'lib/queries';
import { getClientInfo } from 'lib/request';
import { uuid, isValidUuid, parseToken } from 'lib/crypto';
@ -25,10 +25,17 @@ export async function getSession(req) {
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
const website = await getWebsiteByUuid(website_uuid);
let website = await getWebsiteByUuid(website_uuid);
if (!website) {
throw new Error(`Website not found: ${website_uuid}`);
// throw new Error(`Website not found: ${website_uuid}`);
const user_id = 1;
website = await createWebsite(user_id, {
website_uuid,
name: website_uuid,
domain: `http://${website_uuid}`,
share_id: null,
});
}
const { website_id } = website;

17112
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ create table account (
create table website (
website_id int unsigned not null auto_increment primary key,
website_uuid varchar(36) unique not null,
website_uuid varchar(128) unique not null,
user_id int unsigned not null,
name varchar(100) not null,
domain varchar(500),

View File

@ -15,7 +15,7 @@ create table account (
create table website (
website_id serial primary key,
website_uuid uuid unique not null,
website_uuid varchar(128) unique not null,
user_id int not null references account(user_id) on delete cascade,
name varchar(100) not null,
domain varchar(500),