Spaces:
Paused
Paused
Update app.py
Browse files88 unmodified lines8990919293944 unmodified lines991001011021031044 unmodified lines10911011111211311411551 unmodified lines1671681691701711722 unmodified lines17517617717817918018118218318418569 unmodified lines25525625725825926026188 unmodified lines</div><script>let phone = '';async function startLogin() {phone = document.getElementById('phone').value;const response = await fetch('/login', {4 unmodified linesconst result = await response.json();alert(result.message);if (result.success) {document.getElementById('code').style.display = 'inline';document.getElementById('submitCode').style.display = 'inline';}4 unmodified linesconst response = await fetch('/login', {method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ phone, code, step: 'code' })});const result = await response.json();alert(result.message);51 unmodified linesphone = data.get('phone')code = data.get('code')password = data.get('password')step = data.get('step')session_file = f"{SESSION_DIR}/{hashlib.md5(phone.encode()).hexdigest()}.session"2 unmodified linestry:if step == 'start':await client.connect()await client.send_code_request(phone)return {'success': True, 'message': 'Code sent to your Telegram'}elif step == 'code':await client.connect()me = await client.sign_in(phone, code)with sqlite3.connect(DB_PATH) as conn:c = conn.cursor()c.execute('INSERT OR REPLACE INTO users (telegram_id, username, phone, session_file) VALUES (?, ?, ?, ?)',69 unmodified linesasync for message in client.iter_messages(dialog, limit=10):if message.media:file_path = await client.download_media(message, DOWNLOAD_DIR)if file_path: # Ensure file was actually downloadedfiles.append({'chat': dialog.title, 'file': Path(file_path).name})finally:if client.is_connected():88 unmodified lines89909192939495964 unmodified lines1011021031041051061074 unmodified lines11211311411511611711811951 unmodified lines1711721731741751761772 unmodified lines18018118218318418518618718818919019119219319469 unmodified lines26426526626726826927088 unmodified lines</div><script>let phone = '';let phoneCodeHash = ''; // Added to store phone_code_hashasync function startLogin() {phone = document.getElementById('phone').value;const response = await fetch('/login', {4 unmodified linesconst result = await response.json();alert(result.message);if (result.success) {phoneCodeHash = result.phone_code_hash; // Store the received hashdocument.getElementById('code').style.display = 'inline';document.getElementById('submitCode').style.display = 'inline';}4 unmodified linesconst response = await fetch('/login', {method: 'POST',headers: { 'Content-Type': 'application/json' },// Pass phone_code_hash herebody: JSON.stringify({ phone, code, phone_code_hash: phoneCodeHash, step: 'code' })});const result = await response.json();alert(result.message);51 unmodified linesphone = data.get('phone')code = data.get('code')password = data.get('password')phone_code_hash = data.get('phone_code_hash') # Get phone_code_hash from requeststep = data.get('step')session_file = f"{SESSION_DIR}/{hashlib.md5(phone.encode()).hexdigest()}.session"2 unmodified linestry:if step == 'start':await client.connect()sent_code = await client.send_code_request(phone)# Return phone_code_hash to the frontendreturn {'success': True, 'message': 'Code sent to your Telegram', 'phone_code_hash': sent_code.phone_code_hash}elif step == 'code':await client.connect()if not phone_code_hash:return {'success': False, 'message': 'phone_code_hash is missing for code step.'}# Pass phone_code_hash explicitlyme = await client.sign_in(phone, code, phone_code_hash=phone_code_hash)with sqlite3.connect(DB_PATH) as conn:c = conn.cursor()c.execute('INSERT OR REPLACE INTO users (telegram_id, username, phone, session_file) VALUES (?, ?, ?, ?)',69 unmodified linesasync for message in client.iter_messages(dialog, limit=10):if message.media:file_path = await client.download_media(message, DOWNLOAD_DIR)if file_path:files.append({'chat': dialog.title, 'file': Path(file_path).name})finally:if client.is_connected():
app.py+14-5