mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-27 21:01:02 +00:00
feat: refactor hydra api
This commit is contained in:
@@ -5,12 +5,7 @@ import { FriendRequest } from "@types";
|
||||
const getFriendRequests = async (
|
||||
_event: Electron.IpcMainInvokeEvent
|
||||
): Promise<FriendRequest[] | null> => {
|
||||
try {
|
||||
const response = await HydraApi.get(`/profile/friend-requests`);
|
||||
return response.data;
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
return HydraApi.get(`/profile/friend-requests`).catch(() => null);
|
||||
};
|
||||
|
||||
registerEvent("getFriendRequests", getFriendRequests);
|
||||
|
||||
@@ -9,9 +9,7 @@ const getMe = async (
|
||||
_event: Electron.IpcMainInvokeEvent
|
||||
): Promise<UserProfile | null> => {
|
||||
return HydraApi.get(`/profile/me`)
|
||||
.then((response) => {
|
||||
const me = response.data;
|
||||
|
||||
.then((me) => {
|
||||
userAuthRepository.upsert(
|
||||
{
|
||||
id: 1,
|
||||
|
||||
@@ -29,7 +29,7 @@ const updateProfile = async (
|
||||
) => {
|
||||
if (!newProfileImagePath) {
|
||||
return patchUserProfile(displayName).then(
|
||||
(response) => response.data as UserProfile
|
||||
(response) => response as UserProfile
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ const updateProfile = async (
|
||||
imageLength: fileSizeInBytes,
|
||||
})
|
||||
.then(async (preSignedResponse) => {
|
||||
const { presignedUrl, profileImageUrl } = preSignedResponse.data;
|
||||
const { presignedUrl, profileImageUrl } = preSignedResponse;
|
||||
|
||||
const mimeType = await fileTypeFromFile(newProfileImagePath);
|
||||
|
||||
@@ -56,7 +56,7 @@ const updateProfile = async (
|
||||
.catch(() => undefined);
|
||||
|
||||
return patchUserProfile(displayName, profileImageUrl).then(
|
||||
(response) => response.data as UserProfile
|
||||
(response) => response as UserProfile
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ const getUser = async (
|
||||
userId: string
|
||||
): Promise<UserProfile | null> => {
|
||||
try {
|
||||
const response = await HydraApi.get(`/user/${userId}`);
|
||||
const profile = response.data;
|
||||
const profile = await HydraApi.get(`/user/${userId}`);
|
||||
|
||||
const recentGames = await Promise.all(
|
||||
profile.recentGames.map(async (game) => {
|
||||
|
||||
@@ -190,6 +190,7 @@ export class HydraApi {
|
||||
await this.revalidateAccessTokenIfExpired();
|
||||
return this.instance
|
||||
.get(url, this.getAxiosConfig())
|
||||
.then((response) => response.data)
|
||||
.catch(this.handleUnauthorizedError);
|
||||
}
|
||||
|
||||
@@ -199,6 +200,7 @@ export class HydraApi {
|
||||
await this.revalidateAccessTokenIfExpired();
|
||||
return this.instance
|
||||
.post(url, data, this.getAxiosConfig())
|
||||
.then((response) => response.data)
|
||||
.catch(this.handleUnauthorizedError);
|
||||
}
|
||||
|
||||
@@ -208,6 +210,7 @@ export class HydraApi {
|
||||
await this.revalidateAccessTokenIfExpired();
|
||||
return this.instance
|
||||
.put(url, data, this.getAxiosConfig())
|
||||
.then((response) => response.data)
|
||||
.catch(this.handleUnauthorizedError);
|
||||
}
|
||||
|
||||
@@ -217,6 +220,7 @@ export class HydraApi {
|
||||
await this.revalidateAccessTokenIfExpired();
|
||||
return this.instance
|
||||
.patch(url, data, this.getAxiosConfig())
|
||||
.then((response) => response.data)
|
||||
.catch(this.handleUnauthorizedError);
|
||||
}
|
||||
|
||||
@@ -226,6 +230,7 @@ export class HydraApi {
|
||||
await this.revalidateAccessTokenIfExpired();
|
||||
return this.instance
|
||||
.delete(url, this.getAxiosConfig())
|
||||
.then((response) => response.data)
|
||||
.catch(this.handleUnauthorizedError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,7 @@ export const createGame = async (game: Game) => {
|
||||
lastTimePlayed: game.lastTimePlayed,
|
||||
})
|
||||
.then((response) => {
|
||||
const {
|
||||
id: remoteId,
|
||||
playTimeInMilliseconds,
|
||||
lastTimePlayed,
|
||||
} = response.data;
|
||||
const { id: remoteId, playTimeInMilliseconds, lastTimePlayed } = response;
|
||||
|
||||
gameRepository.update(
|
||||
{ objectID: game.objectID },
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getSteamAppAsset } from "@main/helpers";
|
||||
export const mergeWithRemoteGames = async () => {
|
||||
return HydraApi.get("/games")
|
||||
.then(async (response) => {
|
||||
for (const game of response.data) {
|
||||
for (const game of response) {
|
||||
const localGame = await gameRepository.findOne({
|
||||
where: {
|
||||
objectID: game.objectId,
|
||||
|
||||
Reference in New Issue
Block a user