mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-20 09:43:57 +00:00
40 lines
1022 B
TypeScript
40 lines
1022 B
TypeScript
import axios from "axios";
|
|
import { JSDOM } from "jsdom";
|
|
import UserAgent from "user-agents";
|
|
import path from "node:path";
|
|
|
|
export const getFileBuffer = async (url: string) =>
|
|
fetch(url, { method: "GET" }).then((response) =>
|
|
response.arrayBuffer().then((buffer) => Buffer.from(buffer))
|
|
);
|
|
|
|
export const sleep = (ms: number) =>
|
|
new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
export const requestWebPage = async (url: string) => {
|
|
const userAgent = new UserAgent();
|
|
|
|
const data = await axios
|
|
.get(url, {
|
|
headers: {
|
|
"User-Agent": userAgent.toString(),
|
|
},
|
|
})
|
|
.then((response) => response.data);
|
|
|
|
const { window } = new JSDOM(data);
|
|
return window.document;
|
|
};
|
|
|
|
export const isPortableVersion = () => {
|
|
return !!process.env.PORTABLE_EXECUTABLE_FILE;
|
|
};
|
|
|
|
export const normalizePath = (str: string) =>
|
|
path.posix.normalize(str).replace(/\\/g, "/");
|
|
|
|
export const addTrailingSlash = (str: string) =>
|
|
str.endsWith("/") ? str : `${str}/`;
|
|
|
|
export * from "./reg-parser";
|