/** * ======================================================== * Name: Linkvertise Resolver & Metadata Scraper * * Cara Download: * curl -sL "https://code.vamxapi.my.id/snippet/raw/linkvertise" -o linkvertise.js * * Cara Eksekusi: * node linkvertise.js "https://direct-link.net/7075573/6GDiMfTXagIO" * node linkvertise.js "https://linkvertise.com/7075573/6GDiMfTXagIO" * * Author: Vamz Spectre * Source: https://vamxapi.my.id * ======================================================== */ /** * Resolver Linkvertise Engine via Official GraphQL Endpoint * Mendukung linkvertise.com, direct-link.net, link-to.net, link-target.net, dll. */ async function linkvertise(inputUrl) { if (!inputUrl) throw new Error("URL Linkvertise wajib disertakan!"); let resolvedUrl = inputUrl.trim(); // 1. Resolve redirect untuk domain alias (direct-link.net, link-to.net, dll) try { const headRes = await fetch(resolvedUrl, { method: "GET", headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" }, redirect: "manual" }); const loc = headRes.headers.get("location"); if (loc) { resolvedUrl = new URL(loc, resolvedUrl).href; } } catch {} // 2. Parse userId dan hash/slug const parsed = new URL(resolvedUrl); const parts = parsed.pathname.split("/").filter(Boolean); const userId = parts[0] === "access" ? parts[1] : parts[0]; const slug = parts[0] === "access" ? parts[2] : parts[1]; if (!userId || !slug) { throw new Error("Format URL Linkvertise tidak valid (harus mengandung user_id dan slug)"); } // 3. Query Linkvertise GraphQL API const query = ` query getLink($input: PublicLinkIdentificationInput!) { linkByIdentifier(linkIdentificationInput: $input) { id url target_host target_type title is_premium_only view_count description href publisher { id name } } getContent(input: $input) { ... on DetailPageTargetData { type url paste } ... on ContentAccessTaskSet { __typename tasks { id status __typename } } } } `; const gqlRes = await fetch("https://publisher.linkvertise.com/graphql", { method: "POST", headers: { "Content-Type": "application/json", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "Origin": "https://linkvertise.com", "Referer": "https://linkvertise.com/" }, body: JSON.stringify({ query, variables: { input: { userIdAndUrl: { user_id: String(userId), url: String(slug) } } } }) }); if (!gqlRes.ok) { throw new Error(`GraphQL request gagal: HTTP ${gqlRes.status}`); } const json = await gqlRes.json(); const linkData = json.data?.linkByIdentifier; if (!linkData) { const errMsg = json.errors?.[0]?.message || "Linkvertise link tidak ditemukan atau sudah dihapus"; throw new Error(errMsg); } const contentData = json.data?.getContent; let targetUrl = contentData?.url || null; let pasteContent = contentData?.paste || null; if (!targetUrl && linkData.target_host) { targetUrl = linkData.target_host.startsWith("http") ? linkData.target_host : `https://${linkData.target_host}`; } return { success: true, input_url: inputUrl, resolved_url: resolvedUrl, title: linkData.title, target_host: linkData.target_host, destination: targetUrl, paste_content: pasteContent, target_type: linkData.target_type, is_premium_only: Boolean(linkData.is_premium_only), view_count: linkData.view_count, publisher: linkData.publisher }; } /** * CLI Runner: * Langsung eksekusi jika dijalankan via terminal: node linkvertise.js "link" */ const argUrl = process.argv[2]; if (argUrl) { linkvertise(argUrl) .then(result => { console.log(JSON.stringify(result, null, 2)); }) .catch(err => { console.error(JSON.stringify({ success: false, error: err.message }, null, 2)); process.exit(1); }); } else if (process.argv[1] && process.argv.length <= 2) { console.log("Usage: node linkvertise.js \"\""); } if (typeof module !== "undefined" && module.exports) { module.exports = { linkvertise, default: linkvertise }; }