From 08cc970d855f5f4ca338e8b018d4cb982e8e142a Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Wed, 16 Mar 2022 18:21:53 +0000 Subject: [PATCH 1/8] Unscrew version info --- server/src/lib/constants/version.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/lib/constants/version.ts b/server/src/lib/constants/version.ts index 62b51c128..68cbc7ac7 100644 --- a/server/src/lib/constants/version.ts +++ b/server/src/lib/constants/version.ts @@ -4,7 +4,7 @@ const MAJOR = 2; const MINOR = 1; -const PATCH = r; +const PATCH = 5; // As is with all front-facing zkldi projects, the version names for tachi-server // are from an album I like. In this case, the album is Portishead - Dummy. From 134d419fdd5bddf0cc88b33cb01f47e64999f063 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Wed, 16 Mar 2022 18:22:30 +0000 Subject: [PATCH 2/8] Mark develop as 2.2.0-dev --- server/package.json | 2 +- server/src/lib/constants/version.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/package.json b/server/package.json index 5b78ad021..24b2d81ad 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "tachi-server", - "version": "2.1.6", + "version": "2.2.0-dev", "description": "A score tracking server.", "main": "js/index.js", "private": true, diff --git a/server/src/lib/constants/version.ts b/server/src/lib/constants/version.ts index 68cbc7ac7..3dbebc441 100644 --- a/server/src/lib/constants/version.ts +++ b/server/src/lib/constants/version.ts @@ -3,8 +3,8 @@ // essentially share codebases. const MAJOR = 2; -const MINOR = 1; -const PATCH = 5; +const MINOR = 2; +const PATCH = 0; // As is with all front-facing zkldi projects, the version names for tachi-server // are from an album I like. In this case, the album is Portishead - Dummy. From 4927f815b5928956b60b761d95963386feb8db5b Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Sun, 20 Mar 2022 14:58:03 +0000 Subject: [PATCH 3/8] bug: Force Static Import should actually matter. --- .../src/server/router/ir/fervidex/router.test.ts | 15 +++++++++++++++ server/src/server/router/ir/fervidex/router.ts | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/server/src/server/router/ir/fervidex/router.test.ts b/server/src/server/router/ir/fervidex/router.test.ts index f80361666..b5a3dbec5 100644 --- a/server/src/server/router/ir/fervidex/router.test.ts +++ b/server/src/server/router/ir/fervidex/router.test.ts @@ -457,5 +457,20 @@ t.test("POST /ir/fervidex/profile/submit", (t) => { t.end(); }); + t.test("Should disallow requests from non INF2 if forceStaticImport is false.", async (t) => { + await db["fer-settings"].update({ userID: 1 }, { $set: { forceStaticImport: false } }); + + const res = await mockApi + .post("/ir/fervidex/profile/submit") + .set("Authorization", "Bearer mock_token") + .set("User-Agent", "fervidex/1.3.0") + .set("X-Software-Model", "LDJ:J:B:A:2020092900") + .send(ferStaticBody); + + t.equal(res.statusCode, 400, "Should be rejected, as FSI is not set."); + + t.end(); + }); + t.end(); }); diff --git a/server/src/server/router/ir/fervidex/router.ts b/server/src/server/router/ir/fervidex/router.ts index fa81417b8..d606bd9e1 100644 --- a/server/src/server/router/ir/fervidex/router.ts +++ b/server/src/server/router/ir/fervidex/router.ts @@ -92,7 +92,14 @@ const RequireInf2ModelHeaderOrForceStatic: RequestHandler = async (req, res, nex } try { - ParseEA3SoftID(swModel); + const { model } = ParseEA3SoftID(swModel); + + if (model !== MODEL_INFINITAS_2) { + return res.status(400).json({ + success: false, + error: `Refusing to perform static import from non-infinitas client. To do this anyway, enable Force Static Import.`, + }); + } } catch (err) { logger.info(`Invalid softID from ${req[SYMBOL_TachiAPIAuth].userID!}.`, { err }); return res.status(400).json({ From c2cbb6d02a0a3237a6b147cf79657ce549a64c42 Mon Sep 17 00:00:00 2001 From: zkldi Date: Mon, 21 Mar 2022 13:35:32 +0000 Subject: [PATCH 4/8] Make FormatVersion() a constant --- server/src/lib/constants/version.ts | 4 +--- server/src/main.ts | 4 ++-- server/src/server/router/api/v1/status/router.test.ts | 10 +++++----- server/src/server/router/api/v1/status/router.ts | 6 +++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/server/src/lib/constants/version.ts b/server/src/lib/constants/version.ts index 3dbebc441..20a267eae 100644 --- a/server/src/lib/constants/version.ts +++ b/server/src/lib/constants/version.ts @@ -34,6 +34,4 @@ export const VERSION_INFO = { export const VERSION_STR = `${MAJOR}.${MINOR}.${PATCH}`; -export function FormatVersion() { - return `v${VERSION_STR} (${VERSION_INFO.name})`; -} +export const VERSION_PRETTY = `v${VERSION_STR} (${VERSION_INFO.name})`; diff --git a/server/src/main.ts b/server/src/main.ts index 0d83e16e8..f600ab784 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -10,6 +10,7 @@ import fs from "fs"; import http from "http"; import https from "https"; import { LoadDefaultClients } from "lib/builtin-clients/builtin-clients"; +import { VERSION_PRETTY } from "lib/constants/version"; import { HandleSIGTERMGracefully } from "lib/handlers/sigterm"; import CreateLogCtx from "lib/logger/logger"; import { Environment, ServerConfig, TachiConfig } from "lib/setup/config"; @@ -17,11 +18,10 @@ import path from "path"; import server from "server/server"; import fetch from "utils/fetch"; import { InitaliseFolderChartLookup } from "utils/folder"; -import { FormatVersion } from "./lib/constants/version"; const logger = CreateLogCtx(__filename); -logger.info(`Booting ${TachiConfig.NAME} - ${FormatVersion()} [ENV: ${Environment.nodeEnv}]`, { +logger.info(`Booting ${TachiConfig.NAME} - ${VERSION_PRETTY} [ENV: ${Environment.nodeEnv}]`, { bootInfo: true, }); logger.info(`Log level is set to ${ServerConfig.LOGGER_CONFIG.LOG_LEVEL}.`, { bootInfo: true }); diff --git a/server/src/server/router/api/v1/status/router.test.ts b/server/src/server/router/api/v1/status/router.test.ts index 2b7e67156..48cf61256 100644 --- a/server/src/server/router/api/v1/status/router.test.ts +++ b/server/src/server/router/api/v1/status/router.test.ts @@ -1,4 +1,4 @@ -import { FormatVersion } from "lib/constants/version"; +import { VERSION_PRETTY } from "lib/constants/version"; import { CreateFakeAuthCookie } from "test-utils/fake-auth"; import mockApi from "test-utils/mock-api"; import t from "tap"; @@ -16,7 +16,7 @@ t.test("GET /api/v1/status", async (t) => { "Should be roughly the current time (5 seconds lenience)" ); t.type(res.body.body.startTime, "number", "Should return a number for startTime."); - t.equal(res.body.body.version, FormatVersion()); + t.equal(res.body.body.version, VERSION_PRETTY); t.equal(res.body.body.whoami, 1); t.end(); @@ -33,7 +33,7 @@ t.test("GET /api/v1/status", async (t) => { "Should be roughly the current time (5 seconds lenience)" ); t.type(res.body.body.startTime, "number", "Should return a number for startTime."); - t.equal(res.body.body.version, FormatVersion()); + t.equal(res.body.body.version, VERSION_PRETTY); t.equal(res.body.body.whoami, 1); t.end(); @@ -54,7 +54,7 @@ t.test("POST /api/v1/status", async (t) => { Math.abs(Date.now() - res.body.body.serverTime) < 5_000, "Should be roughly the current time (5 seconds lenience)" ); - t.equal(res.body.body.version, FormatVersion()); + t.equal(res.body.body.version, VERSION_PRETTY); t.equal(res.body.body.whoami, 1); t.type(res.body.body.startTime, "number", "Should return a number for startTime."); @@ -73,7 +73,7 @@ t.test("POST /api/v1/status", async (t) => { Math.abs(Date.now() - res.body.body.serverTime) < 5_000, "Should be roughly the current time (5 seconds lenience)" ); - t.equal(res.body.body.version, FormatVersion()); + t.equal(res.body.body.version, VERSION_PRETTY); t.equal(res.body.body.whoami, 1); t.type(res.body.body.startTime, "number", "Should return a number for startTime."); diff --git a/server/src/server/router/api/v1/status/router.ts b/server/src/server/router/api/v1/status/router.ts index 4a37e8d6c..970bc0120 100644 --- a/server/src/server/router/api/v1/status/router.ts +++ b/server/src/server/router/api/v1/status/router.ts @@ -1,6 +1,6 @@ import { Router } from "express"; import { SYMBOL_TachiAPIAuth } from "lib/constants/tachi"; -import { FormatVersion } from "lib/constants/version"; +import { VERSION_PRETTY } from "lib/constants/version"; const router: Router = Router({ mergeParams: true }); @@ -23,7 +23,7 @@ router.get("/", (req, res) => { body: { serverTime: Date.now(), startTime, - version: FormatVersion(), + version: VERSION_PRETTY, whoami: req[SYMBOL_TachiAPIAuth].userID, // converts {foo: true, bar: false, baz: true} into [foo, baz] permissions: Object.entries(req[SYMBOL_TachiAPIAuth].permissions) @@ -52,7 +52,7 @@ router.post("/", (req, res) => { body: { serverTime: Date.now(), startTime, - version: FormatVersion(), + version: VERSION_PRETTY, whoami: req[SYMBOL_TachiAPIAuth].userID, // converts {foo: true, bar: false, baz: true} into [foo, baz] permissions: Object.entries(req[SYMBOL_TachiAPIAuth].permissions) From 9786d9c55c0ae9aacd8f6f3cc8728058681a66aa Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Tue, 22 Mar 2022 17:31:05 +0000 Subject: [PATCH 5/8] Add a /stats endpoint for folder/:folderID --- .../_playtype/folders/_folderID/router.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/folders/_folderID/router.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/folders/_folderID/router.ts index a02e3b2eb..d6a44b593 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/folders/_folderID/router.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/folders/_folderID/router.ts @@ -3,7 +3,7 @@ import db from "external/mongo/db"; import { SYMBOL_TachiData } from "lib/constants/tachi"; import { FilterQuery } from "mongodb"; import { GetGamePTConfig, ScoreDocument } from "tachi-common"; -import { GetFolderCharts, GetPBsOnFolder } from "utils/folder"; +import { GetFolderCharts, GetGradeLampDistributionForFolder, GetPBsOnFolder } from "utils/folder"; import { ParseStrPositiveInt } from "utils/string-checks"; import { GetFolderFromParam } from "../../../../../../../games/_game/_playtype/folders/middleware"; import { RequireSelfRequestFromUser } from "../../../../../middleware"; @@ -35,6 +35,27 @@ router.get("/", async (req, res) => { }); }); +/** + * Returns a users stats on this folder. + * + * @name GET /api/v1/users/:userID/games/:game/:playtype/folders/:folderID/stats + */ +router.get("/stats", async (req, res) => { + const folder = req[SYMBOL_TachiData]!.folderDoc!; + const user = req[SYMBOL_TachiData]!.requestedUser!; + + const stats = await GetGradeLampDistributionForFolder(user.id, folder); + + return res.status(200).json({ + success: true, + description: `Returned statistics for ${folder.title}.`, + body: { + folder, + stats, + }, + }); +}); + /** * Add a folder to the list of recently-viewed folders. This can only * be performed by a session-level token, to stop rogue API keys from causing From d49a1bed266cce1498bc145a8e8a3862fb3b9497 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Tue, 22 Mar 2022 18:02:04 +0000 Subject: [PATCH 6/8] UGPT folderID/timeline should return the requested folder --- .../_userID/games/_game/_playtype/folders/_folderID/router.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/folders/_folderID/router.ts b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/folders/_folderID/router.ts index d6a44b593..8c0712159 100644 --- a/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/folders/_folderID/router.ts +++ b/server/src/server/router/api/v1/users/_userID/games/_game/_playtype/folders/_folderID/router.ts @@ -183,6 +183,7 @@ router.get("/timeline", async (req, res) => { songs, charts, scores, + folder, }, }); }); From abb4501c6da66b9939ee73c11b4f4242718fb336 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Tue, 22 Mar 2022 18:58:53 +0000 Subject: [PATCH 7/8] Set version to v2.1.9 --- server/package.json | 2 +- server/src/lib/constants/version.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/package.json b/server/package.json index 24b2d81ad..57b983f5f 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "tachi-server", - "version": "2.2.0-dev", + "version": "2.1.9", "description": "A score tracking server.", "main": "js/index.js", "private": true, diff --git a/server/src/lib/constants/version.ts b/server/src/lib/constants/version.ts index 20a267eae..c39914d46 100644 --- a/server/src/lib/constants/version.ts +++ b/server/src/lib/constants/version.ts @@ -3,8 +3,8 @@ // essentially share codebases. const MAJOR = 2; -const MINOR = 2; -const PATCH = 0; +const MINOR = 1; +const PATCH = 9; // As is with all front-facing zkldi projects, the version names for tachi-server // are from an album I like. In this case, the album is Portishead - Dummy. From 58dd0a304bb724d9c6d2249bc9088107e5fae005 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Tue, 22 Mar 2022 19:01:10 +0000 Subject: [PATCH 8/8] Add changelog. --- server/CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/CHANGELOG.md b/server/CHANGELOG.md index 08c4cc5c2..7786e6cd6 100644 --- a/server/CHANGELOG.md +++ b/server/CHANGELOG.md @@ -15,6 +15,16 @@ not generally be shown to end users. # Changelog +# 2.1.9 + +- [ENH] Add an endpoint on UGPT/folder/:folderID/stats. This returns lamp and grade distributions for this ugpt:folder combo. +- [ENH] The UGPT Folder timeline endpoint now also returns the folder it worked on. + +***** + +- [BUG] OAuth2 tokens are now properly expired. +- [BUG] ForceStaticImport is no longer always on, even if off. + # 2.1.4 - [BUG] IIDX, BMS and PMS scores can no longer get an invalid grade if they are exactly 77.7777...%