Skip to content

Commit

Permalink
base profile template
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Jul 7, 2024
1 parent bb73f2b commit c94ecd6
Show file tree
Hide file tree
Showing 11 changed files with 666 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/adapters/akatsuki-api/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const authenticate = async (
privileges: response.data.privileges,
}
} catch (e: any) {
console.log(e)
throw new Error(e.response.data.user_feedback)
}
}
Expand All @@ -29,6 +30,7 @@ export const logout = async () => {
try {
await authApiInstance.post("/api/v1/logout")
} catch (e: any) {
console.log(e)
throw new Error(e.response.data.user_feedback)
}
}
5 changes: 3 additions & 2 deletions src/adapters/akatsuki-api/leaderboards.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios"

interface ChosenModeStats {
export interface ChosenModeStats {
rankedScore: number
totalScore: number
playcount: number
Expand All @@ -12,7 +12,7 @@ interface ChosenModeStats {
pp: number
globalLeaderboardRank: number
countryLeaderboardRank: number
max_combo: number
maxCombo: number
}

export interface LeaderboardUser {
Expand Down Expand Up @@ -90,6 +90,7 @@ export const fetchLeaderboard = async (
})),
}
} catch (e: any) {
console.log(e)
throw new Error(e.response.data.user_feedback)
}
}
1 change: 1 addition & 0 deletions src/adapters/akatsuki-api/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const searchUsers = async (
: null,
}
} catch (e: any) {
console.log(e)
throw new Error(e.response.data.user_feedback)
}
}
131 changes: 131 additions & 0 deletions src/adapters/akatsuki-api/userScores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import axios from "axios"

interface UserScoresRequest {
type: "best" | "recent"
mode: number
p: number
l: number
rx: number
id: number
}

export interface UserScoreBeatmap {
beatmapId: number
beatmapsetId: number
beatmapMd5: string
songName: string
ar: number
od: number
difficulty: number
difficulty2?: {
std: number
taiko: number
ctb: number
mania: number
}
maxCombo: number
hitLength: number
ranked: number
rankedStatusFrozen: number
latestUpdate: string
}

export interface UserScore {
id: string
beatmapMd5: string
score: number
maxCombo: number
fullCombo: boolean
mods: number
count300: number
count100: number
count50: number
countGeki: number
countKatu: number
countMiss: number
time: string
playMode: number
accuracy: number
pp: number
rank: string
completed: number
pinned: boolean
beatmap: UserScoreBeatmap
}

export interface UserScoresResponse {
code: number
scores: UserScore[]
}

const scoresApiInstance = axios.create({
baseURL: process.env.REACT_APP_SCORES_API_BASE_URL,
})

export const fetchUserScores = async (
request: UserScoresRequest
): Promise<UserScoresResponse> => {
try {
const response = await scoresApiInstance.get(
`/v1/users/scores/${request.type}`,
{
params: {
mode: request.mode,
rx: request.rx,
p: request.p,
l: request.l,
id: request.id,
},
}
)
return {
code: response.status,
scores: response.data.scores.map((score: any) => ({
id: score.id,
beatmapMd5: score.beatmap_md5,
score: score.score,
maxCombo: score.max_combo,
fullCombo: score.full_combo,
mods: score.mods,
count300: score.count_300,
count100: score.count_100,
count50: score.count_50,
countGeki: score.count_geki,
countKatu: score.count_katu,
countMiss: score.count_miss,
time: score.time,
playMode: score.play_mode,
accuracy: score.accuracy,
pp: score.pp,
rank: score.rank,
completed: score.completed,
pinned: score.pinned,
beatmap: {
beatmapId: score.beatmap.beatmap_id,
beatmapsetId: score.beatmap.beatmapset_id,
beatmapMd5: score.beatmap.beatmap_md5,
songName: score.beatmap.song_name,
ar: score.beatmap.ar,
od: score.beatmap.od,
difficulty: score.beatmap.difficulty,
difficulty2: score.beatmap.difficulty_2
? {
std: score.beatmap.difficulty_2.std,
taiko: score.beatmap.difficulty_2.taiko,
ctb: score.beatmap.difficulty_2.ctb,
mania: score.beatmap.difficulty_2.mania,
}
: null,
maxCombo: score.beatmap.max_combo,
hitLength: score.beatmap.hit_length,
ranked: score.beatmap.ranked,
rankedStatusFrozen: score.beatmap.ranked_status_frozen,
latestUpdate: score.beatmap.latest_update,
},
})),
}
} catch (e: any) {
console.log(e)
throw new Error(e.response.data.user_feedback)
}
}
197 changes: 197 additions & 0 deletions src/adapters/akatsuki-api/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import axios from "axios"

export interface UserResponse {
id: number
username: string
usernameAka: string
registeredOn: Date
privileges: number
latestActivity: Date
country: string
}

export interface UserStats {
rankedScore: number
totalScore: number
playcount: number
playtime: number
replaysWatched: number
totalHits: number
level: number
accuracy: number
pp: number
globalLeaderboardRank: number
countryLeaderboardRank: number
maxCombo: number
}

