safari fix

This commit is contained in:
Andrey Kondratev
2025-08-29 18:05:35 +05:00
parent a08fd5b495
commit 8e3c927cf1
5 changed files with 110 additions and 218 deletions

View File

@@ -19,6 +19,17 @@ const soundcloud = new SoundCloudService();
// Middleware
app.use(express.json());
// Cache-busting middleware for iOS Safari
app.use('/dist/*.js', (req: Request, res: Response, next) => {
res.set({
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
'Pragma': 'no-cache',
'Expires': '0'
});
next();
});
app.use(express.static('public'));
// Ensure downloads directory exists
@@ -29,7 +40,21 @@ if (!fs.existsSync(downloadsDir)) {
// Routes
app.get('/', (req: Request, res: Response) => {
res.sendFile(path.join(__dirname, '../public/index.html'));
// Read and modify index.html to add timestamp for iOS cache busting
const indexPath = path.join(__dirname, '../public/index.html');
let html = fs.readFileSync(indexPath, 'utf8');
// Add timestamp to script URL for cache busting
const timestamp = Date.now();
html = html.replace('dist/script.js?v=2', `dist/script.js?v=${timestamp}`);
res.set({
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0'
});
res.send(html);
});
// Search videos
@@ -189,35 +214,32 @@ app.post('/api/convert', async (req: Request, res: Response) => {
}
});
// Direct Telegram API for sending audio when WebApp fails
// Direct Telegram API for sending audio
app.post('/api/telegram-send', async (req: Request, res: Response) => {
console.log('🚀 Telegram send request received');
try {
const { userId, audioUrl, title }: { userId?: string; audioUrl?: string; title?: string } = req.body;
console.log('🔄 Direct Telegram send request:', { userId, audioUrl, title });
console.log(`📤 Sending to user ${userId}: ${title}`);
if (!userId || !audioUrl || !title) {
return res.status(400).json({ error: 'Missing required fields' });
}
// Get bot instance
const botInstance = (global as any).quixoticBot;
if (!botInstance) {
console.log('❌ No bot instance available');
console.log('❌ Bot not available');
return res.status(500).json({ error: 'Bot not available' });
}
console.log('🤖 Using bot instance for direct send');
// Use userId as chatId for private chats (this is how Telegram works)
const chatId = parseInt(userId);
console.log(`📤 Sending audio to chat ${chatId}`);
await botInstance.sendAudioFile(chatId, audioUrl, title);
console.log('✅ Audio sent successfully via direct API');
console.log('✅ Audio sent successfully');
res.json({ success: true, message: 'Audio sent successfully' });
} catch (error: any) {
console.error('❌ Direct send error:', error.message);
console.error('❌ Send failed:', error.message);
res.status(500).json({ error: error.message });
}
});