Initial lookbook implementation

Pinterest-style visual bookmarking app with:
- URL metadata extraction (OG/Twitter meta, oEmbed fallback)
- Image caching in Postgres with 480px thumbnails
- Multi-tag filtering with Ctrl/Cmd for OR mode
- Fuzzy tag suggestions and inline tag editing
- Browser console auth() with first-use password setup
- Brutalist UI with Commit Mono font and Pico CSS
- Light/dark mode via browser preference
This commit is contained in:
soup 2026-01-16 21:14:23 -05:00
commit fc625fb9cf
Signed by: soup
SSH key fingerprint: SHA256:GYxje8eQkJ6HZKzVWDdyOUF1TyDiprruGhE0Ym8qYDY
486 changed files with 195373 additions and 0 deletions

View file

@ -0,0 +1,45 @@
package auth
import (
"context"
"database/sql"
"time"
)
type Row struct {
ID int64
PasswordHash []byte
CreatedAt time.Time
}
func QGet(ctx context.Context, db *sql.DB) (*Row, error) {
var row Row
err := db.QueryRowContext(ctx, `
SELECT id, password_hash, created_at
FROM auth
ORDER BY id ASC
LIMIT 1
`).Scan(&row.ID, &row.PasswordHash, &row.CreatedAt)
if err == sql.ErrNoRows {
return nil, nil
}
if err != nil {
return nil, err
}
return &row, nil
}
func QCreate(ctx context.Context, db *sql.DB, hash []byte) (Row, error) {
var row Row
err := db.QueryRowContext(ctx, `
INSERT INTO auth (password_hash)
VALUES ($1)
RETURNING id, password_hash, created_at
`, hash).Scan(&row.ID, &row.PasswordHash, &row.CreatedAt)
return row, err
}
func QUpdate(ctx context.Context, db *sql.DB, id int64, hash []byte) error {
_, err := db.ExecContext(ctx, `UPDATE auth SET password_hash = $2 WHERE id = $1`, id, hash)
return err
}

View file

