feat: add osu status to rpc
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import type { EZPPUser, EZPPUserInfoResponse, EZPPUserResponse } from '@/types';
|
||||
import type {
|
||||
EZPPUser,
|
||||
EZPPUserInfoResponse,
|
||||
EZPPUserResponse,
|
||||
EZPPUSerStatusResponse,
|
||||
} from '@/types';
|
||||
import { betterFetch } from '@better-fetch/fetch';
|
||||
|
||||
const BANCHO_ENDPOINT = 'https://c.ez-pp.farm/';
|
||||
@@ -68,4 +73,20 @@ export const ezppfarm = {
|
||||
});
|
||||
return request.error ? undefined : request.data;
|
||||
},
|
||||
getUserStatus: async (userId: number) => {
|
||||
const request = await betterFetch<EZPPUSerStatusResponse>(
|
||||
`${API_ENDPOINT}v1/get_player_status`,
|
||||
{
|
||||
timeout,
|
||||
query: {
|
||||
id: userId,
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'User-Agent': 'EZPPLauncher',
|
||||
},
|
||||
}
|
||||
);
|
||||
return request.error ? undefined : request.data;
|
||||
},
|
||||
};
|
||||
|
@@ -3,15 +3,15 @@ import { invoke } from '@tauri-apps/api/core';
|
||||
export const connect = async () => await invoke('presence_connect');
|
||||
export const disconnect = async () => await invoke('presence_disconnect');
|
||||
export const updateStatus = async (status: {
|
||||
state?: string;
|
||||
details?: string;
|
||||
large_image_key?: string;
|
||||
state?: string | null;
|
||||
details?: string | null;
|
||||
largeImageKey?: string;
|
||||
}) =>
|
||||
await invoke('presence_update_status', {
|
||||
state: status.state,
|
||||
details: status.details,
|
||||
largeImageKey: status.large_image_key,
|
||||
largeImageKey: status.largeImageKey,
|
||||
});
|
||||
export const updateUser = async (user: { username: string; id: string }) =>
|
||||
export const updateUser = async (user: { username: string; id?: string | null }) =>
|
||||
await invoke('presence_update_user', { username: user.username, id: user.id });
|
||||
export const isConnected = async () => await invoke<boolean>('presence_is_connected');
|
||||
|
@@ -185,3 +185,65 @@ export type Release = {
|
||||
browser_download_url: string;
|
||||
}[];
|
||||
};
|
||||
|
||||
export type EZPPUSerStatusResponse = EZPPUserOfflineStatus | EZPPUserOnlineStatus;
|
||||
|
||||
type EZPPUserOfflineStatus = {
|
||||
status: string;
|
||||
player_status: {
|
||||
online: false;
|
||||
last_seen: number;
|
||||
};
|
||||
};
|
||||
|
||||
type EZPPUserOnlineStatus = {
|
||||
status: string;
|
||||
player_status: {
|
||||
online: true;
|
||||
login_time: number;
|
||||
status: {
|
||||
action: EZPPActionStatus;
|
||||
info_text: string;
|
||||
mode: number;
|
||||
mods: number;
|
||||
beatmap: EZPPUserBeatmapStatus | null;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
type EZPPUserBeatmapStatus = {
|
||||
md5: string;
|
||||
id: number;
|
||||
set_id: number;
|
||||
artist: string;
|
||||
title: string;
|
||||
version: string;
|
||||
creator: string;
|
||||
last_update: string;
|
||||
total_length: number;
|
||||
max_combo: number;
|
||||
status: number;
|
||||
plays: number;
|
||||
passes: number;
|
||||
mode: number;
|
||||
bpm: number;
|
||||
cs: number;
|
||||
od: number;
|
||||
ar: number;
|
||||
hp: number;
|
||||
diff: number;
|
||||
};
|
||||
|
||||
export enum EZPPActionStatus {
|
||||
AFK = 1,
|
||||
PLAYING = 2,
|
||||
EDITING = 3,
|
||||
MODDING = 4,
|
||||
MULTIPLAYER_SELECT = 5,
|
||||
WATCHING = 6,
|
||||
TESTING = 8,
|
||||
SUBMITTING = 9,
|
||||
MULTIPLAYER_IDLE = 11,
|
||||
MULTIPLAYER_PLAYING = 12,
|
||||
DIRECT = 13,
|
||||
}
|
||||
|
@@ -89,3 +89,14 @@ export const formatBytes = (bytes: number, decimals = 2) => {
|
||||
export const openURL = async (url: string) => {
|
||||
await invoke('open_url_in_browser', { url });
|
||||
};
|
||||
|
||||
export const urlIsValidImage = async (url: string) => {
|
||||
try {
|
||||
const request = await fetch(url);
|
||||
if (!request.ok) return false;
|
||||
const contentType = request.headers.get('content-type');
|
||||
return contentType?.startsWith('image/');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user