feat: adding local file protocol

This commit is contained in:
Chubby Granny Chaser
2024-06-19 09:48:11 +01:00
parent 1ef8e3fce3
commit 1fb1c9e81a
10 changed files with 42 additions and 54 deletions

View File

@@ -24,7 +24,6 @@ import "./library/remove-game";
import "./library/remove-game-from-library";
import "./misc/open-external";
import "./misc/show-open-dialog";
import "./misc/image-path-to-base-64";
import "./torrenting/cancel-game-download";
import "./torrenting/pause-game-download";
import "./torrenting/resume-game-download";

View File

@@ -1,14 +0,0 @@
import mime from "mime";
import { registerEvent } from "../register-event";
import fs from "node:fs";
const imagePathToBase64 = async (
_event: Electron.IpcMainInvokeEvent,
filePath: string
) => {
const buffer = fs.readFileSync(filePath);
const mimeType = mime.getType(filePath);
return `data:${mimeType};base64,${buffer.toString("base64")}`;
};
registerEvent("imagePathToBase64", imagePathToBase64);

View File

@@ -2,6 +2,7 @@ import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services/hydra-api";
import axios from "axios";
import fs from "node:fs";
import path from "node:path";
import mime from "mime";
import { UserProfile } from "@types";
@@ -26,6 +27,8 @@ const updateProfile = async (
displayName: string,
newProfileImagePath: string | null
): Promise<UserProfile> => {
console.log(newProfileImagePath);
if (!newProfileImagePath) {
return (await patchUserProfile(displayName)).data;
}
@@ -35,7 +38,7 @@ const updateProfile = async (
const fileSizeInBytes = stats.size;
const profileImageUrl = await HydraApi.post(`/presigned-urls/profile-image`, {
imageExt: newProfileImagePath.split(".").at(-1),
imageExt: path.extname(newProfileImagePath).slice(1),
imageLength: fileSizeInBytes,
})
.then(async (preSignedResponse) => {

View File

@@ -2,6 +2,7 @@ import { app, BrowserWindow, net, protocol } from "electron";
import updater from "electron-updater";
import i18n from "i18next";
import path from "node:path";
import url from "node:url";
import { electronApp, optimizer } from "@electron-toolkit/utils";
import { DownloadManager, logger, WindowManager } from "@main/services";
import { dataSource } from "@main/data-source";
@@ -51,9 +52,10 @@ if (process.defaultApp) {
app.whenReady().then(async () => {
electronApp.setAppUserModelId("site.hydralauncher.hydra");
protocol.handle("hydra", (request) =>
net.fetch("file://" + request.url.slice("hydra://".length))
);
protocol.handle("local", (request) => {
const filePath = request.url.slice("local://".length);
return net.fetch(url.pathToFileURL(filePath).toString());
});
await dataSource.initialize();
await dataSource.runMigrations();