Pinterest-like app for saving images, videos, quotes, and embeds. Features: - Go backend with PostgreSQL, SSR templates - Console-based admin auth (login/logout via browser console) - Item types: images, videos (ffmpeg transcoding), quotes, embeds - Media stored as BLOBs in PostgreSQL - OpenGraph metadata extraction for links - Embed detection for YouTube, Vimeo, Twitter/X - Masonry grid layout, item detail pages - Tag system with filtering - Refresh metadata endpoint with change warnings - Replace media endpoint for updating item images/videos
41 lines
979 B
Go
41 lines
979 B
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
type Row struct {
|
|
ID int
|
|
PasswordHash []byte // nil if not set
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
// QGet returns the single admin row.
|
|
func QGet(ctx context.Context, db *sql.DB) (Row, error) {
|
|
query := `SELECT id, password_hash, created_at FROM admin WHERE id = 1`
|
|
|
|
var row Row
|
|
err := db.QueryRowContext(ctx, query).Scan(
|
|
&row.ID,
|
|
&row.PasswordHash,
|
|
&row.CreatedAt,
|
|
)
|
|
return row, err
|
|
}
|
|
|
|
// QSetPassword sets the admin password hash.
|
|
func QSetPassword(ctx context.Context, db *sql.DB, hash []byte) error {
|
|
query := `UPDATE admin SET password_hash = $1 WHERE id = 1`
|
|
_, err := db.ExecContext(ctx, query, hash)
|
|
return err
|
|
}
|
|
|
|
// QHasPassword returns true if a password has been set.
|
|
func QHasPassword(ctx context.Context, db *sql.DB) (bool, error) {
|
|
query := `SELECT password_hash IS NOT NULL FROM admin WHERE id = 1`
|
|
var has bool
|
|
err := db.QueryRowContext(ctx, query).Scan(&has)
|
|
return has, err
|
|
}
|