rhythia-api 242.0.0 → 243.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/createBeatmap.ts +57 -39
- package/api/editProfile.ts +4 -67
- package/api/executeAdminOperation.ts +1030 -681
- package/api/getAvatarUploadUrl.ts +90 -85
- package/api/getBeatmapPage.ts +2 -0
- package/api/getBeatmapPageById.ts +2 -0
- package/api/getBeatmaps.ts +110 -197
- package/api/getCollection.ts +44 -31
- package/api/getMapUploadUrl.ts +90 -93
- package/api/getScore.ts +2 -0
- package/api/getVideoUploadUrl.ts +90 -85
- package/api/submitScoreInternal.ts +506 -461
- package/api/updateBeatmapPage.ts +6 -0
- package/beatmap-file-urls.json +29398 -0
- package/handleApi.ts +24 -21
- package/index.ts +121 -112
- package/package.json +4 -2
- package/queries/admin_delete_user.sql +42 -39
- package/queries/admin_remove_all_scores.sql +6 -3
- package/queries/admin_remove_score.sql +107 -0
- package/queries/admin_update_profile.sql +22 -0
- package/queries/get_beatmaps_v2.sql +48 -0
- package/queries/get_top_scores_for_beatmap3.sql +47 -38
- package/queries/profile_update_guards.sql +66 -0
- package/types/database.ts +1525 -1450
- package/utils/beatmapFiles.ts +102 -0
- package/utils/beatmapHash.ts +336 -0
- package/utils/beatmapTopScores.ts +68 -84
- package/utils/getUserBySession.ts +3 -1
- package/utils/profileUpdateValidation.ts +51 -0
- package/utils/redis.ts +24 -0
- package/utils/rhrReplay.ts +122 -0
- package/utils/star-calc/sspmParser.ts +294 -160
|
@@ -1,38 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
s.
|
|
15
|
-
s.
|
|
16
|
-
s.
|
|
17
|
-
s.
|
|
18
|
-
s.
|
|
19
|
-
s.
|
|
20
|
-
s.
|
|
21
|
-
s.
|
|
22
|
-
s.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
DROP FUNCTION IF EXISTS public.get_top_scores_for_beatmap3(beatmap_hash text);
|
|
2
|
+
|
|
3
|
+
CREATE OR REPLACE FUNCTION public.get_top_scores_for_beatmap3(beatmap_hash text, score_limit integer DEFAULT 50)
|
|
4
|
+
RETURNS TABLE(id bigint, awarded_sp numeric, created_at timestamp without time zone, misses integer, mods json, passed boolean, "replayHwid" text, "songId" text, speed numeric, spin boolean, "userId" bigint, username text, avatar_url text, accuracy numeric)
|
|
5
|
+
LANGUAGE sql
|
|
6
|
+
STABLE
|
|
7
|
+
AS $function$
|
|
8
|
+
WITH bm AS (
|
|
9
|
+
SELECT "noteCount"
|
|
10
|
+
FROM beatmaps
|
|
11
|
+
WHERE "beatmapHash" = beatmap_hash
|
|
12
|
+
)
|
|
13
|
+
SELECT
|
|
14
|
+
s.id,
|
|
15
|
+
s.awarded_sp,
|
|
16
|
+
s.created_at,
|
|
17
|
+
s.misses,
|
|
18
|
+
s.mods,
|
|
19
|
+
s.passed,
|
|
20
|
+
s."replayHwid",
|
|
21
|
+
s."songId",
|
|
22
|
+
s.speed,
|
|
23
|
+
s.spin,
|
|
24
|
+
s."userId",
|
|
25
|
+
p.username,
|
|
26
|
+
p.avatar_url,
|
|
27
|
+
CASE
|
|
28
|
+
WHEN bm."noteCount" > 0 THEN
|
|
29
|
+
ROUND(((bm."noteCount" - s.misses) / bm."noteCount" * 100)::numeric, 2)
|
|
30
|
+
ELSE 0
|
|
31
|
+
END AS accuracy
|
|
32
|
+
FROM leaderboard_map_user l
|
|
33
|
+
JOIN scores s ON s.id = l.best_score_id
|
|
34
|
+
JOIN profiles p ON s."userId" = p.id
|
|
35
|
+
CROSS JOIN bm
|
|
36
|
+
WHERE l."beatmapHash" = beatmap_hash
|
|
37
|
+
AND s.passed = true
|
|
38
|
+
AND p.ban <> 'excluded'
|
|
39
|
+
AND EXISTS (
|
|
40
|
+
SELECT 1
|
|
41
|
+
FROM scores recent
|
|
42
|
+
WHERE recent."userId" = s."userId"
|
|
43
|
+
AND recent.created_at >= now() - interval '30 days'
|
|
44
|
+
)
|
|
45
|
+
ORDER BY l.best_sp DESC
|
|
46
|
+
LIMIT LEAST(GREATEST(COALESCE(score_limit, 50), 1), 50);
|
|
47
|
+
$function$
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
CREATE OR REPLACE FUNCTION public.handle_profile_flag_change()
|
|
2
|
+
RETURNS trigger
|
|
3
|
+
LANGUAGE plpgsql
|
|
4
|
+
AS $function$
|
|
5
|
+
begin
|
|
6
|
+
if new.flag is not distinct from old.flag then
|
|
7
|
+
return new;
|
|
8
|
+
end if;
|
|
9
|
+
|
|
10
|
+
if current_setting('app.bypass_profile_limits', true) = 'on' then
|
|
11
|
+
return new;
|
|
12
|
+
end if;
|
|
13
|
+
|
|
14
|
+
if exists (
|
|
15
|
+
select 1
|
|
16
|
+
from public."profileFlags" pf
|
|
17
|
+
where pf.profile_id = old.id
|
|
18
|
+
) then
|
|
19
|
+
raise exception 'Flag can only be changed once'
|
|
20
|
+
using errcode = 'P0001';
|
|
21
|
+
end if;
|
|
22
|
+
|
|
23
|
+
insert into public."profileFlags" (profile_id, flag, changed_at)
|
|
24
|
+
values (old.id, old.flag, now());
|
|
25
|
+
|
|
26
|
+
return new;
|
|
27
|
+
end;
|
|
28
|
+
$function$;
|
|
29
|
+
|
|
30
|
+
CREATE OR REPLACE FUNCTION public.handle_profile_username_change()
|
|
31
|
+
RETURNS trigger
|
|
32
|
+
LANGUAGE plpgsql
|
|
33
|
+
AS $function$
|
|
34
|
+
declare
|
|
35
|
+
latest_change_at timestamptz;
|
|
36
|
+
begin
|
|
37
|
+
if new.username is not distinct from old.username then
|
|
38
|
+
return new;
|
|
39
|
+
end if;
|
|
40
|
+
|
|
41
|
+
if current_setting('app.bypass_profile_limits', true) = 'on' then
|
|
42
|
+
return new;
|
|
43
|
+
end if;
|
|
44
|
+
|
|
45
|
+
select pu.changed_at
|
|
46
|
+
into latest_change_at
|
|
47
|
+
from public."profileUsernames" pu
|
|
48
|
+
where pu.profile_id = old.id
|
|
49
|
+
order by pu.changed_at desc
|
|
50
|
+
limit 1;
|
|
51
|
+
|
|
52
|
+
if latest_change_at is not null
|
|
53
|
+
and latest_change_at + interval '6 months' > now() then
|
|
54
|
+
raise exception 'Username can only be changed once every 6 months'
|
|
55
|
+
using errcode = 'P0001',
|
|
56
|
+
detail = 'next_username_change_at=' || (latest_change_at + interval '6 months');
|
|
57
|
+
end if;
|
|
58
|
+
|
|
59
|
+
if old.username is not null and btrim(old.username) <> '' then
|
|
60
|
+
insert into public."profileUsernames" (profile_id, username, changed_at)
|
|
61
|
+
values (old.id, old.username, now());
|
|
62
|
+
end if;
|
|
63
|
+
|
|
64
|
+
return new;
|
|
65
|
+
end;
|
|
66
|
+
$function$;
|