mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-22 10:23:56 +00:00
feat: enabling gif upload
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
import { registerEvent } from "../register-event";
|
||||
import { GameShop } from "@types";
|
||||
import { Ludusavi } from "@main/services";
|
||||
|
||||
const checkGameCloudSyncSupport = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
objectId: string,
|
||||
shop: GameShop
|
||||
) => {
|
||||
const games = await Ludusavi.findGames(shop, objectId);
|
||||
return games.length === 1;
|
||||
};
|
||||
|
||||
registerEvent("checkGameCloudSyncSupport", checkGameCloudSyncSupport);
|
||||
@@ -61,7 +61,6 @@ import "./cloud-save/download-game-artifact";
|
||||
import "./cloud-save/get-game-artifacts";
|
||||
import "./cloud-save/get-game-backup-preview";
|
||||
import "./cloud-save/upload-save-game";
|
||||
import "./cloud-save/check-game-cloud-sync-support";
|
||||
import "./cloud-save/delete-game-artifact";
|
||||
import "./notifications/publish-new-repacks-notification";
|
||||
import { isPortableVersion } from "@main/helpers";
|
||||
|
||||
@@ -1,56 +1,75 @@
|
||||
import { registerEvent } from "../register-event";
|
||||
import { HydraApi, PythonInstance } from "@main/services";
|
||||
import { HydraApi } from "@main/services";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { UpdateProfileRequest, UserProfile } from "@types";
|
||||
import { omit } from "lodash-es";
|
||||
import axios from "axios";
|
||||
|
||||
interface PresignedResponse {
|
||||
presignedUrl: string;
|
||||
profileImageUrl: string;
|
||||
}
|
||||
import { fileTypeFromFile } from "file-type";
|
||||
|
||||
const patchUserProfile = async (updateProfile: UpdateProfileRequest) => {
|
||||
return HydraApi.patch<UserProfile>("/profile", updateProfile);
|
||||
};
|
||||
|
||||
const getNewProfileImageUrl = async (localImageUrl: string) => {
|
||||
const { imagePath, mimeType } =
|
||||
await PythonInstance.processProfileImage(localImageUrl);
|
||||
|
||||
const stats = fs.statSync(imagePath);
|
||||
const uploadImage = async (
|
||||
type: "profile-image" | "background-image",
|
||||
imagePath: string
|
||||
) => {
|
||||
const stat = fs.statSync(imagePath);
|
||||
const fileBuffer = fs.readFileSync(imagePath);
|
||||
const fileSizeInBytes = stats.size;
|
||||
const fileSizeInBytes = stat.size;
|
||||
|
||||
const { presignedUrl, profileImageUrl } =
|
||||
await HydraApi.post<PresignedResponse>(`/presigned-urls/profile-image`, {
|
||||
const response = await HydraApi.post<{ presignedUrl: string }>(
|
||||
`/presigned-urls/${type}`,
|
||||
{
|
||||
imageExt: path.extname(imagePath).slice(1),
|
||||
imageLength: fileSizeInBytes,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
await axios.put(presignedUrl, fileBuffer, {
|
||||
const mimeType = await fileTypeFromFile(imagePath);
|
||||
|
||||
await axios.put(response.presignedUrl, fileBuffer, {
|
||||
headers: {
|
||||
"Content-Type": mimeType,
|
||||
"Content-Type": mimeType?.mime,
|
||||
},
|
||||
});
|
||||
|
||||
return profileImageUrl;
|
||||
if (type === "background-image") {
|
||||
return response["backgroundImageUrl"];
|
||||
}
|
||||
|
||||
return response["profileImageUrl"];
|
||||
};
|
||||
|
||||
const updateProfile = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
updateProfile: UpdateProfileRequest
|
||||
) => {
|
||||
if (!updateProfile.profileImageUrl) {
|
||||
return patchUserProfile(omit(updateProfile, "profileImageUrl"));
|
||||
const payload = omit(updateProfile, [
|
||||
"profileImageUrl",
|
||||
"backgroundImageUrl",
|
||||
]);
|
||||
|
||||
if (updateProfile.profileImageUrl) {
|
||||
const profileImageUrl = await uploadImage(
|
||||
"profile-image",
|
||||
updateProfile.profileImageUrl
|
||||
).catch(() => undefined);
|
||||
|
||||
payload["profileImageUrl"] = profileImageUrl;
|
||||
}
|
||||
|
||||
const profileImageUrl = await getNewProfileImageUrl(
|
||||
updateProfile.profileImageUrl
|
||||
).catch(() => undefined);
|
||||
if (updateProfile.backgroundImageUrl) {
|
||||
const backgroundImageUrl = await uploadImage(
|
||||
"background-image",
|
||||
updateProfile.backgroundImageUrl
|
||||
).catch(() => undefined);
|
||||
|
||||
return patchUserProfile({ ...updateProfile, profileImageUrl });
|
||||
payload["backgroundImageUrl"] = backgroundImageUrl;
|
||||
}
|
||||
|
||||
return patchUserProfile(payload);
|
||||
};
|
||||
|
||||
registerEvent("updateProfile", updateProfile);
|
||||
|
||||
Reference in New Issue
Block a user