diff --git a/lib/generators.js b/lib/generators.js new file mode 100644 index 0000000..b542bd7 --- /dev/null +++ b/lib/generators.js @@ -0,0 +1,23 @@ +const crypto = require('crypto'); + +// Characters used when generating a random API key: letters, digits and a handful of symbols. +const API_KEY_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+'; +const API_KEY_LENGTH = 64; + +// Generates a new place id as a random UUID (v4). +function generatePlaceId() { + return crypto.randomUUID(); +} + +// Generates a random alphanumeric+symbol API key of the given length (default 64 characters). +// Uses crypto.randomInt for unbiased selection of each character (rather than bytes % length, +// which would skew towards characters at the start of the alphabet). +function generateApiKey(length = API_KEY_LENGTH) { + let key = ''; + for (let i = 0; i < length; i++) { + key += API_KEY_CHARS[crypto.randomInt(API_KEY_CHARS.length)]; + } + return key; +} + +module.exports = { generatePlaceId, generateApiKey }; diff --git a/migrations/0005_place_name.sql b/migrations/0005_place_name.sql new file mode 100644 index 0000000..ebc9fa4 --- /dev/null +++ b/migrations/0005_place_name.sql @@ -0,0 +1 @@ +ALTER TABLE places ADD COLUMN name TEXT; diff --git a/public/css/style.css b/public/css/style.css index 7ba063c..cbcf5a5 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -170,6 +170,19 @@ button.danger { font-size: 14px; margin-bottom: 4px; color: var(--muted); + display: flex; + flex-direction: column; + gap: 2px; +} + +.place-list-id { + font-size: 14px; +} + +.place-list-owner { + font-size: 11px; + color: var(--muted); + opacity: 0.75; } .place-list li:hover { diff --git a/public/dashboard/index.html b/public/dashboard/index.html index b36d986..da596b9 100644 --- a/public/dashboard/index.html +++ b/public/dashboard/index.html @@ -19,10 +19,14 @@