From 9016b8647ff3f115db0f0446dbb3297e129a7a15 Mon Sep 17 00:00:00 2001 From: Roj Date: Wed, 20 Mar 2024 01:26:35 +0300 Subject: [PATCH] [String Session Generator] Make it possible to choose a library directly with location hash --- islands/SessionStringGenerator.tsx | 106 +++++++++++++++++++++-------- lib/hash_signal.ts | 15 ++++ 2 files changed, 92 insertions(+), 29 deletions(-) create mode 100644 lib/hash_signal.ts diff --git a/islands/SessionStringGenerator.tsx b/islands/SessionStringGenerator.tsx index 6b63aa3..aa9666b 100644 --- a/islands/SessionStringGenerator.tsx +++ b/islands/SessionStringGenerator.tsx @@ -16,7 +16,11 @@ import { import { UNREACHABLE } from "mtkruto/1_utilities.ts"; import { Spinner2 } from "../components/icons/Spinner.tsx"; import { storedString } from "../lib/stored_signals.tsx"; +import { Router } from "../components/Router.tsx"; +import { getHashSignal } from "../lib/hash_signal.ts"; +import { IS_BROWSER } from "$fresh/runtime.ts"; +const hash = getHashSignal(); const sessionString = signal(""); const loading = signal(false); @@ -25,15 +29,50 @@ const apiHash = storedString("", "string-session-generator_apiHash"); const environment = signal<"Production" | "Test">("Production"); const accountType = signal<"Bot" | "User">("Bot"); const account = signal(""); -const library = signal< - | "Telethon" - | "Pyrogram" - | "GramJS" - | "mtcute" - | "MTKruto" ->("Telethon"); // TODO: url-based +const validLibraries = [ + "telethon", + "pyrogram", + "gramjs", + "mtcute", + "mtkruto", +] as const; +type ValidLibrary = (typeof validLibraries)[number]; +function isValidLibrary(string: string): string is ValidLibrary { + return validLibraries.includes(string as unknown as ValidLibrary); +} + +const libraries = [ + { + name: "Telethon", + link: ["telethon.dev", "https://telethon.dev"], + }, + { + name: "Pyrogram", + link: ["pyrogram.org", "https://pyrogram.org"], + }, + { + name: "GramJS", + link: ["gram.js.org", "https://gram.js.org"], + }, + { + name: "mtcute", + link: ["mtcute.dev", "https://mtcute.dev"], + }, + { + name: "MTKruto", + link: ["mtkru.to", "https://mtkru.to"], + }, +]; export function SessionStringGenerator() { + if (!IS_BROWSER) { + return null; + } + const library = hash.value.toLowerCase().slice(1); + if (!isValidLibrary(library)) { + return ; + } + if (loading.value) { return (
@@ -104,21 +143,6 @@ export function SessionStringGenerator() { onChange={(e) => apiHash.value = e.currentTarget.value} /> -