export interface AllModeUserStats {
std: UserStats
taiko: UserStats
ctb: UserStats
mania: UserStats
}

export interface UserBadge {
id: number
name: string
icon: string
colour: string
}

export interface UserTournamentBadge {
id: number
name: string
icon: string
}

export interface UserClan {
id: number
name: string
tag: string
description: string
icon: string
owner: number
status: number // todo enum
}

export interface UserSilenceInfo {
reason: string
end: Date
}

export interface UserFullResponse extends UserResponse {
stats: AllModeUserStats[]
playStyle: number // todo enum
favouriteMode: number // todo enum
badges: UserBadge[]
clan: UserClan
followers: number
tbadges?: UserTournamentBadge[]
customBadge: UserBadge
silenceInfo: UserSilenceInfo

// only visible to admins
cmNotes?: string[] // TODO
banDate?: Date
email?: string
}

const userApiInstance = axios.create({
baseURL: process.env.REACT_APP_USER_API_BASE_URL,
})

export const fetchUser = async (userId: number): Promise<UserFullResponse> => {
try {
const response = await userApiInstance.get("/v1/users/full", {
params: { id: userId },
})
return {
id: response.data.id,
username: response.data.username,
usernameAka: response.data.username_aka,
registeredOn: new Date(response.data.registered_on),
privileges: response.data.privileges,
latestActivity: new Date(response.data.latest_activity),
country: response.data.country,
stats: response.data.stats.map((stats: any) => ({
std: {
rankedScore: stats.std.ranked_score,
totalScore: stats.std.total_score,
playcount: stats.std.playcount,
playtime: stats.std.playtime,
replaysWatched: stats.std.replays_watched,
totalHits: stats.std.total_hits,
level: stats.std.level,
accuracy: stats.std.accuracy,
pp: stats.std.pp,
globalLeaderboardRank: stats.std.global_leaderboard_rank,
countryLeaderboardRank: stats.std.country_leaderboard_rank,
maxCombo: stats.std.max_combo,
},
taiko: {
rankedScore: stats.taiko.ranked_score,
totalScore: stats.taiko.total_score,
playcount: stats.taiko.playcount,
playtime: stats.taiko.playtime,
replaysWatched: stats.taiko.replays_watched,
totalHits: stats.taiko.total_hits,
level: stats.taiko.level,
accuracy: stats.taiko.accuracy,
pp: stats.taiko.pp,
globalLeaderboardRank: stats.taiko.global_leaderboard_rank,
countryLeaderboardRank: stats.taiko.country_leaderboard_rank,
maxCombo: stats.taiko.max_combo,
},
ctb: {
rankedScore: stats.ctb.ranked_score,
totalScore: stats.ctb.total_score,
playcount: stats.ctb.playcount,
playtime: stats.ctb.playtime,
replaysWatched: stats.ctb.replays_watched,
totalHits: stats.ctb.total_hits,
level: stats.ctb.level,
accuracy: stats.ctb.accuracy,
pp: stats.ctb.pp,
globalLeaderboardRank: stats.ctb.global_leaderboard_rank,
countryLeaderboardRank: stats.ctb.country_leaderboard_rank,
maxCombo: stats.ctb.max_combo,
},
mania: {
rankedScore: stats.mania.ranked_score,
totalScore: stats.mania.total_score,
playcount: stats.mania.playcount,
playtime: stats.mania.playtime,
replaysWatched: stats.mania.replays_watched,
totalHits: stats.mania.total_hits,
level: stats.mania.level,
accuracy: stats.mania.accuracy,
pp: stats.mania.pp,
globalLeaderboardRank: stats.mania.global_leaderboard_rank,
countryLeaderboardRank: stats.mania.country_leaderboard_rank,
maxCombo: stats.mania.max_combo,
},
})),
playStyle: response.data.play_style,
favouriteMode: response.data.favourite_mode,
badges: response.data.badges.map((badge: any) => ({
id: badge.id,
name: badge.name,
icon: badge.icon,
colour: badge.colour,
})),
clan: {
id: response.data.clan.id,
name: response.data.clan.name,
tag: response.data.clan.tag,
description: response.data.clan.description,
icon: response.data.clan.icon,
owner: response.data.clan.owner,
status: response.data.clan.status,
},
followers: response.data.followers,
tbadges: response.data.tbadges?.map((tbadge: any) => ({
id: tbadge.id,
name: tbadge.name,
icon: tbadge.icon,
})),
customBadge: {
id: response.data.custom_badge.id,
name: response.data.custom_badge.name,
icon: response.data.custom_badge.icon,
colour: response.data.custom_badge.colour,
},
silenceInfo: {
reason: response.data.silence_info.reason,
end: new Date(response.data.silence_info.end),
},
// TODO?
cmNotes: response.data.cm_notes,
banDate: response.data.ban_date,
email: response.data.email,
}
} catch (e: any) {
console.log(e)
throw new Error(e.response.data.user_feedback)
}
}
Loading

0 comments on commit c94ecd6

Please sign in to comment.