mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
Add zero-dependency SQLite mode so users can run Erupe without
PostgreSQL. A transparent db.DB wrapper auto-translates PostgreSQL
SQL ($N placeholders, now(), ::casts, ILIKE, public. prefix,
TRUNCATE) for SQLite at runtime — all 28 repo files use the wrapper
with no per-query changes needed.
Setup wizard gains two new steps: quest file detection with download
link, and gameplay presets (solo/small/community/rebalanced). The API
server gets a /dashboard endpoint with auto-refreshing stats.
CI release workflow now builds and pushes Docker images to GHCR
alongside binary artifacts on tag push.
Key changes:
- common/db: DB/Tx wrapper with 6 SQL translation rules
- server/migrations/sqlite: full SQLite schema (0001-0005)
- config: Database.Driver field ("postgres" or "sqlite")
- main.go: SQLite connection with WAL mode, single writer
- server/setup: quest check + preset selection steps
- server/api: /dashboard with live stats
- .github/workflows: Docker in release, deduplicate docker.yml
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package signserver
|
|
|
|
import dbutil "erupe-ce/common/db"
|
|
|
|
// SignSessionRepository implements SignSessionRepo with PostgreSQL.
|
|
type SignSessionRepository struct {
|
|
db *dbutil.DB
|
|
}
|
|
|
|
// NewSignSessionRepository creates a new SignSessionRepository.
|
|
func NewSignSessionRepository(db *dbutil.DB) *SignSessionRepository {
|
|
return &SignSessionRepository{db: db}
|
|
}
|
|
|
|
func (r *SignSessionRepository) RegisterUID(uid uint32, token string) (uint32, error) {
|
|
var tid uint32
|
|
err := r.db.QueryRow(`INSERT INTO sign_sessions (user_id, token) VALUES ($1, $2) RETURNING id`, uid, token).Scan(&tid)
|
|
return tid, err
|
|
}
|
|
|
|
func (r *SignSessionRepository) RegisterPSN(psnID, token string) (uint32, error) {
|
|
var tid uint32
|
|
err := r.db.QueryRow(`INSERT INTO sign_sessions (psn_id, token) VALUES ($1, $2) RETURNING id`, psnID, token).Scan(&tid)
|
|
return tid, err
|
|
}
|
|
|
|
func (r *SignSessionRepository) Validate(token string, tokenID uint32) (bool, error) {
|
|
query := `SELECT count(*) FROM sign_sessions WHERE token = $1`
|
|
if tokenID > 0 {
|
|
query += ` AND id = $2`
|
|
}
|
|
var exists int
|
|
err := r.db.QueryRow(query, token, tokenID).Scan(&exists)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return exists > 0, nil
|
|
}
|
|
|
|
func (r *SignSessionRepository) GetPSNIDByToken(token string) (string, error) {
|
|
var psnID string
|
|
err := r.db.QueryRow(`SELECT psn_id FROM sign_sessions WHERE token = $1`, token).Scan(&psnID)
|
|
return psnID, err
|
|
}
|