wfc-server/api/main.go
ppeb 6a40b5c9ec
Store blob hashes, require on login
Blob hashes are now stored in the database under the `hashes` table.
They are stored internally as a map of packIDs to a map of versions to a
map of regions to the hash.

On login, a pack ID, version, and hash are required or the login attempt
is rejected.

Hashes can be updated using the `/api/hash` endpoint.

The schema has been updated accordingly.
2025-03-10 08:39:19 -05:00

44 lines
704 B
Go

package api
import (
"context"
"fmt"
"wwfc/common"
"wwfc/database"
"github.com/jackc/pgx/v4/pgxpool"
)
var (
ctx = context.Background()
pool *pgxpool.Pool
apiSecret string
)
func StartServer(reload bool) {
// Get config
config := common.GetConfig()
apiSecret = config.APISecret
// Start SQL
dbString := fmt.Sprintf("postgres://%s:%s@%s/%s", config.Username, config.Password, config.DatabaseAddress, config.DatabaseName)
dbConf, err := pgxpool.ParseConfig(dbString)
if err != nil {
panic(err)
}
pool, err = pgxpool.ConnectConfig(ctx, dbConf)
if err != nil {
panic(err)
}
err = database.HashInit(pool, ctx)
if err != nil {
panic(err)
}
}
func Shutdown() {
}