1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Scraper Alight Motion Premium Generator
* Creator : @wilz
* Sumber : https://whatsapp.com/channel/0029VbDzmSDGU3BEzv9qZA1U
*
* Instalasi:
* npm i axios
*
* CLI (Langkah 1 - Kirim Email):
* node scraper/amprem.js "[email protected]"
*
* CLI (Langkah 2 - Paste Link):
* node scraper/amprem.js "https://link-magic-dari-email..."
*/
const axios = require('axios');
const fs = require('fs');
const path = require('path');
// ─── Konfigurasi ────────────────────────────────────────────────
const API_URL = "https://anita-studio.netlify.app/.netlify/functions/amprem";
const TIMEOUT = 30000;
const STATE_FILE = path.join(process.cwd(), '.amprem_state.json');
const client = axios.create({
timeout: TIMEOUT,
headers: { 'Content-Type': 'application/json' }
});
// ─── Helper ─────────────────────────────────────────────────────
function isValidEmail(email) {
return /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email);
}
function saveState(email) {
fs.writeFileSync(STATE_FILE, JSON.stringify({ email }), 'utf-8');
}
function loadState() {
if (fs.existsSync(STATE_FILE)) {
return JSON.parse(fs.readFileSync(STATE_FILE, 'utf-8'));
}
return null;
}
function clearState() {
if (fs.existsSync(STATE_FILE)) fs.unlinkSync(STATE_FILE);
}
async function apiPost(action, payload) {
const res = await client.post(API_URL, { action, ...payload });
return res.data;
}
// ─── Step 1: Kirim Magic Link ───────────────────────────────────
async function step1SendLink(email) {
if (!isValidEmail(email)) throw new Error('Format email tidak valid.');
console.log(`[1/2] Mengirim magic link ke: ${email}`);
const res = await apiPost("send-magiclink", { email });
if (!res.success) throw new Error(res.message || "Gagal mengirim magic link");
saveState(email);
console.log('✅ Magic link berhasil dikirim!');
console.log('👉 Silakan cek inbox/spam email Anda, copy URL magic link-nya.');
console.log(`👉 Lalu jalankan: node scraper/amprem.js "URL_LINK"`);
}
// ─── Step 2: Verifikasi & Apply Premium ─────────────────────────
async function step2ApplyPremium(link) {
const state = loadState();
if (!state || !state.email) {
throw new Error('Sesi tidak ditemukan. Jalankan langkah pertama dulu: node scraper/amprem.js "email"');
}
const email = state.email;
console.log(`[1/2] Memverifikasi magic link untuk: ${email}`);
const resVerify = await apiPost("verify-account", { email, rawLink: link });
if (!resVerify.success) throw new Error(resVerify.message || "Gagal verifikasi akun");
const idToken = resVerify.idToken || (resVerify.profile || {}).idToken;
if (!idToken) throw new Error("idToken tidak ditemukan di respons.");
console.log(`[2/2] Mengaktifkan Alight Motion Premium...`);
const resPremium = await apiPost("apply-premium", { email, idToken });
if (!resPremium.success) throw new Error(resPremium.message || "Gagal mengaktifkan premium");
clearState(); // Hapus file state jika sukses
// Tampilkan hasil
const result = { ...resPremium };
delete result.success;
result.email = email;
console.log('\n✅ Alight Motion Premium Berhasil Diaktifkan!');
console.log(JSON.stringify(result, null, 2));
}
// ─── CLI Handler ────────────────────────────────────────────────
if (require.main === module) {
const input = process.argv[2];
if (!input) {
console.error(
'❌ Kesalahan: Parameter tidak ditemukan!\n\n' +
'Cara Penggunaan:\n' +
' Langkah 1: node scraper/amprem.js "<email>"\n' +
' Langkah 2: node scraper/amprem.js "<url_magic_link>"'
);
process.exit(1);
}
(async () => {
try {
if (input.startsWith('http')) {
// Jika input berupa URL, jalankan Step 2
await step2ApplyPremium(input);
} else {
// Jika input berupa Email, jalankan Step 1
await step1SendLink(input);
}
} catch (err) {
console.error(`\n❌ Error: ${err.message}`);
process.exit(1);
}
})();
}
module.exports = { step1SendLink, step2ApplyPremium };