添加清空缓存按钮

This commit is contained in:
CN-JS-HuiBai
2026-04-02 19:14:04 +08:00
parent 5192a3b23f
commit 25dcf22b78
3 changed files with 71 additions and 2 deletions

View File

@@ -113,6 +113,20 @@ wss.on('connection', (ws) => {
ws.on('close', () => removeWsClient(ws));
});
const clearMp4Cache = () => {
const mp4Dir = path.join(__dirname, 'public', 'mp4');
if (!fs.existsSync(mp4Dir)) return;
try {
fs.rmSync(mp4Dir, { recursive: true, force: true });
} catch (err) {
if (typeof fs.rmdirSync === 'function') {
fs.rmdirSync(mp4Dir, { recursive: true });
} else {
throw err;
}
}
};
// Endpoint to list videos in the bucket
app.get('/api/videos', async (req, res) => {
try {
@@ -154,6 +168,17 @@ app.get('/api/videos', async (req, res) => {
}
});
app.post('/api/reset-cache', (req, res) => {
try {
clearMp4Cache();
Object.keys(progressMap).forEach((key) => delete progressMap[key]);
res.json({ message: 'Cache reset' });
} catch (error) {
console.error('Error resetting cache:', error);
res.status(500).json({ error: 'Failed to reset cache', detail: error.message });
}
});
// Endpoint to transcode S3 video streaming to MP4
app.post('/api/transcode', async (req, res) => {
const { key, codec, encoder } = req.body;