Move requesting logic to shared lib

This commit is contained in:
Ajay
2023-02-14 01:20:46 -05:00
parent 5ecb809c73
commit 8c994f362d
7 changed files with 20 additions and 111 deletions

View File

@@ -49,19 +49,6 @@ function indexesOf<T>(array: T[], value: T): number[] {
return array.map((v, i) => v === value ? i : -1).filter(i => i !== -1);
}
function objectToURI<T>(url: string, data: T, includeQuestionMark: boolean): string {
let counter = 0;
for (const key in data) {
const seperator = (url.includes("?") || counter > 0) ? "&" : (includeQuestionMark ? "?" : "");
const value = (typeof(data[key]) === "string") ? data[key] as unknown as string : JSON.stringify(data[key]);
url += seperator + encodeURIComponent(key) + "=" + encodeURIComponent(value);
counter++;
}
return url;
}
function generateUserID(length = 36): string {
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
@@ -84,6 +71,5 @@ export const GenericUtils = {
getErrorMessage,
getLuminance,
generateUserID,
indexesOf,
objectToURI
indexesOf
}

View File

@@ -1,8 +1,8 @@
import { objectToURI } from "@ajayyy/maze-utils";
import Config from "../config";
import GenericNotice, { NoticeOptions } from "../render/GenericNotice";
import { ContentContainer } from "../types";
import Utils from "../utils";
import { GenericUtils } from "./genericUtils";
const utils = new Utils();
export interface ChatConfig {
@@ -62,5 +62,5 @@ export async function openWarningDialog(contentContainer: ContentContainer): Pro
}
export function openChat(config: ChatConfig): void {
window.open("https://chat.sponsor.ajay.app/#" + GenericUtils.objectToURI("", config, false));
window.open("https://chat.sponsor.ajay.app/#" + objectToURI("", config, false));
}