@ -0,0 +1,119 @@
package image
import (
"context"
"database/sql"
"time"
)
type Row struct {
ID int64
ItemID int64
OriginalURL string
ContentType string
Bytes []byte
Width int
Height int
IsThumb bool
CreatedAt time.Time
}
type Ref struct {
ID int64
ItemID int64
IsThumb bool
}
func QListByItem(ctx context.Context, db *sql.DB, itemID int64) ([]Row, error) {
rows, err := db.QueryContext(ctx, `
SELECT id, item_id, original_url, content_type, bytes, width, height, is_thumb, created_at
FROM image
WHERE item_id = $1
ORDER BY is_thumb DESC, id ASC
`, itemID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Row
for rows.Next() {
var row Row
if err := rows.Scan(&row.ID, &row.ItemID, &row.OriginalURL, &row.ContentType, &row.Bytes, &row.Width, &row.Height, &row.IsThumb, &row.CreatedAt); err != nil {
return nil, err
}
items = append(items, row)
}
return items, rows.Err()
}
func QListPrimaryRefsByItems(ctx context.Context, db *sql.DB, itemIDs []int64) (map[int64]Ref, error) {
if len(itemIDs) == 0 {
return map[int64]Ref{}, nil
}
rows, err := db.QueryContext(ctx, `
SELECT id, item_id, is_thumb
FROM image
WHERE item_id = ANY($1)
ORDER BY item_id ASC, is_thumb DESC, id ASC
`, itemIDs)
if err != nil {
return nil, err
}
defer rows.Close()
results := make(map[int64]Ref)
for rows.Next() {
var row Ref
if err := rows.Scan(&row.ID, &row.ItemID, &row.IsThumb); err != nil {
return nil, err
}
if _, exists := results[row.ItemID]; !exists {
results[row.ItemID] = row
}
}
return results, rows.Err()
}
func QFindByID(ctx context.Context, db *sql.DB, id int64) (*Row, error) {
var row Row
err := db.QueryRowContext(ctx, `
SELECT id, item_id, original_url, content_type, bytes, width, height, is_thumb, created_at
FROM image
WHERE id = $1
LIMIT 1
`, id).Scan(&row.ID, &row.ItemID, &row.OriginalURL, &row.ContentType, &row.Bytes, &row.Width, &row.Height, &row.IsThumb, &row.CreatedAt)
if err == sql.ErrNoRows {
return nil, nil
}
if err != nil {
return nil, err
}
return &row, nil
}
func QCreate(ctx context.Context, db *sql.DB, itemID int64, originalURL, contentType string, bytes []byte, width, height int, isThumb bool) (Row, error) {
var row Row
err := db.QueryRowContext(ctx, `
INSERT INTO image (item_id, original_url, content_type, bytes, width, height, is_thumb)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, item_id, original_url, content_type, bytes, width, height, is_thumb, created_at
`, itemID, originalURL, contentType, bytes, width, height, isThumb).Scan(
&row.ID,
&row.ItemID,
&row.OriginalURL,
&row.ContentType,
&row.Bytes,
&row.Width,
&row.Height,
&row.IsThumb,
&row.CreatedAt,
)
return row, err
}
func QDeleteByItem(ctx context.Context, db *sql.DB, itemID int64) error {
_, err := db.ExecContext(ctx, `DELETE FROM image WHERE item_id = $1`, itemID)
return err
}

View file

@ -0,0 +1,100 @@
package item
import (
"context"
"database/sql"
"time"
"github.com/google/uuid"
)
type Row struct {
ID int64
PubID uuid.UUID
SourceURL string
Title string
Description string
SiteName string
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt sql.Null[time.Time]
}
func QList(ctx context.Context, db *sql.DB) ([]Row, error) {
rows, err := db.QueryContext(ctx, `
SELECT id, pub_id, source_url, title, description, site_name, created_at, updated_at, deleted_at
FROM item
WHERE deleted_at IS NULL
ORDER BY created_at DESC
`)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Row
for rows.Next() {
var row Row
if err := rows.Scan(&row.ID, &row.PubID, &row.SourceURL, &row.Title, &row.Description, &row.SiteName, &row.CreatedAt, &row.UpdatedAt, &row.DeletedAt); err != nil {
return nil, err
}
items = append(items, row)
}
return items, rows.Err()
}
func QFindByID(ctx context.Context, db *sql.DB, id int64) (*Row, error) {
var row Row
err := db.QueryRowContext(ctx, `
SELECT id, pub_id, source_url, title, description, site_name, created_at, updated_at, deleted_at
FROM item
WHERE id = $1
LIMIT 1
`, id).Scan(&row.ID, &row.PubID, &row.SourceURL, &row.Title, &row.Description, &row.SiteName, &row.CreatedAt, &row.UpdatedAt, &row.DeletedAt)
if err == sql.ErrNoRows {
return nil, nil
}
if err != nil {
return nil, err
}
return &row, nil
}
func QCreate(ctx context.Context, db *sql.DB, sourceURL, title, description, siteName string) (Row, error) {
var row Row
err := db.QueryRowContext(ctx, `
INSERT INTO item (source_url, title, description, site_name)
VALUES ($1, $2, $3, $4)
RETURNING id, pub_id, source_url, title, description, site_name, created_at, updated_at, deleted_at
`, sourceURL, title, description, siteName).Scan(
&row.ID,
&row.PubID,
&row.SourceURL,
&row.Title,
&row.Description,
&row.SiteName,
&row.CreatedAt,
&row.UpdatedAt,
&row.DeletedAt,
)
return row, err
}
func QUpdateMeta(ctx context.Context, db *sql.DB, id int64, title, description, siteName string) error {
_, err := db.ExecContext(ctx, `
UPDATE item
SET title = $2, description = $3, site_name = $4, updated_at = NOW()
WHERE id = $1
`, id, title, description, siteName)
return err
}
func QSoftDelete(ctx context.Context, db *sql.DB, id int64) error {
_, err := db.ExecContext(ctx, `UPDATE item SET deleted_at = NOW() WHERE id = $1`, id)
return err
}
func QRestore(ctx context.Context, db *sql.DB, id int64) error {
_, err := db.ExecContext(ctx, `UPDATE item SET deleted_at = NULL WHERE id = $1`, id)
return err
}

View file

@ -0,0 +1,51 @@
package session
import (
"context"
"database/sql"
"time"
)
type Row struct {
ID int64
Token string
CreatedAt time.Time
ExpiresAt time.Time
}
func QCreate(ctx context.Context, db *sql.DB, token string, expiresAt time.Time) (Row, error) {
var row Row
err := db.QueryRowContext(ctx, `
INSERT INTO session (token, expires_at)
VALUES ($1, $2)
RETURNING id, token, created_at, expires_at
`, token, expiresAt).Scan(&row.ID, &row.Token, &row.CreatedAt, &row.ExpiresAt)
return row, err
}
func QFindByToken(ctx context.Context, db *sql.DB, token string) (*Row, error) {
var row Row
err := db.QueryRowContext(ctx, `
SELECT id, token, created_at, expires_at
FROM session
WHERE token = $1
LIMIT 1
`, token).Scan(&row.ID, &row.Token, &row.CreatedAt, &row.ExpiresAt)
if err == sql.ErrNoRows {
return nil, nil
}
if err != nil {
return nil, err
}
return &row, nil
}
func QDelete(ctx context.Context, db *sql.DB, token string) error {
_, err := db.ExecContext(ctx, `DELETE FROM session WHERE token = $1`, token)
return err
}
func QDeleteExpired(ctx context.Context, db *sql.DB) error {
_, err := db.ExecContext(ctx, `DELETE FROM session WHERE expires_at < NOW()`)
return err
}

View file

@ -0,0 +1,141 @@
package tag
import (
"context"
"database/sql"
"strings"
"time"
)
type Row struct {
ID int64
Name string
CreatedAt time.Time
}
type ItemTag struct {
ItemID int64
TagID int64
Name string
}
func QList(ctx context.Context, db *sql.DB) ([]Row, error) {
rows, err := db.QueryContext(ctx, `
SELECT id, name, created_at
FROM tag
ORDER BY name ASC
`)
if err != nil {
return nil, err
}
defer rows.Close()
var tags []Row
for rows.Next() {
var row Row
if err := rows.Scan(&row.ID, &row.Name, &row.CreatedAt); err != nil {
return nil, err
}
tags = append(tags, row)
}
return tags, rows.Err()
}
func QListByItem(ctx context.Context, db *sql.DB, itemID int64) ([]Row, error) {
rows, err := db.QueryContext(ctx, `
SELECT t.id, t.name, t.created_at
FROM tag t
JOIN item_tag it ON it.tag_id = t.id
WHERE it.item_id = $1
ORDER BY t.name ASC
`, itemID)
if err != nil {
return nil, err
}
defer rows.Close()
var tags []Row
for rows.Next() {
var row Row
if err := rows.Scan(&row.ID, &row.Name, &row.CreatedAt); err != nil {
return nil, err
}
tags = append(tags, row)
}
return tags, rows.Err()
}
func QListItemTags(ctx context.Context, db *sql.DB) ([]ItemTag, error) {
rows, err := db.QueryContext(ctx, `
SELECT it.item_id, t.id, t.name
FROM item_tag it
JOIN tag t ON t.id = it.tag_id
ORDER BY t.name ASC
`)
if err != nil {
return nil, err
}
defer rows.Close()
var entries []ItemTag
for rows.Next() {
var row ItemTag
if err := rows.Scan(&row.ItemID, &row.TagID, &row.Name); err != nil {
return nil, err
}
entries = append(entries, row)
}
return entries, rows.Err()
}
func QUpsert(ctx context.Context, db *sql.DB, name string) (Row, error) {
cleaned := strings.TrimSpace(strings.ToLower(name))
var row Row
err := db.QueryRowContext(ctx, `
INSERT INTO tag (name)
VALUES ($1)
ON CONFLICT (name) DO UPDATE SET name = EXCLUDED.name
RETURNING id, name, created_at
`, cleaned).Scan(&row.ID, &row.Name, &row.CreatedAt)
return row, err
}
func QReplaceItemTags(ctx context.Context, db *sql.DB, itemID int64, names []string) error {
tx, err := db.BeginTx(ctx, nil)
if err != nil {
return err
}
defer tx.Rollback()
_, err = tx.ExecContext(ctx, `DELETE FROM item_tag WHERE item_id = $1`, itemID)
if err != nil {
return err
}
for _, name := range names {
if strings.TrimSpace(name) == "" {
continue
}
var tagID int64
err = tx.QueryRowContext(ctx, `
INSERT INTO tag (name)
VALUES ($1)
ON CONFLICT (name) DO UPDATE SET name = EXCLUDED.name
RETURNING id
`, strings.TrimSpace(strings.ToLower(name))).Scan(&tagID)
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, `
INSERT INTO item_tag (item_id, tag_id)
VALUES ($1, $2)
ON CONFLICT DO NOTHING
`, itemID, tagID)
if err != nil {
return err
}
}
return tx.Commit()
}