diff --git a/public/index.html b/public/index.html index fa97458..873bc93 100644 --- a/public/index.html +++ b/public/index.html @@ -139,8 +139,12 @@ diff --git a/server.js b/server.js index 39a1f83..d362693 100644 --- a/server.js +++ b/server.js @@ -566,9 +566,11 @@ app.get('/api/videos', async (req, res) => { const safeBucket = bucket.replace(/[^a-z0-9]/gi, '_'); const safeKeySegments = key.split('/').map(segment => segment.replace(/[^a-z0-9]/gi, '_')); const hlsDir = path.join(CACHE_DIR, `hls-${safeBucket}-${safeKeySegments.join('-')}`); + const tmpInputPath = path.join(CACHE_DIR, `s3-input-${safeBucket}-${safeKeySegments.join('-')}.tmp`); return { key: key, - hasTranscodeCache: fs.existsSync(hlsDir) + hasTranscodeCache: fs.existsSync(hlsDir), + hasDownloadCache: fs.existsSync(tmpInputPath) }; }); @@ -639,6 +641,26 @@ app.post('/api/clear-video-transcode-cache', async (req, res) => { } }); +app.post('/api/clear-video-download-cache', async (req, res) => { + try { + const { bucket, key } = req.body; + if (!bucket || !key) { + return res.status(400).json({ error: 'Bucket and key are required' }); + } + const safeBucket = bucket.replace(/[^a-z0-9]/gi, '_'); + const safeKeySegments = key.split('/').map(segment => segment.replace(/[^a-z0-9]/gi, '_')); + const tmpInputPath = path.join(CACHE_DIR, `s3-input-${safeBucket}-${safeKeySegments.join('-')}.tmp`); + + if (fs.existsSync(tmpInputPath)) { + fs.rmSync(tmpInputPath, { force: true }); + } + res.json({ message: 'Download cache cleared for video' }); + } catch (error) { + console.error('Error clearing video download cache:', error); + res.status(500).json({ error: 'Failed to clear download cache', detail: error.message }); + } +}); + app.post('/api/stop-transcode', (req, res) => { try { const { key } = req.body;