feat: cleanup

This commit is contained in:
2025-08-31 11:42:23 +07:00
parent 6114b366c2
commit 4fc2fe6176

View File

@@ -39,9 +39,10 @@ export default {
const timestamp = new Date().toISOString(); const timestamp = new Date().toISOString();
// Format the message with request information // Format the message with request information
const mapLink = (latitude !== 'Unknown' && longitude !== 'Unknown') const hasCoordinates = latitude !== 'Unknown' && longitude !== 'Unknown';
const mapLink = hasCoordinates
? `https://www.google.com/maps?q=${latitude},${longitude}` ? `https://www.google.com/maps?q=${latitude},${longitude}`
: 'Unknown'; : null;
const requestInfo = `URL: ${url} const requestInfo = `URL: ${url}
IP: ${clientIP} IP: ${clientIP}
@@ -49,7 +50,7 @@ Browser: ${userAgent}
Country: ${country} Country: ${country}
Region: ${region} Region: ${region}
City: ${city} City: ${city}
Coordinates: ${latitude}, ${longitude} (${mapLink}) Coordinates: ${latitude}, ${longitude}
Timezone: ${timezone} Timezone: ${timezone}
Timestamp: ${timestamp} Timestamp: ${timestamp}
Original text:`; Original text:`;
@@ -57,7 +58,7 @@ Original text:`;
const formattedMessage = `<code> const formattedMessage = `<code>
${requestInfo} ${requestInfo}
</code> </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;
@@ -85,9 +86,7 @@ ${text}`;
if (!telegramResponse.ok) { if (!telegramResponse.ok) {
return new Response(JSON.stringify({ return new Response(JSON.stringify({
success: false, success: false
error: 'Telegram API error',
details: telegramResult
}), { }), {
status: 500, status: 500,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
@@ -95,18 +94,14 @@ ${text}`;
} }
return new Response(JSON.stringify({ return new Response(JSON.stringify({
success: true, success: true
message: 'Message sent successfully',
telegram_response: telegramResult
}), { }), {
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}); });
} catch (error) { } catch (error) {
return new Response(JSON.stringify({ return new Response(JSON.stringify({
success: false, success: false
error: 'Internal server error',
details: error.message
}), { }), {
status: 500, status: 500,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }