/** * ======================================================== * Name: HyperHost sURL - Link Shortener & Unshortener (CLI & Module) * * Cara Download: * curl -sL "https://code.vamxapi.my.id/snippet/raw/hyperhost-surli" -o hyperhost-surli.js * * Cara Eksekusi: * node hyperhost-surli.js short "https://google.com" * node hyperhost-surli.js unshort "https://surl.li/kjaesz" * * Author: Vamz Spectre * Source: https://vamxapi.my.id * ======================================================== */ const BASE_URL = "https://hyperhost.ua/tools"; const DEFAULT_HEADERS = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", "Accept-Language": "en-US,en;q=0.9" }; /** * Dapatkan CSRF Token & Session Cookies dari HyperHost */ async function getSession(refererPath = "/en/surli") { const tokenRes = await fetch(`${BASE_URL}/csrf-token`, { headers: { ...DEFAULT_HEADERS, "Referer": `${BASE_URL}${refererPath}` } }); if (!tokenRes.ok) { throw new Error(`Gagal mengambil token sesi: HTTP ${tokenRes.status}`); } const cookies = tokenRes.headers.getSetCookie ? tokenRes.headers.getSetCookie().map(c => c.split(";")[0]).join("; ") : (tokenRes.headers.get("set-cookie") || ""); const { csrf_token } = await tokenRes.json(); if (!csrf_token) throw new Error("Gagal mengekstrak CSRF token dari server"); return { csrf_token, cookies }; } /** * 1. Shorten URL (Membuat link pendek surl.li) */ async function shorten(longUrl) { if (!longUrl) throw new Error("URL tujuan wajib diisi!"); const { csrf_token, cookies } = await getSession("/en/surli"); const res = await fetch(`${BASE_URL}/pushData`, { method: "POST", headers: { ...DEFAULT_HEADERS, "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-CSRF-TOKEN": csrf_token, "X-Requested-With": "XMLHttpRequest", "Cookie": cookies, "Referer": `${BASE_URL}/en/surli` }, body: new URLSearchParams({ "data[url]": longUrl }) }); if (!res.ok) { throw new Error(`Gagal memendekkan URL: HTTP ${res.status}`); } const data = await res.json(); if (!data.result || !data.short_url) { throw new Error(data.message || "Gagal membuat shortlink surl.li"); } return { success: true, action: "shorten", originalUrl: longUrl, shortUrl: data.short_url }; } /** * 2. Unshorten URL (Membongkar link pendek) */ async function unshorten(shortUrl) { if (!shortUrl) throw new Error("URL shortlink wajib diisi!"); const { csrf_token, cookies } = await getSession("/en/unshort-link"); const res = await fetch(`${BASE_URL}/unshortData`, { method: "POST", headers: { ...DEFAULT_HEADERS, "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-CSRF-TOKEN": csrf_token, "X-Requested-With": "XMLHttpRequest", "Cookie": cookies, "Referer": `${BASE_URL}/en/unshort-link` }, body: new URLSearchParams({ "data[url]": shortUrl }) }); if (!res.ok) { throw new Error(`Gagal membongkar link: HTTP ${res.status}`); } const data = await res.json(); if (data.errors) { throw new Error(JSON.stringify(data.errors)); } return { success: true, action: "unshorten", shortUrl: data.shortUrl || shortUrl, destinationUrl: data.greatUrl, redirects: data.countRedirects || 1, isSafe: data.isSaveUrl ?? true, previewImage: data.previewIMG || null }; } /** * Universal Dispatcher */ async function surli(command, ...rest) { const clean = (command || "").trim(); if (!clean) throw new Error("Parameter input (short/unshort atau URL) wajib disertakan!"); const lower = clean.toLowerCase(); if (lower === "short" || lower === "shorten") { const targetUrl = rest.join(" ").trim(); if (!targetUrl) throw new Error("URL yang ingin dipendekkan wajib disertakan!"); return await shorten(targetUrl); } if (lower === "unshort" || lower === "unshorten" || lower === "expand") { const targetUrl = rest.join(" ").trim(); if (!targetUrl) throw new Error("URL yang ingin dibongkar wajib disertakan!"); return await unshorten(targetUrl); } // Deteksi otomatis jika input langsung berupa URL: const isShortDomain = /^(https?:\/\/)?(surl\.li|bit\.ly|tinyurl\.com|t\.co|cutt\.ly|is\.gd|rb\.gy)/i.test(clean); if (isShortDomain) { return await unshorten(clean); } if (clean.startsWith("http://") || clean.startsWith("https://")) { return await shorten(clean); } throw new Error(`Perintah tidak dikenali: "${command}". Gunakan "short" atau "unshort".`); } // CommonJS safe export if (typeof module !== "undefined" && module.exports) { module.exports = { surli, shorten, short: shorten, unshorten, unshort: unshorten, default: surli }; } /** * CLI Runner: * node hyperhost-surli.js short "https://google.com" * node hyperhost-surli.js unshort "https://surl.li/kjaesz" */ const cliArgs = process.argv.slice(2); const mainCommand = cliArgs[0] ? cliArgs[0].trim() : null; async function runCli() { if (!mainCommand) { console.log( JSON.stringify( { success: false, message: "Sub-command belum ditentukan.", usage: { short: "node hyperhost-surli.js short ", unshort: "node hyperhost-surli.js unshort " }, examples: [ "node hyperhost-surli.js short \"https://google.com\"", "node hyperhost-surli.js unshort \"https://surl.li/kjaesz\"" ] }, null, 2 ) ); process.exit(1); } const res = await surli(mainCommand, ...cliArgs.slice(1)); console.log(JSON.stringify(res, null, 2)); } if (process.argv[1]) { runCli().catch((err) => { console.error(JSON.stringify({ success: false, error: err.message }, null, 2)); process.exit(1); }); }