mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-26 20:31:03 +00:00
feat: adding local file protocol
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user