SAKE: Support file download requests for champion ghosts from Mario Kart Wii

Helps address issue #43.
This commit is contained in:
MikeIsAStar
2024-09-08 12:50:00 -04:00
parent 46f269d470
commit a55800eb2f
6 changed files with 152 additions and 17 deletions

View File

@@ -21,6 +21,18 @@ const (
"AND courseid = $2 " +
"ORDER BY score ASC " +
"LIMIT 10"
getStoredGhostDataQuery = "" +
"SELECT pid, id " +
"FROM mario_kart_wii_sake " +
"WHERE ($1 = 0 OR regionid = $1) " +
"AND courseid = $2 " +
"ORDER BY score ASC " +
"LIMIT 1"
getFileQuery = "" +
"SELECT ghost " +
"FROM mario_kart_wii_sake " +
"WHERE id = $1 " +
"LIMIT 1"
getGhostFileQuery = "" +
"SELECT ghost " +
"FROM mario_kart_wii_sake " +
@@ -54,21 +66,43 @@ func GetMarioKartWiiTopTenRankings(pool *pgxpool.Pool, ctx context.Context, regi
topTenRankings = append(topTenRankings, topTenRanking)
}
err = rows.Err()
if err != nil {
if err = rows.Err(); err != nil {
return nil, err
}
return topTenRankings, nil
}
func GetMarioKartWiiStoredGhostData(pool *pgxpool.Pool, ctx context.Context, regionId common.MarioKartWiiLeaderboardRegionId,
courseId common.MarioKartWiiCourseId) (int, int, error) {
row := pool.QueryRow(ctx, getStoredGhostDataQuery, regionId, courseId)
var pid int
var fileId int
if err := row.Scan(&pid, &fileId); err != nil {
return 0, 0, err
}
return pid, fileId, nil
}
func GetMarioKartWiiFile(pool *pgxpool.Pool, ctx context.Context, fileId int) ([]byte, error) {
row := pool.QueryRow(ctx, getFileQuery, fileId)
var file []byte
if err := row.Scan(&file); err != nil {
return nil, err
}
return file, nil
}
func GetMarioKartWiiGhostFile(pool *pgxpool.Pool, ctx context.Context, courseId common.MarioKartWiiCourseId,
time int, pid int) ([]byte, error) {
row := pool.QueryRow(ctx, getGhostFileQuery, courseId, time, pid)
var ghost []byte
err := row.Scan(&ghost)
if err != nil {
if err := row.Scan(&ghost); err != nil {
return nil, err
}

View File

@@ -9,23 +9,24 @@ import (
func UpdateTables(pool *pgxpool.Pool, ctx context.Context) {
pool.Exec(ctx, `
ALTER TABLE ONLY public.users
ADD IF NOT EXISTS last_ip_address character varying DEFAULT ''::character varying,
ADD IF NOT EXISTS last_ingamesn character varying DEFAULT ''::character varying,
ADD IF NOT EXISTS has_ban boolean DEFAULT false,
ADD IF NOT EXISTS ban_issued timestamp without time zone,
ADD IF NOT EXISTS ban_expires timestamp without time zone,
ADD IF NOT EXISTS ban_reason character varying,
ADD IF NOT EXISTS ban_reason_hidden character varying,
ADD IF NOT EXISTS ban_moderator character varying,
ADD IF NOT EXISTS ban_tos boolean,
ADD IF NOT EXISTS open_host boolean DEFAULT false;
ALTER TABLE ONLY public.users
ADD IF NOT EXISTS last_ip_address character varying DEFAULT ''::character varying,
ADD IF NOT EXISTS last_ingamesn character varying DEFAULT ''::character varying,
ADD IF NOT EXISTS has_ban boolean DEFAULT false,
ADD IF NOT EXISTS ban_issued timestamp without time zone,
ADD IF NOT EXISTS ban_expires timestamp without time zone,
ADD IF NOT EXISTS ban_reason character varying,
ADD IF NOT EXISTS ban_reason_hidden character varying,
ADD IF NOT EXISTS ban_moderator character varying,
ADD IF NOT EXISTS ban_tos boolean,
ADD IF NOT EXISTS open_host boolean DEFAULT false;
`)
pool.Exec(ctx, `
ALTER TABLE ONLY public.mario_kart_wii_sake
ADD IF NOT EXISTS id serial PRIMARY KEY,
ADD IF NOT EXISTS upload_time timestamp without time zone;
`)