1- import { UserSource } from './UserSource' ;
2- import { Nameplate } from '@clansty/maibot-types' ;
3-
4- export default class AquaDx extends UserSource {
5- private readonly BASE_URL = 'https://aquadx.net/aqua' ;
1+ import AquaDxLike from './AquaDxLike' ;
62
3+ export default class AquaDx extends AquaDxLike {
74 public constructor ( ) {
8- // all override
9- super ( null ) ;
10- }
11-
12- private async fetch ( endpoint : string , query : Record < string , string > , method = 'GET' , body ?: any ) {
13- const url = new URL ( this . BASE_URL + endpoint ) ;
14- url . search = new URLSearchParams ( query ) . toString ( ) ;
15- const init = {
16- method,
17- body : body ? JSON . stringify ( body ) : undefined ,
18- headers : body ? { 'Content-Type' : 'application/json' } : undefined
19- } ;
20- // @ts -ignore
21- if ( typeof window !== 'undefined' ) {
22- // @ts -ignore
23- init . cache = 'no-store' ;
24- }
25- const req = await fetch ( url , init ) ;
26- if ( ! req . ok ) {
27- console . error ( await req . text ( ) ) ;
28- throw new Error ( `获取数据时出错: ${ req . statusText } ` ) ;
29- }
30- return await req . json ( ) as any ;
31- }
32-
33- public override async getUserMusic ( username : string , musicIdList : number [ ] ) {
34- console . log ( '请求 user-music-from-list' , { username, musicIdListLength : musicIdList . length } ) ;
35- return await this . fetch ( '/api/v2/game/mai2/user-music-from-list' , { username } , 'POST' , musicIdList ) ;
36- }
37-
38- public override async getNameplate ( username : string ) : Promise < Nameplate > {
39- console . log ( '请求 user-name-plate' , { username } ) ;
40- return await this . fetch ( '/api/v2/game/mai2/user-name-plate' , { username } ) ;
41- }
42-
43- protected override async _getUserRating ( username : string ) {
44- console . log ( '请求 user-rating' , { username } ) ;
45- const data = await this . fetch ( '/api/v2/game/mai2/user-rating' , { username } ) ;
46- for ( const key of [ 'best35' , 'best15' ] ) {
47- data [ key ] = data [ key ] . map ( ( [ musicId , level , romVersion , achievement ] ) => ( {
48- musicId : parseInt ( musicId ) ,
49- level : parseInt ( level ) ,
50- romVersion : parseInt ( romVersion ) ,
51- achievement : parseInt ( achievement )
52- } ) ) ;
53- }
54- return data ;
55- }
56-
57- protected override async _getUserPreview ( username : string ) {
58- console . log ( '请求 user-summary' , { username } ) ;
59- const res = await this . fetch ( '/api/v2/game/mai2/user-summary' , { username } ) ;
60-
61- // 只需要返回这两个
62- return {
63- userName : res . name ,
64- playerRating : res . rating ,
65- lastRomVersion : res . lastVersion
66- } ;
67- }
68-
69- public override async getChuniUserMusic ( username : string , musicIdList : number [ ] ) {
70- return await this . fetch ( '/api/v2/game/chu3/user-music-from-list' , { username } , 'POST' , musicIdList ) ;
71- }
72-
73- public override async getChuniUserRating ( username : string ) {
74- const data = await this . fetch ( '/api/v2/game/chu3/user-rating' , { username } ) ;
75- for ( const key of [ 'best30' , 'recent10' ] ) {
76- data [ key ] = data [ key ] . map ( ( [ musicId , level , achievement ] ) => ( {
77- musicId : parseInt ( musicId ) ,
78- level : parseInt ( level ) ,
79- achievement : parseInt ( achievement )
80- } ) ) ;
81- }
82- return data ;
83- }
84-
85- public override async getChuniUserPreview ( username : string ) {
86- const res = await this . fetch ( '/api/v2/game/chu3/user-summary' , { username } ) ;
87-
88- // 只需要返回这两个
89- return {
90- userName : res . name ,
91- playerRating : res . rating ,
92- lastRomVersion : res . lastVersion
93- } ;
5+ super ( 'https://aquadx.net/aqua' ) ;
946 }
95- }
7+ }
0 commit comments