feat: cleanup

This commit is contained in:
2025-08-31 11:48:02 +07:00
parent 4fc2fe6176
commit f7250ff365

View File

@@ -23,11 +23,11 @@ export default {
} }
// Collect client request information // Collect client request information
const clientIP = request.headers.get('CF-Connecting-IP') || const clientIP = request.headers.get('CF-Connecting-IP') ||
request.headers.get('X-Forwarded-For') || request.headers.get('X-Forwarded-For') ||
request.headers.get('X-Real-IP') || request.headers.get('X-Real-IP') ||
'Unknown'; 'Unknown';
const userAgent = request.headers.get('User-Agent') || 'Unknown'; const userAgent = request.headers.get('User-Agent') || 'Unknown';
const country = request.cf?.country || 'Unknown'; const country = request.cf?.country || 'Unknown';
const city = request.cf?.city || 'Unknown'; const city = request.cf?.city || 'Unknown';
@@ -40,25 +40,23 @@ export default {
// Format the message with request information // Format the message with request information
const hasCoordinates = latitude !== 'Unknown' && longitude !== 'Unknown'; const hasCoordinates = latitude !== 'Unknown' && longitude !== 'Unknown';
const mapLink = hasCoordinates const mapLink = hasCoordinates
? `https://www.google.com/maps?q=${latitude},${longitude}` ? `https://www.google.com/maps?q=${latitude},${longitude}`
: null; : null;
const requestInfo = `URL: ${url} const requestInfo = `<b>IP</b>: <code>${clientIP}</code>
IP: ${clientIP} <b>Browser</b>: <code>${userAgent}</code>
Browser: ${userAgent} <b>Country</b>: <code>${country}</code>
Country: ${country} <b>Region</b>: <code>${region}</code>
Region: ${region} <b>City</b>: <code>${city}</code>
City: ${city} <b>Coordinates</b>: <code>${latitude}, ${longitude}</code>${mapLink ? ` <a href="${mapLink}">📍</a>` : ''}
Coordinates: ${latitude}, ${longitude} <b>Timezone</b>: <code>${timezone}</code>
Timezone: ${timezone} <b>Timestamp</b>: <code>${timestamp}</code>
Timestamp: ${timestamp} <b>Original text</b>:`;
Original text:`;
const formattedMessage = `<code> const formattedMessage = `${requestInfo}
${requestInfo}
</code> ${text}`;
${mapLink ? `<a href="${mapLink}">📍 View Location on Map</a>\n\n` : ''}${text}`;
const telegramToken = env.TELEGRAM_TOKEN; const telegramToken = env.TELEGRAM_TOKEN;
const telegramChatId = env.TELEGRAM_CHAT_ID; const telegramChatId = env.TELEGRAM_CHAT_ID;
@@ -87,7 +85,7 @@ ${mapLink ? `<a href="${mapLink}">📍 View Location on Map</a>\n\n` : ''}${text
if (!telegramResponse.ok) { if (!telegramResponse.ok) {
return new Response(JSON.stringify({ return new Response(JSON.stringify({
success: false success: false
}), { }), {
status: 500, status: 500,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}); });
@@ -102,7 +100,7 @@ ${mapLink ? `<a href="${mapLink}">📍 View Location on Map</a>\n\n` : ''}${text
} catch (error) { } catch (error) {
return new Response(JSON.stringify({ return new Response(JSON.stringify({
success: false success: false
}), { }), {
status: 500, status: 500,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}); });